static void add_builtin_variable(exec_list *instructions, glsl_symbol_table *symtab, const builtin_variable *proto) { /* Create a new variable declaration from the description supplied by * the caller. */ const glsl_type *const type = symtab->get_type(proto->type); assert(type != NULL); if (proto->mode == ir_var_uniform) { add_uniform(instructions, symtab, proto->name, type); } else { add_variable(instructions, symtab, proto->name, type, proto->mode, proto->slot); } }
/** * Uniforms that are common to all GLSL ES implementations. * * Several constants in GLSL ES have different names than normal desktop GLSL. * Therefore, this function should only be called on the ES path. */ static void generate_common_ES_uniforms(exec_list *instructions, struct _mesa_glsl_parse_state *state) { glsl_symbol_table *const symtab = state->symbols; add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", state->Const.MaxVertexAttribs); add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformVectors", state->Const.MaxVertexUniformComponents); add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", state->Const.MaxVertexTextureImageUnits); add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", state->Const.MaxCombinedTextureImageUnits); add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", state->Const.MaxTextureImageUnits); add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformVectors", state->Const.MaxFragmentUniformComponents); add_uniform(instructions, symtab, "gl_DepthRange", state->symbols->get_type("gl_DepthRangeParameters")); }
int main_indelqual(int argc, char *argv[]) { char *bam_in = NULL; char *bam_out = NULL; /* - == stdout */ char *ref = NULL; int c; static int dindel = 0; int uni_iq = -1; int uni_dq = -1; while (1) { static struct option long_opts[] = { /* see usage sync */ {"help", no_argument, NULL, 'h'}, {"verbose", no_argument, &verbose, 1}, {"debug", no_argument, &debug, 1}, {"dindel", no_argument, &dindel, 1}, {"out", required_argument, NULL, 'o'}, {"uniform", required_argument, NULL, 'u'}, {"ref", required_argument, NULL, 'f'}, {0, 0, 0, 0} /* sentinel */ }; /* keep in sync with long_opts and usage */ static const char *long_opts_str = "hu:f:o:"; /* getopt_long stores the option index here. */ int long_opts_index = 0; c = getopt_long(argc-1, argv+1, /* skipping 'lofreq', just leaving 'command', i.e. call */ long_opts_str, long_opts, & long_opts_index); if (c == -1) { break; } switch (c) { /* keep in sync with long_opts etc */ case 'h': usage(); return 0; case 'u': idq_from_arg(& uni_iq, & uni_dq, optarg); break; case 'f': if (! file_exists(optarg)) { LOG_FATAL("Reference fasta file '%s' does not exist. Exiting...\n", optarg); return 1; } ref = strdup(optarg); break; case 'o': if (0 != strcmp(optarg, "-")) { if (file_exists(optarg)) { LOG_FATAL("Cowardly refusing to overwrite file '%s'. Exiting...\n", optarg); return 1; } } bam_out = strdup(optarg); break; case '?': LOG_FATAL("%s\n", "unrecognized arguments found. Exiting...\n"); return 1; default: break; } } if (1 != argc - optind - 1) { fprintf(stderr, "FATAL: Need exactly one BAM file as last argument\n"); usage(); return 1; } bam_in = (argv + optind + 1)[0]; if ((0 != strcmp(bam_in, "-")) && ! file_exists(bam_in)) { LOG_FATAL("BAM file %s does not exist. Exiting...\n", bam_in); return -1; } if (! bam_out) { bam_out = malloc(2 * sizeof(char)); strcpy(bam_out, "-"); } LOG_DEBUG("uni_iq=%d\n", uni_iq); LOG_DEBUG("uni_dq=%d\n", uni_dq); LOG_DEBUG("bam_in=%s\n", bam_in); LOG_DEBUG("bam_out=%s\n", bam_out); LOG_DEBUG("ref=%s\n", ref); if ((uni_iq != -1 && uni_dq == -1) || (uni_iq == -1 && uni_dq != -1)) { LOG_FATAL("internal logic error: uni_iq=%d uni_dq=%d\n", uni_iq, uni_dq); exit(1); } if (uni_iq != -1 && uni_dq != -1) { if (dindel) { LOG_FATAL("%s\n", "Can't insert both, uniform and dindel qualities"); return -1; } return add_uniform(bam_in, bam_out, uni_iq, uni_dq); } else if (dindel) { if (! ref) { LOG_FATAL("%s\n", "Need reference for Dindel model"); return -1; } return add_dindel(bam_in, bam_out, ref); } else { LOG_FATAL("%s\n", "Please specify either dindel or uniform mode"); return -1; } free(ref); free(bam_out); return 0; }
static void generate_110_uniforms(exec_list *instructions, struct _mesa_glsl_parse_state *state, bool add_deprecated) { glsl_symbol_table *const symtab = state->symbols; if (add_deprecated) { for (unsigned i = 0 ; i < Elements(builtin_110_deprecated_uniforms) ; i++) { add_builtin_variable(instructions, symtab, & builtin_110_deprecated_uniforms[i]); } } if (add_deprecated) { add_builtin_constant(instructions, symtab, "gl_MaxLights", state->Const.MaxLights); add_builtin_constant(instructions, symtab, "gl_MaxClipPlanes", state->Const.MaxClipPlanes); add_builtin_constant(instructions, symtab, "gl_MaxTextureUnits", state->Const.MaxTextureUnits); add_builtin_constant(instructions, symtab, "gl_MaxTextureCoords", state->Const.MaxTextureCoords); } add_builtin_constant(instructions, symtab, "gl_MaxVertexAttribs", state->Const.MaxVertexAttribs); add_builtin_constant(instructions, symtab, "gl_MaxVertexUniformComponents", state->Const.MaxVertexUniformComponents); add_builtin_constant(instructions, symtab, "gl_MaxVaryingFloats", state->Const.MaxVaryingFloats); add_builtin_constant(instructions, symtab, "gl_MaxVertexTextureImageUnits", state->Const.MaxVertexTextureImageUnits); add_builtin_constant(instructions, symtab, "gl_MaxCombinedTextureImageUnits", state->Const.MaxCombinedTextureImageUnits); add_builtin_constant(instructions, symtab, "gl_MaxTextureImageUnits", state->Const.MaxTextureImageUnits); add_builtin_constant(instructions, symtab, "gl_MaxFragmentUniformComponents", state->Const.MaxFragmentUniformComponents); if (add_deprecated) { const glsl_type *const mat4_array_type = glsl_type::get_array_instance(glsl_type::mat4_type, state->Const.MaxTextureCoords); add_uniform(instructions, symtab, "gl_TextureMatrix", mat4_array_type); add_uniform(instructions, symtab, "gl_TextureMatrixInverse", mat4_array_type); add_uniform(instructions, symtab, "gl_TextureMatrixTranspose", mat4_array_type); add_uniform(instructions, symtab, "gl_TextureMatrixInverseTranspose", mat4_array_type); } add_uniform(instructions, symtab, "gl_DepthRange", symtab->get_type("gl_DepthRangeParameters")); if (add_deprecated) { add_uniform(instructions, symtab, "gl_ClipPlane", glsl_type::get_array_instance(glsl_type::vec4_type, state->Const.MaxClipPlanes)); add_uniform(instructions, symtab, "gl_Point", symtab->get_type("gl_PointParameters")); const glsl_type *const material_parameters_type = symtab->get_type("gl_MaterialParameters"); add_uniform(instructions, symtab, "gl_FrontMaterial", material_parameters_type); add_uniform(instructions, symtab, "gl_BackMaterial", material_parameters_type); const glsl_type *const light_source_array_type = glsl_type::get_array_instance(symtab->get_type("gl_LightSourceParameters"), state->Const.MaxLights); add_uniform(instructions, symtab, "gl_LightSource", light_source_array_type); const glsl_type *const light_model_products_type = symtab->get_type("gl_LightModelProducts"); add_uniform(instructions, symtab, "gl_FrontLightModelProduct", light_model_products_type); add_uniform(instructions, symtab, "gl_BackLightModelProduct", light_model_products_type); const glsl_type *const light_products_type = glsl_type::get_array_instance(symtab->get_type("gl_LightProducts"), state->Const.MaxLights); add_uniform(instructions, symtab, "gl_FrontLightProduct", light_products_type); add_uniform(instructions, symtab, "gl_BackLightProduct", light_products_type); add_uniform(instructions, symtab, "gl_TextureEnvColor", glsl_type::get_array_instance(glsl_type::vec4_type, state->Const.MaxTextureUnits)); const glsl_type *const texcoords_vec4 = glsl_type::get_array_instance(glsl_type::vec4_type, state->Const.MaxTextureCoords); add_uniform(instructions, symtab, "gl_EyePlaneS", texcoords_vec4); add_uniform(instructions, symtab, "gl_EyePlaneT", texcoords_vec4); add_uniform(instructions, symtab, "gl_EyePlaneR", texcoords_vec4); add_uniform(instructions, symtab, "gl_EyePlaneQ", texcoords_vec4); add_uniform(instructions, symtab, "gl_ObjectPlaneS", texcoords_vec4); add_uniform(instructions, symtab, "gl_ObjectPlaneT", texcoords_vec4); add_uniform(instructions, symtab, "gl_ObjectPlaneR", texcoords_vec4); add_uniform(instructions, symtab, "gl_ObjectPlaneQ", texcoords_vec4); add_uniform(instructions, symtab, "gl_Fog", symtab->get_type("gl_FogParameters")); } /* Mesa-internal current attrib state */ const glsl_type *const vert_attribs = glsl_type::get_array_instance(glsl_type::vec4_type, VERT_ATTRIB_MAX); add_uniform(instructions, symtab, "gl_CurrentAttribVertMESA", vert_attribs); const glsl_type *const frag_attribs = glsl_type::get_array_instance(glsl_type::vec4_type, FRAG_ATTRIB_MAX); add_uniform(instructions, symtab, "gl_CurrentAttribFragMESA", frag_attribs); }
void qir_lower_uniforms(struct vc4_compile *c) { struct hash_table *ht = _mesa_hash_table_create(c, index_hash, index_compare); /* Walk the instruction list, finding which instructions have more * than one uniform referenced, and add those uniform values to the * ht. */ list_for_each_entry(struct qinst, inst, &c->instructions, link) { uint32_t nsrc = qir_get_op_nsrc(inst->op); uint32_t count = 0; for (int i = 0; i < nsrc; i++) { if (inst->src[i].file == QFILE_UNIF) count++; } if (count <= 1) continue; for (int i = 0; i < nsrc; i++) { if (is_lowerable_uniform(inst, i)) add_uniform(ht, inst->src[i]); } } while (ht->entries) { /* Find the most commonly used uniform in instructions that * need a uniform lowered. */ uint32_t max_count = 0; uint32_t max_index = 0; struct hash_entry *entry; hash_table_foreach(ht, entry) { uint32_t count = (uintptr_t)entry->data; uint32_t index = (uintptr_t)entry->key; if (count > max_count) { max_count = count; max_index = index; } } /* Now, find the instructions using this uniform and make them * reference a temp instead. */ struct qreg temp = qir_get_temp(c); struct qreg unif = { QFILE_UNIF, max_index }; struct qinst *mov = qir_inst(QOP_MOV, temp, unif, c->undef); list_add(&mov->link, &c->instructions); c->defs[temp.index] = mov; list_for_each_entry(struct qinst, inst, &c->instructions, link) { uint32_t nsrc = qir_get_op_nsrc(inst->op); uint32_t count = 0; for (int i = 0; i < nsrc; i++) { if (inst->src[i].file == QFILE_UNIF) count++; } if (count <= 1) continue; for (int i = 0; i < nsrc; i++) { if (is_lowerable_uniform(inst, i) && inst->src[i].index == max_index) { inst->src[i] = temp; remove_uniform(ht, unif); count--; } } /* If the instruction doesn't need lowering any more, * then drop it from the list. */ if (count <= 1) { for (int i = 0; i < nsrc; i++) { if (is_lowerable_uniform(inst, i)) remove_uniform(ht, inst->src[i]); } } } }