-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathrdp_validate_dump.cpp
209 lines (180 loc) · 5.82 KB
/
rdp_validate_dump.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
/* Copyright (c) 2020 Themaister
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "global_managers_init.hpp"
#include "conformance_utils.hpp"
#include "rdp_dump.hpp"
#include "cli_parser.hpp"
#include "context.hpp"
#include "device.hpp"
using namespace RDP;
static void print_help()
{
LOGE("Usage: rdp-validate-dump\n"
"\t<Path to dump>\n"
"\t[--begin-frame <frame>]\n"
"\t[--sync-only]\n"
);
}
static int main_inner(int argc, char *argv[])
{
std::string path;
unsigned begin_frame = 0;
bool sync_only = false;
bool capture = false;
Util::CLICallbacks cbs;
cbs.add("--help", [](Util::CLIParser &parser) { print_help(); parser.end(); });
cbs.add("--begin-frame", [&](Util::CLIParser &parser) { begin_frame = parser.next_uint(); });
cbs.add("--sync-only", [&](Util::CLIParser &) { sync_only = true; });
cbs.add("--capture", [&](Util::CLIParser &) { capture = true; });
cbs.default_handler = [&](const char *arg) { path = arg; };
Util::CLIParser parser(std::move(cbs), argc - 1, argv + 1);
if (capture)
if (!Vulkan::Device::init_renderdoc_capture())
LOGE("Failed to initialize RenderDoc capture.\n");
if (!parser.parse())
{
print_help();
return EXIT_FAILURE;
}
else if (parser.is_ended_state())
return EXIT_SUCCESS;
DumpPlayer player;
if (!player.load_dump(path.c_str()))
{
LOGE("Failed to load dump: %s\n", path.c_str());
return EXIT_FAILURE;
}
ReplayerState state;
if (!state.init(player))
{
LOGE("Failed to initialize Vulkan device.\n");
return EXIT_FAILURE;
}
auto &iface = state.iface;
while (!state.iface.is_eof)
{
if (capture)
state.device->begin_renderdoc_capture();
unsigned current_draw_count = iface.draw_calls_for_context[1];
unsigned current_frame_count = iface.frame_count_for_context[1];
unsigned current_syncs = iface.syncs_for_context[1];
while (current_frame_count == iface.frame_count_for_context[1] &&
((!sync_only && current_draw_count == iface.draw_calls_for_context[1]) ||
(sync_only && current_syncs == iface.syncs_for_context[1])) &&
player.iterate())
{
}
if (capture)
state.device->end_renderdoc_capture();
uint32_t fault_addr;
bool fault_hidden;
current_draw_count = iface.draw_calls_for_context[1];
current_frame_count = iface.frame_count_for_context[1];
current_syncs = iface.syncs_for_context[1];
if (current_frame_count >= begin_frame &&
!compare_memory("TMEM", state.reference->get_tmem(), state.gpu->get_tmem(), 4096, &fault_addr))
{
if (sync_only)
{
LOGE("Dump validation failed in frame %u, sync %u!\n",
current_frame_count, current_syncs);
}
else
{
LOGE("Dump validation failed in frame %u, draw %u!\n",
current_frame_count, current_draw_count);
}
return EXIT_FAILURE;
}
if (current_frame_count >= begin_frame &&
!compare_rdram(*state.reference, *state.gpu, &fault_addr, &fault_hidden))
{
if (sync_only)
{
LOGE("Dump validation failed in frame %u, sync %u!\n",
current_frame_count, current_syncs);
}
else
{
LOGE("Dump validation failed in frame %u, draw %u!\n",
current_frame_count, current_draw_count);
}
if (fault_hidden)
fault_addr *= 2;
if (state.iface.fb.width)
{
int color_x, color_y, depth_x, depth_y;
int color_offset = int(fault_addr - state.iface.fb.addr);
int depth_offset = int(fault_addr - state.iface.fb.depth_addr);
depth_offset >>= 1;
switch (state.iface.fb.size)
{
case 2:
color_offset >>= 1;
break;
case 3:
color_offset >>= 2;
break;
default:
break;
}
color_x = color_offset % state.iface.fb.width;
color_y = color_offset / state.iface.fb.width;
depth_x = depth_offset % state.iface.fb.width;
depth_y = depth_offset / state.iface.fb.width;
if ((color_offset <= depth_offset || depth_offset < 0) && color_offset >= 0)
{
if (fault_hidden)
LOGE("Failure at hidden color coord (%d, %d).\n", color_x, color_y);
else
LOGE("Failure at color coord (%d, %d).\n", color_x, color_y);
}
else if ((depth_offset <= color_offset || color_offset < 0) && depth_offset >= 0)
{
if (fault_hidden)
LOGE("Failure at hidden depth coord (%d, %d).\n", depth_x, depth_y);
else
LOGE("Failure at depth coord (%d, %d).\n", depth_x, depth_y);
}
else
LOGE("Uncertain failure coordinate.\n");
}
return EXIT_FAILURE;
}
state.device->next_frame_context();
if (current_frame_count >= begin_frame)
{
if (sync_only)
LOGI("Passed frame %u, sync %u.\n", current_frame_count, current_syncs);
else
LOGI("Passed frame %u, draw %u.\n", current_frame_count, current_draw_count);
}
}
return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
Granite::Global::init();
int ret = main_inner(argc, argv);
Granite::Global::deinit();
return ret;
}