Skip to content

Commit df3b1cb

Browse files
Merge pull request #2521 from KhronosGroup/fix-2515
MSL: Fix edge case where a reference is taken of packed vector element.
2 parents 0238ebf + 6d5e12d commit df3b1cb

12 files changed

+75
-16
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma clang diagnostic ignored "-Wunused-variable"
2+
3+
#include <metal_stdlib>
4+
#include <simd/simd.h>
5+
#include <metal_atomic>
6+
7+
using namespace metal;
8+
9+
struct AttData0
10+
{
11+
packed_uint3 att0[1];
12+
};
13+
14+
kernel void main0(device AttData0& __restrict _22 [[buffer(0)]])
15+
{
16+
uint newVal = 432u;
17+
uint prevVal = 0u;
18+
uint curVal = 0u;
19+
for (;;)
20+
{
21+
uint _30;
22+
do
23+
{
24+
_30 = prevVal;
25+
} while (!atomic_compare_exchange_weak_explicit((device atomic_uint*)&((device uint*)&_22.att0[0])[0u], &_30, newVal, memory_order_relaxed, memory_order_relaxed) && _30 == prevVal);
26+
curVal = _30;
27+
if (_30 != prevVal)
28+
{
29+
continue;
30+
}
31+
else
32+
{
33+
break;
34+
}
35+
}
36+
}
37+

reference/shaders-msl-no-opt/packing/isolated-scalar-access.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ kernel void main0(device SSBO& _12 [[buffer(0)]])
1717
threadgroup float4 shared_vec4;
1818
threadgroup float3 shared_vec3;
1919
((device float*)&_12.v)[0u] = 10.0;
20-
_12.v3[1u] = 40.0;
20+
((device float*)&_12.v3)[1u] = 40.0;
2121
((device float*)&_12.cm[1])[2u] = 20.0;
2222
((device float*)&_12.rm[1u])[3] = 30.0;
2323
((threadgroup float*)&shared_vec4)[2u] = 40.0;

reference/shaders-msl-no-opt/packing/matrix-2x3-scalar.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ void copy_columns(device SSBOCol& _29, device SSBORow& _41)
7474
static inline __attribute__((always_inline))
7575
void copy_elements(device SSBOCol& _29, device SSBORow& _41)
7676
{
77-
_29.col_major0[0][1u] = ((device float*)&_41.row_major0[1u])[0];
78-
((device float*)&_41.row_major0[1u])[0] = _29.col_major0[0][1u];
77+
((device float*)&_29.col_major0[0])[1u] = ((device float*)&_41.row_major0[1u])[0];
78+
((device float*)&_41.row_major0[1u])[0] = ((device float*)&_29.col_major0[0])[1u];
7979
}
8080

8181
kernel void main0(device SSBOCol& _29 [[buffer(0)]], device SSBORow& _41 [[buffer(1)]])

reference/shaders-msl-no-opt/packing/matrix-3x2-scalar.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ void copy_columns(device SSBOCol& _29, device SSBORow& _41)
7373
static inline __attribute__((always_inline))
7474
void copy_elements(device SSBOCol& _29, device SSBORow& _41)
7575
{
76-
((device float*)&_29.col_major0[0])[1u] = _41.row_major0[1u][0];
77-
_41.row_major0[1u][0] = ((device float*)&_29.col_major0[0])[1u];
76+
((device float*)&_29.col_major0[0])[1u] = ((device float*)&_41.row_major0[1u])[0];
77+
((device float*)&_41.row_major0[1u])[0] = ((device float*)&_29.col_major0[0])[1u];
7878
}
7979

8080
kernel void main0(device SSBOCol& _29 [[buffer(0)]], device SSBORow& _41 [[buffer(1)]])

reference/shaders-msl-no-opt/packing/matrix-3x3-scalar.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ void copy_columns(device SSBOCol& _29, device SSBORow& _41)
8484
static inline __attribute__((always_inline))
8585
void copy_elements(device SSBOCol& _29, device SSBORow& _41)
8686
{
87-
_29.col_major0[0][1u] = _41.row_major0[1u][0];
88-
_41.row_major0[1u][0] = _29.col_major0[0][1u];
87+
((device float*)&_29.col_major0[0])[1u] = ((device float*)&_41.row_major0[1u])[0];
88+
((device float*)&_41.row_major0[1u])[0] = ((device float*)&_29.col_major0[0])[1u];
8989
}
9090

9191
kernel void main0(device SSBOCol& _29 [[buffer(0)]], device SSBORow& _41 [[buffer(1)]])

reference/shaders-msl-no-opt/packing/matrix-3x4-scalar.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ void copy_columns(device SSBOCol& _29, device SSBORow& _41)
8181
static inline __attribute__((always_inline))
8282
void copy_elements(device SSBOCol& _29, device SSBORow& _41)
8383
{
84-
((device float*)&_29.col_major0[0])[1u] = _41.row_major0[1u][0];
85-
_41.row_major0[1u][0] = ((device float*)&_29.col_major0[0])[1u];
84+
((device float*)&_29.col_major0[0])[1u] = ((device float*)&_41.row_major0[1u])[0];
85+
((device float*)&_41.row_major0[1u])[0] = ((device float*)&_29.col_major0[0])[1u];
8686
}
8787

8888
kernel void main0(device SSBOCol& _29 [[buffer(0)]], device SSBORow& _41 [[buffer(1)]])

reference/shaders-msl-no-opt/packing/matrix-4x3-scalar.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ void copy_columns(device SSBOCol& _29, device SSBORow& _41)
8080
static inline __attribute__((always_inline))
8181
void copy_elements(device SSBOCol& _29, device SSBORow& _41)
8282
{
83-
_29.col_major0[0][1u] = ((device float*)&_41.row_major0[1u])[0];
84-
((device float*)&_41.row_major0[1u])[0] = _29.col_major0[0][1u];
83+
((device float*)&_29.col_major0[0])[1u] = ((device float*)&_41.row_major0[1u])[0];
84+
((device float*)&_41.row_major0[1u])[0] = ((device float*)&_29.col_major0[0])[1u];
8585
}
8686

8787
kernel void main0(device SSBOCol& _29 [[buffer(0)]], device SSBORow& _41 [[buffer(1)]])

reference/shaders-msl-no-opt/packing/struct-packing-array-of-scalar.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
1717

1818
kernel void main0(device SSBOScalar& buffer_scalar [[buffer(0)]])
1919
{
20-
buffer_scalar.v[1].a[1u] = 1.0;
20+
((device float*)&buffer_scalar.v[1].a)[1u] = 1.0;
2121
}
2222

reference/shaders-msl-no-opt/packing/struct-packing-recursive.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
2828

2929
kernel void main0(device SSBOScalar& buffer_scalar [[buffer(0)]])
3030
{
31-
buffer_scalar.baz.a.a.a[3u] = 10.0;
31+
((device float*)&buffer_scalar.baz.a.a.a)[3u] = 10.0;
3232
}
3333

reference/shaders-msl-no-opt/packing/struct-packing.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);
2323

2424
kernel void main0(device SSBOScalar& buffer_scalar [[buffer(0)]])
2525
{
26-
buffer_scalar.foo.a[0u] = 10.0;
27-
buffer_scalar.bar.a[0u] = 20.0;
26+
((device float*)&buffer_scalar.foo.a)[0u] = 10.0;
27+
((device float*)&buffer_scalar.bar.a)[0u] = 20.0;
2828
}
2929

0 commit comments

Comments
 (0)