Skip to content

Commit 72b5b7c

Browse files
Merge pull request #2454 from etang-cw/GatherSequoia
MSL: Fix gather functions on Sequoia
2 parents 1823c11 + 8674455 commit 72b5b7c

22 files changed

+360
-568
lines changed

reference/opt/shaders-msl/comp/force-recompile-hooks.swizzle.comp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55

66
using namespace metal;
77

8-
template<typename T> struct spvRemoveReference { typedef T type; };
9-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
10-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
11-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
12-
{
13-
return static_cast<thread T&&>(x);
14-
}
15-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
16-
{
17-
return static_cast<thread T&&>(x);
18-
}
19-
208
enum class spvSwizzle : uint
219
{
2210
none = 0,

reference/opt/shaders-msl/frag/array-of-texture-swizzle-nonconstant-uniform.msl2.argument.discrete.swizzle.frag

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55

66
using namespace metal;
77

8-
template<typename T> struct spvRemoveReference { typedef T type; };
9-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
10-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
11-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
12-
{
13-
return static_cast<thread T&&>(x);
14-
}
15-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
16-
{
17-
return static_cast<thread T&&>(x);
18-
}
19-
208
enum class spvSwizzle : uint
219
{
2210
none = 0,

reference/opt/shaders-msl/frag/array-of-texture-swizzle-nonconstant-uniform.msl2.swizzle.frag

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55

66
using namespace metal;
77

8-
template<typename T> struct spvRemoveReference { typedef T type; };
9-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
10-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
11-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
12-
{
13-
return static_cast<thread T&&>(x);
14-
}
15-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
16-
{
17-
return static_cast<thread T&&>(x);
18-
}
19-
208
enum class spvSwizzle : uint
219
{
2210
none = 0,

reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.argument.discrete.swizzle.frag

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55

66
using namespace metal;
77

8-
template<typename T> struct spvRemoveReference { typedef T type; };
9-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
10-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
11-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
12-
{
13-
return static_cast<thread T&&>(x);
14-
}
15-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
16-
{
17-
return static_cast<thread T&&>(x);
18-
}
19-
208
enum class spvSwizzle : uint
219
{
2210
none = 0,

reference/opt/shaders-msl/frag/array-of-texture-swizzle.msl2.swizzle.frag

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@
55

66
using namespace metal;
77

8-
template<typename T> struct spvRemoveReference { typedef T type; };
9-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
10-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
11-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
12-
{
13-
return static_cast<thread T&&>(x);
14-
}
15-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
16-
{
17-
return static_cast<thread T&&>(x);
18-
}
19-
208
enum class spvSwizzle : uint
219
{
2210
none = 0,

reference/opt/shaders-msl/frag/gather-compare-const-offsets.frag

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,43 @@ struct spvUnsafeArray
4444
}
4545
};
4646

47-
template<typename T> struct spvRemoveReference { typedef T type; };
48-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
49-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
50-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
51-
{
52-
return static_cast<thread T&&>(x);
53-
}
54-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
55-
{
56-
return static_cast<thread T&&>(x);
57-
}
47+
template<typename Tex, typename... Tp>
48+
using spvGatherCompareReturn = decltype(declval<Tex>().gather_compare(declval<sampler>(), declval<Tp>()...));
5849

5950
// Wrapper function that processes a device texture gather with a constant offset array.
60-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename Toff, typename... Tp>
61-
inline vec<T, 4> spvGatherCompareConstOffsets(const device Tex<T>& t, sampler s, Toff coffsets, Tp... params)
51+
template<typename Tex, typename Toff, typename... Tp>
52+
inline spvGatherCompareReturn<Tex, Tp...> spvGatherCompareConstOffsets(const device Tex& t, sampler s, Toff coffsets, Tp... params)
6253
{
63-
vec<T, 4> rslts[4];
54+
spvGatherCompareReturn<Tex, Tp...> rslts[4];
6455
for (uint i = 0; i < 4; i++)
6556
{
66-
rslts[i] = t.gather_compare(s, spvForward<Tp>(params)..., coffsets[i]);
57+
rslts[i] = t.gather_compare(s, params..., coffsets[i]);
6758
}
68-
return vec<T, 4>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
59+
return spvGatherCompareReturn<Tex, Tp...>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
6960
}
7061

7162
// Wrapper function that processes a constant texture gather with a constant offset array.
72-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename Toff, typename... Tp>
73-
inline vec<T, 4> spvGatherCompareConstOffsets(const constant Tex<T>& t, sampler s, Toff coffsets, Tp... params)
63+
template<typename Tex, typename Toff, typename... Tp>
64+
inline spvGatherCompareReturn<Tex, Tp...> spvGatherCompareConstOffsets(const constant Tex& t, sampler s, Toff coffsets, Tp... params)
7465
{
75-
vec<T, 4> rslts[4];
66+
spvGatherCompareReturn<Tex, Tp...> rslts[4];
7667
for (uint i = 0; i < 4; i++)
7768
{
78-
rslts[i] = t.gather_compare(s, spvForward<Tp>(params)..., coffsets[i]);
69+
rslts[i] = t.gather_compare(s, params..., coffsets[i]);
7970
}
80-
return vec<T, 4>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
71+
return spvGatherCompareReturn<Tex, Tp...>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
8172
}
8273

8374
// Wrapper function that processes a thread texture gather with a constant offset array.
84-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename Toff, typename... Tp>
85-
inline vec<T, 4> spvGatherCompareConstOffsets(const thread Tex<T>& t, sampler s, Toff coffsets, Tp... params)
75+
template<typename Tex, typename Toff, typename... Tp>
76+
inline spvGatherCompareReturn<Tex, Tp...> spvGatherCompareConstOffsets(const thread Tex& t, sampler s, Toff coffsets, Tp... params)
8677
{
87-
vec<T, 4> rslts[4];
78+
spvGatherCompareReturn<Tex, Tp...> rslts[4];
8879
for (uint i = 0; i < 4; i++)
8980
{
90-
rslts[i] = t.gather_compare(s, spvForward<Tp>(params)..., coffsets[i]);
81+
rslts[i] = t.gather_compare(s, params..., coffsets[i]);
9182
}
92-
return vec<T, 4>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
83+
return spvGatherCompareReturn<Tex, Tp...>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
9384
}
9485

9586
constant spvUnsafeArray<int2, 4> _38 = spvUnsafeArray<int2, 4>({ int2(-8, 3), int2(-4, 7), int2(0, 3), int2(3, 0) });

reference/opt/shaders-msl/frag/gather-const-offsets.frag

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,94 +44,85 @@ struct spvUnsafeArray
4444
}
4545
};
4646

47-
template<typename T> struct spvRemoveReference { typedef T type; };
48-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
49-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
50-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
51-
{
52-
return static_cast<thread T&&>(x);
53-
}
54-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
55-
{
56-
return static_cast<thread T&&>(x);
57-
}
47+
template<typename Tex, typename... Tp>
48+
using spvGatherReturn = decltype(declval<Tex>().gather(declval<sampler>(), declval<Tp>()...));
5849

5950
// Wrapper function that processes a device texture gather with a constant offset array.
60-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename Toff, typename... Tp>
61-
inline vec<T, 4> spvGatherConstOffsets(const device Tex<T>& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
51+
template<typename Tex, typename Toff, typename... Tp>
52+
inline spvGatherReturn<Tex, Tp...> spvGatherConstOffsets(const device Tex& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
6253
{
63-
vec<T, 4> rslts[4];
54+
spvGatherReturn<Tex, Tp...> rslts[4];
6455
for (uint i = 0; i < 4; i++)
6556
{
6657
switch (c)
6758
{
6859
case component::x:
69-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::x);
60+
rslts[i] = t.gather(s, params..., coffsets[i], component::x);
7061
break;
7162
case component::y:
72-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::y);
63+
rslts[i] = t.gather(s, params..., coffsets[i], component::y);
7364
break;
7465
case component::z:
75-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::z);
66+
rslts[i] = t.gather(s, params..., coffsets[i], component::z);
7667
break;
7768
case component::w:
78-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::w);
69+
rslts[i] = t.gather(s, params..., coffsets[i], component::w);
7970
break;
8071
}
8172
}
82-
return vec<T, 4>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
73+
return spvGatherReturn<Tex, Tp...>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
8374
}
8475

