diff options
author | Jason Ekstrand <[email protected]> | 2017-12-11 22:42:26 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-01-08 14:57:44 -0800 |
commit | 03c543d041c6c7c86a2e7ef0f666f2b1f6dd311d (patch) | |
tree | 725219f3b90b7119fdb42853e7e012ce2802e42f /src/compiler/spirv | |
parent | 936f49268e1a3906130d213fe859b13e85fe0c53 (diff) |
spirv: Switch on vtn_base_type in OpComposite(Extract|Insert)
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.
Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/compiler/spirv')
-rw-r--r-- | src/compiler/spirv/spirv_to_nir.c | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index b639dcdc939..67c74d70aca 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -1485,44 +1485,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)); } } @@ -1530,8 +1525,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: @@ -1550,12 +1545,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: |