From 53dd7552dcbef379a57f33bb5e35f12ae04a3d8d Mon Sep 17 00:00:00 2001 From: bmarques1995 Date: Mon, 9 Dec 2024 01:19:23 -0300 Subject: [PATCH] Backends: DX12: let the user specifies the DepthStencilView format. (#8217) This is particullarly important for those who use RenderPasses. --- backends/imgui_impl_dx12.cpp | 4 ++++ backends/imgui_impl_dx12.h | 3 ++- docs/CHANGELOG.txt | 2 ++ examples/example_win32_directx12/main.cpp | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_dx12.cpp b/backends/imgui_impl_dx12.cpp index bad823c4a..16dcf5392 100644 --- a/backends/imgui_impl_dx12.cpp +++ b/backends/imgui_impl_dx12.cpp @@ -19,6 +19,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2024-12-09: DirectX12: Let user specifies the DepthStencilView format by setting ImGui_ImplDX12_InitInfo::DSVFormat. // 2024-11-15: DirectX12: *BREAKING CHANGE* Changed ImGui_ImplDX12_Init() signature to take a ImGui_ImplDX12_InitInfo struct. Legacy ImGui_ImplDX12_Init() signature is still supported (will obsolete). // 2024-11-15: DirectX12: *BREAKING CHANGE* User is now required to pass function pointers to allocate/free SRV Descriptors. We provide convenience legacy fields to pass a single descriptor, matching the old API, but upcoming features will want multiple. // 2024-10-23: DirectX12: Unmap() call specify written range. The range is informational and may be used by debug tools. @@ -72,6 +73,7 @@ struct ImGui_ImplDX12_Data ID3D12RootSignature* pRootSignature; ID3D12PipelineState* pPipelineState; DXGI_FORMAT RTVFormat; + DXGI_FORMAT DSVFormat; ID3D12DescriptorHeap* pd3dSrvDescHeap; UINT numFramesInFlight; @@ -569,6 +571,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects() psoDesc.SampleMask = UINT_MAX; psoDesc.NumRenderTargets = 1; psoDesc.RTVFormats[0] = bd->RTVFormat; + psoDesc.DSVFormat = bd->DSVFormat; psoDesc.SampleDesc.Count = 1; psoDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE; @@ -735,6 +738,7 @@ bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* init_info) bd->pd3dDevice = init_info->Device; bd->RTVFormat = init_info->RTVFormat; + bd->DSVFormat = init_info->DSVFormat; bd->numFramesInFlight = init_info->NumFramesInFlight; bd->pd3dSrvDescHeap = init_info->SrvDescriptorHeap; diff --git a/backends/imgui_impl_dx12.h b/backends/imgui_impl_dx12.h index 0ade2ac99..644c022ff 100644 --- a/backends/imgui_impl_dx12.h +++ b/backends/imgui_impl_dx12.h @@ -29,7 +29,8 @@ struct ImGui_ImplDX12_InitInfo ID3D12Device* Device; ID3D12CommandQueue* CommandQueue; int NumFramesInFlight; - DXGI_FORMAT RTVFormat; + DXGI_FORMAT RTVFormat; // RenderTarget format. + DXGI_FORMAT DSVFormat; // DepthStencilView format. void* UserData; // Allocating SRV descriptors for textures is up to the application, so we provide callbacks. diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 874c7502f..8a1cc931e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -67,6 +67,8 @@ Other changes: - Fonts: fixed AddCustomRect() not being packed with TexGlyphPadding + not accounted for surface area used to determine best-guess texture size. (#8107) [@YarikTH, @ocornut] - Misc: use SSE 4.2 crc32 instructions when available. (#8169, #4933) [@Teselka] +- Backends: DirectX12: Let user specifies the DepthStencilView format by setting + ImGui_ImplDX12_InitInfo::DSVFormat. (#8217) [@bmarques1995] - Backends: Vulkan: Make user-provided descriptor pool optional. As a convenience, when setting init_info->DescriptorPoolSize then the backend will create and manage one itself. (#8172, #4867) [@zeux] diff --git a/examples/example_win32_directx12/main.cpp b/examples/example_win32_directx12/main.cpp index eeff99c1b..392ba18aa 100644 --- a/examples/example_win32_directx12/main.cpp +++ b/examples/example_win32_directx12/main.cpp @@ -146,6 +146,7 @@ int main(int, char**) init_info.CommandQueue = g_pd3dCommandQueue; init_info.NumFramesInFlight = APP_NUM_FRAMES_IN_FLIGHT; init_info.RTVFormat = DXGI_FORMAT_R8G8B8A8_UNORM; + init_info.DSVFormat = DXGI_FORMAT_UNKNOWN; // Allocating SRV descriptors (for textures) is up to the application, so we provide callbacks. // (current version of the backend will only allocate one descriptor, future versions will need to allocate more) init_info.SrvDescriptorHeap = g_pd3dSrvDescHeap;