8576
// Wrapper function that processes a constant texture gather with a constant offset array.
86-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename Toff, typename... Tp>
87-
inline vec<T, 4> spvGatherConstOffsets(const constant Tex<T>& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
77+
template<typename Tex, typename Toff, typename... Tp>
78+
inline spvGatherReturn<Tex, Tp...> spvGatherConstOffsets(const constant Tex& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
8879
{
89-
vec<T, 4> rslts[4];
80+
spvGatherReturn<Tex, Tp...> rslts[4];
9081
for (uint i = 0; i < 4; i++)
9182
{
9283
switch (c)
9384
{
9485
case component::x:
95-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::x);
86+
rslts[i] = t.gather(s, params..., coffsets[i], component::x);
9687
break;
9788
case component::y:
98-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::y);
89+
rslts[i] = t.gather(s, params..., coffsets[i], component::y);
9990
break;
10091
case component::z:
101-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::z);
92+
rslts[i] = t.gather(s, params..., coffsets[i], component::z);
10293
break;
10394
case component::w:
104-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::w);
95+
rslts[i] = t.gather(s, params..., coffsets[i], component::w);
10596
break;
10697
}
10798
}
108-
return vec<T, 4>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
99+
return spvGatherReturn<Tex, Tp...>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
109100
}
110101

