[Mesa-dev] [PATCH] glsl: use enum glsl_interface_packing in more places.

Dave Airlie airlied at gmail.com
Wed May 11 00:50:29 UTC 2016


From: Dave Airlie <airlied at redhat.com>

Although the glsl_types.h stores this in a bitfield,
we should hide that from everyone else. Hide the cast
in an accessor method and use the enum everywhere.

This makes things a bit nicer in gdb, and improves type
safety.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/compiler/glsl/ir.h                                  |  4 ++++
 src/compiler/glsl/link_uniform_block_active_visitor.cpp |  6 ++----
 src/compiler/glsl/link_uniform_blocks.cpp               |  6 +++---
 src/compiler/glsl/link_uniforms.cpp                     | 16 ++++++++--------
 src/compiler/glsl/linker.h                              |  2 +-
 src/compiler/glsl/lower_buffer_access.cpp               |  2 +-
 src/compiler/glsl/lower_buffer_access.h                 |  2 +-
 src/compiler/glsl/lower_shared_reference.cpp            |  6 +++---
 src/compiler/glsl/lower_ubo_reference.cpp               | 16 ++++++++--------
 src/compiler/glsl/opt_dead_code.cpp                     |  2 +-
 src/compiler/glsl_types.h                               |  8 ++++++++
 11 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
index 2bf04e68..ab06b13 100644
--- a/src/compiler/glsl/ir.h
+++ b/src/compiler/glsl/ir.h
@@ -534,6 +534,10 @@ public:
       return this->interface_type;
    }
 
+   enum glsl_interface_packing get_interface_type_packing() const
+   {
+     return this->interface_type->get_interface_packing();
+   }
    /**
     * Get the max_ifc_array_access pointer
     *
diff --git a/src/compiler/glsl/link_uniform_block_active_visitor.cpp b/src/compiler/glsl/link_uniform_block_active_visitor.cpp
index 54fea70..df8b221 100644
--- a/src/compiler/glsl/link_uniform_block_active_visitor.cpp
+++ b/src/compiler/glsl/link_uniform_block_active_visitor.cpp
@@ -167,8 +167,7 @@ link_uniform_block_active_visitor::visit(ir_variable *var)
     *     also considered active, even if no member of the block is
     *     referenced."
     */
-   if (var->get_interface_type()->interface_packing ==
-       GLSL_INTERFACE_PACKING_PACKED)
+   if (var->get_interface_type_packing() == GLSL_INTERFACE_PACKING_PACKED)
       return visit_continue;
 
    /* Process the block.  Bail if there was an error.
@@ -258,8 +257,7 @@ link_uniform_block_active_visitor::visit_enter(ir_dereference_array *ir)
     * std140 layout qualifier, all its instances have been already marked
     * as used in link_uniform_block_active_visitor::visit(ir_variable *).
     */
