[Mesa-dev] [PATCH 29/31] glsl: Track whether uniforms are active per stage

Marek Olšák maraeo at gmail.com
Mon Jun 12 16:55:54 UTC 2017


From: Kenneth Graunke <kenneth at whitecape.org>

for finer granularity state flagging

v2: Marek - use a bitmask, add shader cache support
---
 src/compiler/glsl/ir_uniform.h      | 5 +++++
 src/compiler/glsl/link_uniforms.cpp | 2 ++
 src/compiler/glsl/shader_cache.cpp  | 2 ++
 3 files changed, 9 insertions(+)

diff --git a/src/compiler/glsl/ir_uniform.h b/src/compiler/glsl/ir_uniform.h
index b6aec7f..b04655b 100644
--- a/src/compiler/glsl/ir_uniform.h
+++ b/src/compiler/glsl/ir_uniform.h
@@ -100,20 +100,25 @@ struct gl_uniform_storage {
     * The number of elements in this uniform.
     *
     * For non-arrays, this is always 0.  For arrays, the value is the size of
     * the array.
     */
    unsigned array_elements;
 
    struct gl_opaque_uniform_index opaque[MESA_SHADER_STAGES];
 
    /**
+    * Mask of shader stages (1 << MESA_SHADER_xxx) where this uniform is used.
+    */
+   unsigned active_shader_mask;
+
+   /**
     * Storage used by the driver for the uniform
     */
    unsigned num_driver_storage;
    struct gl_uniform_driver_storage *driver_storage;
 
    /**
     * Storage used by Mesa for the uniform
     *
     * This form of the uniform is used by Mesa's implementation of \c
     * glGetUniform.  It can also be used by drivers to obtain the value of the
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index b11739c..09d7054 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -697,20 +697,22 @@ private:
          base_type = type->fields.array;
       } else {
          this->uniforms[id].array_elements = 0;
          base_type = type;
       }
 
       /* Initialise opaque data */
       this->uniforms[id].opaque[shader_type].index = ~0;
       this->uniforms[id].opaque[shader_type].active = false;
 
+      this->uniforms[id].active_shader_mask |= 1 << shader_type;
+
       /* This assigns uniform indices to sampler and image uniforms. */
       handle_samplers(base_type, &this->uniforms[id], name);
       handle_images(base_type, &this->uniforms[id], name);
       handle_subroutines(base_type, &this->uniforms[id]);
 
       /* For array of arrays or struct arrays the base location may have
        * already been set so don't set it again.
        */
       if (buffer_block_index == -1 && current_var->data.location == -1) {
          current_var->data.location = id;
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index dd56501..4f0a621 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -569,20 +569,21 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
       blob_write_uint32(metadata, prog->data->UniformStorage[i].storage -
                                   prog->data->UniformDataSlots);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].builtin);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].remap_location);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].block_index);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].atomic_buffer_index);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].offset);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].array_stride);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].hidden);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].is_shader_storage);
+      blob_write_uint32(metadata, prog->data->UniformStorage[i].active_shader_mask);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].matrix_stride);
       blob_write_uint32(metadata, prog->data->UniformStorage[i].row_major);
       blob_write_uint32(metadata,
                         prog->data->UniformStorage[i].num_compatible_subroutines);
       blob_write_uint32(metadata,
                         prog->data->UniformStorage[i].top_level_array_size);
       blob_write_uint32(metadata,
                         prog->data->UniformStorage[i].top_level_array_stride);
       blob_write_bytes(metadata, prog->data->UniformStorage[i].opaque,
                        sizeof(prog->data->UniformStorage[i].opaque));
@@ -633,20 +634,21 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
       uniforms[i].name = ralloc_strdup(prog, blob_read_string (metadata));
       uniforms[i].storage = data + blob_read_uint32(metadata);
       uniforms[i].builtin = blob_read_uint32(metadata);
       uniforms[i].remap_location = blob_read_uint32(metadata);
       uniforms[i].block_index = blob_read_uint32(metadata);
       uniforms[i].atomic_buffer_index = blob_read_uint32(metadata);
       uniforms[i].offset = blob_read_uint32(metadata);
       uniforms[i].array_stride = blob_read_uint32(metadata);
       uniforms[i].hidden = blob_read_uint32(metadata);
       uniforms[i].is_shader_storage = blob_read_uint32(metadata);
+      uniforms[i].active_shader_mask = blob_read_uint32(metadata);
       uniforms[i].matrix_stride = blob_read_uint32(metadata);
       uniforms[i].row_major = blob_read_uint32(metadata);
       uniforms[i].num_compatible_subroutines = blob_read_uint32(metadata);
       uniforms[i].top_level_array_size = blob_read_uint32(metadata);
       uniforms[i].top_level_array_stride = blob_read_uint32(metadata);
       prog->UniformHash->put(i, uniforms[i].name);
 
       memcpy(uniforms[i].opaque,
              blob_read_bytes(metadata, sizeof(uniforms[i].opaque)),
              sizeof(uniforms[i].opaque));
-- 
2.7.4



More information about the mesa-dev mailing list