summaryrefslogtreecommitdiffstats
path: root/tests/hlsl-intrinsic/texture/partial-resident-texture.slang
blob: 6f13bd77a8684fee33cf9ce31e4e2ba69e7b641f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-slang -compute -shaderobj -output-using-type -profile cs_6_7 -dx12 -xslang -Wno-41024
//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

//TEST_INPUT: ubuffer(data=[2], stride=4):out,name outputBuffer
RWStructuredBuffer<int> outputBuffer;

//TEST_INPUT:ubuffer(data=[1 1 1 1]):name=iBuf
RWByteAddressBuffer iBuf;

//TEST_INPUT: Sampler:name samplerState
SamplerState samplerState;

//TEST_INPUT: Sampler:name samplerCmpState
SamplerComparisonState samplerCmpState;

//
// Textures.
//

//TEST_INPUT: Texture1D(size=4, content = one):name t1D_f32v3
Texture1D<float3> t1D_f32v3;
//TEST_INPUT: Texture2D(size=4, content = one):name t2D_f32v3
Texture2D<float3> t2D_f32v3;
//TEST_INPUT: Texture3D(size=4, content = one):name t3D_f32v3
Texture3D<float3> t3D_f32v3;
//TEST_INPUT: TextureCube(size=4, content = one):name tCube_f32v3
TextureCube<float3> tCube_f32v3;
//TEST_INPUT: Texture1D(size=4, content = one, arrayLength=2):name t1DArray_f32v3
Texture1DArray<float3> t1DArray_f32v3;
//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name t2DArray_f32v3
Texture2DArray<float3> t2DArray_f32v3;
//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name tCubeArray_f32v3
TextureCubeArray<float3> tCubeArray_f32v3;

//TEST_INPUT: Texture1D(size=4, content = one):name t1D_f32v4
Texture1D<float4> t1D_f32v4;
//TEST_INPUT: Texture2D(size=4, content = one):name t2D_f32v4
Texture2D<float4> t2D_f32v4;
//TEST_INPUT: Texture3D(size=4, content = one):name t3D_f32v4
Texture3D<float4> t3D_f32v4;
//TEST_INPUT: TextureCube(size=4, content = one):name tCube_f32v4
TextureCube<float4> tCube_f32v4;

//TEST_INPUT: Texture1D(size=4, content = one, arrayLength=2):name t1DArray_f32v4
Texture1DArray<float4> t1DArray_f32v4;
//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=2):name t2DArray_f32v4
Texture2DArray<float4> t2DArray_f32v4;
//TEST_INPUT: TextureCube(size=4, content = one, arrayLength=2):name tCubeArray_f32v4
TextureCubeArray<float4> tCubeArray_f32v4;

//TEST_INPUT: Texture2D(size=4, content = one, format=RGBA32Float, sampleCount=two):name t2DMS_f32v4
Texture2DMS<float4> t2DMS_f32v4;

//
// Depth textures.
//

//TEST_INPUT: Texture2D(size=4, content = zero, format=D32Float):name d2D
DepthTexture2D d2D;
//TEST_INPUT: Texture2D(size=4, content = zero, arrayLength=2, format=D32Float):name d2DArray
DepthTexture2DArray d2DArray;

uint getNotMapped()
{
    // We want to return a status uint that causes `CheckAccessFullyMapped` to return false.
    // These are just educated guesses - actual implementation differ between platforms and drivers.
#if defined(VK)
    return 0xFFFFFFFFU;
#else
    return 0;
#endif
}

