yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Sami Kiminki (NVIDIA)8503 wgsl depth texture (#8645)5c672cef1

master
13.2 KiB279 linesraw
1//TEST:SIMPLE(filecheck=WGSL): -stage fragment -entry fragMain -target wgsl
2
3// In WGSL, `textureSample` and other variants work only for f32 type.
4// But textureGather works for i32, u32 and f32.
5
6//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
7RWStructuredBuffer<int> outputBuffer;
8
9// f32 types
10
11//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_f32v3
12Texture2D<float3> t2D_f32v3;
13//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_f32v3
14TextureCube<float3> tCube_f32v3;
15//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_f32v3
16Texture2DArray<float3> t2DArray_f32v3;
17//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_f32v3
18TextureCubeArray<float3> tCubeArray_f32v3;
19
20//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_f32v4
21Texture2D<float4> t2D_f32v4;
22//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_f32v4
23TextureCube<float4> tCube_f32v4;
24//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_f32v4
25Texture2DArray<float4> t2DArray_f32v4;
26//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_f32v4
27TextureCubeArray<float4> tCubeArray_f32v4;
28
29// i32 types
30
31//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_i32v3
32Texture2D<int3> t2D_i32v3;
33//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_i32v3
34TextureCube<int3> tCube_i32v3;
35//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_i32v3
36Texture2DArray<int3> t2DArray_i32v3;
37//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_i32v3
38TextureCubeArray<int3> tCubeArray_i32v3;
39
40//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_i32v4
41Texture2D<int4> t2D_i32v4;
42//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_i32v4
43TextureCube<int4> tCube_i32v4;
44//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_i32v4
45Texture2DArray<int4> t2DArray_i32v4;
46//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_i32v4
47TextureCubeArray<int4> tCubeArray_i32v4;
48
49// u32 types
50
51//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_u32v3
52Texture2D<uint3> t2D_u32v3;
53//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_u32v3
54TextureCube<uint3> tCube_u32v3;
55//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_u32v3
56Texture2DArray<uint3> t2DArray_u32v3;
57//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_u32v3
58TextureCubeArray<uint3> tCubeArray_u32v3;
59
60//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_u32v4
61Texture2D<uint4> t2D_u32v4;
62//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_u32v4
63TextureCube<uint4> tCube_u32v4;
64//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_u32v4
65Texture2DArray<uint4> t2DArray_u32v4;
66//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_u32v4
67TextureCubeArray<uint4> tCubeArray_u32v4;
68
69// depth
70
71//TEST_INPUT: Texture2D(size=4, content = zero):name d2D
72DepthTexture2D d2D;
73//TEST_INPUT: TextureCube(size=4, content = zero):name dCube
74DepthTextureCube dCube;
75//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name d2DArray
76DepthTexture2DArray d2DArray;
77//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name dCubeArray
78DepthTextureCubeArray dCubeArray;
79
80//TEST_INPUT: Sampler:name samplerState
81SamplerState samplerState;
82//TEST_INPUT: Sampler:name depthSampler
83SamplerComparisonState depthSampler;
84
85
86bool TEST_textureGather<T>(
87    Texture2D<T> t2D,
88    TextureCube<T> tCube,
89    Texture2DArray<T> t2DArray,
90    TextureCubeArray<T> tCubeArray)
91    where T:IArithmetic,ITexelElement
92{
93    // WGSL-LABEL: TEST_textureGather
94    typealias Tv4 = vector<T.Element,4>;
95
96    float u = 0;
97    float u2 = 0.5;
98
99    return true
100        // ==================================
101        // vector<T,4> Gather()
102        // https://www.w3.org/TR/WGSL/#texturegather
103        // ==================================
104
105        // WGSL-COUNT-2: textureGather({{.*}}0{{.*}}t2D
106        && all(Tv4(T.Element(0)) == t2D.Gather(samplerState, float2(u, u)))
107        && all(Tv4(T.Element(0)) == t2D.Gather(samplerState, float2(u2, u), int2(0,0)))
108
109        // WGSL: textureGather({{.*}}0{{.*}}tCube
110        && all(Tv4(T.Element(0)) == tCube.Gather(samplerState, normalize(float3(u, 1 - u, u))))
111
112        // WGSL-COUNT-2: textureGather({{.*}}0{{.*}}t2DArray
113        && all(Tv4(T.Element(0)) == t2DArray.Gather(samplerState, float3(u, u, 0)))
114        && all(Tv4(T.Element(0)) == t2DArray.Gather(samplerState, float3(u2, u, 0), int2(0,0)))
115
116        // WGSL: textureGather({{.*}}0{{.*}}tCubeArray
117        && all(Tv4(T.Element(0)) == tCubeArray.Gather(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
118
119        // ==================================
120        // vector<T,4> GatherRed()
121        // ==================================
122
123        // WGSL-COUNT-2: textureGather({{.*}}0{{.*}}t2D
124        && all(Tv4(T.Element(0)) == t2D.GatherRed(samplerState, float2(u, u)))
125        && all(Tv4(T.Element(0)) == t2D.GatherRed(samplerState, float2(u2, u), int2(0,0)))
126
127        // WGSL: textureGather({{.*}}0{{.*}}tCube
128        && all(Tv4(T.Element(0)) == tCube.GatherRed(samplerState, normalize(float3(u, 1 - u, u))))
129
130        // WGSL-COUNT-2: textureGather({{.*}}0{{.*}}t2DArray
131        && all(Tv4(T.Element(0)) == t2DArray.GatherRed(samplerState, float3(u, u, 0)))
132        && all(Tv4(T.Element(0)) == t2DArray.GatherRed(samplerState, float3(u2, u, 0), int2(0,0)))
133
134        // WGSL: textureGather({{.*}}0{{.*}}tCubeArray
135        && all(Tv4(T.Element(0)) == tCubeArray.GatherRed(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
136
137        // ==================================
138        // vector<T,4> GatherGreen()
139        // ==================================
140
141        // WGSL-COUNT-2: textureGather({{.*}}1{{.*}}t2D
142        && all(Tv4(T.Element(0)) == t2D.GatherGreen(samplerState, float2(u, u)))
143        && all(Tv4(T.Element(0)) == t2D.GatherGreen(samplerState, float2(u2, u), int2(0,0)))
144
145        // WGSL: textureGather({{.*}}1{{.*}}tCube
146        && all(Tv4(T.Element(0)) == tCube.GatherGreen(samplerState, normalize(float3(u, 1 - u, u))))
147
148        // WGSL-COUNT-2: textureGather({{.*}}1{{.*}}t2DArray
149        && all(Tv4(T.Element(0)) == t2DArray.GatherGreen(samplerState, float3(u, u, 0)))
150        && all(Tv4(T.Element(0)) == t2DArray.GatherGreen(samplerState, float3(u2, u, 0), int2(0,0)))
151
152        // WGSL: textureGather({{.*}}1{{.*}}tCubeArray
153        && all(Tv4(T.Element(0)) == tCubeArray.GatherGreen(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
154
155        // ==================================
156        // vector<T,4> GatherBlue()
157        // ==================================
158
159        // WGSL-COUNT-2: textureGather({{.*}}2{{.*}}t2D
160        && all(Tv4(T.Element(0)) == t2D.GatherBlue(samplerState, float2(u, u)))
161        && all(Tv4(T.Element(0)) == t2D.GatherBlue(samplerState, float2(u2, u), int2(0,0)))
162
163        // WGSL: textureGather({{.*}}2{{.*}}tCube
164        && all(Tv4(T.Element(0)) == tCube.GatherBlue(samplerState, normalize(float3(u, 1 - u, u))))
165
166        // WGSL-COUNT-2: textureGather({{.*}}2{{.*}}t2DArray
167        && all(Tv4(T.Element(0)) == t2DArray.GatherBlue(samplerState, float3(u, u, 0)))
168        && all(Tv4(T.Element(0)) == t2DArray.GatherBlue(samplerState, float3(u2, u, 0), int2(0,0)))
169
170        // WGSL: textureGather({{.*}}2{{.*}}tCubeArray
171        && all(Tv4(T.Element(0)) == tCubeArray.GatherBlue(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
172
173        // ==================================
174        // vector<T,4> GatherAlpha()
175        // ==================================
176
177        // WGSL-COUNT-2: textureGather({{.*}}3{{.*}}t2D
178        && all(Tv4(T.Element(0)) == t2D.GatherAlpha(samplerState, float2(u, u)))
179        && all(Tv4(T.Element(0)) == t2D.GatherAlpha(samplerState, float2(u2, u), int2(0,0)))
180
181        // WGSL: textureGather({{.*}}3{{.*}}tCube
182        && all(Tv4(T.Element(0)) == tCube.GatherAlpha(samplerState, normalize(float3(u, 1 - u, u))))
183
184        // WGSL-COUNT-2: textureGather({{.*}}3{{.*}}t2DArray
185        && all(Tv4(T.Element(0)) == t2DArray.GatherAlpha(samplerState, float3(u, u, 0)))
186        && all(Tv4(T.Element(0)) == t2DArray.GatherAlpha(samplerState, float3(u2, u, 0), int2(0,0)))
187
188        // WGSL: textureGather({{.*}}3{{.*}}tCubeArray
189        && all(Tv4(T.Element(0)) == tCubeArray.GatherAlpha(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
190        ;
191}
192
193bool TEST_textureGather_depth()
194{
195    // WGSL-LABEL: TEST_textureGather_depth
196    float u = 0.f;
197    float u2 = 0.5f;
198    float depthCompare = 0.5f;
199
200    return true
201        // ==================================
202        // vector<T,4> Gather()
203        // https://www.w3.org/TR/WGSL/#texturegather
204        // ==================================
205
206        // WGSL-COUNT-10: textureGather({{\(*}}d2D
207        && all(float4(0) == d2D.Gather     (samplerState, float2(u, u)))
208        && all(float4(0) == d2D.GatherRed  (samplerState, float2(u, u)))
209        && all(float4(0) == d2D.GatherGreen(samplerState, float2(u, u)))
210        && all(float4(0) == d2D.GatherBlue (samplerState, float2(u, u)))
211        && all(float4(0) == d2D.GatherAlpha(samplerState, float2(u, u)))
212        && all(float4(0) == d2D.Gather     (samplerState, float2(u, u), int2(0,0)))
213        && all(float4(0) == d2D.GatherRed  (samplerState, float2(u, u), int2(0,0)))
214        && all(float4(0) == d2D.GatherGreen(samplerState, float2(u, u), int2(0,0)))
215        && all(float4(0) == d2D.GatherBlue (samplerState, float2(u, u), int2(0,0)))
216        && all(float4(0) == d2D.GatherAlpha(samplerState, float2(u, u), int2(0,0)))
217
218        // WGSL-COUNT-5: textureGather({{\(*}}dCube
219        && all(float4(0) == dCube.Gather     (samplerState, normalize(float3(u, 1 - u, u))))
220        && all(float4(0) == dCube.GatherRed  (samplerState, normalize(float3(u, 1 - u, u))))
221        && all(float4(0) == dCube.GatherGreen(samplerState, normalize(float3(u, 1 - u, u))))
222        && all(float4(0) == dCube.GatherBlue (samplerState, normalize(float3(u, 1 - u, u))))
223        && all(float4(0) == dCube.GatherAlpha(samplerState, normalize(float3(u, 1 - u, u))))
224
225        // WGSL-COUNT-10: textureGather({{\(*}}d2DArray
226        && all(float4(0) == d2DArray.Gather     (samplerState, float3(u, u, 0)))
227        && all(float4(0) == d2DArray.GatherRed  (samplerState, float3(u, u, 0)))
228        && all(float4(0) == d2DArray.GatherGreen(samplerState, float3(u, u, 0)))
229        && all(float4(0) == d2DArray.GatherBlue (samplerState, float3(u, u, 0)))
230        && all(float4(0) == d2DArray.GatherAlpha(samplerState, float3(u, u, 0)))
231        && all(float4(0) == d2DArray.Gather     (samplerState, float3(u, u, 0), int2(0,0)))
232        && all(float4(0) == d2DArray.GatherRed  (samplerState, float3(u, u, 0), int2(0,0)))
233        && all(float4(0) == d2DArray.GatherGreen(samplerState, float3(u, u, 0), int2(0,0)))
234        && all(float4(0) == d2DArray.GatherBlue (samplerState, float3(u, u, 0), int2(0,0)))
235        && all(float4(0) == d2DArray.GatherAlpha(samplerState, float3(u, u, 0), int2(0,0)))
236
237        // WGSL-COUNT-5: textureGather({{\(*}}dCubeArray
238        && all(float4(0) == dCubeArray.Gather     (samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
239        && all(float4(0) == dCubeArray.GatherRed  (samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
240        && all(float4(0) == dCubeArray.GatherGreen(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
241        && all(float4(0) == dCubeArray.GatherBlue (samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
242        && all(float4(0) == dCubeArray.GatherAlpha(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
243
244        // ==================================
245        // vector<T,4> GatherCmp()
246        // https://www.w3.org/TR/WGSL/#texturegathercompare
247        // ==================================
248
249        // WGSL-COUNT-2: textureGatherCompare({{\(*}}d2D
250        && all(float4(0) == d2D.GatherCmp(depthSampler, float2(u, u), depthCompare))
251        && all(float4(0) == d2D.GatherCmp(depthSampler, float2(u, u), depthCompare, int2(0,0)))
252
253        // WGSL: textureGatherCompare({{\(*}}dCube
254        && all(float4(0) == dCube.GatherCmp(depthSampler, normalize(float3(u, 1 - u, u)), depthCompare))
255
256        // WGSL-COUNT-2: textureGatherCompare({{\(*}}d2DArray
257        && all(float4(0) == d2DArray.GatherCmp(depthSampler, float3(u, u, 0), depthCompare))
258        && all(float4(0) == d2DArray.GatherCmp(depthSampler, float3(u, u, 0), depthCompare, int2(0,0)))
259
260        // WGSL: textureGatherCompare({{\(*}}dCubeArray
261        && all(float4(0) == dCubeArray.GatherCmp(depthSampler, float4(normalize(float3(u, 1 - u, u)), 0), depthCompare))
262        ;
263}
264
265
266void fragMain()
267{
268    bool result = true
269        && TEST_textureGather<float3>(t2D_f32v3, tCube_f32v3, t2DArray_f32v3, tCubeArray_f32v3)
270        && TEST_textureGather<float4>(t2D_f32v4, tCube_f32v4, t2DArray_f32v4, tCubeArray_f32v4)
271        && TEST_textureGather<int32_t3>(t2D_i32v3, tCube_i32v3, t2DArray_i32v3, tCubeArray_i32v3)
272        && TEST_textureGather<int32_t4>(t2D_i32v4, tCube_i32v4, t2DArray_i32v4, tCubeArray_i32v4)
273        && TEST_textureGather<uint32_t3>(t2D_u32v3, tCube_u32v3, t2DArray_u32v3, tCubeArray_u32v3)
274        && TEST_textureGather<uint32_t4>(t2D_u32v4, tCube_u32v4, t2DArray_u32v4, tCubeArray_u32v4)
275        && TEST_textureGather_depth()
276        ;
277
278    outputBuffer[0] = int(result);
279}