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
23.3 KiB568 linesraw
1//TEST:SIMPLE(filecheck=METAL): -stage compute -entry computeMain -target metal -DEMIT_SOURCE
2//TEST:SIMPLE(filecheck=METALLIB): -stage compute -entry computeMain -target metallib -DEMIT_SOURCE -DMETALLIB
3//TEST:SIMPLE(filecheck=HLSL): -stage compute -entry computeMain -target hlsl -DEMIT_SOURCE
4
5// It appears that when kIROp_CombinedTextureSamplerGetSampler is used,
6// "$1" refers to a sampler not the first parameter of the function.
7// This causes to emit an invalid code when the implementation is shared
8// between the combined and not-combined.
9// The following code,
10//   void GetDimensions(out float width) { __intrinsic_asm "*$1 = $0.get_width(0)"; }
11// gets emitted as following,
12//   (*(kernelContext_0->t1D_sampler_0) = (kernelContext_0->t1D_texture_0).get_width(0));
13// when it is expected to be,
14//   (*&width = (kernelContext_0->t1D_texture_0).get_width(0));
15//#define TEST_WHEN_DEFAULT_SAMPLER_WORKS_PROPERLY
16
17//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer
18RWStructuredBuffer<int> outputBuffer;
19
20// TODO: `SamplerXD` cannot be setup with TEST_INPUT method.
21
22Sampler1D<float> t1D;
23Sampler2D<float> t2D;
24Sampler3D<float> t3D;
25SamplerCube<float> tCube;
26
27Sampler1DArray<float> t1DArray;
28Sampler2DArray<float> t2DArray;
29SamplerCubeArray<float> tCubeArray;
30
31Sampler2DShadow d2D;
32SamplerCubeShadow dCube;
33Sampler2DArrayShadow d2DArray;
34SamplerCubeArrayShadow dCubeArray;
35
36bool TEST_texture_float()
37{
38    // Metal textures support `Tv` types, which "denotes a 4-component vector
39    // type based on the templated type <T> for declaring the texture type:
40    //  - If T is float, Tv is float4.
41    //  - If T is half, Tv is half4.
42    //  - If T is int, Tv is int4.
43    //  - If T is uint, Tv is uint4.
44    //  - If T is short, Tv is short4.
45    //  - If T is ushort, Tv is ushort4."
46    typealias Tv = vector<float,4>;
47
48    float u = 0;
49    float u2 = 0.5;
50    constexpr const float ddx = 0.0f;
51    constexpr const float ddy = 0.0f;
52
53    uint width = 0, height = 0, depth = 0;
54    float fwidth = 0.0f, fheight = 0.0f, fdepth = 0.0f;
55    uint numLevels = 0, elements = 0, sampleCount = 0;
56    float fnumLevels = 0.0f, felements = 0.0f;
57
58    bool voidResult = true;
59
60    // ======================
61    //  void GetDimensions()
62    // ======================
63
64#if defined(TEST_WHEN_DEFAULT_SAMPLER_WORKS_PROPERLY)
65    // M-ETAL: .get_width(
66    // M-ETALLIB: call {{.*}}.get_width_texture_1d(
67    t1D.GetDimensions(width);
68    voidResult = voidResult && (uint(4) == width);
69
70    // M-ETAL: .get_width({{.*}}.get_num_mip_levels()
71    // M-ETALLIB: call {{.*}}.get_num_mip_levels_texture_1d(
72    t1D.GetDimensions(0, width, numLevels);
73    voidResult = voidResult && (uint(4) == width);
74    voidResult = voidResult && (uint(3) == numLevels);
75
76    // M-ETAL: .get_width({{.*}}.get_height(
77    // M-ETALLIB: call {{.*}}.get_height_texture_2d(
78    t2D.GetDimensions(width, height);
79    voidResult = voidResult && (uint(4) == width);
80    voidResult = voidResult && (uint(4) == height);
81
82    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels()
83    // M-ETALLIB: call {{.*}}.get_num_mip_levels_texture_2d(
84    t2D.GetDimensions(0, width, height, numLevels);
85    voidResult = voidResult && (uint(4) == width);
86    voidResult = voidResult && (uint(4) == height);
87    voidResult = voidResult && (uint(3) == numLevels);
88
89    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_depth(
90    // M-ETALLIB: call {{.*}}.get_depth_texture_3d(
91    t3D.GetDimensions(width, height, depth);
92    voidResult = voidResult && (uint(4) == width);
93    voidResult = voidResult && (uint(4) == height);
94    voidResult = voidResult && (uint(4) == depth);
95
96    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_depth({{.*}}.get_num_mip_levels()
97    // M-ETALLIB: call {{.*}}.get_num_mip_levels_texture_3d(
98    t3D.GetDimensions(0, width, height, depth, numLevels);
99    voidResult = voidResult && (uint(4) == width);
100    voidResult = voidResult && (uint(4) == height);
101    voidResult = voidResult && (uint(4) == depth);
102    voidResult = voidResult && (uint(3) == numLevels);
103
104    // M-ETAL: .get_width({{.*}}.get_height({{.*}}
105    // M-ETALLIB: call {{.*}}.get_height_texture_cube(
106    tCube.GetDimensions(width, height);
107    voidResult = voidResult && (uint(4) == width);
108    voidResult = voidResult && (uint(4) == height);
109
110    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels()
111    // M-ETALLIB: call {{.*}}.get_num_mip_levels_texture_cube(
112    tCube.GetDimensions(0, width, height, numLevels);
113    voidResult = voidResult && (uint(4) == width);
114    voidResult = voidResult && (uint(4) == height);
115    voidResult = voidResult && (uint(3) == numLevels);
116
117    // M-ETAL: .get_width({{.*}}.get_array_size(
118    // M-ETALLIB: call {{.*}}.get_array_size_texture_1d_array(
119    t1DArray.GetDimensions(width, elements);
120    voidResult = voidResult && (uint(4) == width);
121    voidResult = voidResult && (uint(2) == elements);
122
123    // M-ETAL: .get_width({{.*}}.get_num_mip_levels(
124    // M-ETALLIB: call {{.*}}.get_num_mip_levels_texture_1d_array(
125    t1DArray.GetDimensions(0, width, elements, numLevels);
126    voidResult = voidResult && (uint(4) == width);
127    voidResult = voidResult && (uint(2) == elements);
128    voidResult = voidResult && (uint(3) == numLevels);
129
130    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_array_size(
131    // M-ETALLIB: call {{.*}}.get_array_size_texture_2d_array(
132    t2DArray.GetDimensions(width, height, elements);
133    voidResult = voidResult && (uint(4) == width);
134    voidResult = voidResult && (uint(4) == height);
135    voidResult = voidResult && (uint(2) == elements);
136
137    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels(
138    // M-ETALLIB: call {{.*}}.get_num_mip_levels_texture_2d_array(
139    t2DArray.GetDimensions(0, width, height, elements, numLevels);
140    voidResult = voidResult && (uint(4) == width);
141    voidResult = voidResult && (uint(4) == height);
142    voidResult = voidResult && (uint(2) == elements);
143    voidResult = voidResult && (uint(3) == numLevels);
144
145    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_array_size(
146    // M-ETALLIB: call {{.*}}.get_array_size_texture_cube_array(
147    tCubeArray.GetDimensions(width, height, elements);
148    voidResult = voidResult && (uint(4) == width);
149    voidResult = voidResult && (uint(4) == height);
150    voidResult = voidResult && (uint(2) == elements);
151
152    // M-ETAL: .get_width({{.*}}.get_height({{.*}}.get_num_mip_levels(
153    // M-ETALLIB: call {{.*}}.get_num_mip_levels_texture_cube_array(
154    tCubeArray.GetDimensions(0, width, height, elements, numLevels);
155    voidResult = voidResult && (uint(4) == width);
156    voidResult = voidResult && (uint(4) == height);
157    voidResult = voidResult && (uint(2) == elements);
158    voidResult = voidResult && (uint(3) == numLevels);
159#endif
160
161    bool result = voidResult
162        // ===============================
163        // float CalculateLevelOfDetail()
164        // ===============================
165
166        // METAL: t2D{{.*}}.calculate_clamped_lod({{.*}}
167        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_2d(
168        && float(0) == t2D.CalculateLevelOfDetail(float2(u, u))
169
170        // METAL: t3D{{.*}}.calculate_clamped_lod({{.*}}
171        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_3d(
172        && float(0) == t3D.CalculateLevelOfDetail(float3(u, u, u))
173
174        // METAL: tCube{{.*}}.calculate_clamped_lod({{.*}}
175        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_cube(
176        && float(0) == tCube.CalculateLevelOfDetail(normalize(float3(u, 1 - u, u)))
177
178        // METAL: t2DArray{{.*}}.calculate_clamped_lod({{.*}}
179        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_2d_array(
180        && float(0) == t2DArray.CalculateLevelOfDetail(float2(u, u))
181
182        // METAL: tCubeArray{{.*}}.calculate_clamped_lod({{.*}}
183        // METALLIB: call {{.*}}.calculate_clamped_lod_texture_cube_array(
184        && float(0) == tCubeArray.CalculateLevelOfDetail(normalize(float3(u, 1 - u, u)))
185
186        // Shadow variant
187
188        // METAL: d2D{{.*}}.calculate_clamped_lod({{.*}}
189        // METALLIB: call {{.*}}.calculate_clamped_lod_depth_2d(
190        && float(0) == d2D.CalculateLevelOfDetail(float2(u, u))
191
192        // METAL: dCube{{.*}}.calculate_clamped_lod({{.*}}
193        // METALLIB: call {{.*}}.calculate_clamped_lod_depth_cube(
194        && float(0) == dCube.CalculateLevelOfDetail(normalize(float3(u, 1 - u, u)))
195
196        // METAL: d2DArray{{.*}}.calculate_clamped_lod({{.*}}
197        // METALLIB: call {{.*}}.calculate_clamped_lod_depth_2d_array(
198        && float(0) == d2DArray.CalculateLevelOfDetail(float2(u, u))
199
200        // METAL: dCubeArray{{.*}}.calculate_clamped_lod({{.*}}
201        // METALLIB: call {{.*}}.calculate_clamped_lod_depth_cube_array(
202        && float(0) == dCubeArray.CalculateLevelOfDetail(normalize(float3(u, 1 - u, u)))
203
204        // ========================================
205        // float CalculateLevelOfDetailUnclamped()
206        // ========================================
207
208        // METAL: t2D{{.*}}.calculate_unclamped_lod({{.*}}
209        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_2d(
210        && float(0) >= t2D.CalculateLevelOfDetailUnclamped(float2(u, u))
211
212        // METAL: t3D{{.*}}.calculate_unclamped_lod({{.*}}
213        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_3d(
214        && float(0) >= t3D.CalculateLevelOfDetailUnclamped(float3(u, u, u))
215
216        // METAL: tCube{{.*}}.calculate_unclamped_lod({{.*}}
217        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_cube(
218        && float(0) >= tCube.CalculateLevelOfDetailUnclamped(normalize(float3(u, 1 - u, u)))
219
220        // METAL: t2DArray{{.*}}.calculate_unclamped_lod({{.*}}
221        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_2d_array(
222        && float(0) >= t2DArray.CalculateLevelOfDetailUnclamped(float2(u, u))
223
224        // METAL: tCubeArray{{.*}}.calculate_unclamped_lod({{.*}}
225        // METALLIB: call {{.*}}.calculate_unclamped_lod_texture_cube_array(
226        && float(0) >= tCubeArray.CalculateLevelOfDetailUnclamped(normalize(float3(u, 1 - u, u)))
227
228        // Shadow variant
229
230        // METAL: d2D{{.*}}.calculate_unclamped_lod({{.*}}
231        // METALLIB: call {{.*}}.calculate_unclamped_lod_depth_2d(
232        && float(0) >= d2D.CalculateLevelOfDetailUnclamped(float2(u, u))
233
234        // METAL: dCube{{.*}}.calculate_unclamped_lod({{.*}}
235        // METALLIB: call {{.*}}.calculate_unclamped_lod_depth_cube(
236        && float(0) >= dCube.CalculateLevelOfDetailUnclamped(normalize(float3(u, 1 - u, u)))
237
238        // METAL: d2DArray{{.*}}.calculate_unclamped_lod({{.*}}
239        // METALLIB: call {{.*}}.calculate_unclamped_lod_depth_2d_array(
240        && float(0) >= d2DArray.CalculateLevelOfDetailUnclamped(float2(u, u))
241
242        // METAL: dCubeArray{{.*}}.calculate_unclamped_lod({{.*}}
243        // METALLIB: call {{.*}}.calculate_unclamped_lod_depth_cube_array(
244        && float(0) >= dCubeArray.CalculateLevelOfDetailUnclamped(normalize(float3(u, 1 - u, u)))
245
246        // ===========
247        // T Sample()
248        // ===========
249
250        // METAL: t1D{{.*}}.sample(
251        // METALLIB: call {{.*}}.sample_texture_1d.v4f32(
252        && all(Tv(1) == t1D.Sample(u))
253
254        // METAL: t2D{{.*}}.sample({{.*}}
255        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
256        && all(Tv(1) == t2D.Sample(float2(u, u)))
257
258        // METAL: t3D{{.*}}.sample({{.*}}
259        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
260        && all(Tv(1) == t3D.Sample(float3(u, u, u)))
261
262        // METAL: tCube{{.*}}.sample({{.*}}
263        // METALLIB: call {{.*}}.sample_texture_cube.v4f32(
264        && all(Tv(1) == tCube.Sample(normalize(float3(u, 1 - u, u))))
265
266        // METAL: t1DArray{{.*}}.sample(
267        // METALLIB: call {{.*}}.sample_texture_1d_array.v4f32(
268        && all(Tv(1) == t1DArray.Sample(float2(u, 0)))
269
270        // METAL: t2DArray{{.*}}.sample({{.*}}
271        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
272        && all(Tv(1) == t2DArray.Sample(float3(u, u, 0)))
273
274        // METAL: tCubeArray{{.*}}.sample({{.*}}
275        // METALLIB: call {{.*}}.sample_texture_cube_array.v4f32(
276        && all(Tv(1) == tCubeArray.Sample(float4(normalize(float3(u, 1 - u, u)), 0)))
277
278        // Offset variant
279
280        // METAL: t2D{{.*}}.sample({{.*}}
281        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
282        && all(Tv(1) == t2D.Sample(float2(u, u), int2(1, 1)))
283
284        // METAL: t3D{{.*}}.sample({{.*}}
285        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
286        && all(Tv(1) == t3D.Sample(float3(u, u, u), int3(1, 1, 1)))
287
288        // METAL: t2DArray{{.*}}.sample({{.*}}
289        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
290        && all(Tv(1) == t2DArray.Sample(float3(u, u, 0), int2(1, 1)))
291
292        // Clamp variant
293
294        // METAL: t2D{{.*}}.sample({{.*}} min_lod_clamp(
295        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
296        && all(Tv(1) == t2D.Sample(float2(u, u), int2(1, 1), float(1)))
297
298        // METAL: t3D{{.*}}.sample({{.*}} min_lod_clamp(
299        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
300        && all(Tv(1) == t3D.Sample(float3(u, u, u), int3(1, 1, 1), float(1)))
301
302        // METAL: t2DArray{{.*}}.sample({{.*}} min_lod_clamp(
303        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
304        && all(Tv(1) == t2DArray.Sample(float3(u, u, 0), int2(1, 1), float(1)))
305
306        // ===============
307        // T SampleBias()
308        // ===============
309
310        // METAL: t2D{{.*}}.sample({{.*}}
311        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
312        && all(Tv(1) == t2D.SampleBias(float2(u, u), float(-1)))
313
314        // METAL: t3D{{.*}}.sample({{.*}}
315        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
316        && all(Tv(1) == t3D.SampleBias(float3(u, u, u), float(-1)))
317
318        // METAL: tCube{{.*}}.sample({{.*}}
319        // METALLIB: call {{.*}}.sample_texture_cube.v4f32(
320        && all(Tv(1) == tCube.SampleBias(normalize(float3(u, 1 - u, u)), float(-1)))
321
322        // METAL: t2DArray{{.*}}.sample({{.*}}
323        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
324        && all(Tv(1) == t2DArray.SampleBias(float3(u, u, 0), float(-1)))
325
326        // METAL: tCubeArray{{.*}}.sample({{.*}}
327        // METALLIB: call {{.*}}.sample_texture_cube_array.v4f32(
328        && all(Tv(1) == tCubeArray.SampleBias(float4(normalize(float3(u, 1 - u, u)), 0), float(-1)))
329
330        // Offset variant
331
332        // METAL: t2D{{.*}}.sample({{.*}}
333        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
334        && all(Tv(1) == t2D.SampleBias(float2(u, u), float(-1), int2(1, 1)))
335
336        // METAL: t3D{{.*}}.sample({{.*}}
337        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
338        && all(Tv(1) == t3D.SampleBias(float3(u, u, u), float(-1), int3(1, 1, 1)))
339
340        // METAL: t2DArray{{.*}}.sample({{.*}}
341        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
342        && all(Tv(1) == t2DArray.SampleBias(float3(u, u, 0), float(-1), int2(1, 1)))
343
344        // ===================================
345        //  T SampleLevel()
346        // ===================================
347
348        // METAL: t2D{{.*}}.sample({{.*}} level(
349        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
350        && all(Tv(1) == t2D.SampleLevel(float2(u, u), 0))
351
352        // METAL: t3D{{.*}}.sample({{.*}} level(
353        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
354        && all(Tv(1) == t3D.SampleLevel(float3(u, u, u), 0))
355
356        // METAL: tCube{{.*}}.sample({{.*}} level(
357        // METALLIB: call {{.*}}.sample_texture_cube.v4f32(
358        && all(Tv(1) == tCube.SampleLevel(normalize(float3(u, 1 - u, u)), 0))
359
360        // METAL: t2DArray{{.*}}.sample({{.*}} level(
361        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
362        && all(Tv(1) == t2DArray.SampleLevel(float3(u, u, 0), 0))
363
364        // METAL: tCubeArray{{.*}}.sample({{.*}} level(
365        // METALLIB: call {{.*}}.sample_texture_cube_array.v4f32(
366        && all(Tv(1) == tCubeArray.SampleLevel(float4(normalize(float3(u, 1 - u, u)), 0), 0))
367
368        // Offset variant
369
370        // METAL: t2D{{.*}}.sample({{.*}} level(
371        // METALLIB: call {{.*}}.sample_texture_2d.v4f32(
372        && all(Tv(1) == t2D.SampleLevel(float2(u, u), 0, int2(1, 1)))
373
374        // METAL: t3D{{.*}}.sample({{.*}} level(
375        // METALLIB: call {{.*}}.sample_texture_3d.v4f32(
376        && all(Tv(1) == t3D.SampleLevel(float3(u, u, u), 0, int3(1, 1, 1)))
377
378        // METAL: t2DArray{{.*}}.sample({{.*}} level(
379        // METALLIB: call {{.*}}.sample_texture_2d_array.v4f32(
380        && all(Tv(1) == t2DArray.SampleLevel(float3(u, u, 0), 0, int2(1, 1)))
381
382        // ==================
383        // float SampleCmp()
384        // ==================
385
386        // METAL: d2D{{.*}}.sample_compare(
387        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
388        && float(1) == d2D.SampleCmp(float2(u, u), 0)
389
390        // METAL: d2DArray{{.*}}.sample_compare(
391        // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
392        && float(1) == d2DArray.SampleCmp(float3(u, u, 0), 0)
393
394        // METAL: dCube{{.*}}.sample_compare(
395        // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
396        && float(1) == dCube.SampleCmp(normalize(float3(u, 1 - u, u)), 0)
397
398        // METAL: dCubeArray{{.*}}.sample_compare(
399        // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
400        && float(1) == dCubeArray.SampleCmp(float4(normalize(float3(u, 1 - u, u)), 0), 0)
401
402        // Offset variant
403
404        // METAL: d2D{{.*}}.sample_compare(
405        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
406        && float(1) == d2D.SampleCmp(float2(u2, u), 0, int2(0, 0))
407
408        // ===================================
409        //  float SampleCmpLevelZero()
410        // ===================================
411
412        // METAL: d2D{{.*}}.sample_compare(
413        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
414        && float(1) == d2D.SampleCmpLevelZero(float2(u, u), 0)
415
416        // METAL: d2DArray{{.*}}.sample_compare(
417        // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
418        && float(1) == d2DArray.SampleCmpLevelZero(float3(u, u, 0), 0)
419
420        // METAL: dCube{{.*}}.sample_compare(
421        // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
422        && float(1) == dCube.SampleCmpLevelZero(normalize(float3(u, 1 - u, u)), 0)
423
424        // METAL: dCubeArray{{.*}}.sample_compare(
425        // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
426        && float(1) == dCubeArray.SampleCmpLevelZero(float4(normalize(float3(u, 1-u, u)), 0), 0)
427
428        // Offset variant
429
430        // METAL: d2D{{.*}}.sample_compare(
431        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
432        && float(1) == d2D.SampleCmpLevelZero(float2(u2, u), 0, int2(0, 0))
433
434        // ===================================
435        //  float SampleCmpLevel()
436        // ===================================
437
438        // METAL: d2D{{.*}}.sample_compare(
439        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
440        && float(1) == d2D.SampleCmpLevel(float2(u, u), 0, 1.0)
441
442        // METAL: d2DArray{{.*}}.sample_compare(
443        // METALLIB: call {{.*}}.sample_compare_depth_2d_array.f32(
444        && float(1) == d2DArray.SampleCmpLevel(float3(u, u, 0), 0, 1.0)
445
446        // METAL: dCube{{.*}}.sample_compare(
447        // METALLIB: call {{.*}}.sample_compare_depth_cube.f32(
448        && float(1) == dCube.SampleCmpLevel(normalize(float3(u, 1 - u, u)), 0, 1.0)
449
450        // METAL: dCubeArray{{.*}}.sample_compare(
451        // METALLIB: call {{.*}}.sample_compare_depth_cube_array.f32(
452        && float(1) == dCubeArray.SampleCmpLevel(float4(normalize(float3(u, 1-u, u)), 0), 0, 1.0)
453
454        // Offset variant
455
456        // METAL: d2D{{.*}}.sample_compare(
457        // METALLIB: call {{.*}}.sample_compare_depth_2d.f32(
458        && float(1) == d2D.SampleCmpLevel(float2(u2, u), 0, 1.0, int2(0, 0))
459
460
461        // ==================================
462        //  vector<T,4> Gather()
463        // ==================================
464
465        // METAL: t2D{{.*}}.gather(
466        // METALLIB: call {{.*}}.gather_texture_2d.v4f32(
467        && all(Tv(1) == t2D.Gather(float2(u, u)))
468
469        // METAL: tCube{{.*}}.gather(
470        // METALLIB: call {{.*}}.gather_texture_cube.v4f32(
471        && all(Tv(1) == tCube.Gather(normalize(float3(u, 1 - u, u))))
472
473        // METAL: t2DArray{{.*}}.gather(
474        // METALLIB: call {{.*}}.gather_texture_2d_array.v4f32(
475        && all(Tv(1) == t2DArray.Gather(float3(u, u, 0)))
476
477        // METAL: tCubeArray{{.*}}.gather(
478        // METALLIB: call {{.*}}.gather_texture_cube_array.v4f32(
479        && all(Tv(1) == tCubeArray.Gather(float4(normalize(float3(u, 1 - u, u)), 0)))
480
481        // Offset variant
482
483        // METAL: t2D{{.*}}.gather(
484        // METALLIB: call {{.*}}.gather_texture_2d.v4f32(
485        && all(Tv(1) == t2D.Gather(float2(u2, u), int2(0, 0)))
486
487        // METAL: t2DArray{{.*}}.gather(
488        // METALLIB: call {{.*}}.gather_texture_2d_array.v4f32(
489        && all(Tv(1) == t2DArray.Gather(float3(u2, u, 0), int2(0, 0)))
490
491        // =====================================
492        //  T SampleGrad()
493        // =====================================
494
495        // METAL: t2D{{.*}}.sample(
496        // METALLIB: call {{.*}}.sample_texture_2d_grad.v4f32(
497        && all(Tv(1) == t2D.SampleGrad(float2(u, u), float2(ddx, ddx), float2(ddy, ddy)))
498
499        // METAL: t3D{{.*}}.sample(
500        // METALLIB: call {{.*}}.sample_texture_3d_grad.v4f32(
501        && all(Tv(1) == t3D.SampleGrad(float3(u, u, u), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy)))
502
503        // METAL: tCube{{.*}}.sample(
504        // METALLIB: call {{.*}}.sample_texture_cube_grad.v4f32(
505        && all(Tv(1) == tCube.SampleGrad(normalize(float3(u, 1 - u, u)), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy)))
506
507        // METAL: t2DArray{{.*}}.sample(
508        // METALLIB: call {{.*}}.sample_texture_2d_array_grad.v4f32(
509        && all(Tv(1) == t2DArray.SampleGrad(float3(u, u, 0.0f), float2(ddx, ddx), float2(ddy, ddy)))
510
511        // Offset variant
512
513        // METAL: t2D{{.*}}.sample(
514        // METALLIB: call {{.*}}.sample_texture_2d_grad.v4f32(
515        && all(Tv(1) == t2D.SampleGrad(float2(u2, u), float2(ddx, ddx), float2(ddy, ddy), int2(0, 0)))
516
517        // METAL: t3D{{.*}}.sample(
518        // METALLIB: call {{.*}}.sample_texture_3d_grad.v4f32(
519        && all(Tv(1) == t3D.SampleGrad(float3(u2, u, u), float3(ddx, ddx, ddx), float3(ddy, ddy, ddy), int3(0, 0, 0)))
520
521        // METAL: t2DArray{{.*}}.sample(
522        // METALLIB: call {{.*}}.sample_texture_2d_array_grad.v4f32(
523        && all(Tv(1) == t2DArray.SampleGrad(float3(u2, u, 0.0f), float2(ddx, ddx), float2(ddy, ddy), int2(0, 0)))
524
525        // ===================
526        //  T Load()
527        // ===================
528
529#if defined(TEST_WHEN_DEFAULT_SAMPLER_WORKS_PROPERLY)
530        // M-ETAL: t1D{{.*}}.read(
531        // M-ETALLIB: call {{.*}}.read_texture_1d.v4f32(
532        && all(Tv(1) == t1D.Load(int2(0, 0)))
533
534        // M-ETAL: t2D{{.*}}.read(
535        // M-ETALLIB: call {{.*}}.read_texture_2d.v4f32(
536        && all(Tv(1) == t2D.Load(int3(0, 0, 0)))
537
538        // M-ETAL: t3D{{.*}}.read(
539        // M-ETALLIB: call {{.*}}.read_texture_3d.v4f32(
540        && all(Tv(1) == t3D.Load(int4(0, 0, 0, 0)))
541
542        // M-ETAL: t1DArray{{.*}}.read(
543        // M-ETALLIB: call {{.*}}.read_texture_1d_array.v4f32(
544        && all(Tv(1) == t1DArray.Load(int3(0, 0, 0)))
545
546        // M-ETAL: t2DArray{{.*}}.read(
547        // M-ETALLIB: call {{.*}}.read_texture_2d_array.v4f32(
548        && all(Tv(1) == t2DArray.Load(int4(0, 0, 0, 0)))
549#endif
550        ;
551
552    return result;
553}
554
555
556[numthreads(1, 1, 1)]
557void computeMain()
558{
559    // SPIR: OpEntryPoint
560    // HLSL: void computeMain(
561
562    bool result = true
563        && TEST_texture_float()
564        ;
565
566    // FUNCTIONAL: 1
567    outputBuffer[0] = int(result);
568}