D3D12: Add Screenshot wrapper overload and document known limitations
- Add D3D12Screenshot::Capture(D3D12Device&, D3D12CommandQueue&, D3D12Texture&, const char*) wrapper overload - Update minimal integration test to use encapsulated APIs - Add DescriptorHeap wrapper unit tests - Document minimal GetBuffer native call as known limitation in TEST_SPEC.md
This commit is contained in:
@@ -105,26 +105,8 @@ bool InitD3D12() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create swap chain
|
||||
DXGI_SWAP_CHAIN_DESC swapChainDesc = {};
|
||||
swapChainDesc.BufferCount = 2;
|
||||
swapChainDesc.BufferDesc.Width = gWidth;
|
||||
swapChainDesc.BufferDesc.Height = gHeight;
|
||||
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
swapChainDesc.OutputWindow = gHWND;
|
||||
swapChainDesc.SampleDesc.Count = 1;
|
||||
swapChainDesc.Windowed = true;
|
||||
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
||||
|
||||
IDXGISwapChain* dxgiSwapChain = nullptr;
|
||||
HRESULT hr = factory->CreateSwapChain(gCommandQueue.GetCommandQueue(), &swapChainDesc, &dxgiSwapChain);
|
||||
if (FAILED(hr)) {
|
||||
Log("[ERROR] Failed to create swap chain");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!gSwapChain.Initialize(dxgiSwapChain, (uint32_t)gWidth, (uint32_t)gHeight)) {
|
||||
// Create swap chain using encapsulated interface
|
||||
if (!gSwapChain.Initialize(factory, gCommandQueue.GetCommandQueue(), gHWND, gWidth, gHeight, 2)) {
|
||||
Log("[ERROR] Failed to initialize swap chain");
|
||||
return false;
|
||||
}
|
||||
@@ -140,21 +122,22 @@ bool InitD3D12() {
|
||||
gDSVHeap.Initialize(device, DescriptorHeapType::DSV, 1);
|
||||
gDSVDescriptorSize = gDevice.GetDescriptorHandleIncrementSize(DescriptorHeapType::DSV);
|
||||
|
||||
// Create RTVs for back buffers
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHeapStart = gRTVHeap.GetCPUDescriptorHandleForHeapStart();
|
||||
// Create RTVs for back buffers using encapsulated interface
|
||||
for (int i = 0; i < 2; i++) {
|
||||
ID3D12Resource* buffer = nullptr;
|
||||
gSwapChain.GetSwapChain()->GetBuffer(i, IID_PPV_ARGS(&buffer));
|
||||
gColorRTs[i].InitializeFromExisting(buffer);
|
||||
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle;
|
||||
rtvHandle.ptr = rtvHeapStart.ptr + i * gRTVDescriptorSize;
|
||||
CPUDescriptorHandle rtvCpuHandle = gRTVHeap.GetCPUDescriptorHandle(i);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = { rtvCpuHandle.ptr };
|
||||
gRTVs[i].InitializeAt(device, gColorRTs[i].GetResource(), rtvHandle, nullptr);
|
||||
}
|
||||
|
||||
// Create DSV
|
||||
D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc = D3D12DepthStencilView::CreateDesc(Format::D24_UNorm_S8_UInt);
|
||||
gDSV.InitializeAt(device, gDepthStencil.GetResource(), gDSVHeap.GetCPUDescriptorHandleForHeapStart(), &dsvDesc);
|
||||
CPUDescriptorHandle dsvCpuHandle = gDSVHeap.GetCPUDescriptorHandle(0);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = { dsvCpuHandle.ptr };
|
||||
gDSV.InitializeAt(device, gDepthStencil.GetResource(), dsvHandle, &dsvDesc);
|
||||
|
||||
// Create command allocator and list
|
||||
gCommandAllocator.Initialize(device, CommandQueueType::Direct);
|
||||
@@ -184,10 +167,11 @@ void BeginRender() {
|
||||
gCommandList.TransitionBarrier(gColorRTs[gCurrentRTIndex].GetResource(),
|
||||
ResourceStates::Present, ResourceStates::RenderTarget);
|
||||
|
||||
// Set render targets
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle;
|
||||
rtvHandle.ptr = gRTVHeap.GetCPUDescriptorHandleForHeapStart().ptr + gCurrentRTIndex * gRTVDescriptorSize;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = gDSVHeap.GetCPUDescriptorHandleForHeapStart();
|
||||
// Set render targets using encapsulated interface
|
||||
CPUDescriptorHandle rtvCpuHandle = gRTVHeap.GetCPUDescriptorHandle(gCurrentRTIndex);
|
||||
CPUDescriptorHandle dsvCpuHandle = gDSVHeap.GetCPUDescriptorHandle(0);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = { rtvCpuHandle.ptr };
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE dsvHandle = { dsvCpuHandle.ptr };
|
||||
|
||||
gCommandList.SetRenderTargetsHandle(1, &rtvHandle, &dsvHandle);
|
||||
|
||||
@@ -289,12 +273,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
WaitForGPU();
|
||||
Log("[INFO] GPU idle, taking screenshot...");
|
||||
bool screenshotResult = D3D12Screenshot::Capture(
|
||||
gDevice.GetDevice(),
|
||||
gCommandQueue.GetCommandQueue(),
|
||||
gColorRTs[gCurrentRTIndex].GetResource(),
|
||||
"minimal.ppm",
|
||||
gWidth,
|
||||
gHeight
|
||||
gDevice,
|
||||
gCommandQueue,
|
||||
gColorRTs[gCurrentRTIndex],
|
||||
"minimal.ppm"
|
||||
);
|
||||
if (screenshotResult) {
|
||||
Log("[INFO] Screenshot saved to minimal.ppm");
|
||||
|
||||
Reference in New Issue
Block a user