forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderdoccmd.cpp
More file actions
389 lines (331 loc) · 10.6 KB
/
renderdoccmd.cpp
File metadata and controls
389 lines (331 loc) · 10.6 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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2015-2016 Baldur Karlsson
* Copyright (c) 2014 Crytek
*
* 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 <string>
#include <replay/renderdoc_replay.h>
#include <app/renderdoc_app.h>
using std::string;
using std::wstring;
uint32_t wtoi(wchar_t *str)
{
uint32_t ret = 0;
while(str && *str)
{
if(*str > L'9' || *str < L'0')
break;
uint32_t digit = uint32_t(*str-L'0');
ret *= 10;
ret += digit;
str++;
}
return ret;
}
bool argequal(const char *a, const char *b)
{
if(a == NULL || b == NULL) return false;
while(*a && *b)
{
// only compare ASCII characters in UTF-8 string
if((*a & 0x80) == 0 &&
(*b & 0x80) == 0 &&
tolower(*a) != tolower(*b))
break;
a++;
b++;
}
// if both reached null terminator then strings are equal
return *a == 0 && *b == 0;
}
void readCapOpts(const char *str, CaptureOptions *opts)
{
// serialise from string with two chars per byte
byte *b = (byte *)opts;
for(size_t i=0; i < sizeof(CaptureOptions); i++)
*(b++) = (byte(str[i*2+0] - 'a') << 4) | byte(str[i*2+1] - 'a');
}
// defined in platform .cpps
void DisplayRendererPreview(ReplayRenderer *renderer, TextureDisplay displayCfg);
wstring GetUsername();
void DisplayRendererPreview(ReplayRenderer *renderer)
{
if(renderer == NULL) return;
rdctype::array<FetchTexture> texs;
ReplayRenderer_GetTextures(renderer, &texs);
TextureDisplay d;
for(int32_t i=0; i < texs.count; i++)
{
if(texs[i].creationFlags & eTextureCreate_SwapBuffer)
{
d.texid = texs[i].ID;
d.mip = 0;
d.sampleIdx = ~0U;
d.overlay = eTexOverlay_None;
d.CustomShader = ResourceId();
d.HDRMul = -1.0f;
d.linearDisplayAsGamma = true;
d.FlipY = false;
d.rangemin = 0.0f;
d.rangemax = 1.0f;
d.scale = 1.0f;
d.offx = 0.0f;
d.offy = 0.0f;
d.sliceFace = 0;
d.rawoutput = false;
d.lightBackgroundColour = d.darkBackgroundColour =
FloatVector(0.0f, 0.0f, 0.0f, 0.0f);
d.Red = d.Green = d.Blue = true;
d.Alpha = false;
break;
}
}
rdctype::array<FetchDrawcall> draws;
renderer->GetDrawcalls(0, &draws);
if(draws.count > 0 && draws[draws.count-1].flags & eDraw_Present)
{
ResourceId id = draws[draws.count-1].copyDestination;
if(id != ResourceId())
d.texid = id;
}
DisplayRendererPreview(renderer, d);
}
int renderdoccmd(int argc, char **argv)
{
CaptureOptions opts;
RENDERDOC_GetDefaultCaptureOptions(&opts);
opts.AllowFullscreen = false;
opts.AllowVSync = false;
opts.DelayForDebugger = 5;
opts.HookIntoChildren = true;
if(argc >= 2)
{
// fall through and print usage
if(argequal(argv[1], "--help") || argequal(argv[1], "-h"))
{
}
// if we were given a logfile, load it and continually replay it.
else if(strstr(argv[1], ".rdc") != NULL)
{
float progress = 0.0f;
ReplayRenderer *renderer = NULL;
auto status = RENDERDOC_CreateReplayRenderer(argv[1], &progress, &renderer);
if(renderer && status == eReplayCreate_Success)
DisplayRendererPreview(renderer);
ReplayRenderer_Shutdown(renderer);
return 0;
}
// dump the image from a logfile
if(argequal(argv[1], "--thumb") || argequal(argv[1], "-t"))
{
if(argc >= 3)
{
string jpgname = argv[2];
if(jpgname[jpgname.length()-4] == '.' &&
jpgname[jpgname.length()-3] == 'r' &&
jpgname[jpgname.length()-2] == 'd' &&
jpgname[jpgname.length()-1] == 'c')
{
jpgname.pop_back();
jpgname.pop_back();
jpgname.pop_back();
jpgname += "jpg";
}
else
{
jpgname += ".jpg";
}
uint32_t len = 0;
bool32 ret = RENDERDOC_GetThumbnail(argv[2], NULL, len);
if(!ret)
{
fprintf(stderr, "No thumbnail in '%s' or error retrieving it", argv[2]);
}
else
{
byte *jpgbuf = new byte[len];
RENDERDOC_GetThumbnail(argv[2], jpgbuf, len);
FILE *f = fopen(jpgname.c_str(), "wb");
if(!f)
{
fprintf(stderr, "Couldn't open destination file '%s'.", jpgname.c_str());
}
else
{
fwrite(jpgbuf, 1, len, f);
fclose(f);
}
delete[] jpgbuf;
}
}
else
{
fprintf(stderr, "Not enough parameters to --thumb");
}
return 0;
}
// replay a logfile
else if(argequal(argv[1], "--replay") || argequal(argv[1], "-r"))
{
if(argc >= 3)
{
float progress = 0.0f;
ReplayRenderer *renderer = NULL;
auto status = RENDERDOC_CreateReplayRenderer(argv[2], &progress, &renderer);
if(renderer && status == eReplayCreate_Success)
DisplayRendererPreview(renderer);
ReplayRenderer_Shutdown(renderer);
return 0;
}
else
{
fprintf(stderr, "Not enough parameters to --replay");
}
}
#ifdef WIN32
// if we were given an executable on windows, inject into it
// can't do this on other platforms as there's no nice extension
// and we don't want to just launch any single parameter in case it's
// -h or -help or some other guess/typo
else if(strstr(argv[1], ".exe") != NULL)
{
uint32_t ident = RENDERDOC_ExecuteAndInject(argv[1], NULL, NULL, NULL, &opts, false);
if(ident == 0)
fprintf(stderr, "Failed to create & inject\n");
else
fprintf(stderr, "Created & injected as %d\n", ident);
return ident;
}
#endif
// capture a program with default capture options
else if(argequal(argv[1], "--capture") || argequal(argv[1], "-c"))
{
if(argc >= 4)
{
uint32_t ident = RENDERDOC_ExecuteAndInject(argv[2], NULL, argv[3], NULL, &opts, false);
if(ident == 0)
fprintf(stderr, "Failed to create & inject to '%s' with params \"%s\"\n", argv[2], argv[3]);
else
fprintf(stderr, "Created & injected '%s' with params \"%s\" as %d\n", argv[2], argv[3], ident);
return ident;
}
else if(argc >= 3)
{
uint32_t ident = RENDERDOC_ExecuteAndInject(argv[2], NULL, NULL, NULL, &opts, false);
if(ident == 0)
fprintf(stderr, "Failed to create & inject to '%s'\n", argv[2]);
else
fprintf(stderr, "Created & injected '%s' as %d\n", argv[2], ident);
return ident;
}
else
{
fprintf(stderr, "Not enough parameters to --capture");
}
}
// inject into a running process with default capture options
else if(argequal(argv[1], "--inject") || argequal(argv[1], "-i"))
{
if(argc >= 3)
{
char *pid = argv[2];
while(*pid == '"' || isspace(*pid)) pid++;
uint32_t pidNum = (uint32_t)atoi(pid);
uint32_t ident = RENDERDOC_InjectIntoProcess(pidNum, NULL, &opts, false);
if(ident == 0)
printf("Failed to inject to %u\n", pidNum);
else
printf("Injected to %u as %u\n", pidNum, ident);
return ident;
}
else
{
fprintf(stderr, "Not enough parameters to --inject");
}
}
// spawn remote replay host
else if(argequal(argv[1], "--replayhost") || argequal(argv[1], "-rh"))
{
RENDERDOC_SpawnReplayHost(NULL);
return 1;
}
// replay a logfile over the network on a remote host
else if(argequal(argv[1], "--remotereplay") || argequal(argv[1], "-rr"))
{
if(argc >= 4)
{
RemoteRenderer *remote = NULL;
auto status = RENDERDOC_CreateRemoteReplayConnection(argv[2], &remote);
if(remote == NULL || status != eReplayCreate_Success)
return 1;
float progress = 0.0f;
ReplayRenderer *renderer = NULL;
status = RemoteRenderer_CreateProxyRenderer(remote, 0, argv[3], &progress, &renderer);
if(renderer && status == eReplayCreate_Success)
DisplayRendererPreview(renderer);
RemoteRenderer_Shutdown(remote);
return 0;
}
else
{
fprintf(stderr, "Not enough parameters to --remotereplay");
}
}
// not documented/useful for manual use on the cmd line, used internally
else if(argequal(argv[1], "--cap32for64"))
{
if(argc >= 5)
{
char *pid = argv[2];
while(*pid == '"' || isspace(*pid)) pid++;
uint32_t pidNum = (uint32_t)atoi(pid);
char *log = argv[3];
if(log[0] == 0) log = NULL;
CaptureOptions cmdopts;
readCapOpts(argv[4], &cmdopts);
return RENDERDOC_InjectIntoProcess(pidNum, log, &cmdopts, false);
}
else
{
fprintf(stderr, "Not enough parameters to --cap32for64");
}
}
}
fprintf(stderr, "renderdoccmd usage:\n\n");
fprintf(stderr, " <file.rdc> Launch a preview window that replays this logfile and\n");
fprintf(stderr, " displays the backbuffer.\n");
#ifdef WIN32
fprintf(stderr, " <program.exe> Launch a capture of this program with default options.\n");
#endif
fprintf(stderr, "\n");
fprintf(stderr, " -h, --help Displays this help message.\n");
fprintf(stderr, " -t, --thumb LOGFILE.rdc Dumps the embedded thumbnail to LOGFILE.jpg if it exists.\n");
fprintf(stderr, " -c, --capture PROGRAM Launches capture of the program with default options.\n");
fprintf(stderr, " -i, --inject PID Injects into the specified PID to capture.\n");
fprintf(stderr, " -r, --replay LOGFILE Launch a preview window that replays this logfile and\n");
fprintf(stderr, " displays the backbuffer.\n");
fprintf(stderr, " -rh, --replayhost Starts a replay host server that can be used to remotely\n");
fprintf(stderr, " replay logfiles from another machine.\n");
fprintf(stderr, " -rr, --remotereplay HOST LOGFILE Launch a replay of the logfile and display a preview\n");
fprintf(stderr, " window. Use the remote host to replay all commands.\n");
return 1;
}