[Mesa-dev] [RFC PATCH 23/65] mesa: get rid of a workaround for bindless in _mesa_get_uniform()

Samuel Pitoiset samuel.pitoiset at gmail.com
Fri May 19 16:52:28 UTC 2017


The ARB_bindless_texture spec says:

   "When a sampler or image uniform's value is queried via any
    of the GetUniform* commands, the returned value will reflect
    the most recently set value through either UniformHandle* or
    Uniform1i*, converted to the requested type."

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/compiler/glsl/ir_uniform.h     |  6 ++++++
 src/compiler/glsl/shader_cache.cpp |  2 ++
 src/mesa/main/uniform_query.cpp    | 22 +++++++++++++++++-----
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/compiler/glsl/ir_uniform.h b/src/compiler/glsl/ir_uniform.h
index 9841df8cde..f375d8359d 100644
--- a/src/compiler/glsl/ir_uniform.h
+++ b/src/compiler/glsl/ir_uniform.h
@@ -207,6 +207,12 @@ struct gl_uniform_storage {
     * layout qualifier as specified by ARB_bindless_texture.
     */
    bool is_bindless;
+
+   /**
+    * Whether this uniform variable is declared with the bindless_sampler or
+    * bindless_image and used with a texture/image handle.
+    */
+   bool is_bindless_handle;
 };
 
 #ifdef __cplusplus
diff --git a/src/compiler/glsl/shader_cache.cpp b/src/compiler/glsl/shader_cache.cpp
index 6811cb2f50..3fe3135bd7 100644
--- a/src/compiler/glsl/shader_cache.cpp
+++ b/src/compiler/glsl/shader_cache.cpp
@@ -579,6 +579,7 @@ write_uniforms(struct blob *metadata, struct gl_shader_program *prog)
       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].is_bindless);
+      blob_write_uint32(metadata, prog->data->UniformStorage[i].is_bindless_handle);
       blob_write_uint32(metadata,
                         prog->data->UniformStorage[i].num_compatible_subroutines);
       blob_write_uint32(metadata,
@@ -644,6 +645,7 @@ read_uniforms(struct blob_reader *metadata, struct gl_shader_program *prog)
       uniforms[i].matrix_stride = blob_read_uint32(metadata);
       uniforms[i].row_major = blob_read_uint32(metadata);
       uniforms[i].is_bindless = blob_read_uint32(metadata);
+      uniforms[i].is_bindless_handle = 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);
diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
index be04e48d53..78a852377d 100644
--- a/src/mesa/main/uniform_query.cpp
+++ b/src/mesa/main/uniform_query.cpp
@@ -322,12 +322,20 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
 
    {
       unsigned elements = uni->type->components();
-      /* XXX: Remove the sampler/image check workarounds when bindless is fully
-       * implemented.
-       */
-      const int dmul =
-         (uni->type->is_64bit() && !uni->type->is_sampler() && !uni->type->is_image()) ? 2 : 1;
       const int rmul = glsl_base_type_is_64bit(returnType) ? 2 : 1;
+      int dmul = uni->type->is_64bit() ? 2 : 1;
+
+      if ((uni->type->is_sampler() || uni->type->is_image()) &&
+          !uni->is_bindless_handle) {
+         /* The ARB_bindless_texture spec says:
+          *
+          * "When a sampler or image uniform's value is queried via any of the
+          *  GetUniform* commands, the returned value will reflect the most
+          *  recently set value through either UniformHandle* or Uniform1i*,
+          *  converted to the requested type."
+          */
+         dmul = 1;
+      }
 
       /* Calculate the source base address *BEFORE* modifying elements to
        * account for the size of the user's buffer.
@@ -1007,6 +1015,7 @@ _mesa_uniform(GLint location, GLsizei count, const GLvoid *values,
                }
                sampler->bound = true;
                sh->Program->sh.HasBoundBindlessSampler = true;
+               uni->is_bindless_handle = false;
             } else {
                if (sh->Program->SamplerUnits[unit] != value) {
                   sh->Program->SamplerUnits[unit] = value;
@@ -1053,6 +1062,7 @@ _mesa_uniform(GLint location, GLsizei count, const GLvoid *values,
                image->unit = value;
                image->bound = true;
                sh->Program->sh.HasBoundBindlessImage = true;
+               uni->is_bindless_handle = false;
             } else {
                sh->Program->sh.ImageUnits[unit] = value;
             }
@@ -1318,6 +1328,7 @@ _mesa_uniform_handle(GLint location, GLsizei count, const GLvoid *values,
                &sh->Program->sh.BindlessSamplers[unit];
 
             sampler->bound = false;
+            uni->is_bindless_handle = true;
          }
 
          update_bound_bindless_sampler_flag(sh->Program);
@@ -1341,6 +1352,7 @@ _mesa_uniform_handle(GLint location, GLsizei count, const GLvoid *values,
                &sh->Program->sh.BindlessImages[unit];
 
             image->bound = false;
+            uni->is_bindless_handle = true;
          }
 
          update_bound_bindless_image_flag(sh->Program);
-- 
2.13.0



More information about the mesa-dev mailing list