summaryrefslogtreecommitdiffstats
path: root/src/compiler/spirv/spirv_to_nir.c
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-12-11 23:03:58 -0800
committerJason Ekstrand <[email protected]>2018-01-08 14:57:44 -0800
commitd6a40993031b2ba088d92ce6ab832c50364d0f00 (patch)
tree678681c3e01af4f11bfebaf6aa6de773ea50658e /src/compiler/spirv/spirv_to_nir.c
parent03c543d041c6c7c86a2e7ef0f666f2b1f6dd311d (diff)
spirv: Add better type validation to OpTypeImage
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.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
index 67c74d70aca..0d474957dc9 100644
--- a/src/compiler/spirv/spirv_to_nir.c
+++ b/src/compiler/spirv/spirv_to_nir.c
@@ -1075,10 +1075,12 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
case SpvOpTypeImage: {
val->type->base_type = vtn_base_type_image;
- const struct glsl_type *sampled_type =
- vtn_value(b, w[2], vtn_value_type_type)->type->type;
+ const struct vtn_type *sampled_type =
+ vtn_value(b, w[2], vtn_value_type_type)->type;
- vtn_assert(glsl_type_is_vector_or_scalar(sampled_type));
+ vtn_fail_if(sampled_type->base_type != vtn_base_type_scalar ||
+ glsl_get_bit_size(sampled_type->type) != 32,
+ "Sampled type of OpTypeImage must be a 32-bit scalar");
enum glsl_sampler_dim dim;
switch ((SpvDim)w[3]) {
@@ -1090,7 +1092,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
case SpvDimBuffer: dim = GLSL_SAMPLER_DIM_BUF; break;
case SpvDimSubpassData: dim = GLSL_SAMPLER_DIM_SUBPASS; break;
default:
- vtn_fail("Invalid SPIR-V Sampler dimension");
+ vtn_fail("Invalid SPIR-V image dimensionality");
}
bool is_shadow = w[4];
@@ -1115,15 +1117,16 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode,
val->type->image_format = translate_image_format(b, format);
+ enum glsl_base_type sampled_base_type =
+ glsl_get_base_type(sampled_type->type);
if (sampled == 1) {
val->type->sampled = true;
val->type->type = glsl_sampler_type(dim, is_shadow, is_array,
- glsl_get_base_type(sampled_type));
+ sampled_base_type);
} else if (sampled == 2) {
vtn_assert(!is_shadow);
val->type->sampled = false;
- val->type->type = glsl_image_type(dim, is_array,
- glsl_get_base_type(sampled_type));
+ val->type->type = glsl_image_type(dim, is_array, sampled_base_type);
} else {
vtn_fail("We need to know if the image will be sampled");
}