mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-03 17:24:24 +00:00 
			
		
		
		
	Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. The value is unused in master branch but will be used by the multi-viewport features (docking branch). (#2851)
+ Using SafeRelease() in master.
This commit is contained in:
		@@ -42,6 +42,8 @@ Breaking Changes:
 | 
			
		||||
  Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay).
 | 
			
		||||
  Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate.
 | 
			
		||||
  If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you.
 | 
			
		||||
- Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function. 
 | 
			
		||||
  The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate]
 | 
			
		||||
 | 
			
		||||
Other Changes:
 | 
			
		||||
- InputText, Nav: Fixed Home/End key broken when activating Keyboard Navigation. (#787)
 | 
			
		||||
 
 | 
			
		||||
@@ -85,7 +85,7 @@ int main(int, char**)
 | 
			
		||||
    // Setup Platform/Renderer bindings
 | 
			
		||||
    ImGui_ImplWin32_Init(hwnd);
 | 
			
		||||
    ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT,
 | 
			
		||||
        DXGI_FORMAT_R8G8B8A8_UNORM,
 | 
			
		||||
        DXGI_FORMAT_R8G8B8A8_UNORM, g_pd3dSrvDescHeap,
 | 
			
		||||
        g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),
 | 
			
		||||
        g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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++)
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,7 @@
 | 
			
		||||
 | 
			
		||||
enum DXGI_FORMAT;
 | 
			
		||||
struct ID3D12Device;
 | 
			
		||||
struct ID3D12DescriptorHeap;
 | 
			
		||||
struct ID3D12GraphicsCommandList;
 | 
			
		||||
struct D3D12_CPU_DESCRIPTOR_HANDLE;
 | 
			
		||||
struct D3D12_GPU_DESCRIPTOR_HANDLE;
 | 
			
		||||
@@ -23,7 +24,7 @@ struct D3D12_GPU_DESCRIPTOR_HANDLE;
 | 
			
		||||
// Before calling the render function, caller must prepare cmd_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,
 | 
			
		||||
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 void     ImGui_ImplDX12_Shutdown();
 | 
			
		||||
IMGUI_IMPL_API void     ImGui_ImplDX12_NewFrame();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user