linker: Split set_uniform_binding into separate functions for blocks and samplers
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 4 Apr 2014 17:45:38 +0000 (10:45 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Fri, 11 Apr 2014 19:26:01 +0000 (12:26 -0700)
The two code paths are quite different, and there are some problems in
the handling of uniform blocks.  Future changes will cause these paths
to diverge further.  Ultimately, selecting between the two functions
will happen at the set_uniform_binding call site, and
set_uniform_binding will be deleted.

NOTE: This patch just moves code around.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76323
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Cc: "10.1" <mesa-stable@lists.freedesktop.org>
Cc: github@socker.lepus.uberspace.de
src/glsl/link_uniform_initializers.cpp

index 9d6977d573a667e00f07653543599520e7fcd1ae..9a1035073130f5f926338a97fa393c56ed593ebc 100644 (file)
@@ -84,7 +84,7 @@ copy_constant_to_storage(union gl_constant_value *storage,
 }
 
 void
-set_uniform_binding(void *mem_ctx, gl_shader_program *prog,
+set_sampler_binding(void *mem_ctx, gl_shader_program *prog,
                     const char *name, const glsl_type *type, int binding)
 {
    struct gl_uniform_storage *const storage =
@@ -95,7 +95,7 @@ set_uniform_binding(void *mem_ctx, gl_shader_program *prog,
       return;
    }
 
-   if (storage->type->is_sampler()) {
+   {
       unsigned elements = MAX2(storage->array_elements, 1);
 
       /* From section 4.4.4 of the GLSL 4.20 specification:
@@ -118,7 +118,24 @@ set_uniform_binding(void *mem_ctx, gl_shader_program *prog,
             }
          }
       }
-   } else if (storage->block_index != -1) {
+   }
+
+   storage->initialized = true;
+}
+
+void
+set_block_binding(void *mem_ctx, gl_shader_program *prog,
+                  const char *name, const glsl_type *type, int binding)
+{
+   struct gl_uniform_storage *const storage =
+      get_storage(prog->UniformStorage, prog->NumUserUniformStorage, name);
+
+   if (storage == NULL) {
+      assert(storage != NULL);
+      return;
+   }
+
+   if (storage->block_index != -1) {
       /* This is a field of a UBO.  val is the binding index. */
       for (int i = 0; i < MESA_SHADER_STAGES; i++) {
          int stage_index = prog->UniformBlockStageIndex[i][storage->block_index];
@@ -133,6 +150,25 @@ set_uniform_binding(void *mem_ctx, gl_shader_program *prog,
    storage->initialized = true;
 }
 
+void
+set_uniform_binding(void *mem_ctx, gl_shader_program *prog,
+                    const char *name, const glsl_type *type, int binding)
+{
+   struct gl_uniform_storage *const storage =
+      get_storage(prog->UniformStorage, prog->NumUserUniformStorage, name);
+
+   if (storage == NULL) {
+      assert(storage != NULL);
+      return;
+   }
+
+   if (storage->type->is_sampler()) {
+      set_sampler_binding(mem_ctx, prog, name, type, binding);
+   } else if (storage->block_index != -1) {
+      set_block_binding(mem_ctx, prog, name, type, binding);
+   }
+}
+
 void
 set_uniform_initializer(void *mem_ctx, gl_shader_program *prog,
                        const char *name, const glsl_type *type,