19
19
20
20
// CHANGELOG
21
21
// (minor and older changes stripped away, please see git history for details)
22
+ // 2025-01-15: DirectX12: Texture upload use the command queue provided in ImGui_ImplDX12_InitInfo instead of creating its own.
22
23
// 2024-12-09: DirectX12: Let user specifies the DepthStencilView format by setting ImGui_ImplDX12_InitInfo::DSVFormat.
23
24
// 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).
24
25
// 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.
@@ -64,6 +65,8 @@ struct ImGui_ImplDX12_Texture
64
65
ID3D12Resource* pTextureResource;
65
66
D3D12_CPU_DESCRIPTOR_HANDLE hFontSrvCpuDescHandle;
66
67
D3D12_GPU_DESCRIPTOR_HANDLE hFontSrvGpuDescHandle;
68
+
69
+ ImGui_ImplDX12_Texture () { memset ((void *)this , 0 , sizeof (*this )); }
67
70
};
68
71
69
72
struct ImGui_ImplDX12_Data
@@ -180,8 +183,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
180
183
if (draw_data->DisplaySize .x <= 0 .0f || draw_data->DisplaySize .y <= 0 .0f )
181
184
return ;
182
185
183
- // FIXME: I'm assuming that this only gets called once per frame!
184
- // If not, we can't just re-allocate the IB or VB, we'll have to do a proper allocator.
186
+ // FIXME: We are assuming that this only gets called once per frame!
185
187
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData ();
186
188
bd->frameIndex = bd->frameIndex + 1 ;
187
189
ImGui_ImplDX12_RenderBuffers* fr = &bd->pFrameResources [bd->frameIndex % bd->numFramesInFlight ];
@@ -352,11 +354,11 @@ static void ImGui_ImplDX12_CreateFontsTexture()
352
354
bd->pd3dDevice ->CreateCommittedResource (&props, D3D12_HEAP_FLAG_NONE, &desc,
353
355
D3D12_RESOURCE_STATE_COPY_DEST, nullptr , IID_PPV_ARGS (&pTexture));
354
356
355
- UINT uploadPitch = (width * 4 + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u ) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u );
356
- UINT uploadSize = height * uploadPitch ;
357
+ UINT upload_pitch = (width * 4 + D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u ) & ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1u );
358
+ UINT upload_size = height * upload_pitch ;
357
359
desc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
358
360
desc.Alignment = 0 ;
359
- desc.Width = uploadSize ;
361
+ desc.Width = upload_size ;
360
362
desc.Height = 1 ;
361
363
desc.DepthOrArraySize = 1 ;
362
364
desc.MipLevels = 1 ;
@@ -376,26 +378,28 @@ static void ImGui_ImplDX12_CreateFontsTexture()
376
378
IM_ASSERT (SUCCEEDED (hr));
377
379
378
380
void * mapped = nullptr ;
379
- D3D12_RANGE range = { 0 , uploadSize };
381
+ D3D12_RANGE range = { 0 , upload_size };
380
382
hr = uploadBuffer->Map (0 , &range, &mapped);
381
383
IM_ASSERT (SUCCEEDED (hr));
382
384
for (int y = 0 ; y < height; y++)
383
- memcpy ((void *) ((uintptr_t ) mapped + y * uploadPitch ), pixels + y * width * 4 , width * 4 );
385
+ memcpy ((void *) ((uintptr_t ) mapped + y * upload_pitch ), pixels + y * width * 4 , width * 4 );
384
386
uploadBuffer->Unmap (0 , &range);
385
387
386
388
D3D12_TEXTURE_COPY_LOCATION srcLocation = {};
387
- srcLocation.pResource = uploadBuffer;
388
- srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
389
- srcLocation.PlacedFootprint .Footprint .Format = DXGI_FORMAT_R8G8B8A8_UNORM;
390
- srcLocation.PlacedFootprint .Footprint .Width = width;
391
- srcLocation.PlacedFootprint .Footprint .Height = height;
392
- srcLocation.PlacedFootprint .Footprint .Depth = 1 ;
393
- srcLocation.PlacedFootprint .Footprint .RowPitch = uploadPitch;
394
-
395
389
D3D12_TEXTURE_COPY_LOCATION dstLocation = {};
396
- dstLocation.pResource = pTexture;
397
- dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
398
- dstLocation.SubresourceIndex = 0 ;
390
+ {
391
+ srcLocation.pResource = uploadBuffer;
392
+ srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
393
+ srcLocation.PlacedFootprint .Footprint .Format = DXGI_FORMAT_R8G8B8A8_UNORM;
394
+ srcLocation.PlacedFootprint .Footprint .Width = width;
395
+ srcLocation.PlacedFootprint .Footprint .Height = height;
396
+ srcLocation.PlacedFootprint .Footprint .Depth = 1 ;
397
+ srcLocation.PlacedFootprint .Footprint .RowPitch = upload_pitch;
398
+
399
+ dstLocation.pResource = pTexture;
400
+ dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
401
+ dstLocation.SubresourceIndex = 0 ;
402
+ }
399
403
400
404
D3D12_RESOURCE_BARRIER barrier = {};
401
405
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
@@ -412,15 +416,6 @@ static void ImGui_ImplDX12_CreateFontsTexture()
412
416
HANDLE event = ::CreateEvent (0 , 0 , 0 , 0 );
413
417
IM_ASSERT (event != nullptr );
414
418
415
- D3D12_COMMAND_QUEUE_DESC queueDesc = {};
416
- queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
417
- queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
418
- queueDesc.NodeMask = 1 ;
419
-
420
- ID3D12CommandQueue* cmdQueue = nullptr ;
421
- hr = bd->pd3dDevice ->CreateCommandQueue (&queueDesc, IID_PPV_ARGS (&cmdQueue));
422
- IM_ASSERT (SUCCEEDED (hr));
423
-
424
419
ID3D12CommandAllocator* cmdAlloc = nullptr ;
425
420
hr = bd->pd3dDevice ->CreateCommandAllocator (D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS (&cmdAlloc));
426
421
IM_ASSERT (SUCCEEDED (hr));
@@ -435,6 +430,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()
435
430
hr = cmdList->Close ();
436
431
IM_ASSERT (SUCCEEDED (hr));
437
432
433
+ ID3D12CommandQueue* cmdQueue = bd->InitInfo .CommandQueue ;
438
434
cmdQueue->ExecuteCommandLists (1 , (ID3D12CommandList* const *)&cmdList);
439
435
hr = cmdQueue->Signal (fence, 1 );
440
436
IM_ASSERT (SUCCEEDED (hr));
@@ -444,7 +440,6 @@ static void ImGui_ImplDX12_CreateFontsTexture()
444
440
445
441
cmdList->Release ();
446
442
cmdAlloc->Release ();
447
- cmdQueue->Release ();
448
443
::CloseHandle (event);
449
444
fence->Release ();
450
445
uploadBuffer->Release ();
@@ -707,11 +702,11 @@ void ImGui_ImplDX12_InvalidateDeviceObjects()
707
702
if (!bd || !bd->pd3dDevice )
708
703
return ;
709
704
710
- ImGuiIO& io = ImGui::GetIO ();
711
705
SafeRelease (bd->pRootSignature );
712
706
SafeRelease (bd->pPipelineState );
713
707
714
708
// Free SRV descriptor used by texture
709
+ ImGuiIO& io = ImGui::GetIO ();
715
710
ImGui_ImplDX12_Texture* font_tex = &bd->FontTexture ;
716
711
bd->InitInfo .SrvDescriptorFreeFn (&bd->InitInfo , font_tex->hFontSrvCpuDescHandle , font_tex->hFontSrvGpuDescHandle );
717
712
SafeRelease (font_tex->pTextureResource );
0 commit comments