[Mesa-dev] [PATCH v3 17/44] glsl ubo/ssbo: Use enum to track current buffer access type

Jordan Justen jordan.l.justen at intel.com
Tue Dec 1 00:19:35 PST 2015


v2:
 * Rename ssbo_get_array_length to ssbo_unsized_array_length_access (Iago)
 * Use always use this-> when referencing buffer_access_type (Iago)

Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
---
 src/glsl/lower_ubo_reference.cpp | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/glsl/lower_ubo_reference.cpp b/src/glsl/lower_ubo_reference.cpp
index b74aa3d..b2a1f25 100644
--- a/src/glsl/lower_ubo_reference.cpp
+++ b/src/glsl/lower_ubo_reference.cpp
@@ -162,6 +162,14 @@ public:
    ir_call *ssbo_store(ir_rvalue *deref, ir_rvalue *offset,
                        unsigned write_mask);
 
+   enum {
+      ubo_load_access,
+      ssbo_load_access,
+      ssbo_store_access,
+      ssbo_unsized_array_length_access,
+      ssbo_atomic_access,
+   } buffer_access_type;
+
    void emit_access(bool is_write, ir_dereference *deref,
                     ir_variable *base_offset, unsigned int deref_offset,
                     bool row_major, int matrix_columns,
@@ -189,7 +197,6 @@ public:
    struct gl_uniform_buffer_variable *ubo_var;
    ir_rvalue *uniform_block;
    bool progress;
-   bool is_shader_storage;
 };
 
 /**
@@ -339,10 +346,9 @@ lower_ubo_reference_visitor::setup_for_load_or_store(ir_variable *var,
                            deref, &nonconst_block_index);
 
    /* Locate the block by interface name */
-   this->is_shader_storage = var->is_in_shader_storage_block();
    unsigned num_blocks;
    struct gl_uniform_block **blocks;
-   if (this->is_shader_storage) {
+   if (this->buffer_access_type != ubo_load_access) {
       num_blocks = shader->NumShaderStorageBlocks;
       blocks = shader->ShaderStorageBlocks;
    } else {
@@ -552,6 +558,10 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
    int matrix_columns;
    unsigned packing = var->get_interface_type()->interface_packing;
 
+   this->buffer_access_type =
+      var->is_in_shader_storage_block() ?
+      ssbo_load_access : ubo_load_access;
+
    /* Compute the offset to the start if the dereference as well as other
     * information we need to configure the write
     */
@@ -795,7 +805,7 @@ lower_ubo_reference_visitor::emit_access(bool is_write,
       if (is_write)
          base_ir->insert_after(ssbo_store(deref, offset, write_mask));
       else {
-         if (!this->is_shader_storage) {
+         if (this->buffer_access_type == ubo_load_access) {
              base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
                                            ubo_load(deref->type, offset)));
          } else {
@@ -862,7 +872,7 @@ lower_ubo_reference_visitor::emit_access(bool is_write,
 
             base_ir->insert_after(ssbo_store(swizzle(deref, i, 1), chan_offset, 1));
          } else {
-            if (!this->is_shader_storage) {
+            if (this->buffer_access_type == ubo_load_access) {
                base_ir->insert_before(assign(deref->clone(mem_ctx, NULL),
                                              ubo_load(deref_type, chan_offset),
                                              (1U << i)));
@@ -891,6 +901,8 @@ lower_ubo_reference_visitor::write_to_memory(ir_dereference *deref,
    int matrix_columns;
    unsigned packing = var->get_interface_type()->interface_packing;
 
+   this->buffer_access_type = ssbo_store_access;
+
    /* Compute the offset to the start if the dereference as well as other
     * information we need to configure the write
     */
@@ -1068,6 +1080,8 @@ lower_ubo_reference_visitor::process_ssbo_unsized_array_length(ir_rvalue **rvalu
    unsigned packing = var->get_interface_type()->interface_packing;
    int unsized_array_stride = calculate_unsized_array_stride(deref, packing);
 
+   this->buffer_access_type = ssbo_unsized_array_length_access;
+
    /* Compute the offset to the start if the dereference as well as other
     * information we need to calculate the length.
     */
@@ -1181,6 +1195,8 @@ lower_ubo_reference_visitor::lower_ssbo_atomic_intrinsic(ir_call *ir)
    int matrix_columns;
    unsigned packing = var->get_interface_type()->interface_packing;
 
+   this->buffer_access_type = ssbo_atomic_access;
+
    setup_for_load_or_store(var, deref,
                            &offset, &const_offset,
                            &row_major, &matrix_columns,
-- 
2.6.2



More information about the mesa-dev mailing list