forked from GPUOpen-LibrariesAndSDKs/RenderPipelineShaders
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_builder.cpp
221 lines (181 loc) · 8.29 KB
/
test_builder.cpp
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
// Copyright (c) 2023 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.txt for full license details.
#define CATCH_CONFIG_MAIN
#include "rps/rps.h"
#include "utils/rps_test_common.h"
extern "C" {
typedef struct PrivateUpdateInfo
{
uint32_t width;
uint32_t height;
RpsBool bUseOffscreenRT;
RpsBool bUseMSAA;
} PrivateUpdateInfo;
RpsResult buildRenderToTexture(RpsRenderGraphBuilder hBuilder, const RpsConstant* ppArgs, uint32_t numArgs);
} // extern "C"
RpsResult buildRenderToTextureCpp(RpsRenderGraphBuilder hBuilder, const RpsConstant* ppArgs, uint32_t numArgs)
{
using namespace rps;
REQUIRE(numArgs == 2);
const RpsResourceDesc* pBackBufferDesc = static_cast<const RpsResourceDesc*>(ppArgs[0]);
const PrivateUpdateInfo* pPrivateUpdateInfo = static_cast<const PrivateUpdateInfo*>(ppArgs[1]);
RpsNodeDeclId drawTriangle = rpsRenderGraphDeclareDynamicNode(
hBuilder,
"Triangle",
RPS_NODE_DECL_FLAG_NONE,
{ParameterDesc::Make<ImageView>(AccessAttr(RPS_ACCESS_RENDER_TARGET_BIT), "renderTarget"),
ParameterDesc::Make<RpsClearValue>(SemanticAttr(RPS_SEMANTIC_COLOR_CLEAR_VALUE), "clearValue"),
ParameterDesc::Make<bool>("bMSAA"),
ParameterDesc::Make<ImageView>(
AccessAttr(RPS_ACCESS_RESOLVE_DEST_BIT), "resolveTarget", RPS_PARAMETER_FLAG_OPTIONAL_BIT)});
RpsNodeDeclId bltQuad = rpsRenderGraphDeclareDynamicNode(
hBuilder,
"Quad",
RPS_NODE_DECL_FLAG_NONE,
{ParameterDesc::Make<ImageView>(SemanticAttr(RPS_SEMANTIC_RENDER_TARGET), "backBuffer"),
ParameterDesc::Make<ImageView>(AccessAttr(RPS_ACCESS_SHADER_RESOURCE_BIT, RPS_SHADER_STAGE_PS), "offScreen")});
struct RTTVariables
{
ResourceDesc offscreenRTDesc;
ResourceDesc msaaRTDesc;
ImageView backBufferView;
ImageView offscreenRTView;
ImageView msaaRTView;
RpsClearValue clearValue;
bool bUseMSAA;
};
enum NodeIdentifiers
{
NODE_ID_TRIANGLE,
NODE_ID_MSAA_TRIANGLE,
NODE_BLT,
};
enum ResourceIdentifiers
{
RESOURCE_ID_OFFSCREEN_RT,
RESOURCE_ID_OFFSCREEN_MSAA_RT,
};
RTTVariables* rttVars = rpsRenderGraphAllocateData<RTTVariables>(hBuilder);
REQUIRE(rttVars);
const auto backBufferResId = rpsRenderGraphGetParamResourceId(hBuilder, 0);
REQUIRE(backBufferResId != RPS_RESOURCE_ID_INVALID);
rttVars->offscreenRTDesc = ResourceDesc(
RPS_RESOURCE_TYPE_IMAGE_2D, RPS_FORMAT_R8G8B8A8_UNORM, pPrivateUpdateInfo->width, pPrivateUpdateInfo->height);
rttVars->backBufferView = ImageView{backBufferResId};
rttVars->clearValue = RpsClearValue{{{0.2f, 0.2f, 0.8f, 1.0f}}};
rttVars->bUseMSAA = pPrivateUpdateInfo->bUseMSAA;
if (pPrivateUpdateInfo->bUseOffscreenRT)
{
RpsResourceId offscreenRTResId =
rpsRenderGraphDeclareResource(hBuilder, "OffscreenRT", RESOURCE_ID_OFFSCREEN_RT, &rttVars->offscreenRTDesc);
rttVars->offscreenRTView = ImageView{offscreenRTResId};
if (pPrivateUpdateInfo->bUseMSAA)
{
rttVars->msaaRTDesc = rttVars->offscreenRTDesc;
rttVars->msaaRTDesc.image.sampleCount = 4;
RpsResourceId offscreenRTMsaaResId = rpsRenderGraphDeclareResource(
hBuilder, "OffscreenRTMsaa", RESOURCE_ID_OFFSCREEN_MSAA_RT, &rttVars->msaaRTDesc);
rttVars->msaaRTView = ImageView{offscreenRTMsaaResId};
rpsRenderGraphAddNode(
hBuilder,
drawTriangle,
NODE_ID_MSAA_TRIANGLE,
nullptr,
nullptr,
RPS_CMD_CALLBACK_FLAG_NONE,
{&rttVars->msaaRTView, &rttVars->clearValue, &rttVars->bUseMSAA, &rttVars->offscreenRTView});
}
else
{
rpsRenderGraphAddNode(hBuilder,
drawTriangle,
NODE_ID_TRIANGLE,
nullptr,
nullptr,
RPS_CMD_CALLBACK_FLAG_NONE,
{&rttVars->offscreenRTView, &rttVars->clearValue, &rttVars->bUseMSAA, nullptr});
}
rpsRenderGraphAddNode(hBuilder,
bltQuad,
NODE_BLT,
nullptr,
nullptr,
RPS_CMD_CALLBACK_FLAG_NONE,
{&rttVars->offscreenRTView, &rttVars->backBufferView});
}
else
{
rpsRenderGraphAddNode(hBuilder,
drawTriangle,
pPrivateUpdateInfo->bUseMSAA ? NODE_ID_MSAA_TRIANGLE : NODE_ID_TRIANGLE,
nullptr,
nullptr,
RPS_CMD_CALLBACK_FLAG_NONE,
{&rttVars->backBufferView, &rttVars->clearValue, &rttVars->bUseMSAA, nullptr});
}
return RPS_OK;
}
TEST_CASE("BuildGraphUsingCApiCommon")
{
RpsDevice device = rpsTestUtilCreateDevice([](auto pCreateInfo, auto phDevice) {
RpsNullRuntimeDeviceCreateInfo nullDeviceCreateInfo = {};
nullDeviceCreateInfo.pDeviceCreateInfo = pCreateInfo;
return rpsNullRuntimeDeviceCreate(&nullDeviceCreateInfo, phDevice);
});
// Graph params:
RpsParameterDesc graphParams[2] = {};
graphParams[0].typeInfo = rpsTypeInfoInitFromType(RpsResourceDesc);
graphParams[0].flags = RPS_PARAMETER_FLAG_RESOURCE_BIT;
graphParams[0].name = "backBuffer";
graphParams[1].typeInfo = rpsTypeInfoInitFromType(PrivateUpdateInfo);
graphParams[1].name = "userContext";
RpsRenderGraphSignatureDesc entryInfo = {0};
entryInfo.name = "RenderToTexture_C";
entryInfo.numParams = RPS_TEST_COUNTOF(graphParams);
entryInfo.pParamDescs = graphParams;
RpsRenderGraphCreateInfo renderGraphCreateInfo = {};
renderGraphCreateInfo.mainEntryCreateInfo.pSignatureDesc = &entryInfo;
RpsRenderGraph hRenderGraph = RPS_NULL_HANDLE;
REQUIRE_RPS_OK(rpsRenderGraphCreate(device, &renderGraphCreateInfo, &hRenderGraph));
struct Resolution
{
uint32_t w;
uint32_t h;
};
Resolution resolutions[] = {{1280, 720}, {3840, 2160}};
RpsRenderGraphUpdateInfo renderGraphUpdateInfo = {};
renderGraphUpdateInfo.gpuCompletedFrameIndex = RPS_GPU_COMPLETED_FRAME_INDEX_NONE;
renderGraphUpdateInfo.diagnosticFlags |= RPS_DIAGNOSTIC_ENABLE_ALL;
RpsResourceDesc backBufferResDesc = {};
backBufferResDesc.type = RPS_RESOURCE_TYPE_IMAGE_2D;
backBufferResDesc.temporalLayers = 1;
backBufferResDesc.image.arrayLayers = 1;
backBufferResDesc.image.format = RPS_FORMAT_R8G8B8A8_UNORM;
backBufferResDesc.image.mipLevels = 1;
backBufferResDesc.image.sampleCount = 1;
for (auto res = std::cbegin(resolutions); res != std::cend(resolutions); ++res)
{
backBufferResDesc.image.width = res->w;
backBufferResDesc.image.height = res->h;
for (int32_t iUseOffscreenRT = 0; iUseOffscreenRT < 2; iUseOffscreenRT++)
{
for (int32_t iUseMSAA = 0; iUseMSAA < 2; iUseMSAA++)
{
PrivateUpdateInfo privateUpdateInfo = {res->w, res->h, iUseOffscreenRT, iUseMSAA};
RpsConstant args[] = {&backBufferResDesc, &privateUpdateInfo};
renderGraphUpdateInfo.numArgs = RPS_TEST_COUNTOF(args);
renderGraphUpdateInfo.ppArgs = args;
renderGraphUpdateInfo.pfnBuildCallback = &buildRenderToTexture;
REQUIRE_RPS_OK(rpsRenderGraphUpdate(hRenderGraph, &renderGraphUpdateInfo));
renderGraphUpdateInfo.pfnBuildCallback = &buildRenderToTextureCpp;
REQUIRE_RPS_OK(rpsRenderGraphUpdate(hRenderGraph, &renderGraphUpdateInfo));
}
}
}
rpsRenderGraphDestroy(hRenderGraph);
rpsTestUtilDestroyDevice(device);
}