From fc741596d4ab74348229763511291ea45bbf838a Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Tue, 23 Jul 2019 11:46:34 +0200 Subject: [PATCH] Add tests for struct padding and self-alignment. --- .../packing/member-padding.comp | 19 ++++++++++++++ .../packing/struct-alignment.comp | 25 +++++++++++++++++++ .../packing/member-padding.comp | 14 +++++++++++ .../packing/struct-alignment.comp | 22 ++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 reference/shaders-msl-no-opt/packing/member-padding.comp create mode 100644 reference/shaders-msl-no-opt/packing/struct-alignment.comp create mode 100644 shaders-msl-no-opt/packing/member-padding.comp create mode 100644 shaders-msl-no-opt/packing/struct-alignment.comp diff --git a/reference/shaders-msl-no-opt/packing/member-padding.comp b/reference/shaders-msl-no-opt/packing/member-padding.comp new file mode 100644 index 00000000..a0939047 --- /dev/null +++ b/reference/shaders-msl-no-opt/packing/member-padding.comp @@ -0,0 +1,19 @@ +#include +#include + +using namespace metal; + +struct SSBO +{ + char _m0_pad[16]; + float a; + char _m1_pad[20]; + float b; +}; + +kernel void main0(device SSBO& _9 [[buffer(0)]]) +{ + _9.a = 10.0; + _9.b = 20.0; +} + diff --git a/reference/shaders-msl-no-opt/packing/struct-alignment.comp b/reference/shaders-msl-no-opt/packing/struct-alignment.comp new file mode 100644 index 00000000..8baa8146 --- /dev/null +++ b/reference/shaders-msl-no-opt/packing/struct-alignment.comp @@ -0,0 +1,25 @@ +#include +#include + +using namespace metal; + +struct Foo +{ + packed_float3 a; + float b; +}; + +struct SSBO +{ + float2 a; + float b; + char _m2_pad[4]; + Foo foo; +}; + +kernel void main0(device SSBO& _12 [[buffer(0)]]) +{ + _12.a.x = 10.0; + _12.b = 20.0; +} + diff --git a/shaders-msl-no-opt/packing/member-padding.comp b/shaders-msl-no-opt/packing/member-padding.comp new file mode 100644 index 00000000..a413662f --- /dev/null +++ b/shaders-msl-no-opt/packing/member-padding.comp @@ -0,0 +1,14 @@ +#version 450 +layout(local_size_x = 1) in; + +layout(std140, set = 0, binding = 0) buffer SSBO +{ + layout(offset = 16) float a; + layout(offset = 40) float b; +}; + +void main() +{ + a = 10.0; + b = 20.0; +} diff --git a/shaders-msl-no-opt/packing/struct-alignment.comp b/shaders-msl-no-opt/packing/struct-alignment.comp new file mode 100644 index 00000000..f9f58b73 --- /dev/null +++ b/shaders-msl-no-opt/packing/struct-alignment.comp @@ -0,0 +1,22 @@ +#version 450 +layout(local_size_x = 1) in; + +struct Foo +{ + vec3 a; // <- This one should become packed_float3, and the MSL alignment of the struct is now 4. + float b; +}; + +layout(std140, set = 0, binding = 0) buffer SSBO +{ + vec2 a; + float b; + // <- We expect 4 bytes of padding here since MSL alignment of Foo must be lowered to 4. + Foo foo; +}; + +void main() +{ + a.x = 10.0; + b = 20.0; +}