Commit aa11c2e7 authored by Jason Ekstrand's avatar Jason Ekstrand

spirv: Add a vtn_constant_int helper

Reviewed-by: Karol Herbst's avatarKarol Herbst <kherbst@redhat.com>
parent 93f4aa98
......@@ -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,
......
......@@ -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];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment