aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2020-01-06 12:00:57 -0800
committerMarge Bot <[email protected]>2020-01-14 23:55:00 +0000
commitbc4f089d0167dc22fb86c85fbd0fd0fa6f073a85 (patch)
tree7de37a77455a8e421f92cc6acef4c8e1b3e6fb4c /src/compiler
parent4cabd4812a6b2a15d15cd889778a36956574c9a3 (diff)
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 <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3297>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/glsl_types.cpp52
-rw-r--r--src/compiler/glsl_types.h8
-rw-r--r--src/compiler/nir_types.cpp6
-rw-r--r--src/compiler/nir_types.h1
4 files changed, 67 insertions, 0 deletions
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
@@ -482,6 +482,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
*
* This implements the language rules of GLSL 1.50 for counting the number
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
@@ -160,6 +160,12 @@ glsl_count_vec4_slots(const struct glsl_type *type,
}
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);