summaryrefslogtreecommitdiffstats
path: root/src/compiler/spirv/spirv_to_nir.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-12-11 22:09:02 -0800
committerJason Ekstrand <[email protected]>2018-01-08 14:57:44 -0800
commitf13a5cff723eb9a7baf5850fdbf8d7ebefbb1677 (patch)
treef2dbc15c2040075278cb6b9d5b2efe0332cc23e5 /src/compiler/spirv/spirv_to_nir.c
parent0bb18858fb67558ed8f9173de33c0ea31edf6530 (diff)
spirv: Unify boolean constants and add better validation
Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/compiler/spirv/spirv_to_nir.c')
-rw-r--r--src/compiler/spirv/spirv_to_nir.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 39c0b5f5dbc..ebc1fefc517 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -1281,19 +1281,20 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
val->constant = rzalloc(b, nir_constant);
switch (opcode) {
case SpvOpConstantTrue:
- vtn_assert(val->type->type == glsl_bool_type());
- val->constant->values[0].u32[0] = NIR_TRUE;
- break;
case SpvOpConstantFalse:
- vtn_assert(val->type->type == glsl_bool_type());
- val->constant->values[0].u32[0] = NIR_FALSE;
- break;
-
case SpvOpSpecConstantTrue:
case SpvOpSpecConstantFalse: {
- vtn_assert(val->type->type == glsl_bool_type());
- uint32_t int_val =
- get_specialization(b, val, (opcode == SpvOpSpecConstantTrue));
+ vtn_fail_if(val->type->type != glsl_bool_type(),
+ "Result type of %s must be OpTypeBool",
+ spirv_op_to_string(opcode));
+
+ uint32_t int_val = (opcode == SpvOpConstantTrue ||
+ opcode == SpvOpSpecConstantTrue);
+
+ if (opcode == SpvOpSpecConstantTrue ||
+ opcode == SpvOpSpecConstantFalse)
+ int_val = get_specialization(b, val, int_val);
+
val->constant->values[0].u32[0] = int_val ? NIR_TRUE : NIR_FALSE;
break;
}