summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2020-01-06 11:37:38 -0800
committerMarge Bot <[email protected]>2020-01-14 23:55:00 +0000
commit74ee3f76deec064577b2ce33b6a7ec9828868d57 (patch)
treef28104909fa0b512881acdc4746de1b76f896387 /src
parentb807f7a43a4df6a13ec365a4c2f152a81e64731b (diff)
mesa/st: Move the vec4 type size function into core GLSL types.
The only bit that gallium varied on was handling of bindless. We can retain previous behavior for count_attribute_slots() by passing in "true" (though I suspect this is just giving a silly answer to a silly question), and delete our recursive function from mesa/st. Reviewed-by: Kristian H. Kristensen <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3297>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/glsl_types.cpp16
-rw-r--r--src/compiler/glsl_types.h13
-rw-r--r--src/compiler/nir_types.cpp7
-rw-r--r--src/compiler/nir_types.h2
-rw-r--r--src/mesa/state_tracker/st_glsl_to_nir.cpp9
-rw-r--r--src/mesa/state_tracker/st_glsl_to_tgsi.cpp6
-rw-r--r--src/mesa/state_tracker/st_glsl_types.cpp94
-rw-r--r--src/mesa/state_tracker/st_glsl_types.h7
8 files changed, 45 insertions, 109 deletions
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index c958cc4b90d..a814166f9e5 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -2432,7 +2432,7 @@ glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info,
}
unsigned
-glsl_type::count_attribute_slots(bool is_gl_vertex_input) const
+glsl_type::count_vec4_slots(bool is_gl_vertex_input, bool is_bindless) const
{
/* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
*
@@ -2469,8 +2469,6 @@ glsl_type::count_attribute_slots(bool is_gl_vertex_input) const
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_BOOL:
- case GLSL_TYPE_SAMPLER:
- case GLSL_TYPE_IMAGE:
return this->matrix_columns;
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_UINT64:
@@ -2485,7 +2483,7 @@ glsl_type::count_attribute_slots(bool is_gl_vertex_input) const
for (unsigned i = 0; i < this->length; i++) {
const glsl_type *member_type = this->fields.structure[i].type;
- size += member_type->count_attribute_slots(is_gl_vertex_input);
+ size += member_type->count_vec4_slots(is_gl_vertex_input, is_bindless);
}
return size;
@@ -2493,9 +2491,17 @@ glsl_type::count_attribute_slots(bool is_gl_vertex_input) const
case GLSL_TYPE_ARRAY: {
const glsl_type *element = this->fields.array;
- return this->length * element->count_attribute_slots(is_gl_vertex_input);
+ return this->length * element->count_vec4_slots(is_gl_vertex_input,
+ is_bindless);
}
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
+ if (!is_bindless)
+ return 0;
+ else
+ return 1;
+
case GLSL_TYPE_SUBROUTINE:
return 1;
diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
index 10596603887..c29d589a148 100644
--- a/src/compiler/glsl_types.h
+++ b/src/compiler/glsl_types.h
@@ -473,6 +473,15 @@ public:
unsigned varying_count() const;
/**
+ * Calculate the number of vec4 slots required to hold this type.
+ *
+ * This is the underlying recursive type_size function for
+ * count_attribute_slots() (vertex inputs and varyings) but also for
+ * gallium's !PIPE_CAP_PACKED_UNIFORMS case.
+ */
+ unsigned count_vec4_slots(bool is_gl_vertex_input, 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
@@ -487,7 +496,9 @@ public:
* Vulkan doesn’t make this distinction so the argument should always be
* false.
*/
- unsigned count_attribute_slots(bool is_gl_vertex_input) const;
+ unsigned count_attribute_slots(bool is_gl_vertex_input) const {
+ return count_vec4_slots(is_gl_vertex_input, true);
+ }
/**
* Alignment in bytes of the start of this type in a std140 uniform
diff --git a/src/compiler/nir_types.cpp b/src/compiler/nir_types.cpp
index 817dae09e7b..ecceffeb351 100644
--- a/src/compiler/nir_types.cpp
+++ b/src/compiler/nir_types.cpp
@@ -153,6 +153,13 @@ 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)
+{
+ return type->count_vec4_slots(is_gl_vertex_input, 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 e1fbc830b1c..ff4c7fae85a 100644
--- a/src/compiler/nir_types.h
+++ b/src/compiler/nir_types.h
@@ -80,6 +80,8 @@ unsigned glsl_get_length(const struct glsl_type *type);
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_attribute_slots(const struct glsl_type *type,
bool is_gl_vertex_input);
unsigned glsl_get_component_slots(const struct glsl_type *type);
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index aad93fb71e2..d148e89d823 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -897,6 +897,12 @@ st_nir_lower_samplers(struct pipe_screen *screen, nir_shader *nir,
}
}
+static int
+st_unpacked_uniforms_type_size(const struct glsl_type *type, bool bindless)
+{
+ return glsl_count_vec4_slots(type, false, bindless);
+}
+
void
st_nir_lower_uniforms(struct st_context *st, nir_shader *nir)
{
@@ -905,7 +911,8 @@ st_nir_lower_uniforms(struct st_context *st, nir_shader *nir)
(nir_lower_io_options)0);
NIR_PASS_V(nir, nir_lower_uniforms_to_ubo, 4);
} else {
- NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, st_glsl_uniforms_type_size,
+ NIR_PASS_V(nir, nir_lower_io, nir_var_uniform,
+ st_unpacked_uniforms_type_size,
(nir_lower_io_options)0);
}
}
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index b6c2c2deb77..9a6bf30803f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -2766,12 +2766,12 @@ glsl_to_tgsi_visitor::visit(ir_dereference_array *ir)
if (handle_bound_deref(ir->as_dereference()))
return;
- /* We only need the logic provided by st_glsl_storage_type_size()
+ /* We only need the logic provided by count_vec4_slots()
* for arrays of structs. Indirect sampler and image indexing is handled
* elsewhere.
*/
int element_size = ir->type->without_array()->is_struct() ?
- st_glsl_storage_type_size(ir->type, var->data.bindless) :
+ ir->type->count_vec4_slots(false, var->data.bindless) :
type_size(ir->type);
index = ir->array_index->constant_expression_value(ralloc_parent(ir));
@@ -2876,7 +2876,7 @@ glsl_to_tgsi_visitor::visit(ir_dereference_record *ir)
if (i == (unsigned) ir->field_idx)
break;
const glsl_type *member_type = struct_type->fields.structure[i].type;
- offset += st_glsl_storage_type_size(member_type, var->data.bindless);
+ offset += member_type->count_vec4_slots(false, var->data.bindless);
}
/* If the type is smaller than a vec4, replicate the last channel out. */
diff --git a/src/mesa/state_tracker/st_glsl_types.cpp b/src/mesa/state_tracker/st_glsl_types.cpp
index b0b422f41fe..07275e3b8be 100644
--- a/src/mesa/state_tracker/st_glsl_types.cpp
+++ b/src/mesa/state_tracker/st_glsl_types.cpp
@@ -26,89 +26,6 @@
#include "st_glsl_types.h"
-/**
- * Returns the number of places to offset the uniform index, given the type of
- * a struct member. We use this because samplers and images have backing
- * storeage only when they are bindless.
- */
-int
-st_glsl_storage_type_size(const struct glsl_type *type, bool is_bindless)
-{
- unsigned int i;
- int size;
-
- switch (type->base_type) {
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_INT:
- case GLSL_TYPE_FLOAT:
- case GLSL_TYPE_BOOL:
- if (type->is_matrix()) {
- return type->matrix_columns;
- } else {
- /* Regardless of size of vector, it gets a vec4. This is bad
- * packing for things like floats, but otherwise arrays become a
- * mess. Hopefully a later pass over the code can pack scalars
- * down if appropriate.
- */
- return 1;
- }
- break;
- case GLSL_TYPE_DOUBLE:
- if (type->is_matrix()) {
- if (type->vector_elements <= 2)
- return type->matrix_columns;
- else
- return type->matrix_columns * 2;
- } else {
- /* For doubles if we have a double or dvec2 they fit in one
- * vec4, else they need 2 vec4s.
- */
- if (type->vector_elements <= 2)
- return 1;
- else
- return 2;
- }
- break;
- case GLSL_TYPE_UINT64:
- case GLSL_TYPE_INT64:
- if (type->vector_elements <= 2)
- return 1;
- else
- return 2;
- case GLSL_TYPE_ARRAY:
- assert(type->length > 0);
- return st_glsl_storage_type_size(type->fields.array, is_bindless) *
- type->length;
- case GLSL_TYPE_STRUCT:
- size = 0;
- for (i = 0; i < type->length; i++) {
- size += st_glsl_storage_type_size(type->fields.structure[i].type,
- is_bindless);
- }
- return size;
- case GLSL_TYPE_SAMPLER:
- case GLSL_TYPE_IMAGE:
- if (!is_bindless)
- return 0;
- /* fall through */
- case GLSL_TYPE_SUBROUTINE:
- return 1;
- case GLSL_TYPE_ATOMIC_UINT:
- case GLSL_TYPE_INTERFACE:
- case GLSL_TYPE_VOID:
- case GLSL_TYPE_ERROR:
- case GLSL_TYPE_FUNCTION:
- case GLSL_TYPE_FLOAT16:
- case GLSL_TYPE_UINT16:
- case GLSL_TYPE_INT16:
- case GLSL_TYPE_UINT8:
- case GLSL_TYPE_INT8:
- assert(!"Invalid type in type_size");
- break;
- }
- return 0;
-}
-
int
st_glsl_type_dword_size(const struct glsl_type *type, bool bindless)
{
@@ -159,14 +76,3 @@ st_glsl_type_dword_size(const struct glsl_type *type, bool bindless)
return 0;
}
-
-/**
- * Returns the type size of uniforms when !PIPE_CAP_PACKED_UNIFORMS -- each
- * value or array element is aligned to a vec4 offset and expanded out to a
- * vec4.
- */
-int
-st_glsl_uniforms_type_size(const struct glsl_type *type, bool bindless)
-{
- return st_glsl_storage_type_size(type, bindless);
-}
diff --git a/src/mesa/state_tracker/st_glsl_types.h b/src/mesa/state_tracker/st_glsl_types.h
index 1f2e5ab8f29..fb1c4a269d6 100644
--- a/src/mesa/state_tracker/st_glsl_types.h
+++ b/src/mesa/state_tracker/st_glsl_types.h
@@ -28,16 +28,13 @@
#define __ST_GLSL_TYPES_H__
#include "compiler/glsl_types.h"
+#include "compiler/nir/nir.h"
+#include "compiler/nir_types.h"
#ifdef __cplusplus
extern "C" {
#endif
-int st_glsl_storage_type_size(const struct glsl_type *type,
- bool is_bindless);
-
-int st_glsl_uniforms_type_size(const struct glsl_type *type, bool bindless);
-
int st_glsl_type_dword_size(const struct glsl_type *type, bool bindless);
#ifdef __cplusplus