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
8.9 KiB203 linesraw
1// TODO: There are issues running tests combined texture samplers in DX12. (Github issue #6982)
2//DISABLE_TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -profile cs_6_7 -dx12 -Xslang -DTARGET_DX12 -xslang -Wno-41024
3
4//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -shaderobj -output-using-type -emit-spirv-directly -render-feature hardware-device -xslang -DVK -xslang -Wno-41024
5
6//TEST_INPUT: ubuffer(data=[2], stride=4):out,name outputBuffer
7RWStructuredBuffer<int> outputBuffer;
8
9//TEST_INPUT:ubuffer(data=[1 1 1 1]):name=iBuf
10RWByteAddressBuffer iBuf;
11
12//
13// Combined texture samplers.
14//
15
16//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v3
17Sampler1D<float3> st1D_f32v3;
18//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v3
19Sampler2D<float3> st2D_f32v3;
20//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v3
21Sampler3D<float3> st3D_f32v3;
22
23//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v3
24Sampler1DArray<float3> st1DArray_f32v3;
25//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v3
26Sampler2DArray<float3> st2DArray_f32v3;
27
28//TEST_INPUT: TextureSampler1D(size=4, content = one):name st1D_f32v4
29Sampler1D<float4> st1D_f32v4;
30//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2D_f32v4
31Sampler2D<float4> st2D_f32v4;
32//TEST_INPUT: TextureSampler3D(size=4, content = one):name st3D_f32v4
33Sampler3D<float4> st3D_f32v4;
34
35//TEST_INPUT: TextureSampler1D(size=4, content = one, arrayLength=2):name st1DArray_f32v4
36Sampler1DArray<float4> st1DArray_f32v4;
37//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v4
38Sampler2DArray<float4> st2DArray_f32v4;
39
40//TEST_INPUT: TextureSampler2D(size=4, content = one, sampleCount = two, mipMaps=1, format=RGBA32Float):name st2DMS_f32v4
41 Sampler2DMS<float4> st2DMS_f32v4;
42
43//
44// Combined depth texture samplers.
45//
46
47//TEST_INPUT: TextureSampler2D(size=4, content = zero, format=D32Float):name cd2D
48Sampler2DShadow cd2D;
49//TEST_INPUT: TextureSampler2D(size=4, content = zero, arrayLength=2, format=D32Float):name cd2DArray
50Sampler2DArrayShadow cd2DArray;
51
52uint getNotMapped()
53{
54    // We want to return a status uint that causes `CheckAccessFullyMapped` to return false.
55    // These are just educated guesses - actual implementation differ between platforms and drivers.
56#if defined(VK)
57    return 0xFFFFFFFFU;
58#else
59    return 0;
60#endif
61}
62
63bool TEST_combinedDepth()
64{
65    float u = 0.0;
66    int offset = 0;
67    float clamp = 0.0;
68    float slice = 0.0;
69    float level = 0.0;
70    float compareValue = 0.0;
71
72    uint status;
73
74    return true
75        // =================
76        // float SampleCmp()
77        // =================
78        && (status = getNotMapped(), all(0.0 == cd2D.SampleCmp(float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
79        && (status = getNotMapped(), all(0.0 == cd2DArray.SampleCmp(float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
80
81        // ==========================
82        // float SampleCmpLevelZero()
83        // ==========================
84        && (status = getNotMapped(), all(0.0 == cd2D.SampleCmpLevelZero(float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status)
85        && (status = getNotMapped(), all(0.0 == cd2DArray.SampleCmpLevelZero(float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status)
86
87        // ======================
88        // float SampleCmpLevel()
89        // ======================
90        && (status = getNotMapped(), all(0.0 == cd2D.SampleCmpLevel(float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status)
91        && (status = getNotMapped(), all(0.0 == cd2DArray.SampleCmpLevel(float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status)
92        ;
93}
94
95bool TEST_sampler<T>(
96    Sampler1D<T> t1D,
97    Sampler2D<T> t2D,
98    Sampler3D<T> t3D,
99    Sampler1DArray<T> t1DArray,
100    Sampler2DArray<T> t2DArray,
101) where T : ITexelElement, IArithmetic
102{
103    typealias TN = T;
104
105    float u = 0.0;
106    int offset = 0;
107    float clamp = 0.0;
108    float slice = 0.0;
109    float bias = 0.0;
110    float grad = 0.0;
111    float level = 0.0;
112    constexpr const float ddx = 0.0f;
113    constexpr const float ddy = 0.0f;
114
115    uint status;
116
117    return true
118        // ==========
119        // T Sample()
120        // ==========
121        && (status = getNotMapped(), all(TN(T(1)) == t1D.Sample(u, offset, clamp, status))) && CheckAccessFullyMapped(status)
122        && (status = getNotMapped(), all(TN(T(1)) == t2D.Sample(float2(u), int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
123        && (status = getNotMapped(), all(TN(T(1)) == t3D.Sample(float3(u), int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
124        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.Sample(float2(u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status)
125        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.Sample(float3(u, u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status)
126
127        // ==============
128        // T SampleBias()
129        // ==============
130        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleBias(u, bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
131        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleBias(float2(u), bias, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
132        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleBias(float3(u), bias, int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
133        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleBias(float2(u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
134        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleBias(float3(u, u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
135
136        // ==============
137        // T SampleGrad()
138        // ==============
139        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleGrad(u, ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
140        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleGrad(float2(u), ddx, ddy, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
141        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleGrad(float3(u), ddx, ddy, int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
142        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleGrad(float2(u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
143        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleGrad(float3(u, u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
144
145        // ==============
146        // T SampleLevel()
147        // ==============
148        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleLevel(u, level, offset, status))) && CheckAccessFullyMapped(status)
149        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleLevel(float2(u), level, int2(offset), status))) && CheckAccessFullyMapped(status)
150        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleLevel(float3(u), level, int3(offset), status))) && CheckAccessFullyMapped(status)
151        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleLevel(float2(u, slice), level, offset, status))) && CheckAccessFullyMapped(status)
152        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleLevel(float3(u, u, slice), level, offset, status))) && CheckAccessFullyMapped(status)
153        ;
154}
155
156bool TEST_sparse<T>(
157     Sampler2D<T> s2D,
158     Sampler2DMS<T> s2DMS)
159     where T : ITexelElement, IArithmetic
160 {
161     typealias TN = T;
162     constexpr const int2 offset = int2(0, 0);
163     uint status;
164
165     int sampleIndex = 0;
166     int2 iuv = int2(1, 1);
167     int3 iuvs = int3(iuv, sampleIndex);
168
169     return true
170         && (status = getNotMapped(), all(TN(T(1)) == s2D.Load(iuvs, offset, status))) && CheckAccessFullyMapped(status)
171         && (status = getNotMapped(), all(TN(T(1)) == s2DMS.Load(iuv, sampleIndex, offset, status))) && CheckAccessFullyMapped(status)
172         ;
173 }
174
175[numthreads(2, 2, 1)]
176void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
177{
178    bool result = true
179        // Make sure CheckAccessFullyMapped can return false
180        && (!CheckAccessFullyMapped(getNotMapped()))
181        && TEST_sampler(
182            st1D_f32v3,
183            st2D_f32v3,
184            st3D_f32v3,
185            st1DArray_f32v3,
186            st2DArray_f32v3,
187            )
188        && TEST_sampler(
189            st1D_f32v4,
190            st2D_f32v4,
191            st3D_f32v4,
192            st1DArray_f32v4,
193            st2DArray_f32v4,
194            )
195        && TEST_combinedDepth()
196#if !defined(TARGET_DX12) // HLSL doesn't support samplers for `Load` functions.
197        && TEST_sparse(st2D_f32v4, st2DMS_f32v4)
198#endif
199        ;
200
201    //CHK:1
202    outputBuffer[0] = int(result);
203}