-   if (var->get_interface_type()->interface_packing ==
-       GLSL_INTERFACE_PACKING_PACKED) {
+   if (var->get_interface_type_packing() == GLSL_INTERFACE_PACKING_PACKED) {
       b->var = var;
       process_arrays(this->mem_ctx, ir, b);
    }
diff --git a/src/compiler/glsl/link_uniform_blocks.cpp b/src/compiler/glsl/link_uniform_blocks.cpp
index ac415b5..6f04cf6 100644
--- a/src/compiler/glsl/link_uniform_blocks.cpp
+++ b/src/compiler/glsl/link_uniform_blocks.cpp
@@ -68,7 +68,7 @@ private:
    }
 
    virtual void enter_record(const glsl_type *type, const char *,
-                             bool row_major, const unsigned packing) {
+                             bool row_major, const enum glsl_interface_packing packing) {
       assert(type->is_record());
       if (packing == GLSL_INTERFACE_PACKING_STD430)
          this->offset = glsl_align(
@@ -79,7 +79,7 @@ private:
    }
 
    virtual void leave_record(const glsl_type *type, const char *,
-                             bool row_major, const unsigned packing) {
+                             bool row_major, const enum glsl_interface_packing packing) {
       assert(type->is_record());
 
       /* If this is the last field of a structure, apply rule #9.  The
@@ -104,7 +104,7 @@ private:
 
    virtual void visit_field(const glsl_type *type, const char *name,
                             bool row_major, const glsl_type *,
-                            const unsigned packing,
+                            const enum glsl_interface_packing packing,
                             bool last_field)
    {
       assert(this->index < this->num_variables);
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 92f1095..3021538 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -65,7 +65,7 @@ program_resource_visitor::process(const glsl_type *type, const char *name)
 
    unsigned record_array_count = 1;
    char *name_copy = ralloc_strdup(NULL, name);
-   unsigned packing = type->interface_packing;
+   enum glsl_interface_packing packing = type->get_interface_packing();
 
    recursion(type, &name_copy, strlen(name), false, NULL, packing, false,
              record_array_count, NULL);
@@ -79,9 +79,9 @@ program_resource_visitor::process(ir_variable *var)
    const bool row_major =
       var->data.matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR;
 
-   const unsigned packing = var->get_interface_type() ?
-      var->get_interface_type()->interface_packing :
-      var->type->interface_packing;
+   const enum glsl_interface_packing packing = var->get_interface_type() ?
+      var->get_interface_type_packing() :
+      var->type->get_interface_packing();
 
    const glsl_type *t =
       var->data.from_named_ifc_block ? var->get_interface_type() : var->type;
@@ -116,7 +116,7 @@ void
 program_resource_visitor::recursion(const glsl_type *t, char **name,
                                     size_t name_length, bool row_major,
                                     const glsl_type *record_type,
-                                    const unsigned packing,
+                                    const enum glsl_interface_packing packing,
                                     bool last_field,
                                     unsigned record_array_count,
                                     const glsl_struct_field *named_ifc_member)
@@ -660,7 +660,7 @@ private:
    }
 
    virtual void enter_record(const glsl_type *type, const char *,
-                             bool row_major, const unsigned packing) {
+                             bool row_major, const enum glsl_interface_packing packing) {
       assert(type->is_record());
       if (this->buffer_block_index == -1)
          return;
@@ -673,7 +673,7 @@ private:
    }
 
    virtual void leave_record(const glsl_type *type, const char *,
-                             bool row_major, const unsigned packing) {
+                             bool row_major, const enum glsl_interface_packing packing) {
       assert(type->is_record());
       if (this->buffer_block_index == -1)
          return;
@@ -687,7 +687,7 @@ private:
 
    virtual void visit_field(const glsl_type *type, const char *name,
                             bool row_major, const glsl_type *record_type,
-                            const unsigned packing,
+                            const enum glsl_interface_packing packing,
                             bool /* last_field */)
    {
       assert(!type->without_array()->is_record());
diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h
index 3a0ec8b..5604f04 100644
--- a/src/compiler/glsl/linker.h
+++ b/src/compiler/glsl/linker.h
@@ -199,7 +199,7 @@ private:
     */
    void recursion(const glsl_type *t, char **name, size_t name_length,
                   bool row_major, const glsl_type *record_type,
-                  const unsigned packing,
+                  const enum glsl_interface_packing packing,
                   bool last_field, unsigned record_array_count,
                   const glsl_struct_field *named_ifc_member);
 };
diff --git a/src/compiler/glsl/lower_buffer_access.cpp b/src/compiler/glsl/lower_buffer_access.cpp
index 59a2ae8..bdfabab 100644
--- a/src/compiler/glsl/lower_buffer_access.cpp
+++ b/src/compiler/glsl/lower_buffer_access.cpp
@@ -328,7 +328,7 @@ lower_buffer_access::setup_buffer_access(void *mem_ctx,
                                          bool *row_major,
                                          int *matrix_columns,
                                          const glsl_struct_field **struct_field,
-                                         unsigned packing)
+                                         enum glsl_interface_packing packing)
 {
    *offset = new(mem_ctx) ir_constant(0u);
    *row_major = is_dereferenced_thing_row_major(deref);
diff --git a/src/compiler/glsl/lower_buffer_access.h b/src/compiler/glsl/lower_buffer_access.h
index 8772bdb..db9ac45 100644
--- a/src/compiler/glsl/lower_buffer_access.h
+++ b/src/compiler/glsl/lower_buffer_access.h
@@ -58,7 +58,7 @@ public:
                             ir_rvalue **offset, unsigned *const_offset,
                             bool *row_major, int *matrix_columns,
                             const glsl_struct_field **struct_field,
-                            unsigned packing);
+                            enum glsl_interface_packing packing);
 };
 
 } /* namespace lower_buffer_access */
diff --git a/src/compiler/glsl/lower_shared_reference.cpp b/src/compiler/glsl/lower_shared_reference.cpp
index 1249969..e63e7dd 100644
--- a/src/compiler/glsl/lower_shared_reference.cpp
+++ b/src/compiler/glsl/lower_shared_reference.cpp
@@ -138,7 +138,7 @@ lower_shared_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
    bool row_major;
    int matrix_columns;
    assert(var->get_interface_type() == NULL);
