From 78659ade404a0761968ab5240c812e4c3119d669 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Wed, 11 May 2016 10:49:19 +1000 Subject: glsl: use enum glsl_interface_packing in more places. (v2) 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 Reviewed-by: Ilia Mirkin --- src/compiler/glsl/ir.h | 4 ++++ .../glsl/link_uniform_block_active_visitor.cpp | 6 ++---- src/compiler/glsl/link_uniform_blocks.cpp | 6 +++--- src/compiler/glsl/link_uniforms.cpp | 22 +++++++++++----------- src/compiler/glsl/linker.h | 8 ++++---- 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, 46 insertions(+), 36 deletions(-) diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h index 93716c483d..2afa94cf17 100644 --- a/src/compiler/glsl/ir.h +++ b/src/compiler/glsl/ir.h @@ -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 * diff --git a/src/compiler/glsl/link_uniform_block_active_visitor.cpp b/src/compiler/glsl/link_uniform_block_active_visitor.cpp index 54fea700b5..df8b221af9 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 3c2d13c99c..b816dab9cb 100644 --- a/src/compiler/glsl/link_uniform_blocks.cpp +++ b/src/compiler/glsl/link_uniform_blocks.cpp @@ -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); diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp index ff2989f8cf..3a2ac4d30d 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) @@ -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()); diff --git a/src/compiler/glsl/linker.h b/src/compiler/glsl/linker.h index 3a0ec8b35d..045dc1fff0 100644 --- a/src/compiler/glsl/linker.h +++ b/src/compiler/glsl/linker.h @@ -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); }; diff --git a/src/compiler/glsl/lower_buffer_access.cpp b/src/compiler/glsl/lower_buffer_access.cpp index 59a2ae8c69..bdfababcbf 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 8772bdb76f..db9ac45ef1 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 1249969588..e63e7dd819 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 749deedcd1..c27de0b256 100644 --- a/src/compiler/glsl/lower_ubo_reference.cpp +++ b/src/compiler/glsl/lower_ubo_reference.cpp @@ -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; diff --git a/src/compiler/glsl/opt_dead_code.cpp b/src/compiler/glsl/opt_dead_code.cpp index dbdb7de8bb..3560119697 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 f9a377d764..4e3afe7d13 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -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; -- cgit v1.2.3