-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1284 from KhronosGroup/fix-1282
MSL: Reintroduce workarounds for arrays not being value types
- Loading branch information
Showing
20 changed files
with
881 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
reference/opt/shaders-msl/comp/composite-array-initialization.force-native-array.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct Data | ||
{ | ||
float a; | ||
float b; | ||
}; | ||
|
||
constant float X_tmp [[function_constant(0)]]; | ||
constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0; | ||
|
||
struct Data_1 | ||
{ | ||
float a; | ||
float b; | ||
}; | ||
|
||
struct SSBO | ||
{ | ||
Data_1 outdata[1]; | ||
}; | ||
|
||
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(2u, 1u, 1u); | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromConstantToStack1(thread T (&dst)[A], constant T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromConstantToThreadGroup1(threadgroup T (&dst)[A], constant T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromStackToStack1(thread T (&dst)[A], thread const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromStackToThreadGroup1(threadgroup T (&dst)[A], thread const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromThreadGroupToStack1(thread T (&dst)[A], threadgroup const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromThreadGroupToThreadGroup1(threadgroup T (&dst)[A], threadgroup const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
kernel void main0(device SSBO& _53 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) | ||
{ | ||
Data _25[2] = { Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } }; | ||
|
||
Data _31[2] = { Data{ X, 2.0 }, Data{ 3.0, 5.0 } }; | ||
Data data2[2]; | ||
spvArrayCopyFromStackToStack1(data2, _31); | ||
_53.outdata[gl_WorkGroupID.x].a = _25[gl_LocalInvocationID.x].a + data2[gl_LocalInvocationID.x].a; | ||
_53.outdata[gl_WorkGroupID.x].b = _25[gl_LocalInvocationID.x].b + data2[gl_LocalInvocationID.x].b; | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
reference/opt/shaders-msl/comp/copy-array-of-arrays.force-native-array.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct BUF | ||
{ | ||
int a; | ||
float b; | ||
float c; | ||
}; | ||
|
||
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u); | ||
|
||
kernel void main0(device BUF& o [[buffer(0)]]) | ||
{ | ||
o.a = 4; | ||
o.b = o.c; | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
reference/opt/shaders-msl/vert/return-array.force-native-array.vert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct main0_out | ||
{ | ||
float4 gl_Position [[position]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
float4 vInput1 [[attribute(1)]]; | ||
}; | ||
|
||
vertex main0_out main0(main0_in in [[stage_in]]) | ||
{ | ||
main0_out out = {}; | ||
out.gl_Position = float4(10.0) + in.vInput1; | ||
return out; | ||
} | ||
|
103 changes: 103 additions & 0 deletions
103
reference/shaders-msl-no-opt/vert/pass-array-by-value.force-native-array.vert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
constant float4 _68[4] = { float4(0.0), float4(1.0), float4(2.0), float4(3.0) }; | ||
|
||
struct main0_out | ||
{ | ||
float4 gl_Position [[position]]; | ||
}; | ||
|
||
struct main0_in | ||
{ | ||
int Index1 [[attribute(0)]]; | ||
int Index2 [[attribute(1)]]; | ||
}; | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromConstantToStack1(thread T (&dst)[A], constant T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromConstantToThreadGroup1(threadgroup T (&dst)[A], constant T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromStackToStack1(thread T (&dst)[A], thread const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromStackToThreadGroup1(threadgroup T (&dst)[A], thread const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromThreadGroupToStack1(thread T (&dst)[A], threadgroup const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromThreadGroupToThreadGroup1(threadgroup T (&dst)[A], threadgroup const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
static inline __attribute__((always_inline)) | ||
float4 consume_constant_arrays2(thread const float4 (&positions)[4], thread const float4 (&positions2)[4], thread int& Index1, thread int& Index2) | ||
{ | ||
float4 indexable[4]; | ||
spvArrayCopyFromStackToStack1(indexable, positions); | ||
float4 indexable_1[4]; | ||
spvArrayCopyFromStackToStack1(indexable_1, positions2); | ||
return indexable[Index1] + indexable_1[Index2]; | ||
} | ||
|
||
static inline __attribute__((always_inline)) | ||
float4 consume_constant_arrays(thread const float4 (&positions)[4], thread const float4 (&positions2)[4], thread int& Index1, thread int& Index2) | ||
{ | ||
return consume_constant_arrays2(positions, positions2, Index1, Index2); | ||
} | ||
|
||
vertex main0_out main0(main0_in in [[stage_in]]) | ||
{ | ||
float4 _68_array_copy[4] = { float4(0.0), float4(1.0), float4(2.0), float4(3.0) }; | ||
main0_out out = {}; | ||
float4 LUT2[4]; | ||
LUT2[0] = float4(10.0); | ||
LUT2[1] = float4(11.0); | ||
LUT2[2] = float4(12.0); | ||
LUT2[3] = float4(13.0); | ||
out.gl_Position = consume_constant_arrays(_68_array_copy, LUT2, in.Index1, in.Index2); | ||
return out; | ||
} | ||
|
104 changes: 104 additions & 0 deletions
104
reference/shaders-msl/comp/composite-array-initialization.force-native-array.comp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#pragma clang diagnostic ignored "-Wmissing-prototypes" | ||
|
||
#include <metal_stdlib> | ||
#include <simd/simd.h> | ||
|
||
using namespace metal; | ||
|
||
struct Data | ||
{ | ||
float a; | ||
float b; | ||
}; | ||
|
||
constant float X_tmp [[function_constant(0)]]; | ||
constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0; | ||
|
||
struct Data_1 | ||
{ | ||
float a; | ||
float b; | ||
}; | ||
|
||
struct SSBO | ||
{ | ||
Data_1 outdata[1]; | ||
}; | ||
|
||
constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(2u, 1u, 1u); | ||
|
||
constant Data _25[2] = { Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } }; | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromConstantToStack1(thread T (&dst)[A], constant T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromConstantToThreadGroup1(threadgroup T (&dst)[A], constant T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromStackToStack1(thread T (&dst)[A], thread const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromStackToThreadGroup1(threadgroup T (&dst)[A], thread const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromThreadGroupToStack1(thread T (&dst)[A], threadgroup const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
template<typename T, uint A> | ||
inline void spvArrayCopyFromThreadGroupToThreadGroup1(threadgroup T (&dst)[A], threadgroup const T (&src)[A]) | ||
{ | ||
for (uint i = 0; i < A; i++) | ||
{ | ||
dst[i] = src[i]; | ||
} | ||
} | ||
|
||
static inline __attribute__((always_inline)) | ||
Data combine(thread const Data& a, thread const Data& b) | ||
{ | ||
return Data{ a.a + b.a, a.b + b.b }; | ||
} | ||
|
||
kernel void main0(device SSBO& _53 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]]) | ||
{ | ||
Data data[2] = { Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } }; | ||
Data _31[2] = { Data{ X, 2.0 }, Data{ 3.0, 5.0 } }; | ||
Data data2[2]; | ||
spvArrayCopyFromStackToStack1(data2, _31); | ||
Data param = data[gl_LocalInvocationID.x]; | ||
Data param_1 = data2[gl_LocalInvocationID.x]; | ||
Data _73 = combine(param, param_1); | ||
_53.outdata[gl_WorkGroupID.x].a = _73.a; | ||
_53.outdata[gl_WorkGroupID.x].b = _73.b; | ||
} | ||
|
Oops, something went wrong.