[Mesa-dev] [PATCH 4/4] glsl: store number of explicit uniform loactions in gl_shader_program

Timothy Arceri timothy.arceri at collabora.com
Thu Dec 29 03:15:13 UTC 2016


This allows us to cleanup the functions that pass this count around,
but more importantly we will be able to call the uniform linking
functions from that backends linker without having to pass this
information to the backend directly via Driver.LinkShader().
---
 src/compiler/glsl/link_uniforms.cpp | 19 +++++++------------
 src/compiler/glsl/linker.cpp        | 27 ++++++++++++---------------
 src/compiler/glsl/linker.h          |  3 +--
 src/mesa/main/mtypes.h              |  5 +++++
 4 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index e4275fd..ce6598b 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -918,12 +918,10 @@ find_empty_block(struct gl_shader_program *prog,
 
 static void
 link_setup_uniform_remap_tables(struct gl_context *ctx,
-                                struct gl_shader_program *prog,
-                                unsigned num_explicit_uniform_locs)
+                                struct gl_shader_program *prog)
 {
-   unsigned total_entries = num_explicit_uniform_locs;
-   unsigned empty_locs =
-      prog->NumUniformRemapTable - num_explicit_uniform_locs;
+   unsigned total_entries = prog->NumExplicitUniformLocations;
+   unsigned empty_locs = prog->NumUniformRemapTable - total_entries;
 
    /* Reserve all the explicit locations of the active uniforms. */
    for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
@@ -1082,8 +1080,7 @@ link_setup_uniform_remap_tables(struct gl_context *ctx,
 static void
 link_assign_uniform_storage(struct gl_context *ctx,
                             struct gl_shader_program *prog,
-                            const unsigned num_data_slots,
-                            unsigned num_explicit_uniform_locs)
+                            const unsigned num_data_slots)
 {
    /* On the outside chance that there were no uniforms, bail out.
     */
@@ -1155,7 +1152,7 @@ link_assign_uniform_storage(struct gl_context *ctx,
    assert(parcel.values == data_end);
 #endif
 
-   link_setup_uniform_remap_tables(ctx, prog, num_explicit_uniform_locs);
+   link_setup_uniform_remap_tables(ctx, prog);
 
    /* Set shader cache fields */
    prog->data->NumUniformDataSlots = num_data_slots;
@@ -1166,8 +1163,7 @@ link_assign_uniform_storage(struct gl_context *ctx,
 
 void
 link_assign_uniform_locations(struct gl_shader_program *prog,
-                              struct gl_context *ctx,
-                              unsigned int num_explicit_uniform_locs)
+                              struct gl_context *ctx)
 {
    if (!prog->data->cache_fallback) {
       ralloc_free(prog->data->UniformStorage);
@@ -1228,6 +1224,5 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
    hiddenUniforms->iterate(assign_hidden_uniform_slot_id, &uniform_size);
    delete hiddenUniforms;
 
-   link_assign_uniform_storage(ctx, prog, uniform_size.num_values,
-                               num_explicit_uniform_locs);
+   link_assign_uniform_storage(ctx, prog, uniform_size.num_values);
 }
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 366fa3f..fad49c5 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -3371,12 +3371,14 @@ reserve_subroutine_explicit_locations(struct gl_shader_program *prog,
  * any optimizations happen to handle also inactive uniforms and
  * inactive array elements that may get trimmed away.
  */
-static unsigned
+static void
 check_explicit_uniform_locations(struct gl_context *ctx,
                                  struct gl_shader_program *prog)
 {
+   prog->NumExplicitUniformLocations = 0;
+
    if (!ctx->Extensions.ARB_explicit_uniform_location)
-      return 0;
+      return;
 
    /* This map is used to detect if overlapping explicit locations
     * occur with the same uniform (from different stage) or a different one.
@@ -3385,7 +3387,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
 
    if (!uniform_map) {
       linker_error(prog, "Out of memory during linking.\n");
-      return 0;
+      return;
    }
 
    unsigned entries_total = 0;
@@ -3413,7 +3415,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
             }
             if (!ret) {
                delete uniform_map;
-               return 0;
+               return;
             }
          }
       }
@@ -3438,7 +3440,7 @@ check_explicit_uniform_locations(struct gl_context *ctx,
    }
 
    delete uniform_map;
-   return entries_total;
+   prog->NumExplicitUniformLocations = entries_total;
 }
 
 static bool
@@ -4528,11 +4530,10 @@ disable_varying_optimizations_for_sso(struct gl_shader_program *prog)
 
 static void
 link_and_validate_uniforms(struct gl_context *ctx,
-                           struct gl_shader_program *prog,
-                           unsigned num_explicit_uniform_locs)
+                           struct gl_shader_program *prog)
 {
    update_array_sizes(prog);
-   link_assign_uniform_locations(prog, ctx, num_explicit_uniform_locs);
+   link_assign_uniform_locations(prog, ctx);
 
    if (!prog->data->cache_fallback) {
       link_assign_atomic_counter_resources(ctx, prog);
@@ -4546,7 +4547,6 @@ link_and_validate_uniforms(struct gl_context *ctx,
 
 static bool
 link_varyings_and_uniforms(unsigned first, unsigned last,
-                           unsigned num_explicit_uniform_locs,
                            struct gl_context *ctx,
                            struct gl_shader_program *prog, void *mem_ctx)
 {
@@ -4608,7 +4608,7 @@ link_varyings_and_uniforms(unsigned first, unsigned last,
    if (!link_varyings(prog, first, last, ctx, mem_ctx))
       return false;
 
-   link_and_validate_uniforms(ctx, prog, num_explicit_uniform_locs);
+   link_and_validate_uniforms(ctx, prog);
 
    if (!prog->data->LinkStatus)
       return false;
@@ -4641,8 +4641,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
       return;
    }
 
-   unsigned int num_explicit_uniform_locs = 0;
-
 #ifdef ENABLE_SHADER_CACHE
    /* If transform feedback used on the program then compile all shaders. */
    bool skip_cache = false;
@@ -4826,7 +4824,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
    }
 
    if (!prog->data->cache_fallback) {
-      num_explicit_uniform_locs = check_explicit_uniform_locations(ctx, prog);
+      check_explicit_uniform_locations(ctx, prog);
       link_assign_subroutine_types(prog);
    }
 
@@ -4938,8 +4936,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 
    store_fragdepth_layout(prog);
 
-   if(!link_varyings_and_uniforms(first, last, num_explicit_uniform_locs, ctx,
-                                  prog, mem_ctx))
+   if(!link_varyings_and_uniforms(first, last, ctx, prog, mem_ctx))
       goto done;
 
    /* OpenGL ES < 3.1 requires that a vertex shader and a fragment shader both
diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h
index fd6cb36..abcfdb1 100644
--- a/src/compiler/glsl/linker.h
+++ b/src/compiler/glsl/linker.h
@@ -35,8 +35,7 @@ link_invalidate_variable_locations(exec_list *ir);
 
 extern void
 link_assign_uniform_locations(struct gl_shader_program *prog,
-                              struct gl_context *ctx,
-                              unsigned int num_explicit_uniform_locs);
+                              struct gl_context *ctx);
 
 extern void
 link_set_uniform_initializers(struct gl_shader_program *prog,
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 4572eae..e8ef0b2 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2807,6 +2807,11 @@ struct gl_shader_program
    struct exec_list EmptyUniformLocations;
 
    /**
+    * Total number of explicit uniform location including inactive uniforms.
+    */
+   unsigned NumExplicitUniformLocations;
+
+   /**
     * Map of active uniform names to locations
     *
     * Maps any active uniform that is not an array element to a location.
-- 
2.9.3



More information about the mesa-dev mailing list