/* 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)); }
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); }
loop_variable * loop_variable_state::insert(ir_variable *var) { void *mem_ctx = ralloc_parent(this); loop_variable *lv = rzalloc(mem_ctx, loop_variable); lv->var = var; _mesa_hash_table_insert(this->var_hash, lv->var, lv); this->variables.push_tail(lv); return lv; }
/** * \brief Creates selector component. * \param[in,out] data Selector base component device. * \return Pointer to selector base component device. */ static struct comp_dev *selector_new(struct sof_ipc_comp *comp) { struct sof_ipc_comp_process *ipc_process = (struct sof_ipc_comp_process *)comp; size_t bs = ipc_process->size; struct comp_dev *dev; struct comp_data *cd; int ret; trace_selector("selector_new()"); if (IPC_IS_SIZE_INVALID(ipc_process->config)) { IPC_SIZE_ERROR_TRACE(TRACE_CLASS_SELECTOR, ipc_process->config); return NULL; } dev = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, COMP_SIZE(struct sof_ipc_comp_process)); if (!dev) return NULL; assert(!memcpy_s(&dev->comp, sizeof(struct sof_ipc_comp_process), comp, sizeof(struct sof_ipc_comp_process))); cd = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(*cd)); if (!cd) { rfree(dev); return NULL; } comp_set_drvdata(dev, cd); assert(!memcpy_s(&cd->config, sizeof(cd->config), ipc_process->data, bs)); /* verification of initial parameters */ ret = sel_set_channel_values(cd, cd->config.in_channels_count, cd->config.out_channels_count, cd->config.sel_channel); if (ret < 0) { rfree(cd); rfree(dev); return NULL; } dev->state = COMP_STATE_READY; return dev; }
void common_builtin::SetUp() { this->mem_ctx = ralloc_context(NULL); this->ir.make_empty(); initialize_context_to_defaults(&this->ctx, API_OPENGL_COMPAT); this->shader = rzalloc(this->mem_ctx, gl_shader); this->shader->Type = this->shader_type; this->shader->Stage = _mesa_shader_enum_to_shader_stage(this->shader_type); this->state = new(mem_ctx) _mesa_glsl_parse_state(&this->ctx, this->shader->Stage, this->shader); _mesa_glsl_initialize_types(this->state); _mesa_glsl_initialize_variables(&this->ir, this->state); }
static nir_variable * read_variable(read_ctx *ctx) { nir_variable *var = rzalloc(ctx->nir, nir_variable); read_add_object(ctx, var); var->type = decode_type_from_blob(ctx->blob); bool has_name = blob_read_uint32(ctx->blob); if (has_name) { const char *name = blob_read_string(ctx->blob); var->name = ralloc_strdup(var, name); } else { var->name = NULL; } blob_copy_bytes(ctx->blob, (uint8_t *) &var->data, sizeof(var->data)); var->num_state_slots = blob_read_uint32(ctx->blob); var->state_slots = ralloc_array(var, nir_state_slot, var->num_state_slots); blob_copy_bytes(ctx->blob, (uint8_t *) var->state_slots, var->num_state_slots * sizeof(nir_state_slot)); bool has_const_initializer = blob_read_uint32(ctx->blob); if (has_const_initializer) var->constant_initializer = read_constant(ctx, var); else var->constant_initializer = NULL; bool has_interface_type = blob_read_uint32(ctx->blob); if (has_interface_type) var->interface_type = decode_type_from_blob(ctx->blob); else var->interface_type = NULL; var->num_members = blob_read_uint32(ctx->blob); if (var->num_members > 0) { var->members = ralloc_array(var, struct nir_variable_data, var->num_members); blob_copy_bytes(ctx->blob, (uint8_t *) var->members, var->num_members * sizeof(*var->members)); }
struct brw_compiler * brw_compiler_create(void *mem_ctx, const struct brw_device_info *devinfo) { struct brw_compiler *compiler = rzalloc(mem_ctx, struct brw_compiler); compiler->devinfo = devinfo; compiler->shader_debug_log = shader_debug_log_mesa; compiler->shader_perf_log = shader_perf_log_mesa; brw_fs_alloc_reg_sets(compiler); brw_vec4_alloc_reg_set(compiler); compiler->scalar_stage[MESA_SHADER_VERTEX] = devinfo->gen >= 8 && !(INTEL_DEBUG & DEBUG_VEC4VS); compiler->scalar_stage[MESA_SHADER_GEOMETRY] = devinfo->gen >= 8 && env_var_as_boolean("INTEL_SCALAR_GS", false); compiler->scalar_stage[MESA_SHADER_FRAGMENT] = true; compiler->scalar_stage[MESA_SHADER_COMPUTE] = true; nir_shader_compiler_options *nir_options = rzalloc(compiler, nir_shader_compiler_options); nir_options->native_integers = true; /* In order to help allow for better CSE at the NIR level we tell NIR * to split all ffma instructions during opt_algebraic and we then * re-combine them as a later step. */ nir_options->lower_ffma = true; nir_options->lower_sub = true; /* In the vec4 backend, our dpN instruction replicates its result to all * the components of a vec4. We would like NIR to give us replicated fdot * instructions because it can optimize better for us. * * For the FS backend, it should be lowered away by the scalarizing pass so * we should never see fdot anyway. */ nir_options->fdot_replicates = true; /* We want the GLSL compiler to emit code that uses condition codes */ for (int i = 0; i < MESA_SHADER_STAGES; i++) { compiler->glsl_compiler_options[i].MaxUnrollIterations = 32; compiler->glsl_compiler_options[i].MaxIfDepth = devinfo->gen < 6 ? 16 : UINT_MAX; compiler->glsl_compiler_options[i].EmitCondCodes = true; compiler->glsl_compiler_options[i].EmitNoNoise = true; compiler->glsl_compiler_options[i].EmitNoMainReturn = true; compiler->glsl_compiler_options[i].EmitNoIndirectInput = true; compiler->glsl_compiler_options[i].EmitNoIndirectUniform = false; compiler->glsl_compiler_options[i].LowerClipDistance = true; bool is_scalar = compiler->scalar_stage[i]; compiler->glsl_compiler_options[i].EmitNoIndirectOutput = is_scalar; compiler->glsl_compiler_options[i].EmitNoIndirectTemp = is_scalar; compiler->glsl_compiler_options[i].OptimizeForAOS = !is_scalar; /* !ARB_gpu_shader5 */ if (devinfo->gen < 7) compiler->glsl_compiler_options[i].EmitNoIndirectSampler = true; compiler->glsl_compiler_options[i].NirOptions = nir_options; compiler->glsl_compiler_options[i].LowerBufferInterfaceBlocks = true; } if (compiler->scalar_stage[MESA_SHADER_GEOMETRY]) compiler->glsl_compiler_options[MESA_SHADER_GEOMETRY].EmitNoIndirectInput = false; compiler->glsl_compiler_options[MESA_SHADER_COMPUTE] .LowerShaderSharedVariables = true; return compiler; }
static struct comp_dev *test_keyword_new(struct sof_ipc_comp *comp) { struct comp_dev *dev; struct sof_ipc_comp_process *keyword; struct sof_ipc_comp_process *ipc_keyword = (struct sof_ipc_comp_process *)comp; struct comp_data *cd; struct sof_detect_test_config *cfg; size_t bs; trace_keyword("test_keyword_new()"); if (IPC_IS_SIZE_INVALID(ipc_keyword->config)) { IPC_SIZE_ERROR_TRACE(TRACE_CLASS_KEYWORD, ipc_keyword->config); return NULL; } dev = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, COMP_SIZE(struct sof_ipc_comp_process)); if (!dev) return NULL; keyword = (struct sof_ipc_comp_process *)&dev->comp; assert(!memcpy_s(keyword, sizeof(*keyword), ipc_keyword, sizeof(struct sof_ipc_comp_process))); cd = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(*cd)); if (!cd) goto fail; /* using default processing function */ cd->detect_func = default_detect_test; comp_set_drvdata(dev, cd); cfg = (struct sof_detect_test_config *)ipc_keyword->data; bs = ipc_keyword->size; if (bs > 0) { if (bs != sizeof(struct sof_detect_test_config)) { trace_keyword_error("test_keyword_new() " "error: invalid data size"); goto fail; } if (test_keyword_apply_config(dev, cfg)) { trace_keyword_error("test_keyword_new() " "error: failed to apply config"); goto fail; } } dev->state = COMP_STATE_READY; return dev; fail: if (cd) rfree(cd); rfree(dev); return NULL; }
nir_deref_var * vtn_access_chain_to_deref(struct vtn_builder *b, struct vtn_access_chain *chain) { nir_deref_var *deref_var; if (chain->var->var) { deref_var = nir_deref_var_create(b, chain->var->var); } else { assert(chain->var->members); /* Create the deref_var manually. It will get filled out later. */ deref_var = rzalloc(b, nir_deref_var); deref_var->deref.deref_type = nir_deref_type_var; } struct vtn_type *deref_type = chain->var->type; nir_deref *tail = &deref_var->deref; nir_variable **members = chain->var->members; for (unsigned i = 0; i < chain->length; i++) { enum glsl_base_type base_type = glsl_get_base_type(deref_type->type); switch (base_type) { case GLSL_TYPE_UINT: case GLSL_TYPE_INT: case GLSL_TYPE_FLOAT: case GLSL_TYPE_DOUBLE: case GLSL_TYPE_BOOL: case GLSL_TYPE_ARRAY: { deref_type = deref_type->array_element; nir_deref_array *deref_arr = nir_deref_array_create(b); deref_arr->deref.type = deref_type->type; if (chain->link[i].mode == vtn_access_mode_literal) { deref_arr->deref_array_type = nir_deref_array_type_direct; deref_arr->base_offset = chain->link[i].id; } else { assert(chain->link[i].mode == vtn_access_mode_id); deref_arr->deref_array_type = nir_deref_array_type_indirect; deref_arr->base_offset = 0; deref_arr->indirect = nir_src_for_ssa(vtn_ssa_value(b, chain->link[i].id)->def); } tail->child = &deref_arr->deref; tail = tail->child; break; } case GLSL_TYPE_STRUCT: { assert(chain->link[i].mode == vtn_access_mode_literal); unsigned idx = chain->link[i].id; deref_type = deref_type->members[idx]; if (members) { /* This is a pre-split structure. */ deref_var->var = members[idx]; rewrite_deref_types(&deref_var->deref, members[idx]->type); assert(tail->type == deref_type->type); members = NULL; } else { nir_deref_struct *deref_struct = nir_deref_struct_create(b, idx); deref_struct->deref.type = deref_type->type; tail->child = &deref_struct->deref; tail = tail->child; } break; } default: unreachable("Invalid type for deref"); } } assert(members == NULL); return deref_var; }
static void var_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member, const struct vtn_decoration *dec, void *void_var) { struct vtn_variable *vtn_var = void_var; /* Handle decorations that apply to a vtn_variable as a whole */ switch (dec->decoration) { case SpvDecorationNonWritable: /* Do nothing with this for now */ return; case SpvDecorationBinding: vtn_var->binding = dec->literals[0]; return; case SpvDecorationDescriptorSet: vtn_var->descriptor_set = dec->literals[0]; return; case SpvDecorationLocation: { unsigned location = dec->literals[0]; bool is_vertex_input; if (b->shader->stage == MESA_SHADER_FRAGMENT && vtn_var->mode == vtn_variable_mode_output) { is_vertex_input = false; location += FRAG_RESULT_DATA0; } else if (b->shader->stage == MESA_SHADER_VERTEX && vtn_var->mode == vtn_variable_mode_input) { is_vertex_input = true; location += VERT_ATTRIB_GENERIC0; } else if (vtn_var->mode == vtn_variable_mode_input || vtn_var->mode == vtn_variable_mode_output) { is_vertex_input = false; location += VARYING_SLOT_VAR0; } else { assert(!"Location must be on input or output variable"); } if (vtn_var->var) { vtn_var->var->data.location = location; vtn_var->var->data.explicit_location = true; } else { assert(vtn_var->members); unsigned length = glsl_get_length(glsl_without_array(vtn_var->type->type)); for (unsigned i = 0; i < length; i++) { vtn_var->members[i]->data.location = location; vtn_var->members[i]->data.explicit_location = true; location += glsl_count_attribute_slots(vtn_var->members[i]->interface_type, is_vertex_input); } } return; } default: break; } /* Now we handle decorations that apply to a particular nir_variable */ nir_variable *nir_var = vtn_var->var; if (val->value_type == vtn_value_type_access_chain) { assert(val->access_chain->length == 0); assert(val->access_chain->var == void_var); assert(member == -1); } else { assert(val->value_type == vtn_value_type_type); if (member != -1) nir_var = vtn_var->members[member]; } if (nir_var == NULL) return; switch (dec->decoration) { case SpvDecorationRelaxedPrecision: break; /* FIXME: Do nothing with this for now. */ case SpvDecorationNoPerspective: nir_var->data.interpolation = INTERP_QUALIFIER_NOPERSPECTIVE; break; case SpvDecorationFlat: nir_var->data.interpolation = INTERP_QUALIFIER_FLAT; break; case SpvDecorationCentroid: nir_var->data.centroid = true; break; case SpvDecorationSample: nir_var->data.sample = true; break; case SpvDecorationInvariant: nir_var->data.invariant = true; break; case SpvDecorationConstant: assert(nir_var->constant_initializer != NULL); nir_var->data.read_only = true; break; case SpvDecorationNonWritable: nir_var->data.read_only = true; break; case SpvDecorationComponent: nir_var->data.location_frac = dec->literals[0]; break; case SpvDecorationIndex: nir_var->data.explicit_index = true; nir_var->data.index = dec->literals[0]; break; case SpvDecorationBuiltIn: { SpvBuiltIn builtin = dec->literals[0]; if (builtin == SpvBuiltInWorkgroupSize) { /* This shouldn't be a builtin. It's actually a constant. */ nir_var->data.mode = nir_var_global; nir_var->data.read_only = true; nir_constant *c = rzalloc(nir_var, nir_constant); c->value.u[0] = b->shader->info.cs.local_size[0]; c->value.u[1] = b->shader->info.cs.local_size[1]; c->value.u[2] = b->shader->info.cs.local_size[2]; nir_var->constant_initializer = c; break; } nir_variable_mode mode = nir_var->data.mode; vtn_get_builtin_location(b, builtin, &nir_var->data.location, &mode); nir_var->data.explicit_location = true; nir_var->data.mode = mode; if (builtin == SpvBuiltInFragCoord || builtin == SpvBuiltInSamplePosition) nir_var->data.origin_upper_left = b->origin_upper_left; break; } case SpvDecorationRowMajor: case SpvDecorationColMajor: case SpvDecorationGLSLShared: case SpvDecorationPatch: case SpvDecorationRestrict: case SpvDecorationAliased: case SpvDecorationVolatile: case SpvDecorationCoherent: case SpvDecorationNonReadable: case SpvDecorationUniform: /* This is really nice but we have no use for it right now. */ case SpvDecorationCPacked: case SpvDecorationSaturatedConversion: case SpvDecorationStream: case SpvDecorationOffset: case SpvDecorationXfbBuffer: case SpvDecorationFuncParamAttr: case SpvDecorationFPRoundingMode: case SpvDecorationFPFastMathMode: case SpvDecorationLinkageAttributes: case SpvDecorationSpecId: break; default: unreachable("Unhandled variable decoration"); } }
void vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, const uint32_t *w, unsigned count) { switch (opcode) { case SpvOpVariable: { struct vtn_variable *var = rzalloc(b, struct vtn_variable); var->type = vtn_value(b, w[1], vtn_value_type_type)->type; var->chain.var = var; var->chain.length = 0; struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_access_chain); val->access_chain = &var->chain; struct vtn_type *without_array = var->type; while(glsl_type_is_array(without_array->type)) without_array = without_array->array_element; nir_variable_mode nir_mode; switch ((SpvStorageClass)w[3]) { case SpvStorageClassUniform: case SpvStorageClassUniformConstant: if (without_array->block) { var->mode = vtn_variable_mode_ubo; b->shader->info.num_ubos++; } else if (without_array->buffer_block) { var->mode = vtn_variable_mode_ssbo; b->shader->info.num_ssbos++; } else if (glsl_type_is_image(without_array->type)) { var->mode = vtn_variable_mode_image; nir_mode = nir_var_uniform; b->shader->info.num_images++; } else if (glsl_type_is_sampler(without_array->type)) { var->mode = vtn_variable_mode_sampler; nir_mode = nir_var_uniform; b->shader->info.num_textures++; } else { assert(!"Invalid uniform variable type"); } break; case SpvStorageClassPushConstant: var->mode = vtn_variable_mode_push_constant; assert(b->shader->num_uniforms == 0); b->shader->num_uniforms = vtn_type_block_size(var->type) * 4; break; case SpvStorageClassInput: var->mode = vtn_variable_mode_input; nir_mode = nir_var_shader_in; break; case SpvStorageClassOutput: var->mode = vtn_variable_mode_output; nir_mode = nir_var_shader_out; break; case SpvStorageClassPrivate: var->mode = vtn_variable_mode_global; nir_mode = nir_var_global; break; case SpvStorageClassFunction: var->mode = vtn_variable_mode_local; nir_mode = nir_var_local; break; case SpvStorageClassWorkgroup: var->mode = vtn_variable_mode_workgroup; nir_mode = nir_var_shared; break; case SpvStorageClassCrossWorkgroup: case SpvStorageClassGeneric: case SpvStorageClassAtomicCounter: default: unreachable("Unhandled variable storage class"); } switch (var->mode) { case vtn_variable_mode_local: case vtn_variable_mode_global: case vtn_variable_mode_image: case vtn_variable_mode_sampler: case vtn_variable_mode_workgroup: /* For these, we create the variable normally */ var->var = rzalloc(b->shader, nir_variable); var->var->name = ralloc_strdup(var->var, val->name); var->var->type = var->type->type; var->var->data.mode = nir_mode; switch (var->mode) { case vtn_variable_mode_image: case vtn_variable_mode_sampler: var->var->interface_type = without_array->type; break; default: var->var->interface_type = NULL; break; } break; case vtn_variable_mode_input: case vtn_variable_mode_output: { /* For inputs and outputs, we immediately split structures. This * is for a couple of reasons. For one, builtins may all come in * a struct and we really want those split out into separate * variables. For another, interpolation qualifiers can be * applied to members of the top-level struct ane we need to be * able to preserve that information. */ int array_length = -1; struct vtn_type *interface_type = var->type; if (b->shader->stage == MESA_SHADER_GEOMETRY && glsl_type_is_array(var->type->type)) { /* In Geometry shaders (and some tessellation), inputs come * in per-vertex arrays. However, some builtins come in * non-per-vertex, hence the need for the is_array check. In * any case, there are no non-builtin arrays allowed so this * check should be sufficient. */ interface_type = var->type->array_element; array_length = glsl_get_length(var->type->type); } if (glsl_type_is_struct(interface_type->type)) { /* It's a struct. Split it. */ unsigned num_members = glsl_get_length(interface_type->type); var->members = ralloc_array(b, nir_variable *, num_members); for (unsigned i = 0; i < num_members; i++) { const struct glsl_type *mtype = interface_type->members[i]->type; if (array_length >= 0) mtype = glsl_array_type(mtype, array_length); var->members[i] = rzalloc(b->shader, nir_variable); var->members[i]->name = ralloc_asprintf(var->members[i], "%s.%d", val->name, i); var->members[i]->type = mtype; var->members[i]->interface_type = interface_type->members[i]->type; var->members[i]->data.mode = nir_mode; } } else { var->var = rzalloc(b->shader, nir_variable); var->var->name = ralloc_strdup(var->var, val->name); var->var->type = var->type->type; var->var->interface_type = interface_type->type; var->var->data.mode = nir_mode; } /* For inputs and outputs, we need to grab locations and builtin * information from the interface type. */ vtn_foreach_decoration(b, interface_type->val, var_decoration_cb, var); break; case vtn_variable_mode_param: unreachable("Not created through OpVariable"); } case vtn_variable_mode_ubo: case vtn_variable_mode_ssbo: case vtn_variable_mode_push_constant: /* These don't need actual variables. */ break; } if (count > 4) { assert(count == 5); nir_constant *constant = vtn_value(b, w[4], vtn_value_type_constant)->constant; var->var->constant_initializer = nir_constant_clone(constant, var->var); } vtn_foreach_decoration(b, val, var_decoration_cb, var); if (var->mode == vtn_variable_mode_image || var->mode == vtn_variable_mode_sampler) { /* XXX: We still need the binding information in the nir_variable * for these. We should fix that. */ var->var->data.binding = var->binding; var->var->data.descriptor_set = var->descriptor_set; if (var->mode == vtn_variable_mode_image) var->var->data.image.format = without_array->image_format; } if (var->mode == vtn_variable_mode_local) { assert(var->members == NULL && var->var != NULL); nir_function_impl_add_variable(b->impl, var->var); } else if (var->var) { nir_shader_add_variable(b->shader, var->var); } else if (var->members) { unsigned count = glsl_get_length(without_array->type); for (unsigned i = 0; i < count; i++) { assert(var->members[i]->data.mode != nir_var_local); nir_shader_add_variable(b->shader, var->members[i]); } } else { assert(var->mode == vtn_variable_mode_ubo || var->mode == vtn_variable_mode_ssbo || var->mode == vtn_variable_mode_push_constant); } break; }