Skip to content

Commit cdf21f6

Browse files
committed
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_dx12.cpp # docs/CHANGELOG.txt # imgui.cpp # imgui_internal.h
2 parents d66f4e5 + 20360e0 commit cdf21f6

15 files changed

+590
-250
lines changed

backends/imgui_impl_dx12.cpp

+82-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
99
// FIXME: The transition from removing a viewport and moving the window in an existing hosted viewport tends to flicker.
1010

11+
// The aim of imgui_impl_dx12.h/.cpp is to be usable in your engine without any modification.
12+
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
13+
1114
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
1215
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
1316
// Learn about Dear ImGui:
@@ -19,6 +22,8 @@
1922
// CHANGELOG
2023
// (minor and older changes stripped away, please see git history for details)
2124
// 2024-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
25+
// 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).
26+
// 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.
2227
// 2024-10-23: DirectX12: Unmap() call specify written range. The range is informational and may be used by debug tools.
2328
// 2024-10-07: DirectX12: Changed default texture sampler to Clamp instead of Repeat/Wrap.
2429
// 2024-10-07: DirectX12: Expose selected render state in ImGui_ImplDX12_RenderState, which you can access in 'void* platform_io.Renderer_RenderState' during draw callbacks.
@@ -53,18 +58,29 @@
5358
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
5459
#endif
5560

56-
// DirectX data
61+
// DirectX12 data
62+
struct ImGui_ImplDX12_RenderBuffers;
63+
64+
struct ImGui_ImplDX12_Texture
65+
{
66+
ID3D12Resource* pTextureResource;
67+
D3D12_CPU_DESCRIPTOR_HANDLE hFontSrvCpuDescHandle;
68+
D3D12_GPU_DESCRIPTOR_HANDLE hFontSrvGpuDescHandle;
69+
70+
ImGui_ImplDX12_Texture() { memset((void*)this, 0, sizeof(*this)); }
71+
};
72+
5773
struct ImGui_ImplDX12_Data
5874
{
75+
ImGui_ImplDX12_InitInfo InitInfo;
5976
ID3D12Device* pd3dDevice;
6077
ID3D12RootSignature* pRootSignature;
6178
ID3D12PipelineState* pPipelineState;
6279
DXGI_FORMAT RTVFormat;
63-
ID3D12Resource* pFontTextureResource;
64-
D3D12_CPU_DESCRIPTOR_HANDLE hFontSrvCpuDescHandle;
65-
D3D12_GPU_DESCRIPTOR_HANDLE hFontSrvGpuDescHandle;
6680
ID3D12DescriptorHeap* pd3dSrvDescHeap;
6781
UINT numFramesInFlight;
82+
ImGui_ImplDX12_Texture FontTexture;
83+
bool LegacySingleDescriptorUsed;
6884

6985
ImGui_ImplDX12_Data() { memset((void*)this, 0, sizeof(*this)); }
7086
};
@@ -385,6 +401,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()
385401
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
386402

387403
// Upload texture to graphics system
404+
ImGui_ImplDX12_Texture* font_tex = &bd->FontTexture;
388405
{
389406
D3D12_HEAP_PROPERTIES props;
390407
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
@@ -515,13 +532,13 @@ static void ImGui_ImplDX12_CreateFontsTexture()
515532
srvDesc.Texture2D.MipLevels = desc.MipLevels;
516533
srvDesc.Texture2D.MostDetailedMip = 0;
517534
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
518-
bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, bd->hFontSrvCpuDescHandle);
519-
SafeRelease(bd->pFontTextureResource);
520-
bd->pFontTextureResource = pTexture;
535+
bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, font_tex->hFontSrvCpuDescHandle);
536+
SafeRelease(font_tex->pTextureResource);
537+
font_tex->pTextureResource = pTexture;
521538
}
522539

523540
// Store our identifier
524-
io.Fonts->SetTexID((ImTextureID)bd->hFontSrvGpuDescHandle.ptr);
541+
io.Fonts->SetTexID((ImTextureID)font_tex->hFontSrvGpuDescHandle.ptr);
525542
}
526543

