From: Boris Brezillon Date: Tue, 23 Jun 2020 10:51:49 +0000 (+0200) Subject: spirv: Propagate packed information to glsl_type X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d0c2958f882a9644d98d61c49f3b8a842ea2c48f;p=mesa.git spirv: Propagate packed information to glsl_type We need to parse the CPacked decoration early enough to apply it when calculating field offsets and creating the struct type. Signed-off-by: Boris Brezillon Reviewed-by: Karol Herbst Reviewed-by: Jason Ekstrand Reviewed-by: Jesse Natalie Part-of: --- diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 6f29ab62484..6bd87bfc8db 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -1131,6 +1131,21 @@ struct_member_matrix_stride_cb(struct vtn_builder *b, ctx->fields[member].type = ctx->type->members[member]->type; } +static void +struct_packed_decoration_cb(struct vtn_builder *b, + struct vtn_value *val, int member, + const struct vtn_decoration *dec, void *void_ctx) +{ + vtn_assert(val->type->base_type == vtn_base_type_struct); + if (dec->decoration == SpvDecorationCPacked) { + if (b->shader->info.stage != MESA_SHADER_KERNEL) { + vtn_warn("Decoration only allowed for CL-style kernels: %s", + spirv_decoration_to_string(dec->decoration)); + } + val->type->packed = true; + } +} + static void struct_block_decoration_cb(struct vtn_builder *b, struct vtn_value *val, int member, @@ -1229,11 +1244,7 @@ type_decoration_cb(struct vtn_builder *b, break; case SpvDecorationCPacked: - if (b->shader->info.stage != MESA_SHADER_KERNEL) - vtn_warn("Decoration only allowed for CL-style kernels: %s", - spirv_decoration_to_string(dec->decoration)); - else - type->packed = true; + /* Handled when parsing a struct type, nothing to do here. */ break; case SpvDecorationSaturatedConversion: @@ -1457,10 +1468,13 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, }; } + vtn_foreach_decoration(b, val, struct_packed_decoration_cb, NULL); + if (b->shader->info.stage == MESA_SHADER_KERNEL) { unsigned offset = 0; for (unsigned i = 0; i < num_fields; i++) { - offset = align(offset, glsl_get_cl_alignment(fields[i].type)); + if (!val->type->packed) + offset = align(offset, glsl_get_cl_alignment(fields[i].type)); fields[i].offset = offset; offset += glsl_get_cl_size(fields[i].type); } @@ -1488,7 +1502,8 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, name ? name : "block"); } else { val->type->type = glsl_struct_type(fields, num_fields, - name ? name : "struct", false); + name ? name : "struct", + val->type->packed); } break; }