diff options
author | Jason Ekstrand <[email protected]> | 2019-01-22 11:57:48 -0600 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2019-02-01 17:34:02 +0000 |
commit | 9b37e93e4256ab1610bff5cdacc1e846467fc19d (patch) | |
tree | f8d236dffbbf14fee18c71416e34739007c81095 /src/compiler/spirv/vtn_private.h | |
parent | 5e7f800f32a3d7299b157bd3028fc46455f77e83 (diff) |
spirv: Replace vtn_constant_value with vtn_constant_uint
The uint version is less typing, supports different bit sizes, and is
probably a bit more safe because we're actually verifying that the
SPIR-V value is an integer scalar constant.
Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]>
Diffstat (limited to 'src/compiler/spirv/vtn_private.h')
-rw-r--r-- | src/compiler/spirv/vtn_private.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index 748a2a2e742..07e3311db2e 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -673,10 +673,22 @@ bool vtn_set_instruction_result_type(struct vtn_builder *b, SpvOp opcode, const uint32_t *w, unsigned count); -static inline nir_constant * -vtn_constant_value(struct vtn_builder *b, uint32_t value_id) +static inline uint64_t +vtn_constant_uint(struct vtn_builder *b, uint32_t value_id) { - return vtn_value(b, value_id, vtn_value_type_constant)->constant; + struct vtn_value *val = vtn_value(b, value_id, vtn_value_type_constant); + + vtn_fail_if(val->type->base_type != vtn_base_type_scalar || + !glsl_type_is_integer(val->type->type), + "Expected id %u to be an integer constant", value_id); + + switch (glsl_get_bit_size(val->type->type)) { + case 8: return val->constant->values[0].u8[0]; + case 16: return val->constant->values[0].u16[0]; + case 32: return val->constant->values[0].u32[0]; + case 64: return val->constant->values[0].u64[0]; + default: unreachable("Invalid bit size"); + } } struct vtn_ssa_value *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id); |