SPIRV-Cross/shaders-msl/comp/shared-matrix-array-of-array.comp
Chip Davis fc4a12fd4f MSL: Use a wrapper type for matrices in workgroup storage.
The standard `matrix` type in MSL lacked a constructor in the
`threadgroup` AS. This means that it was impossible to declare a
`threadgroup` variable that contains a matrix. This appears to have been
an oversight that was corrected in macOS 13/Xcode 14 beta 4. This
workaround continues to be required, however, for older systems.

To avoid changing interfaces unnecessarily (which shouldn't be a problem
regardless because the old and new types take up the same amount of
storage), only do this for structs if the struct is positively
identified as being used for workgroup storage.

I'm entirely aware this is inconsistent with the way packed matrices are
handled. One of them should be changed to match the other. Not sure
which one.

Fixes 23 CTS tests under `dEQP-VK.memory_model.shared`.
2022-08-07 17:31:41 -07:00

66 lines
2.4 KiB
Plaintext

#version 450
layout(local_size_x = 1) in;
layout(std140, binding = 0) buffer block { highp uint passed; };
struct S1 {
mediump mat4x3 a[2];
lowp float b;
lowp vec2 c[3];
};
struct S2 {
highp ivec4 a;
bool b[3][1][3];
};
bool compare_float (highp float a, highp float b) { return abs(a - b) < 0.05; }
bool compare_vec2 (highp vec2 a, highp vec2 b) { return compare_float(a.x, b.x)&&compare_float(a.y, b.y); }
bool compare_vec3 (highp vec3 a, highp vec3 b) { return compare_float(a.x, b.x)&&compare_float(a.y, b.y)&&compare_float(a.z, b.z); }
bool compare_mat4x3 (highp mat4x3 a, highp mat4x3 b){ return compare_vec3(a[0], b[0])&&compare_vec3(a[1], b[1])&&compare_vec3(a[2], b[2])&&compare_vec3(a[3], b[3]); }
bool compare_ivec4 (highp ivec4 a, highp ivec4 b) { return a == b; }
bool compare_bool (bool a, bool b) { return a == b; }
shared S1 s1;
shared S2 s2;
void main (void) {
s1.a[0] = mat4x3(0.0, 2.0, -8.0, 6.0, 7.0, 5.0, -6.0, 1.0, 9.0, -4.0, -3.0, 4.0);
s1.a[1] = mat4x3(4.0, 9.0, -9.0, -8.0, -9.0, 8.0, 0.0, 4.0, -4.0, 7.0, 2.0, -1.0);
s1.b = 7.0;
s1.c[0] = vec2(-5.0, -4.0);
s1.c[1] = vec2(3.0, -5.0);
s1.c[2] = vec2(-3.0, -1.0);
s2.a = ivec4(1, 0, -3, 1);
s2.b[0][0][0] = true;
s2.b[0][0][1] = false;
s2.b[0][0][2] = false;
s2.b[1][0][0] = true;
s2.b[1][0][1] = false;
s2.b[1][0][2] = true;
s2.b[2][0][0] = false;
s2.b[2][0][1] = true;
s2.b[2][0][2] = true;
barrier();
memoryBarrier();
bool allOk = true;
allOk = allOk && compare_mat4x3(mat4x3(0.0, 2.0, -8.0, 6.0, 7.0, 5.0, -6.0, 1.0, 9.0, -4.0, -3.0, 4.0), s1.a[0]);
allOk = allOk && compare_mat4x3(mat4x3(4.0, 9.0, -9.0, -8.0, -9.0, 8.0, 0.0, 4.0, -4.0, 7.0, 2.0, -1.0), s1.a[1]);
allOk = allOk && compare_float(7.0, s1.b);
allOk = allOk && compare_vec2(vec2(-5.0, -4.0), s1.c[0]);
allOk = allOk && compare_vec2(vec2(3.0, -5.0), s1.c[1]);
allOk = allOk && compare_vec2(vec2(-3.0, -1.0), s1.c[2]);
allOk = allOk && compare_ivec4(ivec4(1, 0, -3, 1), s2.a);
allOk = allOk && compare_bool(true, s2.b[0][0][0]);
allOk = allOk && compare_bool(false, s2.b[0][0][1]);
allOk = allOk && compare_bool(false, s2.b[0][0][2]);
allOk = allOk && compare_bool(true, s2.b[1][0][0]);
allOk = allOk && compare_bool(false, s2.b[1][0][1]);
allOk = allOk && compare_bool(true, s2.b[1][0][2]);
allOk = allOk && compare_bool(false, s2.b[2][0][0]);
allOk = allOk && compare_bool(true, s2.b[2][0][1]);
allOk = allOk && compare_bool(true, s2.b[2][0][2]);
if (allOk)
passed++;
}