-   const unsigned packing = GLSL_INTERFACE_PACKING_STD430;
+   const enum glsl_interface_packing packing = GLSL_INTERFACE_PACKING_STD430;
 
    setup_buffer_access(mem_ctx, var, deref,
                        &offset, &const_offset,
@@ -206,7 +206,7 @@ lower_shared_reference_visitor::handle_assignment(ir_assignment *ir)
    bool row_major;
    int matrix_columns;
    assert(var->get_interface_type() == NULL);
-   const unsigned packing = GLSL_INTERFACE_PACKING_STD430;
+   const enum glsl_interface_packing packing = GLSL_INTERFACE_PACKING_STD430;
 
    setup_buffer_access(mem_ctx, var, deref,
                        &offset, &const_offset,
@@ -365,7 +365,7 @@ lower_shared_reference_visitor::lower_shared_atomic_intrinsic(ir_call *ir)
    bool row_major;
    int matrix_columns;
    assert(var->get_interface_type() == NULL);
-   const unsigned packing = GLSL_INTERFACE_PACKING_STD430;
+   const enum glsl_interface_packing packing = GLSL_INTERFACE_PACKING_STD430;
    buffer_access_type = shared_atomic_access;
 
    setup_buffer_access(mem_ctx, var, deref,
diff --git a/src/compiler/glsl/lower_ubo_reference.cpp b/src/compiler/glsl/lower_ubo_reference.cpp
index 1a0140f..3a75164 100644
--- a/src/compiler/glsl/lower_ubo_reference.cpp
+++ b/src/compiler/glsl/lower_ubo_reference.cpp
@@ -59,7 +59,7 @@ public:
                                 unsigned *const_offset,
                                 bool *row_major,
                                 int *matrix_columns,
-                                unsigned packing);
+                                enum glsl_interface_packing packing);
    uint32_t ssbo_access_params();
    ir_expression *ubo_load(void *mem_ctx, const struct glsl_type *type,
 			   ir_rvalue *offset);
@@ -97,7 +97,7 @@ public:
    ir_expression *emit_ssbo_get_buffer_size(void *mem_ctx);
 
    unsigned calculate_unsized_array_stride(ir_dereference *deref,
-                                           unsigned packing);
+                                           enum glsl_interface_packing packing);
 
    ir_call *lower_ssbo_atomic_intrinsic(ir_call *ir);
    ir_call *check_for_ssbo_atomic_intrinsic(ir_call *ir);
@@ -250,7 +250,7 @@ lower_ubo_reference_visitor::setup_for_load_or_store(void *mem_ctx,
                                                      unsigned *const_offset,
                                                      bool *row_major,
                                                      int *matrix_columns,
-                                                     unsigned packing)
+                                                     enum glsl_interface_packing packing)
 {
    /* Determine the name of the interface block */
    ir_rvalue *nonconst_block_index;
@@ -316,7 +316,7 @@ lower_ubo_reference_visitor::handle_rvalue(ir_rvalue **rvalue)
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   unsigned packing = var->get_interface_type()->interface_packing;
+   enum glsl_interface_packing packing = var->get_interface_type_packing();
 
    this->buffer_access_type =
       var->is_in_shader_storage_block() ?
@@ -529,7 +529,7 @@ lower_ubo_reference_visitor::write_to_memory(void *mem_ctx,
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   unsigned packing = var->get_interface_type()->interface_packing;
+   enum glsl_interface_packing packing = var->get_interface_type_packing();
 
    this->buffer_access_type = ssbo_store_access;
    this->variable = var;
@@ -638,7 +638,7 @@ lower_ubo_reference_visitor::emit_ssbo_get_buffer_size(void *mem_ctx)
 
 unsigned
 lower_ubo_reference_visitor::calculate_unsized_array_stride(ir_dereference *deref,
-                                                            unsigned packing)
+                                                            enum glsl_interface_packing packing)
 {
    unsigned array_stride = 0;
 
@@ -708,7 +708,7 @@ lower_ubo_reference_visitor::process_ssbo_unsized_array_length(ir_rvalue **rvalu
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   unsigned packing = var->get_interface_type()->interface_packing;
+   enum glsl_interface_packing packing = var->get_interface_type_packing();
    int unsized_array_stride = calculate_unsized_array_stride(deref, packing);
 
    this->buffer_access_type = ssbo_unsized_array_length_access;
@@ -942,7 +942,7 @@ lower_ubo_reference_visitor::lower_ssbo_atomic_intrinsic(ir_call *ir)
    unsigned const_offset;
    bool row_major;
    int matrix_columns;
-   unsigned packing = var->get_interface_type()->interface_packing;
+   enum glsl_interface_packing packing = var->get_interface_type_packing();
 
    this->buffer_access_type = ssbo_atomic_access;
    this->variable = var;
diff --git a/src/compiler/glsl/opt_dead_code.cpp b/src/compiler/glsl/opt_dead_code.cpp
index dbdb7de..3560119 100644
--- a/src/compiler/glsl/opt_dead_code.cpp
+++ b/src/compiler/glsl/opt_dead_code.cpp
@@ -144,7 +144,7 @@ do_dead_code(exec_list *instructions, bool uniform_locations_assigned)
              * layouts, do not eliminate it.
              */
             if (entry->var->is_in_buffer_block()) {
-               if (entry->var->get_interface_type()->interface_packing !=
+               if (entry->var->get_interface_type_packing() !=
                    GLSL_INTERFACE_PACKING_PACKED)
                   continue;
             }
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index a47b0ff..2976812 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -743,6 +743,14 @@ struct glsl_type {
     */
    bool record_compare(const glsl_type *b) const;
 
+   /**
+    * Get the type interface packing.
+    */
+   enum glsl_interface_packing get_interface_packing() const
+   {
+      return (enum glsl_interface_packing)interface_packing;
+   }
+
 private:
 
    static mtx_t mutex;
-- 
2.5.5



More information about the mesa-dev mailing list