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
33.3 KiB776 linesraw
1//TEST:SIMPLE(filecheck=METAL): -stage compute -entry computeMain -target metal
2//TEST:SIMPLE(filecheck=METALLIB): -stage compute -entry computeMain -target metallib
3//TEST:SIMPLE(filecheck=HLSL): -stage compute -entry computeMain -target hlsl -DEXCLUDE_INTEGER_TYPE
4//TEST:SIMPLE(filecheck=SPIR): -stage compute -entry computeMain -target spirv -emit-spirv-directly -DEXCLUDE_HALF_TYPE -DEXCLUDE_SHORT_TYPE
5
6//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=FUNCTIONAL):-slang -compute -dx12 -profile cs_6_6 -shaderobj -output-using-type -xslang -DEXCLUDE_INTEGER_TYPE -xslang -DEXCLUDE_SM_6_7
7//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=FUNCTIONAL):-vk -emit-spirv-directly -compute -shaderobj -output-using-type -render-feature hardware-device -xslang -DEXCLUDE_HALF_TYPE -xslang -DEXCLUDE_SHORT_TYPE
8//DISABLE_TEST(compute, metal):COMPARE_COMPUTE_EX(filecheck-buffer=FUNCTIONAL):-metal -compute -shaderobj -output-using-type
9
10// Internal compiler error on metal
11// TODO: github issue #8486
12
13//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
14RWStructuredBuffer<int> outputBuffer;
15
16//TEST_INPUT: Texture1D(size=4, content = zero):name t1D_f32v3
17Texture1D<float3> t1D_f32v3;
18//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_f32v3
19Texture2D<float3> t2D_f32v3;
20//TEST_INPUT: Texture3D(size=4, content = zero):name t3D_f32v3
21Texture3D<float3> t3D_f32v3;
22//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_f32v3
23TextureCube<float3> tCube_f32v3;
24//TEST_INPUT: Texture1D(size=4, content = zero, arrayLength=2):name t1DArray_f32v3
25Texture1DArray<float3> t1DArray_f32v3;
26//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_f32v3
27Texture2DArray<float3> t2DArray_f32v3;
28//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_f32v3
29TextureCubeArray<float3> tCubeArray_f32v3;
30
31//TEST_INPUT: Texture1D(size=4, content = zero):name t1D_f32
32Texture1D<float4> t1D_f32;
33//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_f32
34Texture2D<float4> t2D_f32;
35//TEST_INPUT: Texture3D(size=4, content = zero):name t3D_f32
36Texture3D<float4> t3D_f32;
37//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_f32
38TextureCube<float4> tCube_f32;
39
40//TEST_INPUT: Texture1D(size=4, content = zero, arrayLength=2):name t1DArray_f32
41Texture1DArray<float4> t1DArray_f32;
42//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_f32
43Texture2DArray<float4> t2DArray_f32;
44//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_f32
45TextureCubeArray<float4> tCubeArray_f32;
46
47//TEST_INPUT: Texture1D(size=4, content = zero):name t1D_f16
48Texture1D<half4> t1D_f16;
49//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_f16
50Texture2D<half4> t2D_f16;
51//TEST_INPUT: Texture3D(size=4, content = zero):name t3D_f16
52Texture3D<half4> t3D_f16;
53//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_f16
54TextureCube<half4> tCube_f16;
55
56//TEST_INPUT: Texture1D(size=4, content = zero, arrayLength=2):name t1DArray_f16
57Texture1DArray<half4> t1DArray_f16;
58//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_f16
59Texture2DArray<half4> t2DArray_f16;
60//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_f16
61TextureCubeArray<half4> tCubeArray_f16;
62
63//TEST_INPUT: Texture1D(size=4, format=RGBA8Sint, content = zero):name t1D_i32
64Texture1D<int4> t1D_i32;
65//TEST_INPUT: Texture2D(size=4, format=RGBA8Sint, content = zero):name t2D_i32
66Texture2D<int4> t2D_i32;
67//TEST_INPUT: Texture3D(size=4, format=RGBA8Sint, content = zero):name t3D_i32
68Texture3D<int4> t3D_i32;
69//TEST_INPUT: TextureCube(size=4, format=RGBA8Sint, content = zero):name tCube_i32
70TextureCube<int4> tCube_i32;
71
72//TEST_INPUT: Texture1D(size=4, format=RGBA8Sint, content = zero, arrayLength=2):name t1DArray_i32
73Texture1DArray<int4> t1DArray_i32;
74//TEST_INPUT: Texture2D(size=4, format=RGBA8Sint, content = zero, arrayLength=2):name t2DArray_i32
75Texture2DArray<int4> t2DArray_i32;
76//TEST_INPUT: TextureCube(size=4, format=RGBA8Sint, content = zero, arrayLength=2):name tCubeArray_i32
77TextureCubeArray<int4> tCubeArray_i32;
78
79//TEST_INPUT: Texture1D(size=4, format=RGBA8Uint, content = zero):name t1D_u32
80Texture1D<uint4> t1D_u32;
81//TEST_INPUT: Texture2D(size=4, format=RGBA8Uint, content = zero):name t2D_u32
82Texture2D<uint4> t2D_u32;
83//TEST_INPUT: Texture3D(size=4, format=RGBA8Uint, content = zero):name t3D_u32
84Texture3D<uint4> t3D_u32;
85//TEST_INPUT: TextureCube(size=4, format=RGBA8Uint, content = zero):name tCube_u32
86TextureCube<uint4> tCube_u32;
87
88//TEST_INPUT: Texture1D(size=4, format=RGBA8Uint, content = zero, arrayLength=2):name t1DArray_u32
89Texture1DArray<uint4> t1DArray_u32;
90//TEST_INPUT: Texture2D(size=4, format=RGBA8Uint, content = zero, arrayLength=2):name t2DArray_u32
91Texture2DArray<uint4> t2DArray_u32;
92//TEST_INPUT: TextureCube(size=4, format=RGBA8Uint, content = zero, arrayLength=2):name tCubeArray_u32
93TextureCubeArray<uint4> tCubeArray_u32;
94
95//TEST_INPUT: Texture1D(size=4, content = zero):name t1D_i16
96Texture1D<int16_t4> t1D_i16;
97//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_i16
98Texture2D<int16_t4> t2D_i16;
99//TEST_INPUT: Texture3D(size=4, content = zero):name t3D_i16
100Texture3D<int16_t4> t3D_i16;
101//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_i16
102TextureCube<int16_t4> tCube_i16;
103
104//TEST_INPUT: Texture1D(size=4, content = zero, arrayLength=2):name t1DArray_i16
105Texture1DArray<int16_t4> t1DArray_i16;
106//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_i16
107Texture2DArray<int16_t4> t2DArray_i16;
108//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_i16
109TextureCubeArray<int16_t4> tCubeArray_i16;
110
111//TEST_INPUT: Texture1D(size=4, content = zero):name t1D_u16
112Texture1D<uint16_t4> t1D_u16;
113//TEST_INPUT: Texture2D(size=4, content = zero):name t2D_u16
114Texture2D<uint16_t4> t2D_u16;
115//TEST_INPUT: Texture3D(size=4, content = zero):name t3D_u16
116Texture3D<uint16_t4> t3D_u16;
117//TEST_INPUT: TextureCube(size=4, content = zero):name tCube_u16
118TextureCube<uint16_t4> tCube_u16;
119
120//TEST_INPUT: Texture1D(size=4, content = zero, arrayLength=2):name t1DArray_u16
121Texture1DArray<uint16_t4> t1DArray_u16;
122//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2):name t2DArray_u16
123Texture2DArray<uint16_t4> t2DArray_u16;
124//TEST_INPUT: TextureCube(size=4, content = zero, arrayLength=2):name tCubeArray_u16
125TextureCubeArray<uint16_t4> tCubeArray_u16;
126
127//TEST_INPUT: Texture2D(size=4, format=D32Float, content = zero):name d2D
128DepthTexture2D d2D;
129//TEST_INPUT: TextureCube(size=4, format=D32Float, content = zero):name dCube
130DepthTextureCube dCube;
131//TEST_INPUT: Texture2D(size=4, format=D32Float, content = zero, arrayLength=2):name d2DArray
132DepthTexture2DArray d2DArray;
133//TEST_INPUT: TextureCube(size=4, format=D32Float, content = zero, arrayLength=2):name dCubeArray
134DepthTextureCubeArray dCubeArray;
135
136//TEST_INPUT: Sampler(filteringMode=point):name samplerState
137SamplerState samplerState;
138//TEST_INPUT: Sampler(depthCompare):name shadowSampler
139SamplerComparisonState shadowSampler;
140
141
142bool TEST_texture<T>(
143    Texture1D<T> t1D,
144    Texture2D<T> t2D,
145    Texture3D<T> t3D,
146    TextureCube<T> tCube,
147    Texture1DArray<T> t1DArray,
148    Texture2DArray<T> t2DArray,
149    TextureCubeArray<T> tCubeArray
150) where T: ITexelElement, IArithmetic
151{
152    // METAL-LABEL: TEST_texture
153    typealias Tvn = T;
154    typealias Tv4 = vector<T.Element,4>;
155
156    float u = 0;
157    float u2 = 0.5;
158    constexpr const float ddx = 0.0f;
159    constexpr const float ddy = 0.0f;
160
161    uint width = 0, height = 0, depth = 0;
162    float fwidth = 0.0f, fheight = 0.0f, fdepth = 0.0f;
163    uint numLevels = 0, elements = 0, sampleCount = 0;
164    float fnumLevels = 0.0f, felements = 0.0f;
165
166    bool voidResult = true;
167
168    // ======================
169    //  void GetDimensions()
170    // ======================
171
172    // METAL: .get_width(
173    // METALLIB: call {{.*}}.get_width_texture_1d(
174    t1D.GetDimensions(width);
175    voidResult = voidResult && (uint(4) == width);
176
177    // METAL: .get_width({{.*}}.get_num_mip_levels()
178    // METALLIB: call {{.*}}.get_num_mip_levels_texture_1d(
179    t1D.GetDimensions(0, width, numLevels);
180    voidResult = voidResult && (uint(4) == width);
181    voidResult = voidResult && (uint(3) == numLevels);
182
183    // METAL: .get_width({{.*}}.get_height(
184    // METALLIB: call {{.*}}.get_height_texture_2d(
185    t2D.GetDimensions(width, height);
186    voidResult = voidResult && (uint(4) == width);
187    voidResult = voidResult && (uint(4) == height);
188
189    // METAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels()
190    // METALLIB: call {{.*}}.get_num_mip_levels_texture_2d(
191    t2D.GetDimensions(0, width, height, numLevels);
192    voidResult = voidResult && (uint(4) == width);
193    voidResult = voidResult && (uint(4) == height);
194    voidResult = voidResult && (uint(3) == numLevels);
195
196    // METAL: .get_width({{.*}}.get_height({{.*}}.get_depth(
197    // METALLIB: call {{.*}}.get_depth_texture_3d(
198    t3D.GetDimensions(width, height, depth);
199    voidResult = voidResult && (uint(4) == width);
200    voidResult = voidResult && (uint(4) == height);
201    voidResult = voidResult && (uint(4) == depth);
202
203    // METAL: .get_width({{.*}}.get_height({{.*}}.get_depth({{.*}}.get_num_mip_levels()
204    // METALLIB: call {{.*}}.get_num_mip_levels_texture_3d(
205    t3D.GetDimensions(0, width, height, depth, numLevels);
206    voidResult = voidResult && (uint(4) == width);
207    voidResult = voidResult && (uint(4) == height);
208    voidResult = voidResult && (uint(4) == depth);
209    voidResult = voidResult && (uint(3) == numLevels);
210
211    // METAL: .get_width({{.*}}.get_height({{.*}}
212    // METALLIB: call {{.*}}.get_height_texture_cube(
213    tCube.GetDimensions(width, height);
214    voidResult = voidResult && (uint(4) == width);
215    voidResult = voidResult && (uint(4) == height);
216
217    // METAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels()
218    // METALLIB: call {{.*}}.get_num_mip_levels_texture_cube(
219    tCube.GetDimensions(0, width, height, numLevels);
220    voidResult = voidResult && (uint(4) == width);
221    voidResult = voidResult && (uint(4) == height);
222    voidResult = voidResult && (uint(3) == numLevels);
223
224    // METAL: .get_width({{.*}}.get_array_size(
225    // METALLIB: call {{.*}}.get_array_size_texture_1d_array(
226    t1DArray.GetDimensions(width, elements);
227    voidResult = voidResult && (uint(4) == width);
228    voidResult = voidResult && (uint(2) == elements);
229
230    // METAL: .get_width({{.*}}.get_num_mip_levels(
231    // METALLIB: call {{.*}}.get_num_mip_levels_texture_1d_array(
232    t1DArray.GetDimensions(0, width, elements, numLevels);
233    voidResult = voidResult && (uint(4) == width);
234    voidResult = voidResult && (uint(2) == elements);
235    voidResult = voidResult && (uint(3) == numLevels);
236
237    // METAL: .get_width({{.*}}.get_height({{.*}}.get_array_size(
238    // METALLIB: call {{.*}}.get_array_size_texture_2d_array(
239    t2DArray.GetDimensions(width, height, elements);
240    voidResult = voidResult && (uint(4) == width);
241    voidResult = voidResult && (uint(4) == height);
242    voidResult = voidResult && (uint(2) == elements);
243
244    // METAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels(
245    // METALLIB: call {{.*}}.get_num_mip_levels_texture_2d_array(
246    t2DArray.GetDimensions(0, width, height, elements, numLevels);
247    voidResult = voidResult && (uint(4) == width);
248    voidResult = voidResult && (uint(4) == height);
249    voidResult = voidResult && (uint(2) == elements);
250    voidResult = voidResult && (uint(3) == numLevels);
251
252    // METAL: .get_width({{.*}}.get_height({{.*}}.get_array_size(
253    // METALLIB: call {{.*}}.get_array_size_texture_cube_array(
254    tCubeArray.GetDimensions(width, height, elements);
255    voidResult = voidResult && (uint(4) == width);
256    voidResult = voidResult && (uint(4) == height);
257    voidResult = voidResult && (uint(2) == elements);
258
259    // METAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels(
260    // METALLIB: call {{.*}}.get_num_mip_levels_texture_cube_array(
261    tCubeArray.GetDimensions(0, width, height, elements, numLevels);
262    voidResult = voidResult && (uint(4) == width);
263    voidResult = voidResult && (uint(4) == height);
264    voidResult = voidResult && (uint(2) == elements);
265    voidResult = voidResult && (uint(3) == numLevels);
266
267    bool result = voidResult
268        // ===============================
269        // float CalculateLevelOfDetail()
270        // ===============================
271
272        // Metal doesn't support LOD for 1D texture
273
274        // METAL: t2D{{.*}}.calculate_clamped_lod({{.*}}
275        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_2d(
276        && float(0) == t2D.CalculateLevelOfDetail(samplerState, float2(u, u))
277
278        // METAL: t3D{{.*}}.calculate_clamped_lod({{.*}}
279        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_3d(
280        && float(0) == t3D.CalculateLevelOfDetail(samplerState, float3(u, u, u))
281
282        // METAL: tCube{{.*}}.calculate_clamped_lod({{.*}}
283        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_cube(
284        && float(0) == tCube.CalculateLevelOfDetail(samplerState, normalize(float3(u, 1 - u, u)))
285
286        // METAL: t2DArray{{.*}}.calculate_clamped_lod({{.*}}
287        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_2d_array(
288        && float(0) == t2DArray.CalculateLevelOfDetail(samplerState, float2(u, u))
289
290        // METAL: tCubeArray{{.*}}.calculate_clamped_lod({{.*}}
291        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_cube_array(
292        && float(0) == tCubeArray.CalculateLevelOfDetail(samplerState, normalize(float3(u, 1 - u, u)))
293
294        // SamplerComparisonState variant
295
296        // Functional tests that require SM higher than 6.6 (as of writing) cannot run.
297#if !defined(EXCLUDE_SM_6_7)
298        // METAL: t2D{{.*}}.calculate_clamped_lod({{.*}}
299        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_2d(
300        && float(0) == t2D.CalculateLevelOfDetail(shadowSampler, float2(u, u))
301
302        // METAL: t3D{{.*}}.calculate_clamped_lod({{.*}}
303        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_3d(
304        && float(0) == t3D.CalculateLevelOfDetail(shadowSampler, float3(u, u, u))
305
306        // METAL: tCube{{.*}}.calculate_clamped_lod({{.*}}
307        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_cube(
308        && float(0) == tCube.CalculateLevelOfDetail(shadowSampler, normalize(float3(u, 1 - u, u)))
309
310        // METAL: t2DArray{{.*}}.calculate_clamped_lod({{.*}}
311        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_2d_array(
312        && float(0) == t2DArray.CalculateLevelOfDetail(shadowSampler, float2(u, u))
313
314        // METAL: tCubeArray{{.*}}.calculate_clamped_lod({{.*}}
315        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_cube_array(
316        && float(0) == tCubeArray.CalculateLevelOfDetail(shadowSampler, normalize(float3(u, 1 - u, u)))
317#endif
318
319        // ========================================
320        // float CalculateLevelOfDetailUnclamped()
321        // ========================================
322
323        // Metal doesn't support LOD for 1D texture
324
325        // METAL: t2D{{.*}}.calculate_unclamped_lod({{.*}}
326        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_2d(
327        && float(0) >= t2D.CalculateLevelOfDetailUnclamped(samplerState, float2(u, u))
328
329        // METAL: t3D{{.*}}.calculate_unclamped_lod({{.*}}
330        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_3d(
331        && float(0) >= t3D.CalculateLevelOfDetailUnclamped(samplerState, float3(u, u, u))
332
333        // METAL: tCube{{.*}}.calculate_unclamped_lod({{.*}}
334        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_cube(
335        && float(0) >= tCube.CalculateLevelOfDetailUnclamped(samplerState, normalize(float3(u, 1 - u, u)))
336
337        // METAL: t2DArray{{.*}}.calculate_unclamped_lod({{.*}}
338        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_2d_array(
339        && float(0) >= t2DArray.CalculateLevelOfDetailUnclamped(samplerState, float2(u, u))
340
341        // METAL: tCubeArray{{.*}}.calculate_unclamped_lod({{.*}}
342        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_cube_array(
343        && float(0) >= tCubeArray.CalculateLevelOfDetailUnclamped(samplerState, normalize(float3(u, 1 - u, u)))
344
345        // SamplerComparisonState variant
346#if !defined(EXCLUDE_SM_6_7)
347        // METAL: t2D{{.*}}.calculate_unclamped_lod({{.*}}
348        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_2d(
349        && float(0) >= t2D.CalculateLevelOfDetailUnclamped(shadowSampler, float2(u, u))
350
351        // METAL: t3D{{.*}}.calculate_unclamped_lod({{.*}}
352        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_3d(
353        && float(0) >= t3D.CalculateLevelOfDetailUnclamped(shadowSampler, float3(u, u, u))
354
355        // METAL: tCube{{.*}}.calculate_unclamped_lod({{.*}}
356        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_cube(
357        && float(0) >= tCube.CalculateLevelOfDetailUnclamped(shadowSampler, normalize(float3(u, 1 - u, u)))
358
359        // METAL: t2DArray{{.*}}.calculate_unclamped_lod({{.*}}
360        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_2d_array(
361        && float(0) >= t2DArray.CalculateLevelOfDetailUnclamped(shadowSampler, float2(u, u))
362
363        // METAL: tCubeArray{{.*}}.calculate_unclamped_lod({{.*}}
364        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_cube_array(
365        && float(0) >= tCubeArray.CalculateLevelOfDetailUnclamped(shadowSampler, normalize(float3(u, 1 - u, u)))
366#endif
367
368        // ===========
369        // T Sample()
370        // ===========
371
372        // METAL: t1D{{.*}}.sample(
373        // METALLIB: call {{.*}}.sample_texture_1d.v4f32(
374        && all(Tvn(T.Element(0)) == t1D.Sample(samplerState, u))
375
376        // METAL: t2D{{.*}}.sample({{.*}}
377        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
378        && all(Tvn(T.Element(0)) == t2D.Sample(samplerState, float2(u, u)))
379
380        // METAL: t3D{{.*}}.sample({{.*}}
381        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
382        && all(Tvn(T.Element(0)) == t3D.Sample(samplerState, float3(u, u, u)))
383
384        // METAL: tCube{{.*}}.sample({{.*}}
385        // METALLIB: call {{.*}}.sample_texture_cube.v4f32(
386        && all(Tvn(T.Element(0)) == tCube.Sample(samplerState, normalize(float3(u, 1 - u, u))))
387
388        // METAL: t1DArray{{.*}}.sample(
389        // METALLIB: call {{.*}}.sample_texture_1d_array.v4f32(
390        && all(Tvn(T.Element(0)) == t1DArray.Sample(samplerState, float2(u, 0)))
391
392        // METAL: t2DArray{{.*}}.sample({{.*}}
393        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
394        && all(Tvn(T.Element(0)) == t2DArray.Sample(samplerState, float3(u, u, 0)))
395
396        // METAL: tCubeArray{{.*}}.sample({{.*}}
397        // METALLIB: call {{.*}}.sample_texture_cube_array.v4f32(
398        && all(Tvn(T.Element(0)) == tCubeArray.Sample(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
399
400        // Offset variant
401
402        // Metal doesn't support Offset for 1D and Cube texture
403
404        // METAL: t2D{{.*}}.sample({{.*}}
405        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
406        && all(Tvn(T.Element(0)) == t2D.Sample(samplerState, float2(u, u), int2(1, 1)))
407
408        // METAL: t3D{{.*}}.sample({{.*}}
409        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
410        && all(Tvn(T.Element(0)) == t3D.Sample(samplerState, float3(u, u, u), int3(1, 1, 1)))
411
412        // METAL: t2DArray{{.*}}.sample({{.*}}
413        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
414        && all(Tvn(T.Element(0)) == t2DArray.Sample(samplerState, float3(u, u, 0), int2(1, 1)))
415
416        // Clamp variant
417
418        // Metal doesn't support Offset for 1D and Cube texture
419
420        // METAL: t2D{{.*}}.sample({{.*}} min_lod_clamp(
421        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
422        && all(Tvn(T.Element(0)) == t2D.Sample(samplerState, float2(u, u), int2(1, 1), float(1)))
423
424        // METAL: t3D{{.*}}.sample({{.*}} min_lod_clamp(
425        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
426        && all(Tvn(T.Element(0)) == t3D.Sample(samplerState, float3(u, u, u), int3(1, 1, 1), float(1)))
427
428        // METAL: t2DArray{{.*}}.sample({{.*}} min_lod_clamp(
429        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
430        && all(Tvn(T.Element(0)) == t2DArray.Sample(samplerState, float3(u, u, 0), int2(1, 1), float(1)))
431
432        // ===============
433        // T SampleBias()
434        // ===============
435
436        // Metal doesn't support Bias for 1D texture
437
438        // METAL: t2D{{.*}}.sample({{.*}}
439        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
440        && all(Tvn(T.Element(0)) == t2D.SampleBias(samplerState, float2(u, u), float(-1)))
441
442        // METAL: t3D{{.*}}.sample({{.*}}
443        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
444        && all(Tvn(T.Element(0)) == t3D.SampleBias(samplerState, float3(u, u, u), float(-1)))
445
446        // METAL: tCube{{.*}}.sample({{.*}}
447        // METALLIB: call {{.*}}.sample_texture_cube.v4f32(
448        && all(Tvn(T.Element(0)) == tCube.SampleBias(samplerState, normalize(float3(u, 1 - u, u)), float(-1)))
449
450        // METAL: t2DArray{{.*}}.sample({{.*}}
451        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
452        && all(Tvn(T.Element(0)) == t2DArray.SampleBias(samplerState, float3(u, u, 0), float(-1)))
453
454        // METAL: tCubeArray{{.*}}.sample({{.*}}
455        // METALLIB: call {{.*}}.sample_texture_cube_array.v4f32(
456        && all(Tvn(T.Element(0)) == tCubeArray.SampleBias(samplerState, float4(normalize(float3(u, 1 - u, u)), 0), float(-1)))
457
458        // Offset variant
459
460        // Metal doesn't support Offset for 1D and Cube texture
461
462        // METAL: t2D{{.*}}.sample({{.*}}
463        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
464        && all(Tvn(T.Element(0)) == t2D.SampleBias(samplerState, float2(u, u), float(-1), int2(1, 1)))
465
466        // METAL: t3D{{.*}}.sample({{.*}}
467        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
468        && all(Tvn(T.Element(0)) == t3D.SampleBias(samplerState, float3(u, u, u), float(-1), int3(1, 1, 1)))
469
470        // METAL: t2DArray{{.*}}.sample({{.*}}
471        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
472        && all(Tvn(T.Element(0)) == t2DArray.SampleBias(samplerState, float3(u, u, 0), float(-1), int2(1, 1)))
473
474        // ===================================
475        //  T SampleLevel()
476        // ===================================
477
478        // Metal doesn't support LOD for 1D texture
479
480        // METAL: t2D{{.*}}.sample({{.*}} level(
481        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
482        && all(Tvn(T.Element(0)) == t2D.SampleLevel(samplerState, float2(u, u), 0))
483
484        // METAL: t3D{{.*}}.sample({{.*}} level(
485        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
486        && all(Tvn(T.Element(0)) == t3D.SampleLevel(samplerState, float3(u, u, u), 0))
487
488        // METAL: tCube{{.*}}.sample({{.*}} level(
489        // METALLIB: call {{.*}}.sample_texture_cube.v4f32(
490        && all(Tvn(T.Element(0)) == tCube.SampleLevel(samplerState, normalize(float3(u, 1 - u, u)), 0))
491
492        // METAL: t2DArray{{.*}}.sample({{.*}} level(
493        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
494        && all(Tvn(T.Element(0)) == t2DArray.SampleLevel(samplerState, float3(u, u, 0), 0))
495
496        // METAL: tCubeArray{{.*}}.sample({{.*}} level(
497        // METALLIB: call {{.*}}.sample_texture_cube_array.v4f32(
498        && all(Tvn(T.Element(0)) == tCubeArray.SampleLevel(samplerState, float4(normalize(float3(u, 1 - u, u)), 0), 0))
499
500        // Offset variant
501
502        // Metal doesn't support LOD for 1D texture
503
504        // METAL: t2D{{.*}}.sample({{.*}} level(
505        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
506        && all(Tvn(T.Element(0)) == t2D.SampleLevel(samplerState, float2(u, u), 0, int2(1, 1)))
507
508        // METAL: t3D{{.*}}.sample({{.*}} level(
509        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
510        && all(Tvn(T.Element(0)) == t3D.SampleLevel(samplerState, float3(u, u, u), 0, int3(1, 1, 1)))
511
512        // METAL: t2DArray{{.*}}.sample({{.*}} level(
513        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
514        && all(Tvn(T.Element(0)) == t2DArray.SampleLevel(samplerState, float3(u, u, 0), 0, int2(1, 1)))
515
516        // ==================
517        // float SampleCmp()
518        // ==================
519
520        // METAL: {{.*}}.sample_compare(
521        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
522        && float(0) == d2D.SampleCmp(shadowSampler, float2(u, u), 0)
523
524        // METAL: {{.*}}.sample_compare(
525        // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
526        && float(0) == d2DArray.SampleCmp(shadowSampler, float3(u, u, 0), 0)
527
528        // METAL: {{.*}}.sample_compare(
529        // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
530        && float(0) == dCube.SampleCmp(shadowSampler, normalize(float3(u, 1 - u, u)), 0)
531
532        // METAL: {{.*}}.sample_compare(
533        // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
534        && float(0) == dCubeArray.SampleCmp(shadowSampler, float4(normalize(float3(u, 1 - u, u)), 0), 0)
535
536        // Offset variant
537
538        // METAL: {{.*}}.sample_compare(
539        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
540        && float(0) == d2D.SampleCmp(shadowSampler, float2(u2, u), 0, int2(0, 0))
541
542        // ===================================
543        //  float SampleCmpLevelZero()
544        // ===================================
545
546        // METAL: {{.*}}.sample_compare(
547        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
548        && float(0) == d2D.SampleCmpLevelZero(shadowSampler, float2(u, u), 0)
549
550        // METAL: {{.*}}.sample_compare(
551        // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
552        && float(0) == d2DArray.SampleCmpLevelZero(shadowSampler, float3(u, u, 0), 0)
553
554        // METAL: {{.*}}.sample_compare(
555        // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
556        && float(0) == dCube.SampleCmpLevelZero(shadowSampler, normalize(float3(u, 1 - u, u)), 0)
557
558        // METAL: {{.*}}.sample_compare(
559        // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
560        && float(0) == dCubeArray.SampleCmpLevelZero(shadowSampler, float4(normalize(float3(u, 1-u, u)), 0), 0)
561
562        // Offset variant
563
564        // METAL: {{.*}}.sample_compare(
565        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
566        && float(0) == d2D.SampleCmpLevelZero(shadowSampler, float2(u2, u), 0, int2(0, 0))
567
568        // ===================================
569        //  float SampleCmpLevel()
570        // ===================================
571
572        // These require SM 6.7 for dx12 but functional compute tests currently do not run with the cs_6_7.
573#if !defined(EXCLUDE_SM_6_7)
574        // METAL: {{.*}}.sample_compare(
575        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
576        && float(0) == d2D.SampleCmpLevel(shadowSampler, float2(u, u), 0, 0.0)
577
578        // METAL: {{.*}}.sample_compare(
579        // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
580        && float(0) == d2DArray.SampleCmpLevel(shadowSampler, float3(u, u, 0), 0, 0.0)
581
582        // METAL: {{.*}}.sample_compare(
583        // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
584        && float(0) == dCube.SampleCmpLevel(shadowSampler, normalize(float3(u, 1 - u, u)), 0, 0.0)
585
586        // METAL: {{.*}}.sample_compare(
587        // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
588        && float(0) == dCubeArray.SampleCmpLevel(shadowSampler, float4(normalize(float3(u, 1-u, u)), 0), 0, 0.0)
589
590        // Offset variant
591
592        // METAL: {{.*}}.sample_compare(
593        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
594        && float(0) == d2D.SampleCmpLevel(shadowSampler, float2(u2, u), 0, 0.0, int2(0, 0))
595#endif
596
597        // ==================================
598        //  vector<T,4> Gather()
599        // ==================================
600
601        // METAL: t2D{{.*}}.gather(
602        // METALLIB: call {{.*}}.gather_texture_2d.v4f32(
603        && all(Tv4(T.Element(0)) == t2D.Gather(samplerState, float2(u, u)))
604
605        // METAL: tCube{{.*}}.gather(
606        // METALLIB: call {{.*}}.gather_texture_cube.v4f32(
607        && all(Tv4(T.Element(0)) == tCube.Gather(samplerState, normalize(float3(u, 1 - u, u))))
608
609        // METAL: t2DArray{{.*}}.gather(
610        // METALLIB: call {{.*}}.gather_texture_2d_array.v4f32(
611        && all(Tv4(T.Element(0)) == t2DArray.Gather(samplerState, float3(u, u, 0)))
612
613        // METAL: tCubeArray{{.*}}.gather(
614        // METALLIB: call {{.*}}.gather_texture_cube_array.v4f32(
615        && all(Tv4(T.Element(0)) == tCubeArray.Gather(samplerState, float4(normalize(float3(u, 1 - u, u)), 0)))
616
617        // Offset variant
618
619        // METAL: t2D{{.*}}.gather(
620        // METALLIB: call {{.*}}.gather_texture_2d.v4f32(
621        && all(Tv4(T.Element(0)) == t2D.Gather(samplerState, float2(u2, u), int2(0, 0)))
622
623        // METAL: t2DArray{{.*}}.gather(
624        // METALLIB: call {{.*}}.gather_texture_2d_array.v4f32(
625        && all(Tv4(T.Element(0)) == t2DArray.Gather(samplerState, float3(u2, u, 0), int2(0, 0)))
626
627        // =====================================
628        //  T SampleGrad()
629        // =====================================
630
631        // Metal doesn't support LOD for 1D texture
632
633        // METAL: t2D{{.*}}.sample(
634        // METALLIB: call {{.*}}.sample_texture_2d_grad.v4f32(
635        && all(Tvn(T.Element(0)) == t2D.SampleGrad(samplerState, float2(u, u), float2(ddx, ddx), float2(ddy, ddy)))
636
637        // METAL: t3D{{.*}}.sample(
638        // METALLIB: call {{.*}}.sample_texture_3d_grad.v4f32(
639        && all(Tvn(T.Element(0)) == t3D.SampleGrad(samplerState, float3(u, u, u), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy)))
640
641        // METAL: tCube{{.*}}.sample(
642        // METALLIB: call {{.*}}.sample_texture_cube_grad.v4f32(
643        && all(Tvn(T.Element(0)) == tCube.SampleGrad(samplerState, normalize(float3(u, 1 - u, u)), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy)))
644
645        // METAL: t2DArray{{.*}}.sample(
646        // METALLIB: call {{.*}}.sample_texture_2d_array_grad.v4f32(
647        && all(Tvn(T.Element(0)) == t2DArray.SampleGrad(samplerState, float3(u, u, 0.0f), float2(ddx, ddx), float2(ddy, ddy)))
648
649        // Offset variant
650
651        // METAL: t2D{{.*}}.sample(
652        // METALLIB: call {{.*}}.sample_texture_2d_grad.v4f32(
653        && all(Tvn(T.Element(0)) == t2D.SampleGrad(samplerState, float2(u2, u), float2(ddx, ddx), float2(ddy, ddy), int2(0, 0)))
654
655        // METAL: t3D{{.*}}.sample(
656        // METALLIB: call {{.*}}.sample_texture_3d_grad.v4f32(
657        && all(Tvn(T.Element(0)) == t3D.SampleGrad(samplerState, float3(u2, u, u), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy), int3(0, 0, 0)))
658
659        // METAL: t2DArray{{.*}}.sample(
660        // METALLIB: call {{.*}}.sample_texture_2d_array_grad.v4f32(
661        && all(Tvn(T.Element(0)) == t2DArray.SampleGrad(samplerState, float3(u2, u, 0.0f), float2(ddx, ddx), float2(ddy, ddy), int2(0, 0)))
662
663        // ===================
664        //  T Load()
665        // ===================
666
667        // METAL: t1D{{.*}}.read(
668        // METALLIB: call {{.*}}.read_texture_1d.v4f32(
669        && all(Tvn(T.Element(0)) == t1D.Load(int2(0, 0)))
670
671        // METAL: t2D{{.*}}.read(
672        // METALLIB: call {{.*}}.read_texture_2d.v4f32(
673        && all(Tvn(T.Element(0)) == t2D.Load(int3(0, 0, 0)))
674
675        // METAL: t3D{{.*}}.read(
676        // METALLIB: call {{.*}}.read_texture_3d.v4f32(
677        && all(Tvn(T.Element(0)) == t3D.Load(int4(0, 0, 0, 0)))
678
679        // METAL: t1DArray{{.*}}.read(
680        // METALLIB: call {{.*}}.read_texture_1d_array.v4f32(
681        && all(Tvn(T.Element(0)) == t1DArray.Load(int3(0, 0, 0)))
682
683        // METAL: t2DArray{{.*}}.read(
684        // METALLIB: call {{.*}}.read_texture_2d_array.v4f32(
685        && all(Tvn(T.Element(0)) == t2DArray.Load(int4(0, 0, 0, 0)))
686
687        // Offset variant
688
689        // Metal doesn't support offset variants for Load
690        ;
691
692    return result;
693}
694
695[numthreads(2, 2, 1)]
696void computeMain()
697{
698    // SPIR: OpEntryPoint
699    // HLSL: void computeMain(
700
701    bool result = true
702        && TEST_texture<float3>(
703            t1D_f32v3,
704            t2D_f32v3,
705            t3D_f32v3,
706            tCube_f32v3,
707            t1DArray_f32v3,
708            t2DArray_f32v3,
709            tCubeArray_f32v3)
710        // Metal textures support `Tv` types, which "denotes a 4-component vector
711        // type based on the templated type <T> for declaring the texture type:
712        //  - If T is float, Tv is float4.
713        //  - If T is half, Tv is half4.
714        //  - If T is int, Tv is int4.
715        //  - If T is uint, Tv is uint4.
716        //  - If T is short, Tv is short4.
717        //  - If T is ushort, Tv is ushort4."
718        && TEST_texture<float4>(
719            t1D_f32,
720            t2D_f32,
721            t3D_f32,
722            tCube_f32,
723            t1DArray_f32,
724            t2DArray_f32,
725            tCubeArray_f32)
726#if !defined(EXCLUDE_HALF_TYPE)
727        && TEST_texture<half4>(
728            t1D_f16,
729            t2D_f16,
730            t3D_f16,
731            tCube_f16,
732            t1DArray_f16,
733            t2DArray_f16,
734            tCubeArray_f16)
735#endif
736#if !defined(EXCLUDE_INTEGER_TYPE)
737        && TEST_texture<int4>(
738            t1D_i32,
739            t2D_i32,
740            t3D_i32,
741            tCube_i32,
742            t1DArray_i32,
743            t2DArray_i32,
744            tCubeArray_i32)
745        && TEST_texture<uint4>(
746            t1D_u32,
747            t2D_u32,
748            t3D_u32,
749            tCube_u32,
750            t1DArray_u32,
751            t2DArray_u32,
752            tCubeArray_u32)
753#if !defined(EXCLUDE_SHORT_TYPE)
754        && TEST_texture<int16_t4>(
755            t1D_i16,
756            t2D_i16,
757            t3D_i16,
758            tCube_i16,
759            t1DArray_i16,
760            t2DArray_i16,
761            tCubeArray_i16)
762        && TEST_texture<uint16_t4>(
763            t1D_u16,
764            t2D_u16,
765            t3D_u16,
766            tCube_u16,
767            t1DArray_u16,
768            t2DArray_u16,
769            tCubeArray_u16)
770#endif
771#endif
772        ;
773
774    // FUNCTIONAL: 1
775    outputBuffer[0] = int(result);
776}