fix: simplify RenderDocCapture usage with TriggerCapture

- Remove BeginCapture/EndCapture complexity for manual frame capture
- Use TriggerCapture for single frame capture (simpler API)
- Move TriggerCapture before Present to ensure frame is captured
- Add SetForegroundWindow/SetFocus before TriggerCapture
- Remove default capture path in Initialize to allow SetCaptureFilePath to work
This commit is contained in:
2026-03-23 19:40:50 +08:00
parent 067c82c3a9
commit 79422cfddd
3 changed files with 28 additions and 65 deletions

View File

@@ -229,12 +229,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return -1;
}
// Initialize RenderDoc capture (MUST be before D3D12 init)
if (!RenderDocCapture::Get().Initialize(nullptr, gHWND)) {
Log("[WARNING] Failed to initialize RenderDoc, frame capture will not be available");
} else {
RenderDocCapture::Get().SetCaptureFilePath(".\\minimal_frame30");
}
RenderDocCapture::Get().Initialize(nullptr, gHWND);
RenderDocCapture::Get().SetCaptureFilePath(".\\minimal_frame30");
// Initialize D3D12
if (!InitD3D12()) {
@@ -277,19 +273,20 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
frameCount++;
EndRender();
// Execute
ExecuteCommandList();
if (frameCount >= targetFrameCount) {
RenderDocCapture::Get().TriggerCapture();
Log("[INFO] RenderDoc capture triggered");
}
// Present
gSwapChain.Present(0, 0);
if (frameCount >= targetFrameCount) {
if (RenderDocCapture::Get().EndCapture()) {
Log("[INFO] RenderDoc capture ended, NumCaptures: %u", RenderDocCapture::Get().GetNumCaptures());
if (RenderDocCapture::Get().GetNumCaptures() > 0) {
RenderDocCaptureInfo info;
if (RenderDocCapture::Get().GetCapture(0, &info)) {
Log("[INFO] Capture file: %s (%u bytes)", info.filename, info.length);
}
}
} else {
Log("[ERROR] Failed to end RenderDoc capture");
}
ExecuteCommandList();
WaitForGPU();
Log("[INFO] GPU idle, taking screenshot...");
bool screenshotResult = D3D12Screenshot::Capture(
@@ -306,22 +303,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
Log("[INFO] RenderDoc capture completed");
break;
}
if (frameCount == targetFrameCount - 1) {
if (RenderDocCapture::Get().BeginCapture("D3D12_Minimal_Test")) {
Log("[INFO] RenderDoc capture started at frame %d", frameCount + 1);
} else {
Log("[ERROR] Failed to start RenderDoc capture");
}
}
EndRender();
// Execute
ExecuteCommandList();
// Present
gSwapChain.Present(0, 0);
}
}