111102
// Wrapper function that processes a thread texture gather with a constant offset array.
112-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename Toff, typename... Tp>
113-
inline vec<T, 4> spvGatherConstOffsets(const thread Tex<T>& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
103+
template<typename Tex, typename Toff, typename... Tp>
104+
inline spvGatherReturn<Tex, Tp...> spvGatherConstOffsets(const thread Tex& t, sampler s, Toff coffsets, component c, Tp... params) METAL_CONST_ARG(c)
114105
{
115-
vec<T, 4> rslts[4];
106+
spvGatherReturn<Tex, Tp...> rslts[4];
116107
for (uint i = 0; i < 4; i++)
117108
{
118109
switch (c)
119110
{
120111
case component::x:
121-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::x);
112+
rslts[i] = t.gather(s, params..., coffsets[i], component::x);
122113
break;
123114
case component::y:
124-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::y);
115+
rslts[i] = t.gather(s, params..., coffsets[i], component::y);
125116
break;
126117
case component::z:
127-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::z);
118+
rslts[i] = t.gather(s, params..., coffsets[i], component::z);
128119
break;
129120
case component::w:
130-
rslts[i] = t.gather(s, spvForward<Tp>(params)..., coffsets[i], component::w);
121+
rslts[i] = t.gather(s, params..., coffsets[i], component::w);
131122
break;
132123
}
133124
}
134-
return vec<T, 4>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
125+
return spvGatherReturn<Tex, Tp...>(rslts[0].w, rslts[1].w, rslts[2].w, rslts[3].w);
135126
}
136127

137128
constant spvUnsafeArray<int2, 4> _30 = spvUnsafeArray<int2, 4>({ int2(-8), int2(-8, 7), int2(7, -8), int2(7) });

reference/shaders-msl-no-opt/asm/frag/texture-access.swizzle.asm.frag

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ uint2 spvTexelBufferCoord(uint tc)
1212
return uint2(tc % 4096, tc / 4096);
1313
}
1414

15-
template<typename T> struct spvRemoveReference { typedef T type; };
16-
template<typename T> struct spvRemoveReference<thread T&> { typedef T type; };
17-
template<typename T> struct spvRemoveReference<thread T&&> { typedef T type; };
18-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type& x)
19-
{
20-
return static_cast<thread T&&>(x);
21-
}
22-
template<typename T> inline constexpr thread T&& spvForward(thread typename spvRemoveReference<T>::type&& x)
23-
{
24-
return static_cast<thread T&&>(x);
25-
}
26-
2715
enum class spvSwizzle : uint
2816
{
2917
none = 0,
@@ -72,9 +60,15 @@ inline T spvTextureSwizzle(T x, uint s)
7260
return spvTextureSwizzle(vec<T, 4>(x, 0, 0, 1), s).x;
7361
}
7462

