i965: delay adding built-in uniforms to Parameters list
authorTimothy Arceri <timothy.arceri@collabora.com>
Tue, 6 Dec 2016 06:34:02 +0000 (17:34 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Fri, 9 Dec 2016 05:29:10 +0000 (16:29 +1100)
This is a step towards using NIR optimisations over GLSL IR
optimisations. Delaying adding built-in uniforms until after
we convert to NIR gives it a chance to optimise them away.

V2: move the new code back to brw_link_shader()

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_link.cpp

index 871a2fc1a9a5d2ad1c7d672b7bbc1294381f3a7c..ca9341740673533c6622ad39d85afa0e646a6620 100644 (file)
@@ -248,29 +248,6 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
 
       _mesa_copy_linked_program_data(shProg, shader);
 
-      /* Make a pass over the IR to add state references for any built-in
-       * uniforms that are used.  This has to be done now (during linking).
-       * Code generation doesn't happen until the first time this shader is
-       * used for rendering.  Waiting until then to generate the parameters is
-       * too late.  At that point, the values for the built-in uniforms won't
-       * get sent to the shader.
-       */
-      foreach_in_list(ir_instruction, node, shader->ir) {
-         ir_variable *var = node->as_variable();
-
-         if ((var == NULL) || (var->data.mode != ir_var_uniform)
-             || (strncmp(var->name, "gl_", 3) != 0))
-            continue;
-
-         const ir_state_slot *const slots = var->get_state_slots();
-         assert(slots != NULL);
-
-         for (unsigned int i = 0; i < var->get_num_state_slots(); i++) {
-            _mesa_add_state_reference(prog->Parameters,
-                                      (gl_state_index *) slots[i].tokens);
-         }
-      }
-
       prog->SamplersUsed = shader->active_samplers;
       prog->ShadowSamplers = shader->shadow_samplers;
       _mesa_update_shader_textures_used(shProg, prog);
@@ -290,6 +267,25 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
       prog->nir = brw_create_nir(brw, shProg, prog, (gl_shader_stage) stage,
                                  compiler->scalar_stage[stage]);
       infos[stage] = prog->nir->info;
+
+      /* Make a pass over the IR to add state references for any built-in
+       * uniforms that are used.  This has to be done now (during linking).
+       * Code generation doesn't happen until the first time this shader is
+       * used for rendering.  Waiting until then to generate the parameters is
+       * too late.  At that point, the values for the built-in uniforms won't
+       * get sent to the shader.
+       */
+      nir_foreach_variable(var, &prog->nir->uniforms) {
+         if (strncmp(var->name, "gl_", 3) == 0) {
+            const nir_state_slot *const slots = var->state_slots;
+            assert(var->state_slots != NULL);
+
+            for (unsigned int i = 0; i < var->num_state_slots; i++) {
+               _mesa_add_state_reference(prog->Parameters,
+                                         (gl_state_index *)slots[i].tokens);
+            }
+         }
+      }
    }
 
    /* The linker tries to dead code eliminate unused varying components,