[Mesa-dev] [PATCH 1/8] spirv: Add a vtn_type field to all vtn_values
Samuel Iglesias Gonsálvez
siglesias at igalia.com
Mon Dec 11 12:51:25 UTC 2017
Patches 1, 3, 4, 5, 6, 7 are,
Reviewed-by: Samuel Iglesias Gonsálvez <siglesias at igalia.com>
Sam
On 07/12/17 17:12, Jason Ekstrand wrote:
> At the moment, this just lets us drop the const_type for constants and
> unify things a bit. Eventually, we will use this to store the types of
> all SPIR-V SSA values.
> ---
> src/compiler/spirv/spirv_to_nir.c | 63 +++++++++++++++++----------------------
> src/compiler/spirv/vtn_private.h | 7 ++---
> 2 files changed, 29 insertions(+), 41 deletions(-)
>
> diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
> index d321d1a..a50b14d 100644
> --- a/src/compiler/spirv/spirv_to_nir.c
> +++ b/src/compiler/spirv/spirv_to_nir.c
> @@ -257,7 +257,7 @@ vtn_ssa_value(struct vtn_builder *b, uint32_t value_id)
> return vtn_undef_ssa_value(b, val->type->type);
>
> case vtn_value_type_constant:
> - return vtn_const_ssa_value(b, val->constant, val->const_type);
> + return vtn_const_ssa_value(b, val->constant, val->type->type);
>
> case vtn_value_type_ssa:
> return val->ssa;
> @@ -1249,7 +1249,7 @@ handle_workgroup_size_decoration_cb(struct vtn_builder *b,
> dec->literals[0] != SpvBuiltInWorkgroupSize)
> return;
>
> - vtn_assert(val->const_type == glsl_vector_type(GLSL_TYPE_UINT, 3));
> + vtn_assert(val->type->type == glsl_vector_type(GLSL_TYPE_UINT, 3));
>
> b->shader->info.cs.local_size[0] = val->constant->values[0].u32[0];
> b->shader->info.cs.local_size[1] = val->constant->values[0].u32[1];
> @@ -1261,21 +1261,21 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> const uint32_t *w, unsigned count)
> {
> struct vtn_value *val = vtn_push_value(b, w[2], vtn_value_type_constant);
> - val->const_type = vtn_value(b, w[1], vtn_value_type_type)->type->type;
> + val->type = vtn_value(b, w[1], vtn_value_type_type)->type;
> val->constant = rzalloc(b, nir_constant);
> switch (opcode) {
> case SpvOpConstantTrue:
> - vtn_assert(val->const_type == glsl_bool_type());
> + vtn_assert(val->type->type == glsl_bool_type());
> val->constant->values[0].u32[0] = NIR_TRUE;
> break;
> case SpvOpConstantFalse:
> - vtn_assert(val->const_type == glsl_bool_type());
> + vtn_assert(val->type->type == glsl_bool_type());
> val->constant->values[0].u32[0] = NIR_FALSE;
> break;
>
> case SpvOpSpecConstantTrue:
> case SpvOpSpecConstantFalse: {
> - vtn_assert(val->const_type == glsl_bool_type());
> + vtn_assert(val->type->type == glsl_bool_type());
> uint32_t int_val =
> get_specialization(b, val, (opcode == SpvOpSpecConstantTrue));
> val->constant->values[0].u32[0] = int_val ? NIR_TRUE : NIR_FALSE;
> @@ -1283,8 +1283,8 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> }
>
> case SpvOpConstant: {
> - vtn_assert(glsl_type_is_scalar(val->const_type));
> - int bit_size = glsl_get_bit_size(val->const_type);
> + vtn_assert(glsl_type_is_scalar(val->type->type));
> + int bit_size = glsl_get_bit_size(val->type->type);
> switch (bit_size) {
> case 64:
> val->constant->values->u64[0] = vtn_u64_literal(&w[3]);
> @@ -1301,9 +1301,9 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> break;
> }
> case SpvOpSpecConstant: {
> - vtn_assert(glsl_type_is_scalar(val->const_type));
> + vtn_assert(glsl_type_is_scalar(val->type->type));
> val->constant->values[0].u32[0] = get_specialization(b, val, w[3]);
> - int bit_size = glsl_get_bit_size(val->const_type);
> + int bit_size = glsl_get_bit_size(val->type->type);
> switch (bit_size) {
> case 64:
> val->constant->values[0].u64[0] =
> @@ -1327,7 +1327,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> for (unsigned i = 0; i < elem_count; i++)
> elems[i] = vtn_value(b, w[i + 3], vtn_value_type_constant)->constant;
>
> - switch (glsl_get_base_type(val->const_type)) {
> + switch (glsl_get_base_type(val->type->type)) {
> case GLSL_TYPE_UINT:
> case GLSL_TYPE_INT:
> case GLSL_TYPE_UINT16:
> @@ -1338,14 +1338,14 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> case GLSL_TYPE_FLOAT16:
> case GLSL_TYPE_BOOL:
> case GLSL_TYPE_DOUBLE: {
> - int bit_size = glsl_get_bit_size(val->const_type);
> - if (glsl_type_is_matrix(val->const_type)) {
> - vtn_assert(glsl_get_matrix_columns(val->const_type) == elem_count);
> + int bit_size = glsl_get_bit_size(val->type->type);
> + if (glsl_type_is_matrix(val->type->type)) {
> + vtn_assert(glsl_get_matrix_columns(val->type->type) == elem_count);
> for (unsigned i = 0; i < elem_count; i++)
> val->constant->values[i] = elems[i]->values[0];
> } else {
> - vtn_assert(glsl_type_is_vector(val->const_type));
> - vtn_assert(glsl_get_vector_elements(val->const_type) == elem_count);
> + vtn_assert(glsl_type_is_vector(val->type->type));
> + vtn_assert(glsl_get_vector_elements(val->type->type) == elem_count);
> for (unsigned i = 0; i < elem_count; i++) {
> switch (bit_size) {
> case 64:
> @@ -1390,22 +1390,14 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> vtn_assert(v1->value_type == vtn_value_type_constant ||
> v1->value_type == vtn_value_type_undef);
>
> - unsigned len0 = v0->value_type == vtn_value_type_constant ?
> - glsl_get_vector_elements(v0->const_type) :
> - glsl_get_vector_elements(v0->type->type);
> - unsigned len1 = v1->value_type == vtn_value_type_constant ?
> - glsl_get_vector_elements(v1->const_type) :
> - glsl_get_vector_elements(v1->type->type);
> + unsigned len0 = glsl_get_vector_elements(v0->type->type);
> + unsigned len1 = glsl_get_vector_elements(v1->type->type);
>
> vtn_assert(len0 + len1 < 16);
>
> - unsigned bit_size = glsl_get_bit_size(val->const_type);
> - unsigned bit_size0 = v0->value_type == vtn_value_type_constant ?
> - glsl_get_bit_size(v0->const_type) :
> - glsl_get_bit_size(v0->type->type);
> - unsigned bit_size1 = v1->value_type == vtn_value_type_constant ?
> - glsl_get_bit_size(v1->const_type) :
> - glsl_get_bit_size(v1->type->type);
> + unsigned bit_size = glsl_get_bit_size(val->type->type);
> + unsigned bit_size0 = glsl_get_bit_size(v0->type->type);
> + unsigned bit_size1 = glsl_get_bit_size(v1->type->type);
>
> vtn_assert(bit_size == bit_size0 && bit_size == bit_size1);
> (void)bit_size0; (void)bit_size1;
> @@ -1476,7 +1468,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
>
> int elem = -1;
> int col = 0;
> - const struct glsl_type *type = comp->const_type;
> + const struct glsl_type *type = comp->type->type;
> for (unsigned i = deref_start; i < count; i++) {
> switch (glsl_get_base_type(type)) {
> case GLSL_TYPE_UINT:
> @@ -1541,7 +1533,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> } else {
> struct vtn_value *insert =
> vtn_value(b, w[4], vtn_value_type_constant);
> - vtn_assert(insert->const_type == type);
> + vtn_assert(insert->type->type == type);
> if (elem == -1) {
> *c = insert->constant;
> } else {
> @@ -1568,15 +1560,14 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
>
> default: {
> bool swap;
> - nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(val->const_type);
> + nir_alu_type dst_alu_type = nir_get_nir_type_for_glsl_type(val->type->type);
> nir_alu_type src_alu_type = dst_alu_type;
> nir_op op = vtn_nir_alu_op_for_spirv_opcode(b, opcode, &swap,
> src_alu_type,
> dst_alu_type);
>
> - unsigned num_components = glsl_get_vector_elements(val->const_type);
> - unsigned bit_size =
> - glsl_get_bit_size(val->const_type);
> + unsigned num_components = glsl_get_vector_elements(val->type->type);
> + unsigned bit_size = glsl_get_bit_size(val->type->type);
>
> nir_const_value src[4];
> vtn_assert(count <= 7);
> @@ -1598,7 +1589,7 @@ vtn_handle_constant(struct vtn_builder *b, SpvOp opcode,
> }
>
> case SpvOpConstantNull:
> - val->constant = vtn_null_constant(b, val->const_type);
> + val->constant = vtn_null_constant(b, val->type->type);
> break;
>
> case SpvOpConstantSampler:
> diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h
> index 5f140b4..6d4ad3c 100644
> --- a/src/compiler/spirv/vtn_private.h
> +++ b/src/compiler/spirv/vtn_private.h
> @@ -480,14 +480,11 @@ struct vtn_value {
> enum vtn_value_type value_type;
> const char *name;
> struct vtn_decoration *decoration;
> + struct vtn_type *type;
> union {
> void *ptr;
> char *str;
> - struct vtn_type *type;
> - struct {
> - nir_constant *constant;
> - const struct glsl_type *const_type;
> - };
> + nir_constant *constant;
> struct vtn_pointer *pointer;
> struct vtn_image_pointer *image;
> struct vtn_sampled_image *sampled_image;
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20171211/a514d61c/attachment.sig>
More information about the mesa-dev
mailing list