|
@@ -22,6 +22,7 @@
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
|
|
+// 2025-01-15: DirectX12: Texture upload use the command queue provided in ImGui_ImplDX12_InitInfo instead of creating its own.
|
|
|
// 2024-12-09: DirectX12: Let user specifies the DepthStencilView format by setting ImGui_ImplDX12_InitInfo::DSVFormat.
|
|
|
// 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.
|
|
@@ -258,6 +259,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
|
|
|
if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
|
|
|
return;
|
|
|
|
|
|
+ // FIXME: We are assuming that this only gets called once per frame!
|
|
|
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
|
|
|
ImGui_ImplDX12_ViewportData* vd = (ImGui_ImplDX12_ViewportData*)draw_data->OwnerViewport->RendererUserData;
|
|
|
vd->FrameIndex++;
|
|
@@ -429,11 +431,11 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
bd->pd3dDevice->CreateCommittedResource(&props, D3D12_HEAP_FLAG_NONE, &desc,
|
|
|
D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pTexture));
|
|
|
|
|
|
- UINT uploadPitch = (width * 4 + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u);
|
|
|
- UINT uploadSize = height * uploadPitch;
|
|
|
+ UINT upload_pitch = (width * 4 + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u);
|
|
|
+ UINT upload_size = height * upload_pitch;
|
|
|
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
|
|
|
desc.Alignment = 0;
|
|
|
- desc.Width = uploadSize;
|
|
|
+ desc.Width = upload_size;
|
|
|
desc.Height = 1;
|
|
|
desc.DepthOrArraySize = 1;
|
|
|
desc.MipLevels = 1;
|
|
@@ -453,26 +455,28 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
void* mapped = nullptr;
|
|
|
- D3D12_RANGE range = { 0, uploadSize };
|
|
|
+ D3D12_RANGE range = { 0, upload_size };
|
|
|
hr = uploadBuffer->Map(0, &range, &mapped);
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
for (int y = 0; y < height; y++)
|
|
|
- memcpy((void*) ((uintptr_t) mapped + y * uploadPitch), pixels + y * width * 4, width * 4);
|
|
|
+ memcpy((void*) ((uintptr_t) mapped + y * upload_pitch), pixels + y * width * 4, width * 4);
|
|
|
uploadBuffer->Unmap(0, &range);
|
|
|
|
|
|
D3D12_TEXTURE_COPY_LOCATION srcLocation = {};
|
|
|
- srcLocation.pResource = uploadBuffer;
|
|
|
- srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
|
|
- srcLocation.PlacedFootprint.Footprint.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
- srcLocation.PlacedFootprint.Footprint.Width = width;
|
|
|
- srcLocation.PlacedFootprint.Footprint.Height = height;
|
|
|
- srcLocation.PlacedFootprint.Footprint.Depth = 1;
|
|
|
- srcLocation.PlacedFootprint.Footprint.RowPitch = uploadPitch;
|
|
|
-
|
|
|
D3D12_TEXTURE_COPY_LOCATION dstLocation = {};
|
|
|
- dstLocation.pResource = pTexture;
|
|
|
- dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
|
|
- dstLocation.SubresourceIndex = 0;
|
|
|
+ {
|
|
|
+ srcLocation.pResource = uploadBuffer;
|
|
|
+ srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
|
|
|
+ srcLocation.PlacedFootprint.Footprint.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
+ srcLocation.PlacedFootprint.Footprint.Width = width;
|
|
|
+ srcLocation.PlacedFootprint.Footprint.Height = height;
|
|
|
+ srcLocation.PlacedFootprint.Footprint.Depth = 1;
|
|
|
+ srcLocation.PlacedFootprint.Footprint.RowPitch = upload_pitch;
|
|
|
+
|
|
|
+ dstLocation.pResource = pTexture;
|
|
|
+ dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
|
|
|
+ dstLocation.SubresourceIndex = 0;
|
|
|
+ }
|
|
|
|
|
|
D3D12_RESOURCE_BARRIER barrier = {};
|
|
|
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
|
@@ -489,15 +493,6 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
HANDLE event = ::CreateEvent(0, 0, 0, 0);
|
|
|
IM_ASSERT(event != nullptr);
|
|
|
|
|
|
- D3D12_COMMAND_QUEUE_DESC queueDesc = {};
|
|
|
- queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
|
|
|
- queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
|
|
|
- queueDesc.NodeMask = 1;
|
|
|
-
|
|
|
- ID3D12CommandQueue* cmdQueue = nullptr;
|
|
|
- hr = bd->pd3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&cmdQueue));
|
|
|
- IM_ASSERT(SUCCEEDED(hr));
|
|
|
-
|
|
|
ID3D12CommandAllocator* cmdAlloc = nullptr;
|
|
|
hr = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdAlloc));
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
@@ -512,6 +507,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
hr = cmdList->Close();
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
|
|
|
|
+ ID3D12CommandQueue* cmdQueue = bd->InitInfo.CommandQueue;
|
|
|
cmdQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
|
|
|
hr = cmdQueue->Signal(fence, 1);
|
|
|
IM_ASSERT(SUCCEEDED(hr));
|
|
@@ -521,7 +517,6 @@ static void ImGui_ImplDX12_CreateFontsTexture()
|
|
|
|
|
|
cmdList->Release();
|
|
|
cmdAlloc->Release();
|
|
|
- cmdQueue->Release();
|
|
|
::CloseHandle(event);
|
|
|
fence->Release();
|
|
|
uploadBuffer->Release();
|
|
@@ -791,11 +786,11 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
|
|
|
if (!bd || !bd->pd3dDevice)
|
|
|
return;
|
|
|
|
|
|
- ImGuiIO& io = ImGui::GetIO();
|
|
|
SafeRelease(bd->pRootSignature);
|
|
|
SafeRelease(bd->pPipelineState);
|
|
|
|
|
|
// Free SRV descriptor used by texture
|
|
|
+ ImGuiIO& io = ImGui::GetIO();
|
|
|
ImGui_ImplDX12_Texture* font_tex = &bd->FontTexture;
|
|
|
bd->InitInfo.SrvDescriptorFreeFn(&bd->InitInfo, font_tex->hFontSrvCpuDescHandle, font_tex->hFontSrvGpuDescHandle);
|
|
|
SafeRelease(font_tex->pTextureResource);
|