glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, const char *name) : gl_type(0), base_type(GLSL_TYPE_STRUCT), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), sampler_type(0), interface_packing(0), vector_elements(0), matrix_columns(0), length(num_fields) { unsigned int i; init_ralloc_type_ctx(); assert(name != NULL); this->name = ralloc_strdup(this->mem_ctx, name); this->fields.structure = ralloc_array(this->mem_ctx, glsl_struct_field, length); for (i = 0; i < length; i++) { this->fields.structure[i].type = fields[i].type; this->fields.structure[i].name = ralloc_strdup(this->fields.structure, fields[i].name); this->fields.structure[i].precision = fields[i].precision; this->fields.structure[i].location = fields[i].location; this->fields.structure[i].interpolation = fields[i].interpolation; this->fields.structure[i].centroid = fields[i].centroid; this->fields.structure[i].sample = fields[i].sample; this->fields.structure[i].matrix_layout = fields[i].matrix_layout; } }
void program_resource_visitor::process(ir_variable *var) { const glsl_type *t = var->type; /* false is always passed for the row_major parameter to the other * processing functions because no information is available to do * otherwise. See the warning in linker.h. */ /* Only strdup the name if we actually will need to modify it. */ if (t->is_record() || (t->is_array() && t->fields.array->is_record())) { char *name = ralloc_strdup(NULL, var->name); recursion(var->type, &name, strlen(name), false); ralloc_free(name); } else if (t->is_interface()) { char *name = ralloc_strdup(NULL, var->type->name); recursion(var->type, &name, strlen(name), false); ralloc_free(name); } else if (t->is_array() && t->fields.array->is_interface()) { char *name = ralloc_strdup(NULL, var->type->fields.array->name); recursion(var->type, &name, strlen(name), false); ralloc_free(name); } else { this->visit_field(t, var->name, false); } }
glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, const char *name) : base_type(GLSL_TYPE_STRUCT), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), sampler_ms(false), sampler_buffer(false), outputstream_type(GLSL_OUTPUTSTREAM_NONE), sample_count(1), inner_type(0), vector_elements(0), matrix_columns(0), HlslName(nullptr), length(num_fields), patch_length(0) { unsigned int i; init_ralloc_type_ctx(); this->name = ralloc_strdup(this->mem_ctx, name); this->fields.structure = ralloc_array(this->mem_ctx, glsl_struct_field, length); for (i = 0; i < length; i++) { this->fields.structure[i].type = fields[i].type; this->fields.structure[i].name = ralloc_strdup(this->mem_ctx, fields[i].name); this->fields.structure[i].semantic = ralloc_strdup(this->mem_ctx, fields[i].semantic); this->fields.structure[i].centroid = fields[i].centroid; this->fields.structure[i].interpolation = fields[i].interpolation; this->fields.structure[i].geometryinput = fields[i].geometryinput; this->fields.structure[i].patchconstant = fields[i].patchconstant; } }
ir_visitor_status ir_array_decomposer_visitor::visit(ir_variable *ir) { if(!basevar) basevar = ir; if(ir->type->is_array()) { unsigned array_count = ir->type->array_size(); void *ctx = ir; while(array_count-- > 0) { char nm[512]; sprintf(&nm[0], "%s_%d", ir->name, array_count); ir_variable *newvar = new (ctx) ir_variable(ir->type->element_type(), ralloc_strdup(ctx, &nm[0]), (ir_variable_mode)ir->mode, (glsl_precision)ir->precision); newvar->parent = ir; newvar->location = array_count; base_ir->insert_after(newvar); hash_table_insert(varhash, newvar, ralloc_strdup(ctx, &nm[0])); } } else if(ir->type->is_matrix()) { unsigned n = ir->type->matrix_columns; void *ctx = ir; while(n-- > 0) { char nm[512]; sprintf(&nm[0], "%s_%d", ir->name, n); ir_variable *newvar = new (ctx) ir_variable(glsl_type::vec4_type, ralloc_strdup(ctx, &nm[0]), (ir_variable_mode)ir->mode, (glsl_precision)ir->precision); newvar->parent = ir; ir->child[n] = newvar; newvar->usedAsAMatrixComponent = true; newvar->location = n; base_ir->insert_after(newvar); hash_table_insert(varhash, newvar, ralloc_strdup(ctx, &nm[0])); } } return visit_continue; }
void ir_remap_agalvars_visitor::handleDeref(ir_variable **varloc) { ir_variable *glvar = *varloc; ir_variable *agalvar = (ir_variable*)hash_table_find(varhash, glvar->name); if(agalvar) { *varloc = agalvar; //fprintf(stderr, "remapping deref -- %s\n", glvar->name); } else if(glvar->name[0] == 'g' && glvar->name[1] == 'l' && glvar->name[2] == '_') { computeAgalName(glvar); agalvar = new (glvar) ir_variable(glvar->type, ralloc_strdup(glvar, &agalName[0]), (ir_variable_mode)glvar->mode, (glsl_precision)glvar->precision); hash_table_insert(varhash, agalvar, ralloc_strdup(agalvar, glvar->name)); hash_table_insert(varhash, agalvar, ralloc_strdup(agalvar, &agalName[0])); hash_table_insert(renamedvars, glvar, glvar); varbase->insert_before(agalvar); *varloc = agalvar; //fprintf(stderr, "renaming: %s -> %s\n", glvar->name, &agalName[0]); } else if (hash_table_find(renamedvars, glvar)) { // already renamed } else { computeAgalName(glvar); glvar->name = ralloc_strdup(glvar, agalName); hash_table_insert(renamedvars, glvar, glvar); } }
void glsl_type::add_structure_member(const glsl_struct_field* field) { check(this->is_record()); unsigned int i; glsl_struct_field* new_fields = ralloc_array(this->mem_ctx, glsl_struct_field, this->length + 1); for (i = 0; i < this->length; i++) { new_fields[i].type = this->fields.structure[i].type; new_fields[i].name = this->fields.structure[i].name; new_fields[i].semantic = this->fields.structure[i].semantic; new_fields[i].centroid = this->fields.structure[i].centroid; new_fields[i].interpolation = this->fields.structure[i].interpolation; new_fields[i].geometryinput = this->fields.structure[i].geometryinput; new_fields[i].patchconstant = this->fields.structure[i].patchconstant; } new_fields[i].type = field->type; new_fields[i].name = ralloc_strdup(new_fields, field->name); new_fields[i].semantic = ralloc_strdup(new_fields, field->semantic); new_fields[i].centroid = field->centroid; new_fields[i].interpolation = field->interpolation; new_fields[i].geometryinput = field->geometryinput; new_fields[i].patchconstant = field->patchconstant; this->fields.structure = new_fields; ++this->length; }
ShVariable* copyShVariableCtx(ShVariable *src, void* mem_ctx) { if (!src) return NULL; ShVariable* ret = (ShVariable*) rzalloc(mem_ctx, ShVariable); assert(ret || !"not enough memory to copy ShVariable"); ret->uniqueId = src->uniqueId; ret->builtin = src->builtin; if (src->name) ret->name = ralloc_strdup(ret, src->name); ret->type = src->type; ret->qualifier = src->qualifier; ret->size = src->size; ret->isMatrix = src->isMatrix; ret->matrixSize[0] = src->matrixSize[0]; ret->matrixSize[1] = src->matrixSize[1]; ret->isArray = src->isArray; for (int i = 0; i < MAX_ARRAYS; i++) ret->arraySize[i] = src->arraySize[i]; if (src->structName) ret->structName = ralloc_strdup(ret, src->structName); ret->structSize = src->structSize; if (ret->structSize) { ret->structSpec = (ShVariable**) rzalloc_array(ret, ShVariable*, ret->structSize); assert(ret->structSpec || !"not enough memory to copy structSpec of ShVariable"); for (int i = 0; i < ret->structSize; i++) ret->structSpec[i] = copyShVariableCtx(src->structSpec[i], ret->structSpec); }
static void build_color_shaders(struct nir_shader **out_vs, struct nir_shader **out_fs, uint32_t frag_output) { nir_builder vs_b; nir_builder fs_b; nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL); nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL); vs_b.shader->info.name = ralloc_strdup(vs_b.shader, "meta_clear_color_vs"); fs_b.shader->info.name = ralloc_strdup(fs_b.shader, "meta_clear_color_fs"); const struct glsl_type *position_type = glsl_vec4_type(); const struct glsl_type *color_type = glsl_vec4_type(); nir_variable *vs_in_pos = nir_variable_create(vs_b.shader, nir_var_shader_in, position_type, "a_position"); vs_in_pos->data.location = VERT_ATTRIB_GENERIC0; nir_variable *vs_out_pos = nir_variable_create(vs_b.shader, nir_var_shader_out, position_type, "gl_Position"); vs_out_pos->data.location = VARYING_SLOT_POS; nir_variable *vs_in_color = nir_variable_create(vs_b.shader, nir_var_shader_in, color_type, "a_color"); vs_in_color->data.location = VERT_ATTRIB_GENERIC1; nir_variable *vs_out_color = nir_variable_create(vs_b.shader, nir_var_shader_out, color_type, "v_color"); vs_out_color->data.location = VARYING_SLOT_VAR0; vs_out_color->data.interpolation = INTERP_MODE_FLAT; nir_variable *fs_in_color = nir_variable_create(fs_b.shader, nir_var_shader_in, color_type, "v_color"); fs_in_color->data.location = vs_out_color->data.location; fs_in_color->data.interpolation = vs_out_color->data.interpolation; nir_variable *fs_out_color = nir_variable_create(fs_b.shader, nir_var_shader_out, color_type, "f_color"); fs_out_color->data.location = FRAG_RESULT_DATA0 + frag_output; nir_copy_var(&vs_b, vs_out_pos, vs_in_pos); nir_copy_var(&vs_b, vs_out_color, vs_in_color); nir_copy_var(&fs_b, fs_out_color, fs_in_color); *out_vs = vs_b.shader; *out_fs = fs_b.shader; }
void glsl_type::replace_structure_member(int memberIndex, const glsl_struct_field* new_field) { this->fields.structure[memberIndex].type = new_field->type; this->fields.structure[memberIndex].name = ralloc_strdup(this->fields.structure, new_field->name); this->fields.structure[memberIndex].semantic = ralloc_strdup(this->fields.structure, new_field->semantic); this->fields.structure[memberIndex].centroid = new_field->centroid; this->fields.structure[memberIndex].interpolation = new_field->interpolation; this->fields.structure[memberIndex].geometryinput = new_field->geometryinput; this->fields.structure[memberIndex].patchconstant = new_field->patchconstant; }
static void build_color_shaders(struct nir_shader **out_vs, struct nir_shader **out_fs, uint32_t frag_output) { nir_builder vs_b; nir_builder fs_b; nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL); nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL); vs_b.shader->info.name = ralloc_strdup(vs_b.shader, "meta_clear_color_vs"); fs_b.shader->info.name = ralloc_strdup(fs_b.shader, "meta_clear_color_fs"); const struct glsl_type *position_type = glsl_vec4_type(); const struct glsl_type *color_type = glsl_vec4_type(); nir_variable *vs_out_pos = nir_variable_create(vs_b.shader, nir_var_shader_out, position_type, "gl_Position"); vs_out_pos->data.location = VARYING_SLOT_POS; nir_intrinsic_instr *in_color_load = nir_intrinsic_instr_create(fs_b.shader, nir_intrinsic_load_push_constant); nir_intrinsic_set_base(in_color_load, 0); nir_intrinsic_set_range(in_color_load, 16); in_color_load->src[0] = nir_src_for_ssa(nir_imm_int(&fs_b, 0)); in_color_load->num_components = 4; nir_ssa_dest_init(&in_color_load->instr, &in_color_load->dest, 4, 32, "clear color"); nir_builder_instr_insert(&fs_b, &in_color_load->instr); nir_variable *fs_out_color = nir_variable_create(fs_b.shader, nir_var_shader_out, color_type, "f_color"); fs_out_color->data.location = FRAG_RESULT_DATA0 + frag_output; nir_store_var(&fs_b, fs_out_color, &in_color_load->dest.ssa, 0xf); nir_ssa_def *outvec = radv_meta_gen_rect_vertices(&vs_b); nir_store_var(&vs_b, vs_out_pos, outvec, 0xf); const struct glsl_type *layer_type = glsl_int_type(); nir_variable *vs_out_layer = nir_variable_create(vs_b.shader, nir_var_shader_out, layer_type, "v_layer"); vs_out_layer->data.location = VARYING_SLOT_LAYER; vs_out_layer->data.interpolation = INTERP_MODE_FLAT; nir_ssa_def *inst_id = nir_load_system_value(&vs_b, nir_intrinsic_load_instance_id, 0); nir_ssa_def *base_instance = nir_load_system_value(&vs_b, nir_intrinsic_load_base_instance, 0); nir_ssa_def *layer_id = nir_iadd(&vs_b, inst_id, base_instance); nir_store_var(&vs_b, vs_out_layer, layer_id, 0x1); *out_vs = vs_b.shader; *out_fs = fs_b.shader; }
/** * Replace any declaration of gl_TessLevel* as an array of floats with a * declaration of gl_TessLevel*MESA as a vec4. */ ir_visitor_status lower_tess_level_visitor::visit(ir_variable *ir) { if ((!ir->name) || ((strcmp(ir->name, "gl_TessLevelInner") != 0) && (strcmp(ir->name, "gl_TessLevelOuter") != 0))) return visit_continue; assert (ir->type->is_array()); if (strcmp(ir->name, "gl_TessLevelOuter") == 0) { if (this->old_tess_level_outer_var) return visit_continue; old_tess_level_outer_var = ir; assert(ir->type->fields.array == glsl_type::float_type); /* Clone the old var so that we inherit all of its properties */ new_tess_level_outer_var = ir->clone(ralloc_parent(ir), NULL); /* And change the properties that we need to change */ new_tess_level_outer_var->name = ralloc_strdup(new_tess_level_outer_var, "gl_TessLevelOuterMESA"); new_tess_level_outer_var->type = glsl_type::vec4_type; new_tess_level_outer_var->data.max_array_access = 0; ir->replace_with(new_tess_level_outer_var); } else if (strcmp(ir->name, "gl_TessLevelInner") == 0) { if (this->old_tess_level_inner_var) return visit_continue; old_tess_level_inner_var = ir; assert(ir->type->fields.array == glsl_type::float_type); /* Clone the old var so that we inherit all of its properties */ new_tess_level_inner_var = ir->clone(ralloc_parent(ir), NULL); /* And change the properties that we need to change */ new_tess_level_inner_var->name = ralloc_strdup(new_tess_level_inner_var, "gl_TessLevelInnerMESA"); new_tess_level_inner_var->type = glsl_type::vec2_type; new_tess_level_inner_var->data.max_array_access = 0; ir->replace_with(new_tess_level_inner_var); } else { assert(0); } this->progress = true; return visit_continue; }
ir_visitor_status ir_unique_agalvars_visitor::visit(ir_variable *ir) { if(hash_table_find(varhash, ir->name)) { char nm[512]; sprintf(&nm[0], "%s_%d", ir->name, tmpcount++); //fprintf(stderr, "uniquing %s --> %s\n", ir->name, &nm[0]); ir->name = (char*)ralloc_strdup(ir, &nm[0]); } hash_table_insert(varhash, (void*)0x1, ralloc_strdup(ir, ir->name)); return visit_continue; }
virtual void visit_field(const glsl_type *type, const char *name, bool row_major, const glsl_type *record_type) { assert(this->index < this->num_variables); gl_uniform_buffer_variable *v = &this->variables[this->index++]; v->Name = ralloc_strdup(mem_ctx, name); v->Type = type; v->RowMajor = row_major; if (this->is_array_instance) { v->IndexName = ralloc_strdup(mem_ctx, name); char *open_bracket = strchr(v->IndexName, '['); assert(open_bracket != NULL); char *close_bracket = strchr(open_bracket, ']'); assert(close_bracket != NULL); /* Length of the tail without the ']' but with the NUL. */ unsigned len = strlen(close_bracket + 1) + 1; memmove(open_bracket, close_bracket + 1, len); } else { v->IndexName = v->Name; } const unsigned alignment = record_type ? record_type->std140_base_alignment(!!v->RowMajor) : type->std140_base_alignment(!!v->RowMajor); unsigned size = type->std140_size(!!v->RowMajor); this->offset = glsl_align(this->offset, alignment); v->Offset = this->offset; this->offset += size; /* From the GL_ARB_uniform_buffer_object spec: * * "For uniform blocks laid out according to [std140] rules, the * minimum buffer object size returned by the * UNIFORM_BLOCK_DATA_SIZE query is derived by taking the offset of * the last basic machine unit consumed by the last uniform of the * uniform block (including any end-of-array or end-of-structure * padding), adding one, and rounding up to the next multiple of * the base alignment required for a vec4." */ this->buffer_size = glsl_align(this->offset, 16); }
ir_rvalue* ir_array_decomposer_visitor::computeNewRValue(ir_rvalue *rval) { ir_dereference_array *da = rval->as_dereference_array(); if(da && (da->array->type->is_array() || da->array->type->is_matrix())) { ir_constant *ci = da->array_index->constant_expression_value(); if(!ci) { return NULL; } ir_variable *src = da->variable_referenced(); if(!src) { return NULL; } // make sure unsized arrays end up with a reasonable size if(src->max_array_access < ci->get_int_component(0)) { src->max_array_access = ci->get_int_component(0); //fprintf(stderr, "updating max access: %d\n", src->max_array_access); } void *ctx = ralloc_parent(base_ir); char nm[512] = {0}; sprintf(&nm[0], "%s_%d", src->name, ci->get_int_component(0)); ir_variable *v = (ir_variable*)hash_table_find(varhash, &nm[0]); if(!v) { v = new (ctx) ir_variable(src->type->element_type(), ralloc_strdup(ctx, &nm[0]), (ir_variable_mode)src->mode, (glsl_precision)src->precision); v->parent = src; v->location = ci->get_int_component(0); basevar->insert_before(v); hash_table_insert(varhash, v, ralloc_strdup(ctx, &nm[0])); } ir_dereference_variable *dv = new(ctx) ir_dereference_variable(v); int c = v->type->vector_elements; if(c == 4) { return dv; } char si[5] = "xyzw"; si[c] = 0; ir_swizzle *sz = ir_swizzle::create(dv, si, c); return sz; } return NULL; }
void _mesa_clear_shader_program_data(struct gl_shader_program *shProg) { unsigned i; shProg->NumUniformStorage = 0; shProg->UniformStorage = NULL; shProg->NumUniformRemapTable = 0; shProg->UniformRemapTable = NULL; shProg->UniformHash = NULL; ralloc_free(shProg->InfoLog); shProg->InfoLog = ralloc_strdup(shProg, ""); ralloc_free(shProg->BufferInterfaceBlocks); shProg->BufferInterfaceBlocks = NULL; shProg->NumBufferInterfaceBlocks = 0; ralloc_free(shProg->UniformBlocks); shProg->UniformBlocks = NULL; shProg->NumUniformBlocks = 0; ralloc_free(shProg->ShaderStorageBlocks); shProg->ShaderStorageBlocks = NULL; shProg->NumShaderStorageBlocks = 0; for (i = 0; i < MESA_SHADER_STAGES; i++) { ralloc_free(shProg->InterfaceBlockStageIndex[i]); shProg->InterfaceBlockStageIndex[i] = NULL; } ralloc_free(shProg->AtomicBuffers); shProg->AtomicBuffers = NULL; shProg->NumAtomicBuffers = 0; }
/** * Clear (free) the shader program state that gets produced by linking. */ void _mesa_clear_shader_program_data(struct gl_context *ctx, struct gl_shader_program *shProg) { if (shProg->UniformStorage) { unsigned i; for (i = 0; i < shProg->NumUserUniformStorage; ++i) _mesa_uniform_detach_all_driver_storage(&shProg->UniformStorage[i]); ralloc_free(shProg->UniformStorage); shProg->NumUserUniformStorage = 0; shProg->UniformStorage = NULL; } if (shProg->UniformRemapTable) { ralloc_free(shProg->UniformRemapTable); shProg->NumUniformRemapTable = 0; shProg->UniformRemapTable = NULL; } if (shProg->UniformHash) { string_to_uint_map_dtor(shProg->UniformHash); shProg->UniformHash = NULL; } assert(shProg->InfoLog != NULL); ralloc_free(shProg->InfoLog); shProg->InfoLog = ralloc_strdup(shProg, ""); }
int main (int argc, char *argv[]) { char *filename = NULL; void *ctx = ralloc(NULL, void*); char *info_log = ralloc_strdup(ctx, ""); const char *shader; int ret; if (argc) { filename = argv[1]; } shader = load_text_file (ctx, filename); if (shader == NULL) return 1; ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, API_OPENGL); printf("%s", shader); fprintf(stderr, "%s", info_log); ralloc_free(ctx); return ret; }
const glsl_type * glsl_type::get_array_instance(const glsl_type *base, unsigned array_size) { if (array_types == NULL) { array_types = hash_table_ctor(64, hash_table_string_hash, hash_table_string_compare); } /* Generate a name using the base type pointer in the key. This is * done because the name of the base type may not be unique across * shaders. For example, two shaders may have different record types * named 'foo'. */ char key[128]; snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size); const glsl_type *t = (glsl_type *) hash_table_find(array_types, key); if (t == NULL) { t = new glsl_type(base, array_size); hash_table_insert(array_types, (void *) t, ralloc_strdup(mem_ctx, key)); } assert(t->base_type == GLSL_TYPE_ARRAY); assert(t->length == array_size); assert(t->fields.array == base); return t; }
/* NOTE: for cloning nir_variables, bypass nir_variable_create to avoid * having to deal with locals and globals separately: */ nir_variable * nir_variable_clone(const nir_variable *var, nir_shader *shader) { nir_variable *nvar = rzalloc(shader, nir_variable); nvar->type = var->type; nvar->name = ralloc_strdup(nvar, var->name); nvar->data = var->data; nvar->num_state_slots = var->num_state_slots; nvar->state_slots = ralloc_array(nvar, nir_state_slot, var->num_state_slots); memcpy(nvar->state_slots, var->state_slots, var->num_state_slots * sizeof(nir_state_slot)); if (var->constant_initializer) { nvar->constant_initializer = nir_constant_clone(var->constant_initializer, nvar); } nvar->interface_type = var->interface_type; nvar->num_members = var->num_members; if (var->num_members) { nvar->members = ralloc_array(nvar, struct nir_variable_data, var->num_members); memcpy(nvar->members, var->members, var->num_members * sizeof(*var->members)); }
glsl_type::glsl_type(glsl_base_type base_type, unsigned vector_elements, unsigned matrix_columns, const char *name, const char* InHlslName) : base_type(base_type), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), sampler_ms(false), sampler_buffer(false), outputstream_type(GLSL_OUTPUTSTREAM_NONE), sample_count(1), inner_type(0), vector_elements(vector_elements), matrix_columns(matrix_columns), length(0), patch_length(0) { init_ralloc_type_ctx(); this->name = ralloc_strdup(BaseTypesContext, name); this->HlslName = ralloc_strdup(BaseTypesContext, InHlslName); /* Neither dimension is zero or both dimensions are zero. */ check((vector_elements == 0) == (matrix_columns == 0)); memset(&fields, 0, sizeof(fields)); }
glsl_type::glsl_type( enum glsl_sampler_dim dim, bool shadow, bool array, bool multisample, int samples, bool is_sampler_buffer, const struct glsl_type* type, const char *name, const char* InHlslName) : base_type(GLSL_TYPE_SAMPLER), sampler_dimensionality(dim), sampler_shadow(shadow), sampler_array(array), sampler_ms(multisample), sampler_buffer(is_sampler_buffer), outputstream_type(GLSL_OUTPUTSTREAM_NONE), sample_count(samples), inner_type(type), vector_elements(0), matrix_columns(0), length(0), patch_length(0) { init_ralloc_type_ctx(); this->name = ralloc_strdup(this->mem_ctx, name); this->HlslName = ralloc_strdup(this->mem_ctx, InHlslName); memset(&fields, 0, sizeof(fields)); }
/** * Replace any declaration of gl_ClipDistance as an array of floats with a * declaration of gl_ClipDistanceMESA as an array of vec4's. */ ir_visitor_status lower_clip_distance_visitor::visit(ir_variable *ir) { /* No point in looking for the declaration of gl_ClipDistance if * we've already found it. */ if (this->old_clip_distance_var) return visit_continue; if (ir->name && strcmp(ir->name, "gl_ClipDistance") == 0) { this->progress = true; this->old_clip_distance_var = ir; assert (ir->type->is_array()); assert (ir->type->element_type() == glsl_type::float_type); unsigned new_size = (ir->type->array_size() + 3) / 4; /* Clone the old var so that we inherit all of its properties */ this->new_clip_distance_var = ir->clone(ralloc_parent(ir), NULL); /* And change the properties that we need to change */ this->new_clip_distance_var->name = ralloc_strdup(this->new_clip_distance_var, "gl_ClipDistanceMESA"); this->new_clip_distance_var->type = glsl_type::get_array_instance(glsl_type::vec4_type, new_size); this->new_clip_distance_var->max_array_access = ir->max_array_access / 4; ir->replace_with(this->new_clip_distance_var); } return visit_continue; }
static void process_block_array(struct uniform_block_array_elements *ub_array, char **name, size_t name_length, gl_uniform_block *blocks, ubo_visitor *parcel, gl_uniform_buffer_variable *variables, const struct link_uniform_block_active *const b, unsigned *block_index, unsigned *binding_offset, struct gl_context *ctx, struct gl_shader_program *prog) { if (ub_array) { for (unsigned j = 0; j < ub_array->num_array_elements; j++) { size_t new_length = name_length; /* Append the subscript to the current variable name */ ralloc_asprintf_rewrite_tail(name, &new_length, "[%u]", ub_array->array_elements[j]); process_block_array(ub_array->array, name, new_length, blocks, parcel, variables, b, block_index, binding_offset, ctx, prog); } } else { unsigned i = *block_index; const glsl_type *type = b->type->without_array(); blocks[i].Name = ralloc_strdup(blocks, *name); blocks[i].Uniforms = &variables[(*parcel).index]; /* The GL_ARB_shading_language_420pack spec says: * * "If the binding identifier is used with a uniform block * instanced as an array then the first element of the array * takes the specified block binding and each subsequent * element takes the next consecutive uniform block binding * point." */ blocks[i].Binding = (b->has_binding) ? b->binding + *binding_offset : 0; blocks[i].UniformBufferSize = 0; blocks[i]._Packing = gl_uniform_block_packing(type->interface_packing); parcel->process(type, blocks[i].Name); blocks[i].UniformBufferSize = parcel->buffer_size; /* Check SSBO size is lower than maximum supported size for SSBO */ if (b->is_shader_storage && parcel->buffer_size > ctx->Const.MaxShaderStorageBlockSize) { linker_error(prog, "shader storage block `%s' has size %d, " "which is larger than than the maximum allowed (%d)", b->type->name, parcel->buffer_size, ctx->Const.MaxShaderStorageBlockSize); } blocks[i].NumUniforms = (unsigned)(ptrdiff_t)(&variables[parcel->index] - blocks[i].Uniforms); *block_index = *block_index + 1; *binding_offset = *binding_offset + 1; } }
static bool config_get_string(ALLEGRO_CONFIG *cfg, const char *sec, const char *key, char **ret, bool optional) { const char *value; *ret = NULL; value = al_get_config_value(cfg, sec, key); if (value == NULL) { if (!optional) log_err("Error in section %s: Key %s not found\n", sec, key); return false; } if (value[0] == '\0') { if (!optional) log_err("Error in section %s: Key %s empty\n", sec, key); return false; } *ret = ralloc_strdup(NULL, value); if (*ret == NULL) { log_err("Out of memory\n"); return false; } return true; }
/** * Merges a uniform block into an array of uniform blocks that may or * may not already contain a copy of it. * * Returns the index of the new block in the array. */ int link_cross_validate_uniform_block(void *mem_ctx, struct gl_uniform_block **linked_blocks, unsigned int *num_linked_blocks, struct gl_uniform_block *new_block) { for (unsigned int i = 0; i < *num_linked_blocks; i++) { struct gl_uniform_block *old_block = &(*linked_blocks)[i]; if (strcmp(old_block->Name, new_block->Name) == 0) return link_uniform_blocks_are_compatible(old_block, new_block) ? i : -1; } *linked_blocks = reralloc(mem_ctx, *linked_blocks, struct gl_uniform_block, *num_linked_blocks + 1); int linked_block_index = (*num_linked_blocks)++; struct gl_uniform_block *linked_block = &(*linked_blocks)[linked_block_index]; memcpy(linked_block, new_block, sizeof(*new_block)); linked_block->Uniforms = ralloc_array(*linked_blocks, struct gl_uniform_buffer_variable, linked_block->NumUniforms); memcpy(linked_block->Uniforms, new_block->Uniforms, sizeof(*linked_block->Uniforms) * linked_block->NumUniforms); linked_block->Name = ralloc_strdup(*linked_blocks, linked_block->Name); for (unsigned int i = 0; i < linked_block->NumUniforms; i++) { struct gl_uniform_buffer_variable *ubo_var = &linked_block->Uniforms[i]; if (ubo_var->Name == ubo_var->IndexName) { ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name); ubo_var->IndexName = ubo_var->Name; } else { ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name); ubo_var->IndexName = ralloc_strdup(*linked_blocks, ubo_var->IndexName); } } return linked_block_index; }
void program_resource_visitor::process(const glsl_type *type, const char *name) { assert(type->without_array()->is_record() || type->without_array()->is_interface()); char *name_copy = ralloc_strdup(NULL, name); recursion(type, &name_copy, strlen(name), false, NULL, false); ralloc_free(name_copy); }
/** * Clear (free) the shader program state that gets produced by linking. */ void _mesa_clear_shader_program_data(struct gl_context *ctx, struct gl_shader_program *shProg) { for (gl_shader_stage sh = 0; sh < MESA_SHADER_STAGES; sh++) { if (shProg->_LinkedShaders[sh] != NULL) { _mesa_delete_linked_shader(ctx, shProg->_LinkedShaders[sh]); shProg->_LinkedShaders[sh] = NULL; } } shProg->data->linked_stages = 0; if (shProg->data->UniformStorage) { for (unsigned i = 0; i < shProg->data->NumUniformStorage; ++i) _mesa_uniform_detach_all_driver_storage(&shProg->data-> UniformStorage[i]); ralloc_free(shProg->data->UniformStorage); shProg->data->NumUniformStorage = 0; shProg->data->UniformStorage = NULL; } if (shProg->UniformRemapTable) { ralloc_free(shProg->UniformRemapTable); shProg->NumUniformRemapTable = 0; shProg->UniformRemapTable = NULL; } if (shProg->UniformHash) { string_to_uint_map_dtor(shProg->UniformHash); shProg->UniformHash = NULL; } assert(shProg->data->InfoLog != NULL); ralloc_free(shProg->data->InfoLog); shProg->data->InfoLog = ralloc_strdup(shProg->data, ""); ralloc_free(shProg->data->UniformBlocks); shProg->data->UniformBlocks = NULL; shProg->data->NumUniformBlocks = 0; ralloc_free(shProg->data->ShaderStorageBlocks); shProg->data->ShaderStorageBlocks = NULL; shProg->data->NumShaderStorageBlocks = 0; ralloc_free(shProg->data->AtomicBuffers); shProg->data->AtomicBuffers = NULL; shProg->data->NumAtomicBuffers = 0; if (shProg->ProgramResourceList) { ralloc_free(shProg->ProgramResourceList); shProg->ProgramResourceList = NULL; shProg->NumProgramResourceList = 0; } }
glsl_type::glsl_type(enum glsl_outputstream_type output_stream_type, const struct glsl_type* type, const char *name) : base_type(GLSL_TYPE_OUTPUTSTREAM), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), sampler_ms(false), sampler_buffer(false), outputstream_type(output_stream_type), sample_count(1), inner_type(type), vector_elements(0), matrix_columns(0), HlslName(nullptr), length(0), patch_length(0) { init_ralloc_type_ctx(); this->name = ralloc_strdup(this->mem_ctx, name); memset(&fields, 0, sizeof(fields)); }
/** * Merges a uniform block into an array of uniform blocks that may or * may not already contain a copy of it. * * Returns the index of the new block in the array. */ int link_cross_validate_uniform_block(void *mem_ctx, struct gl_uniform_block **linked_blocks, unsigned int *num_linked_blocks, struct gl_uniform_block *new_block) { for (unsigned int i = 0; i < *num_linked_blocks; i++) { struct gl_uniform_block *old_block = &(*linked_blocks)[i]; if (strcmp(old_block->Name, new_block->Name) == 0) { if (old_block->NumUniforms != new_block->NumUniforms) { return -1; } for (unsigned j = 0; j < old_block->NumUniforms; j++) { if (strcmp(old_block->Uniforms[j].Name, new_block->Uniforms[j].Name) != 0) return -1; if (old_block->Uniforms[j].Offset != new_block->Uniforms[j].Offset) return -1; if (old_block->Uniforms[j].RowMajor != new_block->Uniforms[j].RowMajor) return -1; } return i; } } *linked_blocks = reralloc(mem_ctx, *linked_blocks, struct gl_uniform_block, *num_linked_blocks + 1); int linked_block_index = (*num_linked_blocks)++; struct gl_uniform_block *linked_block = &(*linked_blocks)[linked_block_index]; memcpy(linked_block, new_block, sizeof(*new_block)); linked_block->Uniforms = ralloc_array(*linked_blocks, struct gl_uniform_buffer_variable, linked_block->NumUniforms); memcpy(linked_block->Uniforms, new_block->Uniforms, sizeof(*linked_block->Uniforms) * linked_block->NumUniforms); for (unsigned int i = 0; i < linked_block->NumUniforms; i++) { struct gl_uniform_buffer_variable *ubo_var = &linked_block->Uniforms[i]; ubo_var->Name = ralloc_strdup(*linked_blocks, ubo_var->Name); } return linked_block_index; }
glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields, const char *name) : base_type(GLSL_TYPE_STRUCT), sampler_dimensionality(0), sampler_shadow(0), sampler_array(0), sampler_type(0), vector_elements(0), matrix_columns(0), length(num_fields) { unsigned int i; init_ralloc_type_ctx(); this->name = ralloc_strdup(this->mem_ctx, name); this->fields.structure = ralloc_array(this->mem_ctx, glsl_struct_field, length); for (i = 0; i < length; i++) { this->fields.structure[i].type = fields[i].type; this->fields.structure[i].name = ralloc_strdup(this->fields.structure, fields[i].name); } }