glsl: use enum glsl_interface_packing in more places. (v2)
authorDave Airlie <airlied@redhat.com>
Wed, 11 May 2016 00:49:19 +0000 (10:49 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 6 Jun 2016 05:58:37 +0000 (15:58 +1000)
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.

v2: fix a few pieces of interface I missed that caused some
piglit regressions.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
src/compiler/glsl/ir.h
src/compiler/glsl/link_uniform_block_active_visitor.cpp
src/compiler/glsl/link_uniform_blocks.cpp
src/compiler/glsl/link_uniforms.cpp
src/compiler/glsl/linker.h
src/compiler/glsl/lower_buffer_access.cpp
src/compiler/glsl/lower_buffer_access.h
src/compiler/glsl/lower_shared_reference.cpp
src/compiler/glsl/lower_ubo_reference.cpp
src/compiler/glsl/opt_dead_code.cpp
src/compiler/glsl_types.h

index 93716c483de351005d2b2b5b8c427776956962f6..2afa94cf17077e8ba0d48278345ab40910d22935 100644 (file)
@@ -537,6 +537,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
     *
index 54fea700b5323c783016489f9586372b1a3caef5..df8b221af921faf9337b1cedbe25fff402bc1d43 100644 (file)
@@ -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);
    }
index 3c2d13c99c72dd34f40d52839f15360ad083de0f..b816dab9cb7d4202f920ad1f97280f347978e2a8 100644 (file)
@@ -70,7 +70,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(
@@ -81,7 +81,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
@@ -106,7 +106,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);
index ff2989f8cff7c15a0c545cf5ba0300da64282e2e..3a2ac4d30d762cd969ce83b0dafdf1239bad41b1 100644 (file)
@@ -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)
@@ -228,7 +228,7 @@ void
 program_resource_visitor::visit_field(const glsl_type *type, const char *name,
                                       bool row_major,
                                       const glsl_type *,
-                                      const unsigned,
+                                      const enum glsl_interface_packing,
                                       bool /* last_field */)
 {
    visit_field(type, name, row_major);
@@ -243,13 +243,13 @@ program_resource_visitor::visit_field(const glsl_struct_field *field)
 
 void
 program_resource_visitor::enter_record(const glsl_type *, const char *, bool,
-                                       const unsigned)
+                                       const enum glsl_interface_packing)
 {
 }
 
 void
 program_resource_visitor::leave_record(const glsl_type *, const char *, bool,
-                                       const unsigned)
+                                       const enum glsl_interface_packing)
 {
 }
 
@@ -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());
index 3a0ec8b35d3e76c7122b49c1c26f899ce49dbb7f..045dc1fff02c0708f36bf600b19fdc0239926dd4 100644 (file)
@@ -156,7 +156,7 @@ protected:
     */
    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);
 
    /**
@@ -180,10 +180,10 @@ protected:
    virtual void visit_field(const glsl_struct_field *field);
 
    virtual void enter_record(const glsl_type *type, const char *name,
-                             bool row_major, const unsigned packing);
+                             bool row_major, const enum glsl_interface_packing packing);
 
    virtual void leave_record(const glsl_type *type, const char *name,
-                             bool row_major, const unsigned packing);
+                             bool row_major, const enum glsl_interface_packing packing);
 
    virtual void set_buffer_offset(unsigned offset);
 
@@ -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);
 };
index 59a2ae8c69e48db8724a957312f08331b3a474bf..bdfababcbf9df08076168f5e81fc0defcbb986f4 100644 (file)
@@ -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);
index 8772bdb76ff5e6226e47541b8bfa87f66e27a090..db9ac45ef1079bdb0481f880e6209ef4ec5d7659 100644 (file)
@@ -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 */
index 12499695882833ed2a3e2734f33a3b0c5e8e66d3..e63e7dd819301f12acab4154159c51b20e3edd7a 100644 (file)
@@ -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,
index 749deedcd1c92519067cf4ba6cff1deb4031e74a..c27de0b2565d4ae2a78a3083f19d4d5d26e524ce 100644 (file)
@@ -61,7 +61,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);
@@ -99,7 +99,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);
@@ -273,7 +273,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;
@@ -344,7 +344,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() ?
@@ -557,7 +557,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;
@@ -666,7 +666,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;
 
@@ -736,7 +736,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;
@@ -970,7 +970,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;
index dbdb7de8bb873bb97828ac20131749f440e44eaf..35601196974aab6b0d50304ceaab15a41e53c68a 100644 (file)
@@ -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;
             }
index f9a377d764c2e6d78f1d5728e34e8d5d414d2e7b..4e3afe7d139e6e5dfe23e47f596eb27f2f3b533c 100644 (file)
@@ -745,6 +745,14 @@ struct glsl_type {
     */
    bool record_compare(const glsl_type *b, bool match_locations = true) 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;