Compare commits
6 Commits
features/s
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
08400f5be7 | ||
|
40b2286d16 | ||
|
3260ea6954 | ||
|
8be0723fb7 | ||
|
e97b97467e | ||
|
3381ab423b |
@ -6,6 +6,9 @@
|
||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||
|
||||
// The aim of imgui_impl_dx12.h/.cpp is to be usable in your engine without any modification.
|
||||
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
@ -16,6 +19,8 @@
|
||||
|
||||
// CHANGELOG
|
||||
// (minor and older changes stripped away, please see git history for details)
|
||||
// 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.
|
||||
// 2024-10-07: DirectX12: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
||||
// 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.
|
||||
@ -50,17 +55,24 @@
|
||||
#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below.
|
||||
#endif
|
||||
|
||||
// DirectX data
|
||||
// DirectX12 data
|
||||
struct ImGui_ImplDX12_RenderBuffers;
|
||||
|
||||
struct ImGui_ImplDX12_Texture
|
||||
{
|
||||
ID3D12Resource* pTextureResource;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE hFontSrvCpuDescHandle;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE hFontSrvGpuDescHandle;
|
||||
};
|
||||
|
||||
struct ImGui_ImplDX12_Data
|
||||
{
|
||||
ImGui_ImplDX12_InitInfo InitInfo;
|
||||
ID3D12Device* pd3dDevice;
|
||||
ID3D12RootSignature* pRootSignature;
|
||||
ID3D12PipelineState* pPipelineState;
|
||||
DXGI_FORMAT RTVFormat;
|
||||
ID3D12Resource* pFontTextureResource;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE hFontSrvCpuDescHandle;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE hFontSrvGpuDescHandle;
|
||||
ImGui_ImplDX12_Texture FontTexture;
|
||||
ID3D12DescriptorHeap* pd3dSrvDescHeap;
|
||||
UINT numFramesInFlight;
|
||||
|
||||
@ -310,6 +322,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
||||
io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
|
||||
|
||||
// Upload texture to graphics system
|
||||
ImGui_ImplDX12_Texture* font_tex = &bd->FontTexture;
|
||||
{
|
||||
D3D12_HEAP_PROPERTIES props;
|
||||
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
||||
@ -440,13 +453,13 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
||||
srvDesc.Texture2D.MipLevels = desc.MipLevels;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
||||
bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, bd->hFontSrvCpuDescHandle);
|
||||
SafeRelease(bd->pFontTextureResource);
|
||||
bd->pFontTextureResource = pTexture;
|
||||
bd->pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, font_tex->hFontSrvCpuDescHandle);
|
||||
SafeRelease(font_tex->pTextureResource);
|
||||
font_tex->pTextureResource = pTexture;
|
||||
}
|
||||
|
||||
// Store our identifier
|
||||
io.Fonts->SetTexID((ImTextureID)bd->hFontSrvGpuDescHandle.ptr);
|
||||
io.Fonts->SetTexID((ImTextureID)font_tex->hFontSrvGpuDescHandle.ptr);
|
||||
}
|
||||
|
||||
bool ImGui_ImplDX12_CreateDeviceObjects()
|
||||
@ -692,8 +705,15 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
SafeRelease(bd->pRootSignature);
|
||||
SafeRelease(bd->pPipelineState);
|
||||
SafeRelease(bd->pFontTextureResource);
|
||||
io.Fonts->SetTexID(0); // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
||||
|
||||
// Free SRV descriptor used by texture
|
||||
ImGui_ImplDX12_Texture* font_tex = &bd->FontTexture;
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
if (bd->InitInfo.SrvDescriptorFreeFn != NULL)
|
||||
#endif
|
||||
bd->InitInfo.SrvDescriptorFreeFn(&bd->InitInfo, font_tex->hFontSrvCpuDescHandle, font_tex->hFontSrvGpuDescHandle);
|
||||
SafeRelease(font_tex->pTextureResource);
|
||||
io.Fonts->SetTexID(0); // We copied bd->hFontSrvGpuDescHandle to io.Fonts->TexID so let's clear that as well.
|
||||
|
||||
for (UINT i = 0; i < bd->numFramesInFlight; i++)
|
||||
{
|
||||
@ -703,8 +723,7 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
|
||||
}
|
||||
}
|
||||
|
||||
bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle)
|
||||
bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* init_info)
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
IMGUI_CHECKVERSION();
|
||||
@ -712,21 +731,39 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
||||
|
||||
// Setup backend capabilities flags
|
||||
ImGui_ImplDX12_Data* bd = IM_NEW(ImGui_ImplDX12_Data)();
|
||||
|
||||
bd->InitInfo = *init_info; // Deep copy
|
||||
bd->pd3dDevice = init_info->Device;
|
||||
bd->RTVFormat = init_info->RTVFormat;
|
||||
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
||||
bd->pd3dSrvDescHeap = init_info->SrvDescriptorHeap;
|
||||
|
||||
io.BackendRendererUserData = (void*)bd;
|
||||
io.BackendRendererName = "imgui_impl_dx12";
|
||||
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
|
||||
|
||||
bd->pd3dDevice = device;
|
||||
bd->RTVFormat = rtv_format;
|
||||
bd->hFontSrvCpuDescHandle = font_srv_cpu_desc_handle;
|
||||
bd->hFontSrvGpuDescHandle = font_srv_gpu_desc_handle;
|
||||
bd->pFrameResources = new ImGui_ImplDX12_RenderBuffers[num_frames_in_flight];
|
||||
bd->numFramesInFlight = num_frames_in_flight;
|
||||
bd->pd3dSrvDescHeap = cbv_srv_heap;
|
||||
bd->frameIndex = UINT_MAX;
|
||||
// Allocate 1 SRV descriptor for the font texture
|
||||
if (init_info->SrvDescriptorAllocFn != NULL)
|
||||
{
|
||||
IM_ASSERT(init_info->SrvDescriptorFreeFn != NULL);
|
||||
init_info->SrvDescriptorAllocFn(&bd->InitInfo, &bd->FontTexture.hFontSrvCpuDescHandle, &bd->FontTexture.hFontSrvGpuDescHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
IM_ASSERT(init_info->LegacySingleSrvCpuDescriptor.ptr != 0 && init_info->LegacySingleSrvGpuDescriptor.ptr != 0);
|
||||
bd->FontTexture.hFontSrvCpuDescHandle = init_info->LegacySingleSrvCpuDescriptor;
|
||||
bd->FontTexture.hFontSrvGpuDescHandle = init_info->LegacySingleSrvGpuDescriptor;
|
||||
#else
|
||||
IM_ASSERT(init_info->SrvDescriptorAllocFn != NULL);
|
||||
IM_ASSERT(init_info->SrvDescriptorFreeFn != NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Create buffers with a default size (they will later be grown as needed)
|
||||
for (int i = 0; i < num_frames_in_flight; i++)
|
||||
bd->frameIndex = UINT_MAX;
|
||||
bd->pFrameResources = new ImGui_ImplDX12_RenderBuffers[bd->numFramesInFlight];
|
||||
for (int i = 0; i < (int)bd->numFramesInFlight; i++)
|
||||
{
|
||||
ImGui_ImplDX12_RenderBuffers* fr = &bd->pFrameResources[i];
|
||||
fr->IndexBuffer = nullptr;
|
||||
@ -738,6 +775,22 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
// Legacy initialization API Obsoleted in 1.91.5
|
||||
// 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'
|
||||
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)
|
||||
{
|
||||
ImGui_ImplDX12_InitInfo init_info;
|
||||
init_info.Device = device;
|
||||
init_info.NumFramesInFlight = num_frames_in_flight;
|
||||
init_info.RTVFormat = rtv_format;
|
||||
init_info.SrvDescriptorHeap = srv_descriptor_heap;
|
||||
init_info.LegacySingleSrvCpuDescriptor = font_srv_cpu_desc_handle;
|
||||
init_info.LegacySingleSrvGpuDescriptor = font_srv_gpu_desc_handle;;
|
||||
return ImGui_ImplDX12_Init(&init_info);
|
||||
}
|
||||
#endif
|
||||
|
||||
void ImGui_ImplDX12_Shutdown()
|
||||
{
|
||||
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
||||
@ -747,6 +800,7 @@ void ImGui_ImplDX12_Shutdown()
|
||||
// Clean up windows and device objects
|
||||
ImGui_ImplDX12_InvalidateDeviceObjects();
|
||||
delete[] bd->pFrameResources;
|
||||
|
||||
io.BackendRendererName = nullptr;
|
||||
io.BackendRendererUserData = nullptr;
|
||||
io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset;
|
||||
|
@ -6,6 +6,9 @@
|
||||
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
|
||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||
|
||||
// The aim of imgui_impl_dx12.h/.cpp is to be usable in your engine without any modification.
|
||||
// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
|
||||
|
||||
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||
// Learn about Dear ImGui:
|
||||
@ -18,24 +21,42 @@
|
||||
#include "imgui.h" // IMGUI_IMPL_API
|
||||
#ifndef IMGUI_DISABLE
|
||||
#include <dxgiformat.h> // DXGI_FORMAT
|
||||
#include <d3d12.h> // D3D12_CPU_DESCRIPTOR_HANDLE
|
||||
|
||||
struct ID3D12Device;
|
||||
struct ID3D12DescriptorHeap;
|
||||
struct ID3D12GraphicsCommandList;
|
||||
struct D3D12_CPU_DESCRIPTOR_HANDLE;
|
||||
struct D3D12_GPU_DESCRIPTOR_HANDLE;
|
||||
// Initialization data, for ImGui_ImplDX12_Init()
|
||||
struct ImGui_ImplDX12_InitInfo
|
||||
{
|
||||
ID3D12Device* Device;
|
||||
ID3D12CommandQueue* CommandQueue;
|
||||
int NumFramesInFlight;
|
||||
DXGI_FORMAT RTVFormat;
|
||||
void* UserData;
|
||||
|
||||
// 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)
|
||||
ID3D12DescriptorHeap* SrvDescriptorHeap;
|
||||
void (*SrvDescriptorAllocFn)(ImGui_ImplDX12_InitInfo* info, D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_desc_handle);
|
||||
void (*SrvDescriptorFreeFn)(ImGui_ImplDX12_InitInfo* info, D3D12_CPU_DESCRIPTOR_HANDLE cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE gpu_desc_handle);
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE LegacySingleSrvCpuDescriptor; // To facilitate transition from single descriptor to allocator callback, you may use those.
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE LegacySingleSrvGpuDescriptor;
|
||||
#endif
|
||||
|
||||
ImGui_ImplDX12_InitInfo() { memset(this, 0, sizeof(*this)); }
|
||||
};
|
||||
|
||||
// Follow "Getting Started" link and check examples/ folder to learn about using backends!
|
||||
|
||||
// Before calling the render function, caller must prepare the command list by resetting it and setting the appropriate
|
||||
// render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle.
|
||||
// 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.
|
||||
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle);
|
||||
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* info);
|
||||
IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown();
|
||||
IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame();
|
||||
IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list);
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
// Legacy initialization API Obsoleted in 1.91.5
|
||||
// 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'
|
||||
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);
|
||||
#endif
|
||||
|
||||
// Use if you want to reset your rendering device without losing Dear ImGui state.
|
||||
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();
|
||||
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();
|
||||
|
@ -35,6 +35,28 @@ HOW TO UPDATE?
|
||||
and API updates have been a little more frequent lately. They are documented below and in imgui.cpp and should not affect all users.
|
||||
- Please report any issue!
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
VERSION 1.91.6 WIP (In Progress)
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
Breaking changes:
|
||||
|
||||
- Backends: DX12: Changed ImGui_ImplDX12_Init() signature to take a
|
||||
ImGui_ImplDX12_InitInfo struct.
|
||||
- Using the new API, application 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.
|
||||
- Legacy ImGui_ImplDX12_Init() signature is still supported (will obsolete).
|
||||
|
||||
Other changes:
|
||||
|
||||
- Error Handling: fixed cases where recoverable error handling would crash when
|
||||
processing errors outside of the NewFrame()..EndFrame() scope. (#1651)
|
||||
- Examples: Win32+DX12: Using a basic free-list allocator to manage multiple
|
||||
SRV descriptors.
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
VERSION 1.91.5 (Released 2024-11-07)
|
||||
-----------------------------------------------------------------------
|
||||
@ -64,6 +86,11 @@ Other changes:
|
||||
between _Header and _HeaderHovered which was introduced v1.91 (#8106, #1861)
|
||||
- Buttons: using ImGuiItemFlags_ButtonRepeat makes default button behavior use
|
||||
PressedOnClick instead of PressedOnClickRelease when unspecified.
|
||||
- This is intended to make the +/- buttons of InputInt/InputFloat react on the
|
||||
initial mouse down event.
|
||||
- Note that it may reveal incorrect usage if you were using InputInt/InputFloat
|
||||
without persistent storage by relying solely on e.g. IsItemDeactivatedAfterEdit():
|
||||
this was never supported and didn't work consistantly (see #8149).
|
||||
- InputText: fixed a bug (regression in 1.91.2) where modifying text buffer within
|
||||
a callback would sometimes prevents further appending to the buffer.
|
||||
- Tabs, Style: made ImGuiCol_TabDimmedSelectedOverline alpha 0 (not visible) in default
|
||||
@ -86,6 +113,7 @@ Other changes:
|
||||
- Examples: Android+OpenGL: Using ALooper_pollOnce() instead of ALooper_pollAll()
|
||||
which has been deprecated. (#8013) [@feather179]
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
VERSION 1.91.4 (Released 2024-10-18)
|
||||
-----------------------------------------------------------------------
|
||||
|
@ -22,23 +22,70 @@
|
||||
#pragma comment(lib, "dxguid.lib")
|
||||
#endif
|
||||
|
||||
#include "imgui_internal.h"
|
||||
// Config for example app
|
||||
static const int APP_NUM_FRAMES_IN_FLIGHT = 3;
|
||||
static const int APP_NUM_BACK_BUFFERS = 3;
|
||||
static const int APP_SRV_HEAP_SIZE = 64;
|
||||
|
||||
struct FrameContext
|
||||
{
|
||||
ID3D12CommandAllocator* CommandAllocator;
|
||||
UINT64 FenceValue;
|
||||
ID3D12CommandAllocator* CommandAllocator;
|
||||
UINT64 FenceValue;
|
||||
};
|
||||
|
||||
// Simple free list based allocator
|
||||
struct ExampleDescriptorHeapAllocator
|
||||
{
|
||||
ID3D12DescriptorHeap* Heap = nullptr;
|
||||
D3D12_DESCRIPTOR_HEAP_TYPE HeapType = D3D12_DESCRIPTOR_HEAP_TYPE_NUM_TYPES;
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE HeapStartCpu;
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE HeapStartGpu;
|
||||
UINT HeapHandleIncrement;
|
||||
ImVector<int> FreeIndices;
|
||||
|
||||
void Create(ID3D12Device* device, ID3D12DescriptorHeap* heap)
|
||||
{
|
||||
IM_ASSERT(Heap == nullptr && FreeIndices.empty());
|
||||
Heap = heap;
|
||||
D3D12_DESCRIPTOR_HEAP_DESC desc = heap->GetDesc();
|
||||
HeapType = desc.Type;
|
||||
HeapStartCpu = Heap->GetCPUDescriptorHandleForHeapStart();
|
||||
HeapStartGpu = Heap->GetGPUDescriptorHandleForHeapStart();
|
||||
HeapHandleIncrement = device->GetDescriptorHandleIncrementSize(HeapType);
|
||||
FreeIndices.reserve((int)desc.NumDescriptors);
|
||||
for (int n = desc.NumDescriptors; n > 0; n--)
|
||||
FreeIndices.push_back(n);
|
||||
}
|
||||
void Destroy()
|
||||
{
|
||||
Heap = NULL;
|
||||
FreeIndices.clear();
|
||||
}
|
||||
void Alloc(D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_desc_handle)
|
||||
{
|
||||
IM_ASSERT(FreeIndices.Size > 0);
|
||||
int idx = FreeIndices.back();
|
||||
FreeIndices.pop_back();
|
||||
out_cpu_desc_handle->ptr = HeapStartCpu.ptr + (idx * HeapHandleIncrement);
|
||||
out_gpu_desc_handle->ptr = HeapStartGpu.ptr + (idx * HeapHandleIncrement);
|
||||
}
|
||||
void Free(D3D12_CPU_DESCRIPTOR_HANDLE out_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE out_gpu_desc_handle)
|
||||
{
|
||||
int cpu_idx = (int)((out_cpu_desc_handle.ptr - HeapStartCpu.ptr) / HeapHandleIncrement);
|
||||
int gpu_idx = (int)((out_gpu_desc_handle.ptr - HeapStartGpu.ptr) / HeapHandleIncrement);
|
||||
IM_ASSERT(cpu_idx == gpu_idx);
|
||||
FreeIndices.push_back(cpu_idx);
|
||||
}
|
||||
};
|
||||
|
||||
// Data
|
||||
static int const NUM_FRAMES_IN_FLIGHT = 3;
|
||||
static FrameContext g_frameContext[NUM_FRAMES_IN_FLIGHT] = {};
|
||||
static FrameContext g_frameContext[APP_NUM_FRAMES_IN_FLIGHT] = {};
|
||||
static UINT g_frameIndex = 0;
|
||||
|
||||
static int const NUM_BACK_BUFFERS = 3;
|
||||
static ID3D12Device* g_pd3dDevice = nullptr;
|
||||
static ID3D12DescriptorHeap* g_pd3dRtvDescHeap = nullptr;
|
||||
static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = nullptr;
|
||||
static ExampleDescriptorHeapAllocator g_pd3dSrvDescHeapAlloc;
|
||||
static ID3D12CommandQueue* g_pd3dCommandQueue = nullptr;
|
||||
static ID3D12GraphicsCommandList* g_pd3dCommandList = nullptr;
|
||||
static ID3D12Fence* g_fence = nullptr;
|
||||
@ -47,8 +94,8 @@ static UINT64 g_fenceLastSignaledValue = 0;
|
||||
static IDXGISwapChain3* g_pSwapChain = nullptr;
|
||||
static bool g_SwapChainOccluded = false;
|
||||
static HANDLE g_hSwapChainWaitableObject = nullptr;
|
||||
static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS] = {};
|
||||
static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
|
||||
static ID3D12Resource* g_mainRenderTargetResource[APP_NUM_BACK_BUFFERS] = {};
|
||||
static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[APP_NUM_BACK_BUFFERS] = {};
|
||||
|
||||
// Forward declarations of helper functions
|
||||
bool CreateDeviceD3D(HWND hWnd);
|
||||
@ -93,10 +140,18 @@ int main(int, char**)
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplWin32_Init(hwnd);
|
||||
ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM, g_pd3dSrvDescHeap,
|
||||
g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),
|
||||
g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());
|
||||
|
||||
ImGui_ImplDX12_InitInfo init_info = {};
|
||||
init_info.Device = g_pd3dDevice;
|
||||
init_info.CommandQueue = g_pd3dCommandQueue;
|
||||
init_info.NumFramesInFlight = APP_NUM_FRAMES_IN_FLIGHT;
|
||||
init_info.RTVFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
// 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;
|
||||
init_info.SrvDescriptorAllocFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_handle) { return g_pd3dSrvDescHeapAlloc.Alloc(out_cpu_handle, out_gpu_handle); };
|
||||
init_info.SrvDescriptorFreeFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle, D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle) { return g_pd3dSrvDescHeapAlloc.Free(cpu_handle, gpu_handle); };
|
||||
ImGui_ImplDX12_Init(&init_info);
|
||||
|
||||
// Load Fonts
|
||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||
@ -249,7 +304,7 @@ bool CreateDeviceD3D(HWND hWnd)
|
||||
DXGI_SWAP_CHAIN_DESC1 sd;
|
||||
{
|
||||
ZeroMemory(&sd, sizeof(sd));
|
||||
sd.BufferCount = NUM_BACK_BUFFERS;
|
||||
sd.BufferCount = APP_NUM_BACK_BUFFERS;
|
||||
sd.Width = 0;
|
||||
sd.Height = 0;
|
||||
sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
@ -292,7 +347,7 @@ bool CreateDeviceD3D(HWND hWnd)
|
||||
{
|
||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
|
||||
desc.NumDescriptors = NUM_BACK_BUFFERS;
|
||||
desc.NumDescriptors = APP_NUM_BACK_BUFFERS;
|
||||
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
|
||||
desc.NodeMask = 1;
|
||||
if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dRtvDescHeap)) != S_OK)
|
||||
@ -300,7 +355,7 @@ bool CreateDeviceD3D(HWND hWnd)
|
||||
|
||||
SIZE_T rtvDescriptorSize = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
|
||||
D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = g_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
|
||||
for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
|
||||
for (UINT i = 0; i < APP_NUM_BACK_BUFFERS; i++)
|
||||
{
|
||||
g_mainRenderTargetDescriptor[i] = rtvHandle;
|
||||
rtvHandle.ptr += rtvDescriptorSize;
|
||||
@ -310,10 +365,11 @@ bool CreateDeviceD3D(HWND hWnd)
|
||||
{
|
||||
D3D12_DESCRIPTOR_HEAP_DESC desc = {};
|
||||
desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
desc.NumDescriptors = 1;
|
||||
desc.NumDescriptors = APP_SRV_HEAP_SIZE;
|
||||
desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
|
||||
if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dSrvDescHeap)) != S_OK)
|
||||
return false;
|
||||
g_pd3dSrvDescHeapAlloc.Create(g_pd3dDevice, g_pd3dSrvDescHeap);
|
||||
}
|
||||
|
||||
{
|
||||
@ -325,7 +381,7 @@ bool CreateDeviceD3D(HWND hWnd)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
|
||||
for (UINT i = 0; i < APP_NUM_FRAMES_IN_FLIGHT; i++)
|
||||
if (g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g_frameContext[i].CommandAllocator)) != S_OK)
|
||||
return false;
|
||||
|
||||
@ -351,7 +407,7 @@ bool CreateDeviceD3D(HWND hWnd)
|
||||
return false;
|
||||
swapChain1->Release();
|
||||
dxgiFactory->Release();
|
||||
g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
|
||||
g_pSwapChain->SetMaximumFrameLatency(APP_NUM_BACK_BUFFERS);
|
||||
g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
|
||||
}
|
||||
|
||||
@ -364,7 +420,7 @@ void CleanupDeviceD3D()
|
||||
CleanupRenderTarget();
|
||||
if (g_pSwapChain) { g_pSwapChain->SetFullscreenState(false, nullptr); g_pSwapChain->Release(); g_pSwapChain = nullptr; }
|
||||
if (g_hSwapChainWaitableObject != nullptr) { CloseHandle(g_hSwapChainWaitableObject); }
|
||||
for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
|
||||
for (UINT i = 0; i < APP_NUM_FRAMES_IN_FLIGHT; i++)
|
||||
if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = nullptr; }
|
||||
if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = nullptr; }
|
||||
if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = nullptr; }
|
||||
@ -386,7 +442,7 @@ void CleanupDeviceD3D()
|
||||
|
||||
void CreateRenderTarget()
|
||||
{
|
||||
for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
|
||||
for (UINT i = 0; i < APP_NUM_BACK_BUFFERS; i++)
|
||||
{
|
||||
ID3D12Resource* pBackBuffer = nullptr;
|
||||
g_pSwapChain->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer));
|
||||
@ -399,13 +455,13 @@ void CleanupRenderTarget()
|
||||
{
|
||||
WaitForLastSubmittedFrame();
|
||||
|
||||
for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
|
||||
for (UINT i = 0; i < APP_NUM_BACK_BUFFERS; i++)
|
||||
if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = nullptr; }
|
||||
}
|
||||
|
||||
void WaitForLastSubmittedFrame()
|
||||
{
|
||||
FrameContext* frameCtx = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT];
|
||||
FrameContext* frameCtx = &g_frameContext[g_frameIndex % APP_NUM_FRAMES_IN_FLIGHT];
|
||||
|
||||
UINT64 fenceValue = frameCtx->FenceValue;
|
||||
if (fenceValue == 0)
|
||||
@ -427,7 +483,7 @@ FrameContext* WaitForNextFrameResources()
|
||||
HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, nullptr };
|
||||
DWORD numWaitableObjects = 1;
|
||||
|
||||
FrameContext* frameCtx = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
|
||||
FrameContext* frameCtx = &g_frameContext[nextFrameIndex % APP_NUM_FRAMES_IN_FLIGHT];
|
||||
UINT64 fenceValue = frameCtx->FenceValue;
|
||||
if (fenceValue != 0) // means no fence was signaled
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.91.5
|
||||
// dear imgui, v1.91.6 WIP
|
||||
// (main code and documentation)
|
||||
|
||||
// Help:
|
||||
@ -5788,7 +5788,7 @@ bool ImGui::IsItemDeactivatedAfterEdit()
|
||||
return IsItemDeactivated() && (g.ActiveIdPreviousFrameHasBeenEditedBefore || (g.ActiveId == 0 && g.ActiveIdHasBeenEditedBefore));
|
||||
}
|
||||
|
||||
// == GetItemID() == GetFocusID()
|
||||
// == (GetItemID() == GetFocusID() && GetFocusID() != 0)
|
||||
bool ImGui::IsItemFocused()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -10542,7 +10542,7 @@ bool ImGui::ErrorLog(const char* msg)
|
||||
// Output to tooltip
|
||||
if (g.IO.ConfigErrorRecoveryEnableTooltip)
|
||||
{
|
||||
if (BeginErrorTooltip())
|
||||
if (g.WithinFrameScope && BeginErrorTooltip())
|
||||
{
|
||||
if (g.ErrorCountCurrentFrame < 20)
|
||||
{
|
||||
@ -10579,7 +10579,7 @@ void ImGui::ErrorCheckEndFrameFinalizeErrorTooltip()
|
||||
BulletText("Code should use PushID()/PopID() in loops, or append \"##xx\" to same-label identifiers!");
|
||||
BulletText("Empty label e.g. Button(\"\") == same ID as parent widget/node. Use Button(\"##xx\") instead!");
|
||||
//BulletText("Code intending to use duplicate ID may use e.g. PushItemFlag(ImGuiItemFlags_AllowDuplicateId, true); ... PopItemFlag()"); // Not making this too visible for fear of it being abused.
|
||||
BulletText("Set io.ConfigDebugDetectIdConflicts=false to disable this warning in non-programmers builds.");
|
||||
BulletText("Set io.ConfigDebugHighlightIdConflicts=false to disable this warning in non-programmers builds.");
|
||||
Separator();
|
||||
Text("(Hold CTRL to: use");
|
||||
SameLine();
|
||||
|
6
imgui.h
6
imgui.h
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.91.5
|
||||
// dear imgui, v1.91.6 WIP
|
||||
// (headers)
|
||||
|
||||
// Help:
|
||||
@ -28,8 +28,8 @@
|
||||
|
||||
// Library Version
|
||||
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
|
||||
#define IMGUI_VERSION "1.91.5"
|
||||
#define IMGUI_VERSION_NUM 19150
|
||||
#define IMGUI_VERSION "1.91.6 WIP"
|
||||
#define IMGUI_VERSION_NUM 19151
|
||||
#define IMGUI_HAS_TABLE
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.91.5
|
||||
// dear imgui, v1.91.6 WIP
|
||||
// (demo code)
|
||||
|
||||
// Help:
|
||||
|
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.91.5
|
||||
// dear imgui, v1.91.6 WIP
|
||||
// (drawing and font code)
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.91.5
|
||||
// dear imgui, v1.91.6 WIP
|
||||
// (internal structures/api)
|
||||
|
||||
// You may use this file to debug, understand or extend Dear ImGui features but we don't provide any guarantee of forward compatibility.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.91.5
|
||||
// dear imgui, v1.91.6 WIP
|
||||
// (tables and columns code)
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.91.5
|
||||
// dear imgui, v1.91.6 WIP
|
||||
// (widgets code)
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user