527544
bool ImGui_ImplDX12_CreateDeviceObjects()
@@ -774,41 +791,87 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
774791
ImGuiIO& io = ImGui::GetIO();
775792
SafeRelease(bd->pRootSignature);
776793
SafeRelease(bd->pPipelineState);
777-
SafeRelease(bd->pFontTextureResource);
778-
io.Fonts->SetTexID(0); // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
794+
795+
// Free SRV descriptor used by texture
796+
ImGui_ImplDX12_Texture* font_tex = &bd->FontTexture;
797+
bd->InitInfo.SrvDescriptorFreeFn(&bd->InitInfo, font_tex->hFontSrvCpuDescHandle, font_tex->hFontSrvGpuDescHandle);
798+
SafeRelease(font_tex->pTextureResource);
799+
io.Fonts->SetTexID(0); // We copied bd->hFontSrvGpuDescHandle to io.Fonts->TexID so let's clear that as well.
779800
}
780801

781-
bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
782-
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle)
802+
bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* init_info)
783803
{
784804
ImGuiIO& io = ImGui::GetIO();
785805
IMGUI_CHECKVERSION();
786806
IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
787807

788808
// Setup backend capabilities flags
789809
ImGui_ImplDX12_Data* bd = IM_NEW(ImGui_ImplDX12_Data)();
810+
bd->InitInfo = *init_info; // Deep copy
811+
init_info = &bd->InitInfo;
812+
813+
bd->pd3dDevice = init_info->Device;
814+
bd->RTVFormat = init_info->RTVFormat;
815+
bd->numFramesInFlight = init_info->NumFramesInFlight;
816+
bd->pd3dSrvDescHeap = init_info->SrvDescriptorHeap;
817+
790818
io.BackendRendererUserData = (void*)bd;
791819
io.BackendRendererName = "imgui_impl_dx12";
792820
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
793821
io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
794822
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
795823
ImGui_ImplDX12_InitPlatformInterface();
796824

797-
bd->pd3dDevice = device;
798-
bd->RTVFormat = rtv_format;
799-
bd->hFontSrvCpuDescHandle = font_srv_cpu_desc_handle;
800-
bd->hFontSrvGpuDescHandle = font_srv_gpu_desc_handle;
801-
bd->numFramesInFlight = num_frames_in_flight;
802-
bd->pd3dSrvDescHeap = cbv_srv_heap;
803-
804825
// Create a dummy ImGui_ImplDX12_ViewportData holder for the main viewport,
805826
// Since this is created and managed by the application, we will only use the ->Resources[] fields.
806827
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
807828
main_viewport->RendererUserData = IM_NEW(ImGui_ImplDX12_ViewportData)(bd->numFramesInFlight);
808829

830+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
831+
if (init_info->SrvDescriptorAllocFn == NULL)
832+
{
833+
// Wrap legacy behavior of passing space for a single descriptor
834+
IM_ASSERT(init_info->LegacySingleSrvCpuDescriptor.ptr != 0 && init_info->LegacySingleSrvGpuDescriptor.ptr != 0);
835+
init_info->SrvDescriptorAllocFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_handle)
836+
{
837+
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
838+
IM_ASSERT(bd->LegacySingleDescriptorUsed == false);
839+
*out_cpu_handle = bd->InitInfo.LegacySingleSrvCpuDescriptor;
840+
*out_gpu_handle = bd->InitInfo.LegacySingleSrvGpuDescriptor;
841+
bd->LegacySingleDescriptorUsed = true;
842+
};
843+
init_info->SrvDescriptorFreeFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE, D3D12_GPU_DESCRIPTOR_HANDLE)
844+
{
845+
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
846+
IM_ASSERT(bd->LegacySingleDescriptorUsed == true);
847+
bd->LegacySingleDescriptorUsed = false;
848+
};
849+
}
850+
#endif
851+
852+
// Allocate 1 SRV descriptor for the font texture
853+
IM_ASSERT(init_info->SrvDescriptorAllocFn != NULL && init_info->SrvDescriptorFreeFn != NULL);
854+
init_info->SrvDescriptorAllocFn(&bd->InitInfo, &bd->FontTexture.hFontSrvCpuDescHandle, &bd->FontTexture.hFontSrvGpuDescHandle);
855+
809856
return true;
810857
}
811858

