summaryrefslogtreecommitdiffstats
path: root/src/compiler/spirv
diff options
context:
space:
mode:
authorKarol Herbst <[email protected]>2018-03-04 19:06:24 +0100
committerKarol Herbst <[email protected]>2019-03-19 04:08:07 +0000
commit659f333b3a4ff92ff985b168728ad37fe3d7e437 (patch)
treeb8d1344245f3b7c9c84bca9f7866668ab48dba67 /src/compiler/spirv
parentb98955e128ca3470d89c925f58567f2369f8072a (diff)
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 <[email protected]> Reviewed-by: Erik Faye-Lund <[email protected]>
Diffstat (limited to 'src/compiler/spirv')
-rw-r--r--src/compiler/spirv/spirv_to_nir.c17
-rw-r--r--src/compiler/spirv/vtn_private.h7
2 files changed, 23 insertions, 1 deletions
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 */