summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCaio Marcelo de Oliveira Filho <[email protected]>2019-08-21 21:04:27 -0700
committerCaio Marcelo de Oliveira Filho <[email protected]>2019-09-10 14:36:46 -0700
commitb6384e57f5f6e454c06ec1ada1c1138dd0dc84f2 (patch)
treeaed5a658175ce51873f257f55b8e2e12a1804aa8 /src
parentd40978f396523ea1b719c0999b0650b1cb4ebc54 (diff)
mesa/st: Lookup parameters without using names
Use the new MainUniformStorageIndex field in Parameter instead. It was added so we could match those in the SPIR-V case, where names are optional. v2: Use MainUniformStorageIndex for all cases. Reviewed-by: Alejandro PiƱeiro <[email protected]> [v1] Reviewed-by: Timothy Arceri <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/state_tracker/st_glsl_to_nir.cpp51
1 files changed, 9 insertions, 42 deletions
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index dac5ba2378d..52f56642078 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -109,51 +109,18 @@ st_nir_assign_vs_in_locations(nir_shader *nir)
}
static int
-st_nir_lookup_parameter_index(const struct gl_program_parameter_list *params,
- const char *name)
+st_nir_lookup_parameter_index(struct gl_program *prog, nir_variable *var)
{
- int loc = _mesa_lookup_parameter_index(params, name);
-
- /* is there a better way to do this? If we have something like:
- *
- * struct S {
- * float f;
- * vec4 v;
- * };
- * uniform S color;
- *
- * Then what we get in prog->Parameters looks like:
- *
- * 0: Name=color.f, Type=6, DataType=1406, Size=1
- * 1: Name=color.v, Type=6, DataType=8b52, Size=4
- *
- * So the name doesn't match up and _mesa_lookup_parameter_index()
- * fails. In this case just find the first matching "color.*"..
- *
- * Note for arrays you could end up w/ color[n].f, for example.
- *
- * glsl_to_tgsi works slightly differently in this regard. It is
- * emitting something more low level, so it just translates the
- * params list 1:1 to CONST[] regs. Going from GLSL IR to TGSI,
- * it just calculates the additional offset of struct field members
- * in glsl_to_tgsi_visitor::visit(ir_dereference_record *ir) or
- * glsl_to_tgsi_visitor::visit(ir_dereference_array *ir). It never
- * needs to work backwards to get base var loc from the param-list
- * which already has them separated out.
+ /* Lookup the first parameter that the uniform storage that match the
+ * variable location.
*/
- if (loc < 0) {
- int namelen = strlen(name);
- for (unsigned i = 0; i < params->NumParameters; i++) {
- struct gl_program_parameter *p = &params->Parameters[i];
- if ((strncmp(p->Name, name, namelen) == 0) &&
- ((p->Name[namelen] == '.') || (p->Name[namelen] == '['))) {
- loc = i;
- break;
- }
- }
+ for (unsigned i = 0; i < prog->Parameters->NumParameters; i++) {
+ int index = prog->Parameters->Parameters[i].MainUniformStorageIndex;
+ if (index == var->data.location)
+ return i;
}
- return loc;
+ return -1;
}
static void
@@ -204,7 +171,7 @@ st_nir_assign_uniform_locations(struct gl_context *ctx,
loc = _mesa_add_state_reference(prog->Parameters, stateTokens);
}
} else {
- loc = st_nir_lookup_parameter_index(prog->Parameters, uniform->name);
+ loc = st_nir_lookup_parameter_index(prog, uniform);
/* We need to check that loc is not -1 here before accessing the
* array. It can be negative for example when we have a struct that