859+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
860+
// Legacy initialization API Obsoleted in 1.91.5
861+
// font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture, they must be in 'srv_descriptor_heap'
862+
bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* srv_descriptor_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle)
863+
{
864+
ImGui_ImplDX12_InitInfo init_info;
865+
init_info.Device = device;
866+
init_info.NumFramesInFlight = num_frames_in_flight;
867+
init_info.RTVFormat = rtv_format;
868+
init_info.SrvDescriptorHeap = srv_descriptor_heap;
869+
init_info.LegacySingleSrvCpuDescriptor = font_srv_cpu_desc_handle;
870+
init_info.LegacySingleSrvGpuDescriptor = font_srv_gpu_desc_handle;;
871+
return ImGui_ImplDX12_Init(&init_info);
872+
}
873+
#endif
874+
812875
void ImGui_ImplDX12_Shutdown()
813876
{
814877
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();

backends/imgui_impl_dx12.h

+32-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
88
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
99

10+
// The aim of imgui_impl_dx12.h/.cpp is to be usable in your engine without any modification.
11+
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
12+
1013
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
1114
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
1215
// Learn about Dear ImGui:
@@ -19,24 +22,42 @@
1922
#include "imgui.h" // IMGUI_IMPL_API
2023
#ifndef IMGUI_DISABLE
2124
#include <dxgiformat.h> // DXGI_FORMAT
25+
#include <d3d12.h> // D3D12_CPU_DESCRIPTOR_HANDLE
2226

23-
struct ID3D12Device;
24-
struct ID3D12DescriptorHeap;
25-
struct ID3D12GraphicsCommandList;
26-
struct D3D12_CPU_DESCRIPTOR_HANDLE;
27-
struct D3D12_GPU_DESCRIPTOR_HANDLE;
27+
// Initialization data, for ImGui_ImplDX12_Init()
28+
struct ImGui_ImplDX12_InitInfo
29+
{
30+
ID3D12Device* Device;
31+
ID3D12CommandQueue* CommandQueue;
32+
int NumFramesInFlight;
33+
DXGI_FORMAT RTVFormat;
34+
void* UserData;
2835

29-
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
36+
// Allocating SRV descriptors for textures is up to the application, so we provide callbacks.
37+
// (current version of the backend will only allocate one descriptor, future versions will need to allocate more)
38+
ID3D12DescriptorHeap* SrvDescriptorHeap;
39+
void (*SrvDescriptorAllocFn)(ImGui_ImplDX12_InitInfo* info, D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_desc_handle);
40+
void (*SrvDescriptorFreeFn)(ImGui_ImplDX12_InitInfo* info, D3D12_CPU_DESCRIPTOR_HANDLE cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE gpu_desc_handle);
41+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
42+
D3D12_CPU_DESCRIPTOR_HANDLE LegacySingleSrvCpuDescriptor; // To facilitate transition from single descriptor to allocator callback, you may use those.
43+
D3D12_GPU_DESCRIPTOR_HANDLE LegacySingleSrvGpuDescriptor;
44+
#endif
3045

31-
// Before calling the render function, caller must prepare the command list by resetting it and setting the appropriate
32-
// render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle.
33-
// font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture.
34-
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
35-
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle);
46+
ImGui_ImplDX12_InitInfo() { memset(this, 0, sizeof(*this)); }
47+
};
48+
49+
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
50+
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* info);
3651
IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown();
3752
IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame();
3853
IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list);
3954