63+
template<typename Tex, typename... Tp>
64+
using spvGatherReturn = decltype(declval<Tex>().gather(declval<sampler>(), declval<Tp>()...));
65+
66+
template<typename Tex, typename... Tp>
67+
using spvGatherCompareReturn = decltype(declval<Tex>().gather_compare(declval<sampler>(), declval<Tp>()...));
68+
7569
// Wrapper function that swizzles texture gathers.
76-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename... Ts>
77-
inline vec<T, 4> spvGatherSwizzle(const thread Tex<T>& t, sampler s, uint sw, component c, Ts... params) METAL_CONST_ARG(c)
70+
template<typename Tex, typename... Ts>
71+
inline spvGatherReturn<Tex, Ts...> spvGatherSwizzle(const thread Tex& t, sampler s, uint sw, component c, Ts... params) METAL_CONST_ARG(c)
7872
{
7973
if (sw)
8074
{
@@ -83,35 +77,35 @@ inline vec<T, 4> spvGatherSwizzle(const thread Tex<T>& t, sampler s, uint sw, co
8377
case spvSwizzle::none:
8478
break;
8579
case spvSwizzle::zero:
86-
return vec<T, 4>(0, 0, 0, 0);
80+
return spvGatherReturn<Tex, Ts...>(0, 0, 0, 0);
8781
case spvSwizzle::one:
88-
return vec<T, 4>(1, 1, 1, 1);
82+
return spvGatherReturn<Tex, Ts...>(1, 1, 1, 1);
8983
case spvSwizzle::red:
90-
return t.gather(s, spvForward<Ts>(params)..., component::x);
84+
return t.gather(s, params..., component::x);
9185
case spvSwizzle::green:
92-
return t.gather(s, spvForward<Ts>(params)..., component::y);
86+
return t.gather(s, params..., component::y);
9387
case spvSwizzle::blue:
94-
return t.gather(s, spvForward<Ts>(params)..., component::z);
88+
return t.gather(s, params..., component::z);
9589
case spvSwizzle::alpha:
96-
return t.gather(s, spvForward<Ts>(params)..., component::w);
90+
return t.gather(s, params..., component::w);
9791
}
9892
}
9993
switch (c)
10094
{
10195
case component::x:
102-
return t.gather(s, spvForward<Ts>(params)..., component::x);
96+
return t.gather(s, params..., component::x);
10397
case component::y:
104-
return t.gather(s, spvForward<Ts>(params)..., component::y);
98+
return t.gather(s, params..., component::y);
10599
case component::z:
106-
return t.gather(s, spvForward<Ts>(params)..., component::z);
100+
return t.gather(s, params..., component::z);
107101
case component::w:
108-
return t.gather(s, spvForward<Ts>(params)..., component::w);
102+
return t.gather(s, params..., component::w);
109103
}
110104
}
111105

112106
// Wrapper function that swizzles depth texture gathers.
113-
template<typename T, template<typename, access = access::sample, typename = void> class Tex, typename... Ts>
114-
inline vec<T, 4> spvGatherCompareSwizzle(const thread Tex<T>& t, sampler s, uint sw, Ts... params)
107+
template<typename Tex, typename... Ts>
108+
inline spvGatherCompareReturn<Tex, Ts...> spvGatherCompareSwizzle(const thread Tex& t, sampler s, uint sw, Ts... params)
115109
{
116110
if (sw)
117111
{
@@ -124,12 +118,12 @@ inline vec<T, 4> spvGatherCompareSwizzle(const thread Tex<T>& t, sampler s, uint
124118
case spvSwizzle::green:
125119
case spvSwizzle::blue:
126120
case spvSwizzle::alpha:
127-
return vec<T, 4>(0, 0, 0, 0);
121+
return spvGatherCompareReturn<Tex, Ts...>(0, 0, 0, 0);
128122
case spvSwizzle::one:
129-
return vec<T, 4>(1, 1, 1, 1);
123+
return spvGatherCompareReturn<Tex, Ts...>(1, 1, 1, 1);
130124
}
131125
}
132-
return t.gather_compare(s, spvForward<Ts>(params)...);
126+
return t.gather_compare(s, params...);
133127
}
134128

135129
fragment void main0(constant uint* spvSwizzleConstants [[buffer(30)]], texture1d<float> tex1d [[texture(0)]], texture2d<float> tex2d [[texture(1)]], texture3d<float> tex3d [[texture(2)]], texturecube<float> texCube [[texture(3)]], texture2d_array<float> tex2dArray [[texture(4)]], texturecube_array<float> texCubeArray [[texture(5)]], depth2d<float> depth2d [[texture(6)]], depthcube<float> depthCube [[texture(7)]], depth2d_array<float> depth2dArray [[texture(8)]], depthcube_array<float> depthCubeArray [[texture(9)]], texture2d<float> texBuffer [[texture(10)]], sampler tex1dSamp [[sampler(0)]], sampler tex2dSamp [[sampler(1)]], sampler tex3dSamp [[sampler(2)]], sampler texCubeSamp [[sampler(3)]], sampler tex2dArraySamp [[sampler(4)]], sampler texCubeArraySamp [[sampler(5)]], sampler depth2dSamp [[sampler(6)]], sampler depthCubeSamp [[sampler(7)]], sampler depth2dArraySamp [[sampler(8)]], sampler depthCubeArraySamp [[sampler(9)]])

0 commit comments

Comments
 (0)