st/glsl_to_nir: set paramater value offset as driver location for packed uniforms
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 22 Mar 2018 00:52:19 +0000 (11:52 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Tue, 10 Apr 2018 04:43:45 +0000 (14:43 +1000)
This allows us to simplify the code and will also be useful for supporting
bindless textures.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_nir.h
src/mesa/state_tracker/st_nir_lower_uniforms_to_ubo.c

index a5a284fb22abea3af321e666c7f8a4dfd36ebaeb..bcf6a7ceb6a00ecc70f910ded3b5d97337b60441 100644 (file)
@@ -294,11 +294,16 @@ st_nir_assign_uniform_locations(struct gl_context *ctx,
          if (ctx->Const.PackedDriverUniformStorage) {
             loc = _mesa_add_sized_state_reference(prog->Parameters,
                                                   stateTokens, comps, false);
+            loc = prog->Parameters->ParameterValueOffset[loc];
          } else {
             loc = _mesa_add_state_reference(prog->Parameters, stateTokens);
          }
       } else {
          loc = st_nir_lookup_parameter_index(prog->Parameters, uniform->name);
+
+         if (ctx->Const.PackedDriverUniformStorage) {
+            loc = prog->Parameters->ParameterValueOffset[loc];
+         }
       }
 
       uniform->data.driver_location = loc;
@@ -804,7 +809,7 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog,
    if (st->ctx->Const.PackedDriverUniformStorage) {
       NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_type_dword_size,
                  (nir_lower_io_options)0);
-      NIR_PASS_V(nir, st_nir_lower_uniforms_to_ubo, prog->Parameters);
+      NIR_PASS_V(nir, st_nir_lower_uniforms_to_ubo);
    }
 
    if (screen->get_param(screen, PIPE_CAP_NIR_SAMPLERS_AS_DEREF))
index 3dd78fb1155ef31bd5222853b524a6c16325cce1..1c2e32a5e6f3a152deaa3903b87cd04daad5e26f 100644 (file)
@@ -36,8 +36,7 @@ struct nir_shader;
 void st_nir_lower_builtin(struct nir_shader *shader);
 void st_nir_lower_tex_src_plane(struct nir_shader *shader, unsigned free_slots,
                                 unsigned lower_2plane, unsigned lower_3plane);
-bool st_nir_lower_uniforms_to_ubo(struct nir_shader *shader,
-                                  const struct gl_program_parameter_list *params);
+bool st_nir_lower_uniforms_to_ubo(struct nir_shader *shader);
 
 void st_finalize_nir(struct st_context *st, struct gl_program *prog,
                      struct gl_shader_program *shader_program,
index b2f8f833bbbf8b6cf5337da3bd3b653fd38d4303..1727f8214a085d9722b93a3180f3d561f1b77f81 100644 (file)
@@ -36,8 +36,7 @@
 #include "program/prog_parameter.h"
 
 static bool
-lower_instr(nir_intrinsic_instr *instr, nir_builder *b,
-            const struct gl_program_parameter_list *params)
+lower_instr(nir_intrinsic_instr *instr, nir_builder *b)
 {
    b->cursor = nir_before_instr(&instr->instr);
 
@@ -50,11 +49,9 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b,
    }
 
    if (instr->intrinsic == nir_intrinsic_load_uniform) {
-      unsigned pvo = params->ParameterValueOffset[nir_intrinsic_base(instr)];
-
       nir_ssa_def *ubo_idx = nir_imm_int(b, 0);
       nir_ssa_def *ubo_offset =
-         nir_iadd(b, nir_imm_int(b, 4 * pvo),
+         nir_iadd(b, nir_imm_int(b, 4 * nir_intrinsic_base(instr)),
                   nir_imul(b, nir_imm_int(b, 4),
                            nir_ssa_for_src(b, instr->src[0], 1)));
 
@@ -77,8 +74,7 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b,
 }
 
 bool
-st_nir_lower_uniforms_to_ubo(nir_shader *shader,
-                             const struct gl_program_parameter_list *params)
+st_nir_lower_uniforms_to_ubo(nir_shader *shader)
 {
    bool progress = false;
 
@@ -90,7 +86,7 @@ st_nir_lower_uniforms_to_ubo(nir_shader *shader,
             nir_foreach_instr_safe(instr, block) {
                if (instr->type == nir_instr_type_intrinsic)
                   progress |= lower_instr(nir_instr_as_intrinsic(instr),
-                                          &builder, params);
+                                          &builder);
             }
          }