diff options
author | Jason Ekstrand <[email protected]> | 2019-06-06 09:53:27 -0500 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2019-06-19 21:05:54 +0000 |
commit | aa11c2e75e191f8201fe5462ef8c14e81dde964e (patch) | |
tree | f5c007cfd5d44fe520518f5133ea9df5b80629c2 /src/compiler/spirv | |
parent | 93f4aa98894cbc57325b90ecb128b22e6448de23 (diff) |
spirv: Add a vtn_constant_int helper
Reviewed-by: Karol Herbst <[email protected]>
Diffstat (limited to 'src/compiler/spirv')
-rw-r--r-- | src/compiler/spirv/vtn_private.h | 18 | ||||
-rw-r--r-- | src/compiler/spirv/vtn_variables.c | 18 |
2 files changed, 19 insertions, 17 deletions
diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index 1b2be93621f..58b9553c1b8 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -716,6 +716,24 @@ vtn_constant_uint(struct vtn_builder *b, uint32_t value_id) } } +static inline int64_t +vtn_constant_int(struct vtn_builder *b, uint32_t value_id) +{ + 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][0].i8; + case 16: return val->constant->values[0][0].i16; + case 32: return val->constant->values[0][0].i32; + case 64: return val->constant->values[0][0].i64; + default: unreachable("Invalid bit size"); + } +} + struct vtn_ssa_value *vtn_ssa_value(struct vtn_builder *b, uint32_t value_id); struct vtn_ssa_value *vtn_create_ssa_value(struct vtn_builder *b, diff --git a/src/compiler/spirv/vtn_variables.c b/src/compiler/spirv/vtn_variables.c index 925d2549d4c..1a9ca0745fa 100644 --- a/src/compiler/spirv/vtn_variables.c +++ b/src/compiler/spirv/vtn_variables.c @@ -2403,23 +2403,7 @@ vtn_handle_variables(struct vtn_builder *b, SpvOp opcode, struct vtn_value *link_val = vtn_untyped_value(b, w[i]); if (link_val->value_type == vtn_value_type_constant) { chain->link[idx].mode = vtn_access_mode_literal; - const unsigned bit_size = glsl_get_bit_size(link_val->type->type); - switch (bit_size) { - case 8: - chain->link[idx].id = link_val->constant->values[0][0].i8; - break; - case 16: - chain->link[idx].id = link_val->constant->values[0][0].i16; - break; - case 32: - chain->link[idx].id = link_val->constant->values[0][0].i32; - break; - case 64: - chain->link[idx].id = link_val->constant->values[0][0].i64; - break; - default: - vtn_fail("Invalid bit size: %u", bit_size); - } + chain->link[idx].id = vtn_constant_int(b, w[i]); } else { chain->link[idx].mode = vtn_access_mode_id; chain->link[idx].id = w[i]; |