[Mesa-dev] [PATCH 04/12] nir: Make nir_lower_samplers take a gl_shader_stage, not a gl_program *.

Kenneth Graunke kenneth at whitecape.org
Wed Apr 8 00:06:27 PDT 2015


We don't actually need a gl_program struct.  We only used it to
translate prog->Target (i.e. GL_VERTEX_PROGRAM) to the gl_shader_stage
(i.e. MESA_SHADER_VERTEX).  We may as well just pass that.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/nir/nir.h                       |  2 +-
 src/glsl/nir/nir_lower_samplers.cpp      | 26 ++++++++++++--------------
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp |  2 +-
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index 17a9354..679911c 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1612,7 +1612,7 @@ void nir_lower_phis_to_scalar(nir_shader *shader);
 
 void nir_lower_samplers(nir_shader *shader,
                         struct gl_shader_program *shader_program,
-                        struct gl_program *prog);
+                        gl_shader_stage stage);
 
 void nir_lower_system_values(nir_shader *shader);
 void nir_lower_tex_projector(nir_shader *shader);
diff --git a/src/glsl/nir/nir_lower_samplers.cpp b/src/glsl/nir/nir_lower_samplers.cpp
index 1e509a9..7a7cf85 100644
--- a/src/glsl/nir/nir_lower_samplers.cpp
+++ b/src/glsl/nir/nir_lower_samplers.cpp
@@ -36,11 +36,9 @@ extern "C" {
 }
 
 static unsigned
-get_sampler_index(struct gl_shader_program *shader_program, const char *name,
-                  const struct gl_program *prog)
+get_sampler_index(struct gl_shader_program *shader_program,
+                  gl_shader_stage stage, const char *name)
 {
-   GLuint shader = _mesa_program_enum_to_shader_stage(prog->Target);
-
    unsigned location;
    if (!shader_program->UniformHash->get(location, name)) {
       linker_error(shader_program,
@@ -48,7 +46,7 @@ get_sampler_index(struct gl_shader_program *shader_program, const char *name,
       return 0;
    }
 
-   if (!shader_program->UniformStorage[location].sampler[shader].active) {
+   if (!shader_program->UniformStorage[location].sampler[stage].active) {
       assert(0 && "cannot return a sampler");
       linker_error(shader_program,
                    "cannot return a sampler named %s, because it is not "
@@ -57,12 +55,12 @@ get_sampler_index(struct gl_shader_program *shader_program, const char *name,
       return 0;
    }
 
-   return shader_program->UniformStorage[location].sampler[shader].index;
+   return shader_program->UniformStorage[location].sampler[stage].index;
 }
 
 static void
 lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program,
-              const struct gl_program *prog, void *mem_ctx)
+              gl_shader_stage stage, void *mem_ctx)
 {
    if (instr->sampler == NULL)
       return;
@@ -133,7 +131,7 @@ lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program,
       }
    }
 
-   instr->sampler_index += get_sampler_index(shader_program, name, prog);
+   instr->sampler_index += get_sampler_index(shader_program, stage, name);
 
    instr->sampler = NULL;
 }
@@ -141,7 +139,7 @@ lower_sampler(nir_tex_instr *instr, struct gl_shader_program *shader_program,
 typedef struct {
    void *mem_ctx;
    struct gl_shader_program *shader_program;
-   struct gl_program *prog;
+   gl_shader_stage stage;
 } lower_state;
 
 static bool
@@ -152,7 +150,7 @@ lower_block_cb(nir_block *block, void *_state)
    nir_foreach_instr(block, instr) {
       if (instr->type == nir_instr_type_tex) {
          nir_tex_instr *tex_instr = nir_instr_as_tex(instr);
-         lower_sampler(tex_instr, state->shader_program, state->prog,
+         lower_sampler(tex_instr, state->shader_program, state->stage,
                        state->mem_ctx);
       }
    }
@@ -162,23 +160,23 @@ lower_block_cb(nir_block *block, void *_state)
 
 static void
 lower_impl(nir_function_impl *impl, struct gl_shader_program *shader_program,
-           struct gl_program *prog)
+           gl_shader_stage stage)
 {
    lower_state state;
 
    state.mem_ctx = ralloc_parent(impl);
    state.shader_program = shader_program;
-   state.prog = prog;
+   state.stage = stage;
 
    nir_foreach_block(impl, lower_block_cb, &state);
 }
 
 extern "C" void
 nir_lower_samplers(nir_shader *shader, struct gl_shader_program *shader_program,
-                   struct gl_program *prog)
+                   gl_shader_stage stage)
 {
    nir_foreach_overload(shader, overload) {
       if (overload->impl)
-         lower_impl(overload->impl, shader_program, prog);
+         lower_impl(overload->impl, shader_program, stage);
    }
 }
diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
index a874337..7c56290 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
@@ -141,7 +141,7 @@ fs_visitor::emit_nir_code()
    nir_validate_shader(nir);
 
    if (shader_prog) {
-      nir_lower_samplers(nir, shader_prog, shader->base.Program);
+      nir_lower_samplers(nir, shader_prog, stage);
       nir_validate_shader(nir);
    }
 
-- 
2.3.5



More information about the mesa-dev mailing list