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
10.3 KiB231 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -profile cs_6_7 -dx12 -xslang -Wno-41024
2//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
3
4//TEST_INPUT: ubuffer(data=[2], stride=4):out,name outputBuffer
5RWStructuredBuffer<int> outputBuffer;
6
7//TEST_INPUT:ubuffer(data=[1 1 1 1]):name=iBuf
8RWByteAddressBuffer iBuf;
9
10//TEST_INPUT: Sampler:name samplerState
11SamplerState samplerState;
12
13//TEST_INPUT: Sampler:name samplerCmpState
14SamplerComparisonState samplerCmpState;
15
16//
17// Textures.
18//
19
20//TEST_INPUT: Texture1D(size=4, content = one):name t1D_f32v3
21Texture1D<float3> t1D_f32v3;
22//TEST_INPUT: Texture2D(size=4, content = one):name t2D_f32v3
23Texture2D<float3> t2D_f32v3;
24//TEST_INPUT: Texture3D(size=4, content = one):name t3D_f32v3
25Texture3D<float3> t3D_f32v3;
26//TEST_INPUT: TextureCube(size=4, content = one):name tCube_f32v3
27TextureCube<float3> tCube_f32v3;
28//TEST_INPUT: Texture1D(size=4, content = one, arrayLength=2):name t1DArray_f32v3
29Texture1DArray<float3> t1DArray_f32v3;
30//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name t2DArray_f32v3
31Texture2DArray<float3> t2DArray_f32v3;
32//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name tCubeArray_f32v3
33TextureCubeArray<float3> tCubeArray_f32v3;
34
35//TEST_INPUT: Texture1D(size=4, content = one):name t1D_f32v4
36Texture1D<float4> t1D_f32v4;
37//TEST_INPUT: Texture2D(size=4, content = one):name t2D_f32v4
38Texture2D<float4> t2D_f32v4;
39//TEST_INPUT: Texture3D(size=4, content = one):name t3D_f32v4
40Texture3D<float4> t3D_f32v4;
41//TEST_INPUT: TextureCube(size=4, content = one):name tCube_f32v4
42TextureCube<float4> tCube_f32v4;
43
44//TEST_INPUT: Texture1D(size=4, content = one, arrayLength=2):name t1DArray_f32v4
45Texture1DArray<float4> t1DArray_f32v4;
46//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name t2DArray_f32v4
47Texture2DArray<float4> t2DArray_f32v4;
48//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name tCubeArray_f32v4
49TextureCubeArray<float4> tCubeArray_f32v4;
50
51//TEST_INPUT: Texture2D(size=4, content = one, format=RGBA32Float, sampleCount=two):name t2DMS_f32v4
52Texture2DMS<float4> t2DMS_f32v4;
53
54//
55// Depth textures.
56//
57
58//TEST_INPUT: Texture2D(size=4, content = zero, format=D32Float):name d2D
59DepthTexture2D d2D;
60//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2, format=D32Float):name d2DArray
61DepthTexture2DArray d2DArray;
62
63uint getNotMapped()
64{
65    // We want to return a status uint that causes `CheckAccessFullyMapped` to return false.
66    // These are just educated guesses - actual implementation differ between platforms and drivers.
67#if defined(VK)
68    return 0xFFFFFFFFU;
69#else
70    return 0;
71#endif
72}
73
74bool TEST_depthTexture()
75{
76    float u = 0.0;
77    int offset = 0;
78    float clamp = 0.0;
79    float slice = 0.0;
80    float level = 0.0;
81    float compareValue = 0.0;
82
83    uint status;
84
85    return true
86        // =================
87        // float SampleCmp()
88        // =================
89        && (status = getNotMapped(), all(0.0 == d2D.SampleCmp(samplerCmpState, float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
90        && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmp(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
91
92        // ==========================
93        // float SampleCmpLevelZero()
94        // ==========================
95        && (status = getNotMapped(), all(0.0 == d2D.SampleCmpLevelZero(samplerCmpState, float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status)
96        && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmpLevelZero(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status)
97
98        // ======================
99        // float SampleCmpLevel()
100        // ======================
101        && (status = getNotMapped(), all(0.0 == d2D.SampleCmpLevel(samplerCmpState, float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status)
102        && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmpLevel(samplerCmpState, float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status)
103        ;
104}
105
106bool TEST_texture<T>(
107    Texture1D<T> t1D,
108    Texture2D<T> t2D,
109    Texture3D<T> t3D,
110    TextureCube<T> tCube,
111    Texture1DArray<T> t1DArray,
112    Texture2DArray<T> t2DArray,
113    TextureCubeArray<T> tCubeArray,
114    )
115    where T : ITexelElement, IArithmetic
116{
117    typealias TN = T;
118
119    float u = 0.0;
120    int offset = 0;
121    float clamp = 0.0;
122    float slice = 0.0;
123    float bias = 0.0;
124    float grad = 0.0;
125    float level = 0.0;
126    constexpr const float ddx = 0.0f;
127    constexpr const float ddy = 0.0f;
128
129    uint status;
130
131    return true
132        // ==========
133        // T Sample()
134        // ==========
135        && (status = getNotMapped(), all(TN(T(1)) == t1D.Sample(samplerState, u, offset, clamp, status))) && CheckAccessFullyMapped(status)
136        && (status = getNotMapped(), all(TN(T(1)) == t2D.Sample(samplerState, float2(u), int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
137        && (status = getNotMapped(), all(TN(T(1)) == t3D.Sample(samplerState, float3(u), int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
138        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.Sample(samplerState, float2(u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status)
139        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.Sample(samplerState, float3(u, u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status)
140
141        // ==============
142        // T SampleBias()
143        // ==============
144        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleBias(samplerState, u, bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
145        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleBias(samplerState, float2(u), bias, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
146        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleBias(samplerState, float3(u), bias, int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
147        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleBias(samplerState, float2(u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
148        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleBias(samplerState, float3(u, u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
149
150        // ==============
151        // T SampleGrad()
152        // ==============
153        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleGrad(samplerState, u, ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
154        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleGrad(samplerState, float2(u), ddx, ddy, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
155        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleGrad(samplerState, float3(u), ddx, ddy, int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
156        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleGrad(samplerState, float2(u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
157        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleGrad(samplerState, float3(u, u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
158
159        // ==============
160        // T SampleLevel()
161        // ==============
162        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleLevel(samplerState, u, level, offset, status))) && CheckAccessFullyMapped(status)
163        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleLevel(samplerState, float2(u), level, int2(offset), status))) && CheckAccessFullyMapped(status)
164        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleLevel(samplerState, float3(u), level, int3(offset), status))) && CheckAccessFullyMapped(status)
165        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleLevel(samplerState, float2(u, slice), level, offset, status))) && CheckAccessFullyMapped(status)
166        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleLevel(samplerState, float3(u, u, slice), level, offset, status))) && CheckAccessFullyMapped(status)
167        ;
168}
169
170bool TEST_load<T>(
171    Texture2D<T> t2D,
172    Texture2DMS<T> t2DMS)
173    where T : ITexelElement, IArithmetic
174{
175    typealias TN = T;
176    constexpr const int2 offset = int2(0, 0);
177    uint status;
178    float clamp = 0;
179
180    float2 uv = float2(0.5f, 0.5f);
181
182    int sampleIndex = 0;
183    int2 iuv = int2(1, 1);
184    int3 iuvs = int3(iuv, sampleIndex);
185
186    return true
187
188        && (status = getNotMapped(), all(TN(T(1)) == t2DMS.Load(iuv, sampleIndex, offset, status))) && CheckAccessFullyMapped(status)
189        && (status = getNotMapped(), all(TN(T(1)) == t2D.Load(iuvs, offset, status))) && CheckAccessFullyMapped(status)
190            // SPIRV does not support sparse buffer loads.
191#if !defined(VK)
192        && (status = getNotMapped(), 2 == outputBuffer.Load(0, status)) && CheckAccessFullyMapped(status)
193        && (status = getNotMapped(), 1 == iBuf.Load(0, status)) && CheckAccessFullyMapped(status)
194        && (status = getNotMapped(), all(int2(1) == iBuf.Load2(0, status))) && CheckAccessFullyMapped(status)
195        && (status = getNotMapped(), all(int3(1) == iBuf.Load3(0, status))) && CheckAccessFullyMapped(status)
196        && (status = getNotMapped(), all(int4(1) == iBuf.Load4(0, status))) && CheckAccessFullyMapped(status)
197#endif
198        ;
199}
200
201[numthreads(2, 2, 1)]
202void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
203{
204    bool result = true
205        // Make sure CheckAccessFullyMapped can return false
206        && (!CheckAccessFullyMapped(getNotMapped()))
207        && TEST_texture(
208            t1D_f32v3,
209            t2D_f32v3,
210            t3D_f32v3,
211            tCube_f32v3,
212            t1DArray_f32v3,
213            t2DArray_f32v3,
214            tCubeArray_f32v3,
215            )
216        &&  TEST_texture(
217            t1D_f32v4,
218            t2D_f32v4,
219            t3D_f32v4,
220            tCube_f32v4,
221            t1DArray_f32v4,
222            t2DArray_f32v4,
223            tCubeArray_f32v4,
224            )
225        && TEST_depthTexture()
226        && TEST_load(t2D_f32v4, t2DMS_f32v4)
227        ;
228
229    //CHK:1
230    outputBuffer[0] = int(result);
231}