[Mesa-dev] [PATCH 08/11] spirv: Switch on vtn_base_type in OpComposite(Extract|Insert)
Jason Ekstrand
jason at jlekstrand.net
Sun Dec 17 05:46:18 UTC 2017
This is a bit simpler since we have fewer enum values in the case. It's
also a bit more efficient because we're making fewer glsl_get_* calls.
While we're at it, add better type validation.
---
src/compiler/spirv/spirv_to_nir.c | 69 ++++++++++++++++++---------------------
1 file changed, 32 insertions(+), 37 deletions(-)
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 4a30a23..83c75c7 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -1486,44 +1486,39 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
int elem = -1;
int col = 0;
- const struct glsl_type *type = comp->type->type;
+ const struct vtn_type *type = comp->type;
for (unsigned i = deref_start; i < count; i++) {
- switch (glsl_get_base_type(type)) {
- case GLSL_TYPE_UINT:
- case GLSL_TYPE_INT:
- case GLSL_TYPE_UINT16:
- case GLSL_TYPE_INT16:
- case GLSL_TYPE_UINT64:
- case GLSL_TYPE_INT64:
- case GLSL_TYPE_FLOAT:
- case GLSL_TYPE_FLOAT16:
- case GLSL_TYPE_DOUBLE:
- case GLSL_TYPE_BOOL:
- /* If we hit this granularity, we're picking off an element */
- if (glsl_type_is_matrix(type)) {
- vtn_assert(col == 0 && elem == -1);
- col = w[i];
- elem = 0;
- type = glsl_get_column_type(type);
- } else {
- vtn_assert(elem <= 0 && glsl_type_is_vector(type));
- elem = w[i];
- type = glsl_scalar_type(glsl_get_base_type(type));
- }
- continue;
-
- case GLSL_TYPE_ARRAY:
+ vtn_fail_if(w[i] > type->length,
+ "%uth index of %s is %u but the type has only "
+ "%u elements", i - deref_start,
+ spirv_op_to_string(opcode), w[i], type->length);
+
+ switch (type->base_type) {
+ case vtn_base_type_vector:
+ elem = w[i];
+ type = type->array_element;
+ break;
+
+ case vtn_base_type_matrix:
+ assert(col == 0 && elem == -1);
+ col = w[i];
+ elem = 0;
+ type = type->array_element;
+ break;
+
+ case vtn_base_type_array:
c = &(*c)->elements[w[i]];
- type = glsl_get_array_element(type);
- continue;
+ type = type->array_element;
+ break;
- case GLSL_TYPE_STRUCT:
+ case vtn_base_type_struct:
c = &(*c)->elements[w[i]];
- type = glsl_get_struct_field(type, w[i]);
- continue;
+ type = type->members[w[i]];
+ break;
default:
- vtn_fail("Invalid constant type");
+ vtn_fail("%s must only index into composite types",
+ spirv_op_to_string(opcode));
}
}
@@ -1531,8 +1526,8 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
if (elem == -1) {
val->constant = *c;
} else {
- unsigned num_components = glsl_get_vector_elements(type);
- unsigned bit_size = glsl_get_bit_size(type);
+ unsigned num_components = type->length;
+ unsigned bit_size = glsl_get_bit_size(type->type);
for (unsigned i = 0; i < num_components; i++)
switch(bit_size) {
case 64:
@@ -1551,12 +1546,12 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
} else {
struct vtn_value *insert =
vtn_value(b, w[4], vtn_value_type_constant);
- vtn_assert(insert->type->type == type);
+ vtn_assert(insert->type == type);
if (elem == -1) {
*c = insert->constant;
} else {
- unsigned num_components = glsl_get_vector_elements(type);
- unsigned bit_size = glsl_get_bit_size(type);
+ unsigned num_components = type->length;
+ unsigned bit_size = glsl_get_bit_size(type->type);
for (unsigned i = 0; i < num_components; i++)
switch (bit_size) {
case 64:
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list