[Mesa-dev] [PATCH 40/70] st/mesa/glsl: move SamplerTargets to gl_program

Timothy Arceri timothy.arceri at collabora.com
Tue Dec 20 10:37:50 UTC 2016


This will help allow us to simplify the handling of samplers by
storing them in a single location rather than duplicating them in
both gl_linked_shader and gl_program.
---
 src/compiler/glsl/link_uniforms.cpp       |  7 ++++---
 src/mesa/main/mtypes.h                    | 14 ++++++++------
 src/mesa/main/uniform_query.cpp           |  2 +-
 src/mesa/main/uniforms.c                  |  2 +-
 src/mesa/program/ir_to_mesa.cpp           |  2 +-
 src/mesa/state_tracker/st_glsl_to_nir.cpp |  2 +-
 6 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 8604dba..57a7db4 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -1248,10 +1248,11 @@ link_assign_uniform_storage(struct gl_context *ctx,
          parcel.shader_samplers_used;
       prog->_LinkedShaders[i]->shadow_samplers = parcel.shader_shadow_samplers;
 
-      STATIC_ASSERT(sizeof(prog->_LinkedShaders[i]->SamplerTargets) ==
+      STATIC_ASSERT(sizeof(prog->_LinkedShaders[i]->Program->sh.SamplerTargets) ==
                     sizeof(parcel.targets));
-      memcpy(prog->_LinkedShaders[i]->SamplerTargets, parcel.targets,
-             sizeof(prog->_LinkedShaders[i]->SamplerTargets));
+      memcpy(prog->_LinkedShaders[i]->Program->sh.SamplerTargets,
+             parcel.targets,
+             sizeof(prog->_LinkedShaders[i]->Program->sh.SamplerTargets));
    }
 
 #ifndef NDEBUG
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 8e13add..797e1e9 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2000,6 +2000,11 @@ struct gl_program
          struct gl_uniform_block **UniformBlocks;
          struct gl_uniform_block **ShaderStorageBlocks;
 
+         /** Which texture target is being sampled
+          * (TEXTURE_1D/2D/3D/etc_INDEX)
+          */
+         gl_texture_index SamplerTargets[MAX_SAMPLERS];
+
          union {
             struct {
                /**
@@ -2355,9 +2360,6 @@ struct gl_linked_shader
    GLbitfield shadow_samplers;	/**< Samplers used for shadow sampling. */
    /*@}*/
 
-   /** Which texture target is being sampled (TEXTURE_1D/2D/3D/etc_INDEX) */
-   gl_texture_index SamplerTargets[MAX_SAMPLERS];
-
    /**
     * Number of default uniform block components used by this shader.
     *
@@ -2388,14 +2390,14 @@ struct gl_linked_shader
    struct gl_shader_info info;
 };
 
-static inline GLbitfield gl_external_samplers(struct gl_linked_shader *shader)
+static inline GLbitfield gl_external_samplers(struct gl_program *prog)
 {
    GLbitfield external_samplers = 0;
-   GLbitfield mask = shader->Program->SamplersUsed;
+   GLbitfield mask = prog->SamplersUsed;
 
    while (mask) {
       int idx = u_bit_scan(&mask);
-      if (shader->SamplerTargets[idx] == TEXTURE_EXTERNAL_INDEX)
+      if (prog->sh.SamplerTargets[idx] == TEXTURE_EXTERNAL_INDEX)
          external_samplers |= (1 << idx);
    }
 
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index 047d21a..145eff0 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -1107,7 +1107,7 @@ _mesa_sampler_uniforms_pipeline_are_valid(struct gl_pipeline_object *pipeline)
       while (mask) {
          const int s = u_bit_scan(&mask);
          GLuint unit = shader->Program->SamplerUnits[s];
-         GLuint tgt = shader->SamplerTargets[s];
+         GLuint tgt = shader->Program->sh.SamplerTargets[s];
 
          /* FIXME: Samplers are initialized to 0 and Mesa doesn't do a
           * great job of eliminating unused uniforms currently so for now
diff --git a/src/mesa/main/uniforms.c b/src/mesa/main/uniforms.c
index 5534fcf..51db39e 100644
--- a/src/mesa/main/uniforms.c
+++ b/src/mesa/main/uniforms.c
@@ -80,7 +80,7 @@ _mesa_update_shader_textures_used(struct gl_shader_program *shProg,
    while (mask) {
       const int s = u_bit_scan(&mask);
       GLuint unit = prog->SamplerUnits[s];
-      GLuint tgt = shader->SamplerTargets[s];
+      GLuint tgt = prog->sh.SamplerTargets[s];
       assert(unit < ARRAY_SIZE(prog->TexturesUsed));
       assert(tgt < NUM_TEXTURE_TARGETS);
 
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index f360f8f..80516f4 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -2918,7 +2918,7 @@ get_mesa_program(struct gl_context *ctx,
    do_set_program_inouts(shader->ir, prog, shader->Stage);
 
    prog->ShadowSamplers = shader->shadow_samplers;
-   prog->ExternalSamplersUsed = gl_external_samplers(shader);
+   prog->ExternalSamplersUsed = gl_external_samplers(prog);
    _mesa_update_shader_textures_used(shader_program, prog);
 
    /* Set the gl_FragDepth layout. */
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index d5309e4..60d101c 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -413,7 +413,7 @@ st_nir_get_mesa_program(struct gl_context *ctx,
    }
 
    prog->ShadowSamplers = shader->shadow_samplers;
-   prog->ExternalSamplersUsed = gl_external_samplers(shader);
+   prog->ExternalSamplersUsed = gl_external_samplers(prog);
    _mesa_update_shader_textures_used(shader_program, prog);
 
    /* Avoid reallocation of the program parameter list, because the uniform
-- 
2.9.3



More information about the mesa-dev mailing list