|
@@ -13,6 +13,7 @@
|
|
|
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
+// 2019-10-18: DirectX12: *BREAKING CHANGE* Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function.
|
|
|
// 2019-05-29: DirectX12: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
|
|
|
// 2019-04-30: DirectX12: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
|
// 2019-03-29: Misc: Various minor tidying up.
|
|
@@ -56,6 +57,14 @@ static FrameResources* g_pFrameResources = NULL;
|
|
|
static UINT g_numFramesInFlight = 0;
|
|
|
static UINT g_frameIndex = UINT_MAX;
|
|
|
|
|
|
+template<typename T>
|
|
|
+static void SafeRelease(T*& res)
|
|
|
+{
|
|
|
+ if (res)
|
|
|
+ res->Release();
|
|
|
+ res = NULL;
|
|
|
+}
|
|
|
+
|
|
|
struct VERTEX_CONSTANT_BUFFER
|
|
|
{
|
|
|
float mvp[4][4];
|
|
@@ -132,7 +141,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|
|
// Create and grow vertex/index buffers if needed
|
|
|
if (fr->VertexBuffer == NULL || fr->VertexBufferSize < draw_data->TotalVtxCount)
|
|
|
{
|
|
|
- if (fr->VertexBuffer != NULL) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; }
|
|
|
+ SafeRelease(fr->VertexBuffer);
|
|
|
fr->VertexBufferSize = draw_data->TotalVtxCount + 5000;
|
|
|
D3D12_HEAP_PROPERTIES props;
|
|
|
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
|
@@ -155,7 +164,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|
|
}
|
|
|
if (fr->IndexBuffer == NULL || fr->IndexBufferSize < draw_data->TotalIdxCount)
|
|
|
{
|
|
|
- if (fr->IndexBuffer != NULL) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; }
|
|
|
+ SafeRelease(fr->IndexBuffer);
|
|
|
fr->IndexBufferSize = draw_data->TotalIdxCount + 10000;
|
|
|
D3D12_HEAP_PROPERTIES props;
|
|
|
memset(&props, 0, sizeof(D3D12_HEAP_PROPERTIES));
|
|
@@ -375,8 +384,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
srvDesc.Texture2D.MostDetailedMip = 0;
|
|
|
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
|
|
|
g_pd3dDevice->CreateShaderResourceView(pTexture, &srvDesc, g_hFontSrvCpuDescHandle);
|
|
|
- if (g_pFontTextureResource != NULL)
|
|
|
- g_pFontTextureResource->Release();
|
|
|
+ SafeRelease(g_pFontTextureResource);
|
|
|
g_pFontTextureResource = pTexture;
|
|
|
}
|
|
|
|
|
@@ -588,21 +596,24 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
|
|
|
if (!g_pd3dDevice)
|
|
|
return;
|
|
|
|
|
|
+ SafeRelease(g_pVertexShaderBlob);
|
|
|
+ SafeRelease(g_pPixelShaderBlob);
|
|
|
+ SafeRelease(g_pRootSignature);
|
|
|
+ SafeRelease(g_pPipelineState);
|
|
|
+ SafeRelease(g_pFontTextureResource);
|
|
|
+
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
- if (g_pVertexShaderBlob) { g_pVertexShaderBlob->Release(); g_pVertexShaderBlob = NULL; }
|
|
|
- if (g_pPixelShaderBlob) { g_pPixelShaderBlob->Release(); g_pPixelShaderBlob = NULL; }
|
|
|
- if (g_pRootSignature) { g_pRootSignature->Release(); g_pRootSignature = NULL; }
|
|
|
- if (g_pPipelineState) { g_pPipelineState->Release(); g_pPipelineState = NULL; }
|
|
|
- if (g_pFontTextureResource) { g_pFontTextureResource->Release(); g_pFontTextureResource = NULL; io.Fonts->TexID = NULL; } // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
|
+ io.Fonts->TexID = NULL; // We copied g_pFontTextureView to io.Fonts->TexID so let's clear that as well.
|
|
|
+
|
|
|
for (UINT i = 0; i < g_numFramesInFlight; i++)
|
|
|
{
|
|
|
FrameResources* fr = &g_pFrameResources[i];
|
|
|
- if (fr->IndexBuffer) { fr->IndexBuffer->Release(); fr->IndexBuffer = NULL; }
|
|
|
- if (fr->VertexBuffer) { fr->VertexBuffer->Release(); fr->VertexBuffer = NULL; }
|
|
|
+ SafeRelease(fr->IndexBuffer);
|
|
|
+ SafeRelease(fr->VertexBuffer);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format,
|
|
|
+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)
|
|
|
{
|
|
|
// Setup back-end capabilities flags
|
|
@@ -617,6 +628,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
|
|
|
g_pFrameResources = new FrameResources[num_frames_in_flight];
|
|
|
g_numFramesInFlight = num_frames_in_flight;
|
|
|
g_frameIndex = UINT_MAX;
|
|
|
+ IM_UNUSED(cbv_srv_heap); // Unused in master branch (will be used by multi-viewports)
|
|
|
|
|
|
// Create buffers with a default size (they will later be grown as needed)
|
|
|
for (int i = 0; i < num_frames_in_flight; i++)
|