Skip to content

Commit

Permalink
Backends: DX12: let the user specifies the DepthStencilView format. (#…
Browse files Browse the repository at this point in the history
…8217)

This is particullarly important for those who use RenderPasses.
  • Loading branch information
bmarques1995 authored and ocornut committed Dec 9, 2024
1 parent 2671f68 commit 53dd755
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backends/imgui_impl_dx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -72,6 +73,7 @@ struct ImGui_ImplDX12_Data
ID3D12RootSignature* pRootSignature;
ID3D12PipelineState* pPipelineState;
DXGI_FORMAT RTVFormat;
DXGI_FORMAT DSVFormat;
ID3D12DescriptorHeap* pd3dSrvDescHeap;
UINT numFramesInFlight;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion backends/imgui_impl_dx12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions examples/example_win32_directx12/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 53dd755

Please sign in to comment.