From 4994e75852a8140072cc5dd74fac4638150a4a9e Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 23 Oct 2024 12:40:20 +0200 Subject: [PATCH] Backends: DX12: Unmap() call specify written range. The range is informational and may be used by debug tools. --- backends/imgui_impl_dx12.cpp | 11 +++++++++-- docs/CHANGELOG.txt | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backends/imgui_impl_dx12.cpp b/backends/imgui_impl_dx12.cpp index be117b6c1..7a428a1a5 100644 --- a/backends/imgui_impl_dx12.cpp +++ b/backends/imgui_impl_dx12.cpp @@ -16,6 +16,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 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. // 2024-10-07: DirectX12: Compiling with '#define ImTextureID=ImU64' is unnecessary now that dear imgui defaults ImTextureID to u64 instead of void*. @@ -218,9 +219,9 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL } // Upload vertex/index data into a single contiguous GPU buffer + // During Map() we specify a null read range (as per DX12 API, this is informational and for tooling only) void* vtx_resource, *idx_resource; - D3D12_RANGE range; - memset(&range, 0, sizeof(D3D12_RANGE)); + D3D12_RANGE range = { 0, 0 }; if (fr->VertexBuffer->Map(0, &range, &vtx_resource) != S_OK) return; if (fr->IndexBuffer->Map(0, &range, &idx_resource) != S_OK) @@ -235,7 +236,13 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL vtx_dst += draw_list->VtxBuffer.Size; idx_dst += draw_list->IdxBuffer.Size; } + + // During Unmap() we specify the written range (as per DX12 API, this is informational and for tooling only) + range.End = (SIZE_T)((intptr_t)vtx_dst - (intptr_t)vtx_resource); + IM_ASSERT(range.End == draw_data->TotalVtxCount * sizeof(ImDrawVert)); fr->VertexBuffer->Unmap(0, &range); + range.End = (SIZE_T)((intptr_t)idx_dst - (intptr_t)idx_resource); + IM_ASSERT(range.End == draw_data->TotalIdxCount * sizeof(ImDrawIdx)); fr->IndexBuffer->Unmap(0, &range); // Setup desired DX state diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2342c4726..f66866e9e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -43,6 +43,9 @@ Breaking changes: Other changes: +- Backends: DX12: Unmap() call specify written range. The range is informational and may be used by debug tools. + + ----------------------------------------------------------------------- VERSION 1.91.4 (Released 2024-10-18) -----------------------------------------------------------------------