From 659f333b3a4ff92ff985b168728ad37fe3d7e437 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Sun, 4 Mar 2018 19:06:24 +0100 Subject: glsl: add packed for struct types We need this for OpenCL kernels because we have to apply C rules for alignment and padding inside structs and for this we also have to know if a struct is packed or not. v2: fix for kernel params Signed-off-by: Karol Herbst Reviewed-by: Erik Faye-Lund --- src/compiler/spirv/spirv_to_nir.c | 17 ++++++++++++++++- src/compiler/spirv/vtn_private.h | 7 +++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/compiler/spirv') diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c index 3b7f8d8a9ac..5becd3418da 100644 --- a/src/compiler/spirv/spirv_to_nir.c +++ b/src/compiler/spirv/spirv_to_nir.c @@ -819,6 +819,13 @@ struct_member_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 + ctx->type->packed = true; + break; + case SpvDecorationSaturatedConversion: case SpvDecorationFuncParamAttr: case SpvDecorationFPRoundingMode: @@ -979,6 +986,13 @@ 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; + break; + case SpvDecorationSaturatedConversion: case SpvDecorationFuncParamAttr: case SpvDecorationFPRoundingMode: @@ -1242,6 +1256,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, val->type->length = num_fields; val->type->members = ralloc_array(b, struct vtn_type *, num_fields); val->type->offsets = ralloc_array(b, unsigned, num_fields); + val->type->packed = false; NIR_VLA(struct glsl_struct_field, fields, count); for (unsigned i = 0; i < num_fields; i++) { @@ -1266,7 +1281,7 @@ vtn_handle_type(struct vtn_builder *b, SpvOp opcode, const char *name = val->name ? val->name : "struct"; - val->type->type = glsl_struct_type(fields, num_fields, name); + val->type->type = glsl_struct_type(fields, num_fields, name, false); break; } diff --git a/src/compiler/spirv/vtn_private.h b/src/compiler/spirv/vtn_private.h index bdf326c26f7..20aedc170d9 100644 --- a/src/compiler/spirv/vtn_private.h +++ b/src/compiler/spirv/vtn_private.h @@ -335,6 +335,13 @@ struct vtn_type { * (i.e. a block that contains only builtins). */ bool builtin_block:1; + + /* for structs and unions it specifies the minimum alignment of the + * members. 0 means packed. + * + * Set by CPacked and Alignment Decorations in kernels. + */ + bool packed:1; }; /* Members for pointer types */ -- cgit v1.2.3