aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-12-11 22:25:09 -0800
committerJason Ekstrand <[email protected]>2018-01-08 14:57:44 -0800
commit936f49268e1a3906130d213fe859b13e85fe0c53 (patch)
tree7df75cb283b1b2a847c8bd4e46b646d90eb232b8 /src/compiler
parentdabce5061d9a49ebbf269d651e086e638be01aa9 (diff)
spirv: Refactor Op[Spec]ConstantComposite and add better validation
Now that vtn_base_type is a real and full base type, we can switch on that instead of the GLSL base type which is a lot fewer cases in our switch. Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/spirv/spirv_to_nir.c68
1 files changed, 32 insertions, 36 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 014de781cc1..b639dcdc939 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -1341,60 +1341,56 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
}
break;
}
+
case SpvOpSpecConstantComposite:
case SpvOpConstantComposite: {
unsigned elem_count = count - 3;
+ vtn_fail_if(elem_count != val->type->length,
+ "%s has %u constituents, expected %u",
+ spirv_op_to_string(opcode), elem_count, val->type->length);
+
nir_constant **elems = ralloc_array(b, nir_constant *, elem_count);
for (unsigned i = 0; i < elem_count; i++)
elems[i] = vtn_value(b, w[i + 3], vtn_value_type_constant)->constant;
- switch (glsl_get_base_type(val->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_BOOL:
- case GLSL_TYPE_DOUBLE: {
+ switch (val->type->base_type) {
+ case vtn_base_type_vector: {
+ assert(glsl_type_is_vector(val->type->type));
int bit_size = glsl_get_bit_size(val->type->type);
- if (glsl_type_is_matrix(val->type->type)) {
- vtn_assert(glsl_get_matrix_columns(val->type->type) == elem_count);
- for (unsigned i = 0; i < elem_count; i++)
- val->constant->values[i] = elems[i]->values[0];
- } else {
- vtn_assert(glsl_type_is_vector(val->type->type));
- vtn_assert(glsl_get_vector_elements(val->type->type) == elem_count);
- for (unsigned i = 0; i < elem_count; i++) {
- switch (bit_size) {
- case 64:
- val->constant->values[0].u64[i] = elems[i]->values[0].u64[0];
- break;
- case 32:
- val->constant->values[0].u32[i] = elems[i]->values[0].u32[0];
- break;
- case 16:
- val->constant->values[0].u16[i] = elems[i]->values[0].u16[0];
- break;
- default:
- vtn_fail("Invalid SpvOpConstantComposite bit size");
- }
+ for (unsigned i = 0; i < elem_count; i++) {
+ switch (bit_size) {
+ case 64:
+ val->constant->values[0].u64[i] = elems[i]->values[0].u64[0];
+ break;
+ case 32:
+ val->constant->values[0].u32[i] = elems[i]->values[0].u32[0];
+ break;
+ case 16:
+ val->constant->values[0].u16[i] = elems[i]->values[0].u16[0];
+ break;
+ default:
+ vtn_fail("Invalid SpvOpConstantComposite bit size");
}
}
- ralloc_free(elems);
break;
}
- case GLSL_TYPE_STRUCT:
- case GLSL_TYPE_ARRAY:
+
+ case vtn_base_type_matrix:
+ assert(glsl_type_is_matrix(val->type->type));
+ for (unsigned i = 0; i < elem_count; i++)
+ val->constant->values[i] = elems[i]->values[0];
+ break;
+
+ case vtn_base_type_struct:
+ case vtn_base_type_array:
ralloc_steal(val->constant, elems);
val->constant->num_elements = elem_count;
val->constant->elements = elems;
break;
default:
- vtn_fail("Unsupported type for constants");
+ vtn_fail("Result type of %s must be a composite type",
+ spirv_op_to_string(opcode));
}
break;
}