55+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
56+
// Legacy initialization API Obsoleted in 1.91.5
57+
// font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture, they must be in 'srv_descriptor_heap'
58+
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* srv_descriptor_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle);
59+
#endif
60+
4061
// Use if you want to reset your rendering device without losing Dear ImGui state.
4162
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();
4263
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();

backends/imgui_impl_opengl3.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
167167
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
168168
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
169+
// Typically you would run: python3 ./gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
169170
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
170171
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
171172
#define IMGL3W_IMPL
@@ -699,7 +700,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture()
699700
#endif
700701
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
701702

702-
// Store our identifier
703+
// Store identifier
703704
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
704705

705706
// Restore state

docs/CHANGELOG.txt

+36-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,36 @@ HOW TO UPDATE?
3535
and API updates have been a little more frequent lately. They are documented below and in imgui.cpp and should not affect all users.
3636
- Please report any issue!
3737

38+
-----------------------------------------------------------------------
39+
VERSION 1.91.6 WIP (In Progress)
40+
-----------------------------------------------------------------------
41+
42+
Breaking changes:
43+
44+
- Backends: DX12: Changed ImGui_ImplDX12_Init() signature to take a
45+
ImGui_ImplDX12_InitInfo struct.
46+
- Using the new API, application is now required to pass function pointers
47+
to allocate/free SRV Descriptors.
48+
- We provide convenience legacy fields to pass a single descriptor,
49+
matching the old API, but upcoming features will want multiple.
50+
- Legacy ImGui_ImplDX12_Init() signature is still supported (will obsolete).
51+
52+
Other changes:
53+
54+
- Error Handling: fixed cases where recoverable error handling would crash when
55+
processing errors outside of the NewFrame()..EndFrame() scope. (#1651)
56+
- Misc: changed embedded ProggyClean encoding to save a bit of binary space (~12kb to 9.5kb).
57+
- Misc: added IMGUI_DISABLE_DEFAULT_FONT to strip embedded font from binary. (#8161)
58+
[@demonese]
59+
- Tools: binary_to_compressed_c: added -u8/-u32/-base85 export options.
60+
- Demo: example tree used by Property Editor & Selection demos properly freed
61+
on application closure. (#8158) [@Legulysse]
62+
- Examples: Win32+DX12: Using a basic free-list allocator to manage multiple
63+
SRV descriptors.
64+
65+
Docking+Viewports Branch:
66+
67+
3868
-----------------------------------------------------------------------
3969
VERSION 1.91.5 (Released 2024-11-07)
4070
-----------------------------------------------------------------------
@@ -64,6 +94,11 @@ Other changes:
6494
between _Header and _HeaderHovered which was introduced v1.91 (#8106, #1861)
6595
- Buttons: using ImGuiItemFlags_ButtonRepeat makes default button behavior use
6696
PressedOnClick instead of PressedOnClickRelease when unspecified.
97+
- This is intended to make the +/- buttons of InputInt/InputFloat react on the
98+
initial mouse down event.
99+
- Note that it may reveal incorrect usage if you were using InputInt/InputFloat
100+
without persistent storage by relying solely on e.g. IsItemDeactivatedAfterEdit():
101+
this was never supported and didn't work consistantly (see #8149).
67102
- InputText: fixed a bug (regression in 1.91.2) where modifying text buffer within
68103
a callback would sometimes prevents further appending to the buffer.
69104
- Tabs, Style: made ImGuiCol_TabDimmedSelectedOverline alpha 0 (not visible) in default
@@ -89,7 +124,7 @@ Other changes:
89124
Docking+Viewports Branch:
90125

91126
- Backends: GLFW: added Linux workaround for spurious mouse up events emitted while dragging
92-
and creating new viewports. Generally they would be interrupting a dragging operations.
127+
and creating new viewports. Generally they would be interrupting a dragging operations.
93128
(#3158, #7733, #7922) [@rokups, @ocornut]
94129
- Docking: fixed using ImGuiDockNodeFlags_KeepAliveOnly with DockSpaceOverViewport():
95130
the normally invisible space did erroneously claim mouse hover and could be potentially

0 commit comments

Comments
 (0)