add RenderDocCapture to D3D12 quad, sphere, triangle integration tests

- Add RenderDocCapture include
- Initialize RenderDocCapture before D3D12 device creation
- SetDevice after D3D12 device initialization
- TriggerCapture on frame 29 before Present
- Add RenderDocCapture::Get().Shutdown() on exit
This commit is contained in:
2026-03-23 20:14:28 +08:00
parent 79422cfddd
commit 6f6bb13da4
3 changed files with 39 additions and 6 deletions

View File

@@ -28,6 +28,7 @@
#include "XCEngine/Debug/Logger.h" #include "XCEngine/Debug/Logger.h"
#include "XCEngine/Debug/ConsoleLogSink.h" #include "XCEngine/Debug/ConsoleLogSink.h"
#include "XCEngine/Debug/FileLogSink.h" #include "XCEngine/Debug/FileLogSink.h"
#include "XCEngine/Debug/RenderDocCapture.h"
#include "XCEngine/Containers/String.h" #include "XCEngine/Containers/String.h"
#include "third_party/stb/stb_image.h" #include "third_party/stb/stb_image.h"
@@ -352,11 +353,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return -1; return -1;
} }
RenderDocCapture::Get().Initialize(nullptr, gHWND);
RenderDocCapture::Get().SetCaptureFilePath(".\\quad_frame30");
if (!InitD3D12()) { if (!InitD3D12()) {
Log("[ERROR] Failed to initialize D3D12"); Log("[ERROR] Failed to initialize D3D12");
return -1; return -1;
} }
RenderDocCapture::Get().SetDevice(gDevice.GetDevice());
ShowWindow(gHWND, nShowCmd); ShowWindow(gHWND, nShowCmd);
UpdateWindow(gHWND); UpdateWindow(gHWND);
@@ -394,9 +400,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
frameCount++; frameCount++;
if (frameCount >= targetFrameCount) { if (frameCount >= targetFrameCount) {
ExecuteCommandList(); Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
WaitForGPU(); WaitForGPU();
bool screenshotResult = D3D12Screenshot::Capture( bool screenshotResult = D3D12Screenshot::Capture(
gDevice, gDevice,
gCommandQueue, gCommandQueue,
@@ -411,6 +416,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
break; break;
} }
if (frameCount == targetFrameCount - 1) {
RenderDocCapture::Get().TriggerCapture();
Log("[INFO] RenderDoc capture triggered");
}
EndRender(); EndRender();
ExecuteCommandList(); ExecuteCommandList();
gSwapChain.Present(0, 0); gSwapChain.Present(0, 0);
@@ -422,6 +432,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
gSwapChain.Shutdown(); gSwapChain.Shutdown();
gDevice.Shutdown(); gDevice.Shutdown();
RenderDocCapture::Get().Shutdown();
Logger::Get().Shutdown(); Logger::Get().Shutdown();
Log("[INFO] D3D12 Quad Test Finished"); Log("[INFO] D3D12 Quad Test Finished");

View File

@@ -30,6 +30,7 @@
#include "XCEngine/Debug/Logger.h" #include "XCEngine/Debug/Logger.h"
#include "XCEngine/Debug/ConsoleLogSink.h" #include "XCEngine/Debug/ConsoleLogSink.h"
#include "XCEngine/Debug/FileLogSink.h" #include "XCEngine/Debug/FileLogSink.h"
#include "XCEngine/Debug/RenderDocCapture.h"
#include "XCEngine/Containers/String.h" #include "XCEngine/Containers/String.h"
#include "XCEngine/Math/Matrix4.h" #include "XCEngine/Math/Matrix4.h"
#include "XCEngine/Math/Vector3.h" #include "XCEngine/Math/Vector3.h"
@@ -440,11 +441,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return -1; return -1;
} }
RenderDocCapture::Get().Initialize(nullptr, gHWND);
RenderDocCapture::Get().SetCaptureFilePath(".\\sphere_frame30");
if (!InitD3D12()) { if (!InitD3D12()) {
Log("[ERROR] Failed to initialize D3D12"); Log("[ERROR] Failed to initialize D3D12");
return -1; return -1;
} }
RenderDocCapture::Get().SetDevice(gDevice.GetDevice());
ShowWindow(gHWND, nShowCmd); ShowWindow(gHWND, nShowCmd);
UpdateWindow(gHWND); UpdateWindow(gHWND);
@@ -486,9 +492,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
frameCount++; frameCount++;
if (frameCount >= targetFrameCount) { if (frameCount >= targetFrameCount) {
ExecuteCommandList(); Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
WaitForGPU(); WaitForGPU();
bool screenshotResult = D3D12Screenshot::Capture( bool screenshotResult = D3D12Screenshot::Capture(
gDevice, gDevice,
gCommandQueue, gCommandQueue,
@@ -503,6 +508,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
break; break;
} }
if (frameCount == targetFrameCount - 1) {
RenderDocCapture::Get().TriggerCapture();
Log("[INFO] RenderDoc capture triggered");
}
EndRender(); EndRender();
ExecuteCommandList(); ExecuteCommandList();
gSwapChain.Present(0, 0); gSwapChain.Present(0, 0);
@@ -514,6 +524,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
gSwapChain.Shutdown(); gSwapChain.Shutdown();
gDevice.Shutdown(); gDevice.Shutdown();
RenderDocCapture::Get().Shutdown();
Logger::Get().Shutdown(); Logger::Get().Shutdown();
Log("[INFO] D3D12 Sphere Test Finished"); Log("[INFO] D3D12 Sphere Test Finished");

View File

@@ -27,6 +27,7 @@
#include "XCEngine/Debug/Logger.h" #include "XCEngine/Debug/Logger.h"
#include "XCEngine/Debug/ConsoleLogSink.h" #include "XCEngine/Debug/ConsoleLogSink.h"
#include "XCEngine/Debug/FileLogSink.h" #include "XCEngine/Debug/FileLogSink.h"
#include "XCEngine/Debug/RenderDocCapture.h"
#include "XCEngine/Containers/String.h" #include "XCEngine/Containers/String.h"
using namespace XCEngine::RHI; using namespace XCEngine::RHI;
@@ -286,11 +287,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return -1; return -1;
} }
RenderDocCapture::Get().Initialize(nullptr, gHWND);
RenderDocCapture::Get().SetCaptureFilePath(".\\triangle_frame30");
if (!InitD3D12()) { if (!InitD3D12()) {
MessageBox(NULL, L"Failed to initialize D3D12", L"Error", MB_OK); MessageBox(NULL, L"Failed to initialize D3D12", L"Error", MB_OK);
return -1; return -1;
} }
RenderDocCapture::Get().SetDevice(gDevice.GetDevice());
ShowWindow(gHWND, nShowCmd); ShowWindow(gHWND, nShowCmd);
UpdateWindow(gHWND); UpdateWindow(gHWND);
@@ -324,8 +330,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
frameCount++; frameCount++;
if (frameCount >= targetFrameCount) { if (frameCount >= targetFrameCount) {
Log("[INFO] Reached target frame count %d - taking screenshot before present!", targetFrameCount); Log("[INFO] Reached target frame count %d - taking screenshot!", targetFrameCount);
ExecuteCommandList();
WaitForGPU(); WaitForGPU();
Log("[INFO] GPU idle, taking screenshot..."); Log("[INFO] GPU idle, taking screenshot...");
bool screenshotResult = D3D12Screenshot::Capture( bool screenshotResult = D3D12Screenshot::Capture(
@@ -342,6 +347,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
break; break;
} }
if (frameCount == targetFrameCount - 1) {
RenderDocCapture::Get().TriggerCapture();
Log("[INFO] RenderDoc capture triggered");
}
EndRender(); EndRender();
ExecuteCommandList(); ExecuteCommandList();
gSwapChain.Present(0, 0); gSwapChain.Present(0, 0);
@@ -353,6 +363,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
gSwapChain.Shutdown(); gSwapChain.Shutdown();
gDevice.Shutdown(); gDevice.Shutdown();
RenderDocCapture::Get().Shutdown();
Logger::Get().Shutdown(); Logger::Get().Shutdown();
Log("[INFO] D3D12 Triangle Test Finished"); Log("[INFO] D3D12 Triangle Test Finished");