[Mesa-dev] [PATCH 21/23] glsl/linker: Assign image uniform indices.

Francisco Jerez currojerez at riseup.net
Tue Nov 26 00:08:32 PST 2013


---
 src/glsl/link_uniforms.cpp | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/glsl/link_uniforms.cpp b/src/glsl/link_uniforms.cpp
index c75a38c..5780bb2 100644
--- a/src/glsl/link_uniforms.cpp
+++ b/src/glsl/link_uniforms.cpp
@@ -374,6 +374,7 @@ public:
       this->shader_samplers_used = 0;
       this->shader_shadow_samplers = 0;
       this->next_sampler = 0;
+      this->next_image = 0;
       memset(this->targets, 0, sizeof(this->targets));
    }
 
@@ -470,6 +471,24 @@ private:
       }
    }
 
+   void handle_images(const glsl_type *base_type,
+                      struct gl_uniform_storage *uniform)
+   {
+      if (base_type->is_image()) {
+         uniform->image[shader_type].index = this->next_image;
+         uniform->image[shader_type].active = true;
+
+         /* Increment the image index by 1 for non-arrays and by the
+          * number of array elements for arrays.
+          */
+         this->next_image += MAX2(1, uniform->array_elements);
+
+      } else {
+         uniform->image[shader_type].index = ~0;
+         uniform->image[shader_type].active = false;
+      }
+   }
+
    virtual void visit_field(const glsl_type *type, const char *name,
                             bool row_major)
    {
@@ -505,8 +524,9 @@ private:
 	 base_type = type;
       }
 
-      /* This assigns sampler uniforms to sampler units. */
+      /* This assigns uniform indices to sampler and image uniforms. */
       handle_samplers(base_type, &this->uniforms[id]);
+      handle_images(base_type, &this->uniforms[id]);
 
       /* If there is already storage associated with this uniform, it means
        * that it was set while processing an earlier shader stage.  For
@@ -564,6 +584,7 @@ private:
 
    struct gl_uniform_storage *uniforms;
    unsigned next_sampler;
+   unsigned next_image;
 
 public:
    union gl_constant_value *values;
@@ -767,6 +788,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog)
        *     types cannot have initializers."
        */
       memset(sh->SamplerUnits, 0, sizeof(sh->SamplerUnits));
+      memset(sh->ImageUnits, 0, sizeof(sh->ImageUnits));
 
       link_update_uniform_buffer_variables(sh);
 
-- 
1.8.3.4



More information about the mesa-dev mailing list