mesa: Fill Parameter storage indices even when not using SPIR-V
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 4 Sep 2019 16:28:54 +0000 (09:28 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Tue, 10 Sep 2019 21:36:46 +0000 (14:36 -0700)
When creating Parameters, fill in the associated uniform storage
indices, like it is done with the NIR linker used for SPIR-V.  This
will allow later code to not rely on names (which would never work for
SPIR-V where names are optional).

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/program/ir_to_mesa.cpp

index 053912a84100bf43831656744262d8180f81de9c..30e8606b2539fc69707c8f8dee4044982cdbf4dd 100644 (file)
@@ -2390,7 +2390,7 @@ public:
    add_uniform_to_shader(struct gl_context *ctx,
                          struct gl_shader_program *shader_program,
                         struct gl_program_parameter_list *params)
-      : ctx(ctx), params(params), idx(-1)
+      : ctx(ctx), shader_program(shader_program), params(params), idx(-1)
    {
       /* empty */
    }
@@ -2411,6 +2411,7 @@ private:
                             bool last_field);
 
    struct gl_context *ctx;
+   struct gl_shader_program *shader_program;
    struct gl_program_parameter_list *params;
    int idx;
    ir_variable *var;
@@ -2472,6 +2473,21 @@ add_uniform_to_shader::visit_field(const glsl_type *type, const char *name,
     */
    if (this->idx < 0)
       this->idx = index;
+
+   /* Each Parameter will hold the index to the backing uniform storage.
+    * This avoids relying on names to match parameters and uniform
+    * storages later when associating uniform storage.
+    */
+   unsigned location;
+   const bool found =
+      shader_program->UniformHash->get(location, params->Parameters[index].Name);
+   assert(found);
+
+   for (unsigned i = 0; i < num_params; i++) {
+      struct gl_program_parameter *param = &params->Parameters[index + i];
+      param->UniformStorageIndex = location;
+      param->MainUniformStorageIndex = params->Parameters[this->idx].UniformStorageIndex;
+   }
 }
 
 /**