-
Notifications
You must be signed in to change notification settings - Fork 25
/
test_mrt_viewport_clear_shared.hpp
339 lines (268 loc) · 8.09 KB
/
test_mrt_viewport_clear_shared.hpp
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// Copyright (c) 2024 Advanced Micro Devices, Inc.
//
// This file is part of the AMD Render Pipeline Shaders SDK which is
// released under the MIT LICENSE.
//
// See file LICENSE.txt for full license details.
#pragma once
#include "utils/rps_test_host.hpp"
RPS_DECLARE_RPSL_ENTRY(test_mrt_viewport_clear, rps_main);
static const char c_Shader[] = R"(
struct V2P
{
float4 Pos : SV_Position;
float2 UV : TEXCOORD0;
};
V2P VSSimple(uint vertexId : SV_VertexID)
{
V2P result;
// Cover top left of the viewport, leaning Z 0 to 1 from left to right.
result.Pos = float4(
(vertexId & 1) * 2.0f - 1.0f,
(vertexId & 2) * -1.0f + 1.0f,
(vertexId & 1) * 1.0f,
1);
result.UV = float2((vertexId & 1) * 1.0f, (vertexId & 2) * 0.5f);
return result;
}
struct PSOutMrt5
{
float4 RT0 : SV_Target0;
float4 RT1 : SV_Target1;
float4 RT2 : SV_Target2;
float4 RT3 : SV_Target3;
float4 RT4 : SV_Target4;
};
PSOutMrt5 PSMrt5(V2P psIn)
{
PSOutMrt5 result;
result.RT0 = float4(psIn.UV, 0, 1);
result.RT1 = float4(psIn.UV, 1.0f / 4, 1);
result.RT2 = float4(psIn.UV, 2.0f / 4, 1);
result.RT3 = float4(psIn.UV, 3.0f / 4, 1);
result.RT4 = float4(psIn.UV, 4.0f / 4, 1);
return result;
}
struct PSOutMrt3
{
float4 RT0 : SV_Target0;
float4 RT1 : SV_Target1;
float4 RT2 : SV_Target2;
};
PSOutMrt3 PSMrt3(V2P psIn)
{
PSOutMrt3 result;
result.RT0 = float4(psIn.UV.x, 0, psIn.UV.y, 1);
result.RT1 = float4(psIn.UV.x, 1.0f / 2, psIn.UV.y, 1);
result.RT2 = float4(psIn.UV.x, 2.0f / 2, psIn.UV.y, 1);
return result;
}
struct GSInput
{
uint vertexId : DUMMYVERTEXID;
};
GSInput VSRtArray(uint vertexId : SV_VertexID)
{
GSInput vsOut;
vsOut.vertexId = vertexId;
return vsOut;
}
struct G2P
{
float4 Pos : SV_Position;
float2 UV : TEXCOORD0;
uint RtIndex : SV_RenderTargetArrayIndex;
};
[maxvertexcount(6)]
void GSRtArray(triangle GSInput Input[3], inout TriangleStream<G2P> gsOutStream)
{
G2P gsOutVert;
for(uint32_t iRT = 0; iRT < 2; iRT++)
{
gsOutVert.RtIndex = iRT;
gsOutVert.Pos = float4(-1, 1, 0, 1);
gsOutVert.UV = float2(0, 0);
gsOutStream.Append(gsOutVert);
gsOutVert.Pos = float4( 1, 1, 0, 1);
gsOutVert.UV = float2(1, 0);
gsOutStream.Append(gsOutVert);
gsOutVert.Pos = float4(-1,-1, 0, 1);
gsOutVert.UV = float2(0, 1);
gsOutStream.Append(gsOutVert);
gsOutStream.RestartStrip();
}
}
float4 PSRtArray(G2P psIn) : SV_Target0
{
return float4(psIn.UV, psIn.RtIndex * 1.0f, 1.0f);
}
V2P VSBlt(uint vertexId : SV_VertexID)
{
V2P result;
result.Pos = float4(
(vertexId & 1) * 4.0f - 1.0f,
(vertexId & 2) * -2.0f + 1.0f,
0, 1);
result.UV = float2((vertexId & 1) * 2.0f, (vertexId & 2) * 1.0f);
return result;
}
[[vk::binding(1, 0)]]
Texture2D g_tex : register(t0);
[[vk::binding(0, 0)]]
SamplerState g_sampler : register(s0);
float4 PSBlt(V2P psIn) : SV_Target0
{
return g_tex.SampleLevel(g_sampler, psIn.UV, 0);
}
[maxvertexcount(18)]
void GSRtArrayToCube(triangle GSInput Input[3], inout TriangleStream<G2P> gsOutStream)
{
G2P gsOutVert;
for(uint32_t iRT = 0; iRT < 6; iRT++)
{
gsOutVert.RtIndex = iRT;
gsOutVert.Pos = float4(-1, 1, 0, 1);
gsOutVert.UV = float2(0, 0);
gsOutStream.Append(gsOutVert);
gsOutVert.Pos = float4( 3, 1, 0, 1);
gsOutVert.UV = float2(2, 0);
gsOutStream.Append(gsOutVert);
gsOutVert.Pos = float4(-1,-3, 0, 1);
gsOutVert.UV = float2(0, 2);
gsOutStream.Append(gsOutVert);
gsOutStream.RestartStrip();
}
}
[[vk::binding(2, 0)]]
Texture2D g_texArr[12] : register(t0);
void PSRtArrayToCubeMRT(G2P psIn,
out float4 rt0 : SV_Target0,
out float4 rt1 : SV_Target1,
out float4 rt2 : SV_Target2,
out float4 rt3 : SV_Target3,
out float4 rt4 : SV_Target4,
out float4 rt5 : SV_Target5)
{
float4 colorSrc0 = g_texArr[psIn.RtIndex].SampleLevel(g_sampler, psIn.UV, 0);
float4 colorSrc1 = g_texArr[psIn.RtIndex + 6].SampleLevel(g_sampler, psIn.UV, 0);
rt0 = lerp(colorSrc0, colorSrc1, 1 / 7.0f); // cube 0
rt1 = lerp(colorSrc0, colorSrc1, 2 / 7.0f); // cube 1
rt2 = lerp(colorSrc0, colorSrc1, 3 / 7.0f); // cube 2
rt3 = lerp(colorSrc0, colorSrc1, 5 / 7.0f); // cube 3
rt4 = lerp(colorSrc0, colorSrc1, 6 / 7.0f); // cube 4
rt5 = lerp(colorSrc0, colorSrc1, 4 / 7.0f); // cube 5
}
static const float PI = 3.14159265f;
[[vk::binding(1, 0)]]
TextureCube<float4> g_cubeTex : register(t0);
float4 PSBltCube(V2P psIn) : SV_Target0
{
float phi = psIn.UV.x * PI * 2;
float theta = psIn.UV.y * PI;
float sinTheta = sin(theta);
float3 coord = float3(
sinTheta * sin(phi),
sinTheta * cos(phi),
cos(theta));
return g_cubeTex.SampleLevel(g_sampler, coord, 0);
}
[[vk::binding(1, 0)]]
Texture2D<float> g_DepthSrv : register(t0);
[[vk::binding(3, 0)]]
Texture2D<uint2> g_StencilSrv : register(t1);
struct CBData
{
uint drawId;
float flatDepth;
};
#if VULKAN
[[vk::push_constant]] CBData cb;
#else
ConstantBuffer<CBData> cb : register(b0);
#endif
V2P VSSimpleFlatDepth(uint vertexId : SV_VertexID)
{
V2P result;
// Cover top left of the viewport, leaning Z 0 to 1 from left to right.
result.Pos = float4(
(vertexId & 1) * 2.0f - 1.0f,
(vertexId & 2) * -1.0f + 1.0f,
cb.flatDepth,
1);
result.UV = float2((vertexId & 1) * 1.0f, (vertexId & 2) * 0.5f);
return result;
}
float4 PSWriteDepthStencil(V2P psIn) : SV_Target0
{
uint2 tile = (uint2)(psIn.Pos.xy) / 12;
if ((cb.drawId == 0) == ((tile.x & 1u) != (tile.y & 1u)))
discard;
return float4(0, 1, 0, 0);
}
float4 PSReadDepthWriteStencil(V2P psIn, uint sampleIdx : SV_SampleIndex) : SV_Target0
{
float fDepthSrvValue = g_DepthSrv.Load(int3(psIn.Pos.xy, 0));
return float4(0, 0, fDepthSrvValue, 0);
}
float4 PSReadDepthStencil(V2P psIn, uint sampleIdx : SV_SampleIndex) : SV_Target0
{
float fDepthSrvValue = g_DepthSrv.Load(int3(psIn.Pos.xy, 0));
#if VULKAN
#define STENCIL_COMPONENT r
#else
#define STENCIL_COMPONENT g
#endif
uint uStencilValue = g_StencilSrv.Load(int3(psIn.Pos.xy, 0)).STENCIL_COMPONENT;
return float4(uStencilValue / 2.0f, fDepthSrvValue, 0, 1);
}
)";
#define TEST_APP_NAME_RAW "TestMultipleRenderTargetClear"
using namespace DirectX;
class TestRpsMrtViewportClear : public RpsTestHost
{
public:
struct ViewportData
{
XMFLOAT4 data;
ViewportData()
{
}
ViewportData(const ViewportData& r)
{
FAIL();
data = r.data;
}
ViewportData& operator=(const ViewportData& r)
{
FAIL();
data = r.data;
return *this;
}
};
TestRpsMrtViewportClear()
{
}
protected:
void Init(RpsDevice hRpsDevice)
{
RpsTestHost::OnInit(hRpsDevice, rpsTestLoadRpslEntry(test_mrt_viewport_clear, rps_main));
}
virtual void BindNodes(RpsSubprogram hRpslEntry) override
{
RpsResult result =
rpsProgramBindNode(hRpslEntry, "test_unordered_5_mrt_no_ds", &TestRpsMrtViewportClear::Draw5MrtNoDS, this);
REQUIRE(result == RPS_OK);
result = rpsProgramBindNode(hRpslEntry, "test_unordered_3_mrt_ds", &TestRpsMrtViewportClear::Draw3MrtDS, this);
REQUIRE(result == RPS_OK);
result = rpsProgramBindNode(hRpslEntry, "test_rt_array", &TestRpsMrtViewportClear::DrawRtArray, this);
REQUIRE(result == RPS_OK);
result = rpsProgramBindNode(hRpslEntry, "test_large_array", &TestRpsMrtViewportClear::DrawLargeArray, this);
REQUIRE(result == RPS_OK);
}
protected:
virtual void Draw5MrtNoDS(const RpsCmdCallbackContext* pContext) = 0;
virtual void Draw3MrtDS(const RpsCmdCallbackContext* pContext) = 0;
virtual void DrawRtArray(const RpsCmdCallbackContext* pContext) = 0;
virtual void DrawMrtWithArray(const RpsCmdCallbackContext* pContext) = 0;
virtual void DrawLargeArray(const RpsCmdCallbackContext* pContext) = 0;
};