@@ -72,13 +72,15 @@ struct ImGui_ImplDX12_Data
72
72
ID3D12RootSignature* pRootSignature;
73
73
ID3D12PipelineState* pPipelineState;
74
74
DXGI_FORMAT RTVFormat;
75
- ImGui_ImplDX12_Texture FontTexture;
76
75
ID3D12DescriptorHeap* pd3dSrvDescHeap;
77
76
UINT numFramesInFlight;
78
77
79
78
ImGui_ImplDX12_RenderBuffers* pFrameResources;
80
79
UINT frameIndex;
81
80
81
+ ImGui_ImplDX12_Texture FontTexture;
82
+ bool LegacySingleDescriptorUsed;
83
+
82
84
ImGui_ImplDX12_Data () { memset ((void *)this , 0 , sizeof (*this )); frameIndex = UINT_MAX; }
83
85
};
84
86
@@ -708,10 +710,7 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
708
710
709
711
// Free SRV descriptor used by texture
710
712
ImGui_ImplDX12_Texture* font_tex = &bd->FontTexture ;
711
- #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
712
- if (bd->InitInfo .SrvDescriptorFreeFn != NULL )
713
- #endif
714
- bd->InitInfo .SrvDescriptorFreeFn (&bd->InitInfo , font_tex->hFontSrvCpuDescHandle , font_tex->hFontSrvGpuDescHandle );
713
+ bd->InitInfo .SrvDescriptorFreeFn (&bd->InitInfo , font_tex->hFontSrvCpuDescHandle , font_tex->hFontSrvGpuDescHandle );
715
714
SafeRelease (font_tex->pTextureResource );
716
715
io.Fonts ->SetTexID (0 ); // We copied bd->hFontSrvGpuDescHandle to io.Fonts->TexID so let's clear that as well.
717
716
@@ -731,8 +730,9 @@ bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* init_info)
731
730
732
731
// Setup backend capabilities flags
733
732
ImGui_ImplDX12_Data* bd = IM_NEW (ImGui_ImplDX12_Data)();
734
-
735
733
bd->InitInfo = *init_info; // Deep copy
734
+ init_info = &bd->InitInfo ;
735
+
736
736
bd->pd3dDevice = init_info->Device ;
737
737
bd->RTVFormat = init_info->RTVFormat ;
738
738
bd->numFramesInFlight = init_info->NumFramesInFlight ;
@@ -742,23 +742,31 @@ bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* init_info)
742
742
io.BackendRendererName = " imgui_impl_dx12" ;
743
743
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
744
744
745
- // Allocate 1 SRV descriptor for the font texture
746
- if (init_info->SrvDescriptorAllocFn != NULL )
747
- {
748
- IM_ASSERT (init_info->SrvDescriptorFreeFn != NULL );
749
- init_info->SrvDescriptorAllocFn (&bd->InitInfo , &bd->FontTexture .hFontSrvCpuDescHandle , &bd->FontTexture .hFontSrvGpuDescHandle );
750
- }
751
- else
752
- {
753
745
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
746
+ if (init_info->SrvDescriptorAllocFn == NULL )
747
+ {
748
+ // Wrap legacy behavior of passing space for a single descriptor
754
749
IM_ASSERT (init_info->LegacySingleSrvCpuDescriptor .ptr != 0 && init_info->LegacySingleSrvGpuDescriptor .ptr != 0 );
755
- bd->FontTexture .hFontSrvCpuDescHandle = init_info->LegacySingleSrvCpuDescriptor ;
756
- bd->FontTexture .hFontSrvGpuDescHandle = init_info->LegacySingleSrvGpuDescriptor ;
757
- #else
758
- IM_ASSERT (init_info->SrvDescriptorAllocFn != NULL );
759
- IM_ASSERT (init_info->SrvDescriptorFreeFn != NULL );
760
- #endif
750
+ init_info->SrvDescriptorAllocFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_handle)
751
+ {
752
+ ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData ();
753
+ IM_ASSERT (bd->LegacySingleDescriptorUsed == false );
754
+ *out_cpu_handle = bd->InitInfo .LegacySingleSrvCpuDescriptor ;
755
+ *out_gpu_handle = bd->InitInfo .LegacySingleSrvGpuDescriptor ;
756
+ bd->LegacySingleDescriptorUsed = true ;
757
+ };
758
+ init_info->SrvDescriptorFreeFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_GPU_DESCRIPTOR_HANDLE)
759
+ {
760
+ ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData ();
761
+ IM_ASSERT (bd->LegacySingleDescriptorUsed == true );
762
+ bd->LegacySingleDescriptorUsed = false ;
763
+ };
761
764
}
765
+ #endif
766
+
767
+ // Allocate 1 SRV descriptor for the font texture
768
+ IM_ASSERT (init_info->SrvDescriptorAllocFn != NULL && init_info->SrvDescriptorFreeFn != NULL );
769
+ init_info->SrvDescriptorAllocFn (&bd->InitInfo , &bd->FontTexture .hFontSrvCpuDescHandle , &bd->FontTexture .hFontSrvGpuDescHandle );
762
770
763
771
// Create buffers with a default size (they will later be grown as needed)
764
772
bd->frameIndex = UINT_MAX;
0 commit comments