Repository navigation
Expand file tree
/
Copy pathtest_visualizer_shared.h
More file actions
265 lines (217 loc) · 8.04 KB
/
Copy pathtest_visualizer_shared.h
File metadata and controls
265 lines (217 loc) · 8.04 KB
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
// Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
//
// This file is part of the AMD Render Pipeline Shaders SDK which is
// released under the AMD INTERNAL EVALUATION LICENSE.
//
// See file LICENSE.RTF for full license details.
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <stdarg.h>
#include <DirectXMath.h>
#include "rps/rps.h"
#include "rps_visualizer.h"
#include "utils/rps_test_common.h"
#include "core/rps_util.hpp"
RPS_DECLARE_RPSL_ENTRY(test_visualizer, main);
static const char c_Shader[] = R"(
#ifdef __hlsl_dx_compiler
[[vk::binding(0, 0)]]
#endif
cbuffer SceneConstantBuffer : register(b0)
{
float4x4 offset;
float uvDistort;
float aspectRatio;
};
struct PSInput
{
float4 position : SV_POSITION;
float4 color : COLOR;
float4 uv : TEXCOORD;
};
#ifdef __hlsl_dx_compiler
[[vk::binding(1, 0)]]
#endif
Texture2D g_texture : register(t0);
#ifdef __hlsl_dx_compiler
[[vk::binding(2, 0)]]
#endif
SamplerState g_sampler : register(s0);
PSInput VSMain(float4 position : POSITION, float4 color : COLOR, float4 uv : TEXCOORD)
{
PSInput result;
position.y *= aspectRatio;
result.position = mul(offset, position);
result.color = color;
result.uv = uv;
result.uv.z = uvDistort;
return result;
}
float4 PSMain(PSInput input) : SV_TARGET
{
input.uv.y += sin(input.uv.x * 10.f) * input.uv.z;
return g_texture.Sample(g_sampler, input.uv.xy) * input.color;
}
)";
#define TEST_APP_NAME_RAW "TestVisualizer"
using namespace DirectX;
class TestRpsRenderVisualizer
{
public:
struct SceneConstantBuffer
{
XMFLOAT4X4 offset;
float uvDistort;
float aspectRatio;
};
struct Vertex
{
XMFLOAT3 position;
XMFLOAT4 color;
XMFLOAT2 uv;
};
public:
TestRpsRenderVisualizer()
: m_translation(0.f)
, m_rotation(0.f)
{
XMStoreFloat4x4(&m_quadConstantData.offset, XMMatrixIdentity());
m_quadConstantData.uvDistort = 0.1f;
m_quadConstantData.aspectRatio = 1.0f;
}
protected:
RpsRenderGraph GetRpsRenderGraph() const
{
return m_rpsRenderGraph;
}
void OnInit()
{
if (s_UseNullRuntime)
{
CreateRpsNullRuntimeDevice(m_rpsDevice);
}
else
{
CreateRpsDevice(m_rpsDevice);
}
LoadRpsPipeline();
}
virtual void UpdateRpsPipeline(uint64_t frameIndex,
uint64_t completedFrameIndex,
const RpsResourceDesc& backBufferDesc,
RpsRuntimeResource* pBackBuffers)
{
if (m_rpsRenderGraph != RPS_NULL_HANDLE)
{
const RpsRuntimeResource* argResources[] = {pBackBuffers};
RpsConstant argDataRenderToTexture[] = {&backBufferDesc, &m_useMSAA};
RpsConstant argDataGeneral[] = {&backBufferDesc};
RpsRenderGraphUpdateInfo updateInfo = {};
updateInfo.frameIndex = frameIndex;
updateInfo.gpuCompletedFrameIndex = completedFrameIndex;
updateInfo.numArgs = uint32_t(s_UseRenderToTextureImplementation ? RPS_COUNTOF(argDataRenderToTexture)
: RPS_COUNTOF(argDataGeneral));
updateInfo.ppArgs = s_UseRenderToTextureImplementation ? argDataRenderToTexture : argDataGeneral;
updateInfo.ppArgResources = argResources;
updateInfo.diagnosticFlags = RPS_DIAGNOSTIC_ENABLE_RUNTIME_DEBUG_NAMES;
if (completedFrameIndex == RPS_GPU_COMPLETED_FRAME_INDEX_NONE)
{
updateInfo.diagnosticFlags = RPS_DIAGNOSTIC_ENABLE_ALL;
}
//Disable for null runtime
REQUIRE_RPS_OK(rpsRenderGraphUpdate(m_rpsRenderGraph, &updateInfo));
if (m_HasResized)
{
RpsVisualizerUpdateInfo updateInfo = {m_rpsRenderGraph};
REQUIRE_RPS_OK(rpsVisualizerUpdate(m_rpsVisualizer, &updateInfo));
}
}
}
void OnCleanUp()
{
rpsVisualizerDestroy(m_rpsVisualizer);
rpsRenderGraphDestroy(m_rpsRenderGraph);
rpsTestUtilDestroyDevice(m_rpsDevice);
}
void OnUpdate(uint32_t frameIndex, uint32_t width, uint32_t height)
{
const float translationSpeed = 0.01f;
const float offsetBounds = 1.4f;
m_translation += translationSpeed;
if (m_translation > offsetBounds)
{
m_translation = -offsetBounds;
}
XMMATRIX transform = XMMatrixAffineTransformation2D(
XMVectorSplatOne(), XMVectorZero(), m_rotation, XMVectorSet(m_translation, 0.f, 0.f, 0.f));
XMStoreFloat4x4(&m_triangleAnimationData.offset, transform);
m_triangleAnimationData.uvDistort = 0.1f;
m_triangleAnimationData.aspectRatio = static_cast<float>(width) / height;
}
void OnRender(uint64_t frameIndex, RpsRuntimeCommandBuffer cmdBuf, uint32_t cmdBegin, uint32_t cmdCount)
{
RpsRenderGraphRecordCommandInfo recordInfo = {};
recordInfo.hCmdBuffer = cmdBuf;
recordInfo.pUserContext = this;
recordInfo.frameIndex = frameIndex;
recordInfo.cmdBeginIndex = cmdBegin;
recordInfo.numCmds = cmdCount;
RpsResult result = rpsRenderGraphRecordCommands(m_rpsRenderGraph, &recordInfo);
REQUIRE(result == RPS_OK);
REQUIRE_RPS_OK(rpsVisualizerDrawImGui(m_rpsVisualizer));
m_HasResized = false;
}
protected:
virtual void CreateRpsDevice(RpsDevice& rpsDeviceOut) = 0;
virtual void CreateRpsNullRuntimeDevice(RpsDevice& rpsDeviceOut) = 0;
virtual void DrawTriangle(const RpsCmdCallbackContext* pContext, bool bMSAA) = 0;
private:
static void DummyCb(const RpsCmdCallbackContext*)
{
}
static void DrawTriangleCb(const RpsCmdCallbackContext* pContext)
{
auto pThis = static_cast<TestRpsRenderVisualizer*>(pContext->pCmdCallbackContext);
const bool bMSAA = *rpsCmdGetArg<bool, 1>(pContext);
pThis->DrawTriangle(pContext, bMSAA);
}
void LoadRpsPipeline()
{
RpsRenderGraphCreateInfo renderGraphCreateInfo = {};
renderGraphCreateInfo.mainEntryCreateInfo.hRpslEntryPoint = rpsTestLoadRpslEntry(test_visualizer, main);
RpsResult result = rpsRenderGraphCreate(m_rpsDevice, &renderGraphCreateInfo, &m_rpsRenderGraph);
REQUIRE(result == RPS_OK);
RpsSubprogram hRpslEntry = rpsRenderGraphGetMainEntry(m_rpsRenderGraph);
if (s_UseRenderToTextureImplementation && !s_UseNullRuntime)
{
//Regular implementation
result = rpsProgramBindNode(hRpslEntry, "Geometry", &DrawTriangleCb, this);
REQUIRE(result == RPS_OK);
result = rpsProgramBindNode(hRpslEntry, "GeometryMSAA", &DrawTriangleCb, this);
REQUIRE(result == RPS_OK);
}
else
{
//Dummy Command for null runtime
result = rpsProgramBindNode(hRpslEntry, nullptr, &DummyCb, this);
REQUIRE(result == RPS_OK);
}
result = rpsVisualizerCreate(m_rpsDevice, nullptr, &m_rpsVisualizer);
REQUIRE(result == RPS_OK);
}
private:
RpsDevice m_rpsDevice = RPS_NULL_HANDLE;
RpsRenderGraph m_rpsRenderGraph = RPS_NULL_HANDLE;
float m_translation = 0.0f;
float m_rotation = 0.0f;
bool m_useMSAA = true;
protected:
static constexpr bool s_UseNullRuntime = true;
static constexpr bool s_UseRenderToTextureImplementation = false;
static_assert(s_UseRenderToTextureImplementation || s_UseNullRuntime,
"If the RenderToTextureImplementation is not used, the NullRuntime is required.");
RpsVisualizer m_rpsVisualizer = RPS_NULL_HANDLE;
SceneConstantBuffer m_triangleAnimationData;
SceneConstantBuffer m_quadConstantData;
bool m_HasResized = true;
};