bool TEST_depthTexture()
{
    float u = 0.0;
    int offset = 0;
    float clamp = 0.0;
    float slice = 0.0;
    float level = 0.0;
    float compareValue = 0.0;

    uint status;

    return true
        // =================
        // float SampleCmp()
        // =================
        && (status = getNotMapped(), all(0.0 == d2D.SampleCmp(samplerCmpState, float2(u), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmp(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)

        // ==========================
        // float SampleCmpLevelZero()
        // ==========================
        && (status = getNotMapped(), all(0.0 == d2D.SampleCmpLevelZero(samplerCmpState, float2(u), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmpLevelZero(samplerCmpState, float3(u, u, slice), compareValue, int2(offset), status))) && CheckAccessFullyMapped(status)

        // ======================
        // float SampleCmpLevel()
        // ======================
        && (status = getNotMapped(), all(0.0 == d2D.SampleCmpLevel(samplerCmpState, float2(u), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(0.0 == d2DArray.SampleCmpLevel(samplerCmpState, float3(u, u, slice), compareValue, level, int2(offset), status))) && CheckAccessFullyMapped(status)
        ;
}

bool TEST_texture<T>(
    Texture1D<T> t1D,
    Texture2D<T> t2D,
    Texture3D<T> t3D,
    TextureCube<T> tCube,
    Texture1DArray<T> t1DArray,
    Texture2DArray<T> t2DArray,
    TextureCubeArray<T> tCubeArray,
    )
    where T : ITexelElement, IArithmetic
{
    typealias TN = T;

    float u = 0.0;
    int offset = 0;
    float clamp = 0.0;
    float slice = 0.0;
    float bias = 0.0;
    float grad = 0.0;
    float level = 0.0;
    constexpr const float ddx = 0.0f;
    constexpr const float ddy = 0.0f;

    uint status;

    return true
        // ==========
        // T Sample()
        // ==========
        && (status = getNotMapped(), all(TN(T(1)) == t1D.Sample(samplerState, u, offset, clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2D.Sample(samplerState, float2(u), int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t3D.Sample(samplerState, float3(u), int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.Sample(samplerState, float2(u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.Sample(samplerState, float3(u, u, slice), offset, clamp, status))) && CheckAccessFullyMapped(status)

        // ==============
        // T SampleBias()
        // ==============
        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleBias(samplerState, u, bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleBias(samplerState, float2(u), bias, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleBias(samplerState, float3(u), bias, int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleBias(samplerState, float2(u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleBias(samplerState, float3(u, u, slice), bias, offset, clamp, status))) && CheckAccessFullyMapped(status)

        // ==============
        // T SampleGrad()
        // ==============
        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleGrad(samplerState, u, ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleGrad(samplerState, float2(u), ddx, ddy, int2(offset), clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleGrad(samplerState, float3(u), ddx, ddy, int3(offset), clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleGrad(samplerState, float2(u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleGrad(samplerState, float3(u, u, slice), ddx, ddy, offset, clamp, status))) && CheckAccessFullyMapped(status)

        // ==============
        // T SampleLevel()
        // ==============
        && (status = getNotMapped(), all(TN(T(1)) == t1D.SampleLevel(samplerState, u, level, offset, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2D.SampleLevel(samplerState, float2(u), level, int2(offset), status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t3D.SampleLevel(samplerState, float3(u), level, int3(offset), status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t1DArray.SampleLevel(samplerState, float2(u, slice), level, offset, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2DArray.SampleLevel(samplerState, float3(u, u, slice), level, offset, status))) && CheckAccessFullyMapped(status)
        ;
}

bool TEST_load<T>(
    Texture2D<T> t2D,
    Texture2DMS<T> t2DMS)
    where T : ITexelElement, IArithmetic
{
    typealias TN = T;
    constexpr const int2 offset = int2(0, 0);
    uint status;
    float clamp = 0;

    float2 uv = float2(0.5f, 0.5f);

    int sampleIndex = 0;
    int2 iuv = int2(1, 1);
    int3 iuvs = int3(iuv, sampleIndex);

    return true

        && (status = getNotMapped(), all(TN(T(1)) == t2DMS.Load(iuv, sampleIndex, offset, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(TN(T(1)) == t2D.Load(iuvs, offset, status))) && CheckAccessFullyMapped(status)
            // SPIRV does not support sparse buffer loads.
#if !defined(VK)
        && (status = getNotMapped(), 2 == outputBuffer.Load(0, status)) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), 1 == iBuf.Load(0, status)) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(int2(1) == iBuf.Load2(0, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(int3(1) == iBuf.Load3(0, status))) && CheckAccessFullyMapped(status)
        && (status = getNotMapped(), all(int4(1) == iBuf.Load4(0, status))) && CheckAccessFullyMapped(status)
#endif
        ;
}

[numthreads(2, 2, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
    bool result = true
        // Make sure CheckAccessFullyMapped can return false
        && (!CheckAccessFullyMapped(getNotMapped()))
        && TEST_texture(
            t1D_f32v3,
            t2D_f32v3,
            t3D_f32v3,
            tCube_f32v3,
            t1DArray_f32v3,
            t2DArray_f32v3,
            tCubeArray_f32v3,
            )
        &&  TEST_texture(
            t1D_f32v4,
            t2D_f32v4,
            t3D_f32v4,
            tCube_f32v4,
            t1DArray_f32v4,
            t2DArray_f32v4,
            tCubeArray_f32v4,
            )
        && TEST_depthTexture()
        && TEST_load(t2D_f32v4, t2DMS_f32v4)
        ;

    //CHK:1
    outputBuffer[0] = int(result);
}