From bc4f089d0167dc22fb86c85fbd0fd0fa6f073a85 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 6 Jan 2020 12:00:57 -0800 Subject: mesa/st: Move the dword slot counting function to glsl_types as well. To implement NIR-to-TGSI, we need to be able to get the size of the uniform variable for the TGSI declaration, not just the .driver_location. With its location in mesa/st, drivers couldn't link to it from nir-to-tgsi. This feels like a common enough function to want, so let's share it in the core compiler. Reviewed-by: Kristian H. Kristensen Part-of: --- src/compiler/glsl_types.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/compiler/glsl_types.h | 8 +++++++ src/compiler/nir_types.cpp | 6 ++++++ src/compiler/nir_types.h | 1 + 4 files changed, 67 insertions(+) (limited to 'src/compiler') diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index a814166f9e5..e664f4ab4cd 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -2517,6 +2517,58 @@ glsl_type::count_vec4_slots(bool is_gl_vertex_input, bool is_bindless) const return 0; } +unsigned +glsl_type::count_dword_slots(bool is_bindless) const +{ + switch (this->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + case GLSL_TYPE_FLOAT: + case GLSL_TYPE_BOOL: + return this->components(); + case GLSL_TYPE_UINT16: + case GLSL_TYPE_INT16: + case GLSL_TYPE_FLOAT16: + return DIV_ROUND_UP(this->components(), 2); + case GLSL_TYPE_UINT8: + case GLSL_TYPE_INT8: + return DIV_ROUND_UP(this->components(), 4); + case GLSL_TYPE_IMAGE: + case GLSL_TYPE_SAMPLER: + if (!is_bindless) + return 0; + /* FALLTHROUGH */ + case GLSL_TYPE_DOUBLE: + case GLSL_TYPE_UINT64: + case GLSL_TYPE_INT64: + return this->components() * 2; + case GLSL_TYPE_ARRAY: + return this->fields.array->count_dword_slots(is_bindless) * + this->length; + + case GLSL_TYPE_STRUCT: { + unsigned size = 0; + for (unsigned i = 0; i < this->length; i++) { + size += this->fields.structure[i].type->count_dword_slots(is_bindless); + } + return size; + } + + case GLSL_TYPE_ATOMIC_UINT: + return 0; + case GLSL_TYPE_SUBROUTINE: + return 1; + case GLSL_TYPE_VOID: + case GLSL_TYPE_ERROR: + case GLSL_TYPE_INTERFACE: + case GLSL_TYPE_FUNCTION: + default: + unreachable("invalid type in st_glsl_type_dword_size()"); + } + + return 0; +} + int glsl_type::coordinate_components() const { diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h index c29d589a148..76a6fd2e448 100644 --- a/src/compiler/glsl_types.h +++ b/src/compiler/glsl_types.h @@ -481,6 +481,14 @@ public: */ unsigned count_vec4_slots(bool is_gl_vertex_input, bool bindless) const; + /** + * Calculate the number of vec4 slots required to hold this type. + * + * This is the underlying recursive type_size function for + * gallium's PIPE_CAP_PACKED_UNIFORMS case. + */ + unsigned count_dword_slots(bool bindless) const; + /** * Calculate the number of attribute slots required to hold this type * diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp index ecceffeb351..1e45df74452 100644 --- a/src/compiler/nir_types.cpp +++ b/src/compiler/nir_types.cpp @@ -159,6 +159,12 @@ glsl_count_vec4_slots(const struct glsl_type *type, return type->count_vec4_slots(is_gl_vertex_input, is_bindless); } +unsigned +glsl_count_dword_slots(const struct glsl_type *type, bool is_bindless) +{ + return type->count_dword_slots(is_bindless); +} + unsigned glsl_count_attribute_slots(const struct glsl_type *type, bool is_gl_vertex_input) diff --git a/src/compiler/nir_types.h b/src/compiler/nir_types.h index ff4c7fae85a..d61cfeb3978 100644 --- a/src/compiler/nir_types.h +++ b/src/compiler/nir_types.h @@ -82,6 +82,7 @@ unsigned glsl_get_aoa_size(const struct glsl_type *type); unsigned glsl_count_vec4_slots(const struct glsl_type *type, bool is_gl_vertex_input, bool is_bindless); +unsigned glsl_count_dword_slots(const struct glsl_type *type, bool is_bindless); unsigned glsl_count_attribute_slots(const struct glsl_type *type, bool is_gl_vertex_input); unsigned glsl_get_component_slots(const struct glsl_type *type); -- cgit v1.2.3