Skip to content

Commit 38ab25a

Browse files
author
devsh
committed
only pass queues to font atlas creation
1 parent 96ff988 commit 38ab25a

File tree

2 files changed

+46
-39
lines changed

2 files changed

+46
-39
lines changed

include/nbl/ext/ImGui/ImGui.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ class UI final : public core::IReferenceCounted
159159
void createMDIBuffer(SCreationParameters& creationParams);
160160
void handleMouseEvents(const SUpdateParameters& params) const;
161161
void handleKeyEvents(const SUpdateParameters& params) const;
162-
video::ISemaphore::future_t<video::IQueue::RESULT> createFontAtlasTexture(video::IGPUCommandBuffer* cmdBuffer, SCreationParameters& creationParams);
162+
// NOTE: in the future this will also need a compute queue to do mip-maps
163+
video::ISemaphore::future_t<video::IQueue::RESULT> createFontAtlasTexture(video::IQueue* transfer);
163164

164165
SCachedCreationParams m_cachedCreationParams;
165166

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,29 @@ void UI::createPipeline(SCreationParameters& creationParams)
335335
}
336336
}
337337

338-
ISemaphore::future_t<IQueue::RESULT> UI::createFontAtlasTexture(IGPUCommandBuffer* cmdBuffer, SCreationParameters& creationParams)
338+
ISemaphore::future_t<IQueue::RESULT> UI::createFontAtlasTexture(video::IQueue* transfer)
339339
{
340+
system::logger_opt_ptr logger = m_cachedCreationParams.utilities->getLogger();
341+
auto* device = m_cachedCreationParams.utilities->getLogicalDevice();
342+
343+
smart_refctd_ptr<IGPUCommandBuffer> transientCmdBuf;
344+
{
345+
using pool_flags_t = IGPUCommandPool::CREATE_FLAGS;
346+
347+
smart_refctd_ptr<IGPUCommandPool> pool = device->createCommandPool(transfer->getFamilyIndex(), pool_flags_t::RESET_COMMAND_BUFFER_BIT | pool_flags_t::TRANSIENT_BIT);
348+
if (!pool)
349+
{
350+
logger.log("Could not create command pool!", ILogger::ELL_ERROR);
351+
return IQueue::RESULT::OTHER_ERROR;
352+
}
353+
354+
if (!pool->createCommandBuffers(IGPUCommandPool::BUFFER_LEVEL::PRIMARY, 1u, &transientCmdBuf))
355+
{
356+
logger.log("Could not create transistent command buffer!", ILogger::ELL_ERROR);
357+
return IQueue::RESULT::OTHER_ERROR;
358+
}
359+
}
360+
340361
// Load Fonts
341362
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
342363
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
@@ -370,6 +391,7 @@ ISemaphore::future_t<IQueue::RESULT> UI::createFontAtlasTexture(IGPUCommandBuffe
370391
_NBL_STATIC_INLINE_CONSTEXPR auto NBL_FORMAT_FONT = EF_R8G8B8A8_UNORM;
371392
const auto buffer = make_smart_refctd_ptr< CCustomAllocatorCPUBuffer<null_allocator<uint8_t>, true> >(image_size, pixels, adopt_memory);
372393

394+
// TODO: In the future use CAssetConverter to replace everything below this line
373395
IGPUImage::SCreationParams params;
374396
params.flags = static_cast<IImage::E_CREATE_FLAGS>(0u);
375397
params.type = IImage::ET_2D;
@@ -405,34 +427,34 @@ ISemaphore::future_t<IQueue::RESULT> UI::createFontAtlasTexture(IGPUCommandBuffe
405427
region->imageExtent = { params.extent.width, params.extent.height, 1u };
406428
}
407429

408-
auto image = creationParams.utilities->getLogicalDevice()->createImage(std::move(params));
430+
auto image = device->createImage(std::move(params));
409431

410432
if (!image)
411433
{
412-
creationParams.utilities->getLogger()->log("Could not create font image!", ILogger::ELL_ERROR);
434+
logger.log("Could not create font image!", ILogger::ELL_ERROR);
413435
return IQueue::RESULT::OTHER_ERROR;
414436
}
415437
image->setObjectDebugName("Nabla ImGUI default font");
416438

417-
if (!creationParams.utilities->getLogicalDevice()->allocate(image->getMemoryReqs(), image.get()).isValid())
439+
if (!device->allocate(image->getMemoryReqs(), image.get()).isValid())
418440
{
419-
creationParams.utilities->getLogger()->log("Could not allocate memory for font image!", ILogger::ELL_ERROR);
441+
logger.log("Could not allocate memory for font image!", ILogger::ELL_ERROR);
420442
return IQueue::RESULT::OTHER_ERROR;
421443
}
422444

423445
SIntendedSubmitInfo sInfo;
424446
{
425-
IQueue::SSubmitInfo::SCommandBufferInfo cmdInfo = { cmdBuffer };
447+
IQueue::SSubmitInfo::SCommandBufferInfo cmdInfo = { transientCmdBuf.get() };
426448

427-
auto scratchSemaphore = creationParams.utilities->getLogicalDevice()->createSemaphore(0);
449+
auto scratchSemaphore = device->createSemaphore(0);
428450
if (!scratchSemaphore)
429451
{
430-
creationParams.utilities->getLogger()->log("Could not create scratch semaphore", ILogger::ELL_ERROR);
452+
logger.log("Could not create scratch semaphore", ILogger::ELL_ERROR);
431453
return IQueue::RESULT::OTHER_ERROR;
432454
}
433455
scratchSemaphore->setObjectDebugName("Nabla IMGUI extension Scratch Semaphore");
434456

435-
sInfo.queue = creationParams.transfer;
457+
sInfo.queue = transfer;
436458
sInfo.waitSemaphores = {};
437459
sInfo.commandBuffers = { &cmdInfo, 1 };
438460
sInfo.scratchSemaphore =
@@ -460,13 +482,13 @@ ISemaphore::future_t<IQueue::RESULT> UI::createFontAtlasTexture(IGPUCommandBuffe
460482
}
461483
};
462484

463-
cmdBuffer->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
464-
cmdBuffer->pipelineBarrier(E_DEPENDENCY_FLAGS::EDF_NONE,{.imgBarriers=barriers});
485+
transientCmdBuf->begin(IGPUCommandBuffer::USAGE::ONE_TIME_SUBMIT_BIT);
486+
transientCmdBuf->pipelineBarrier(E_DEPENDENCY_FLAGS::EDF_NONE,{.imgBarriers=barriers});
465487
// We cannot use the `AutoSubmit` variant of the util because we need to add a pipeline barrier with a transition onto the command buffer after the upload.
466488
// old layout is UNDEFINED because we don't want a content preserving transition, we can just put ourselves in transfer right away
467-
if (!creationParams.utilities->updateImageViaStagingBuffer(sInfo,pixels,image->getCreationParameters().format,image.get(),transferLayout,regions.range))
489+
if (!m_cachedCreationParams.utilities->updateImageViaStagingBuffer(sInfo,pixels,image->getCreationParameters().format,image.get(),transferLayout,regions.range))
468490
{
469-
creationParams.utilities->getLogger()->log("Could not upload font image contents", ILogger::ELL_ERROR);
491+
logger.log("Could not upload font image contents", ILogger::ELL_ERROR);
470492
return IQueue::RESULT::OTHER_ERROR;
471493
}
472494

@@ -475,13 +497,13 @@ ISemaphore::future_t<IQueue::RESULT> UI::createFontAtlasTexture(IGPUCommandBuffe
475497
// transition to READ_ONLY_OPTIMAL ready for rendering with sampling
476498
barriers[0].oldLayout = barriers[0].newLayout;
477499
barriers[0].newLayout = IGPUImage::LAYOUT::READ_ONLY_OPTIMAL;
478-
cmdBuffer->pipelineBarrier(E_DEPENDENCY_FLAGS::EDF_NONE,{.imgBarriers=barriers});
479-
cmdBuffer->end();
500+
transientCmdBuf->pipelineBarrier(E_DEPENDENCY_FLAGS::EDF_NONE,{.imgBarriers=barriers});
501+
transientCmdBuf->end();
480502

481503
const auto submit = sInfo.popSubmit({});
482-
if (creationParams.transfer->submit(submit)!=IQueue::RESULT::SUCCESS)
504+
if (transfer->submit(submit)!=IQueue::RESULT::SUCCESS)
483505
{
484-
creationParams.utilities->getLogger()->log("Could not submit workload for font texture upload.", ILogger::ELL_ERROR);
506+
logger.log("Could not submit workload for font texture upload.", ILogger::ELL_ERROR);
485507
return IQueue::RESULT::OTHER_ERROR;
486508
}
487509
}
@@ -493,7 +515,7 @@ ISemaphore::future_t<IQueue::RESULT> UI::createFontAtlasTexture(IGPUCommandBuffe
493515
params.subresourceRange = regions.subresource;
494516
params.image = smart_refctd_ptr(image);
495517

496-
m_fontAtlasTexture = creationParams.utilities->getLogicalDevice()->createImageView(std::move(params));
518+
m_fontAtlasTexture = device->createImageView(std::move(params));
497519
}
498520

499521
ISemaphore::future_t<IQueue::RESULT> retval(IQueue::RESULT::SUCCESS);
@@ -845,36 +867,20 @@ UI::UI(SCreationParameters&& creationParams)
845867
assert(false);
846868
}
847869

848-
smart_refctd_ptr<IGPUCommandBuffer> transistentCMD;
849-
{
850-
using pool_flags_t = IGPUCommandPool::CREATE_FLAGS;
851-
852-
smart_refctd_ptr<IGPUCommandPool> pool = creationParams.utilities->getLogicalDevice()->createCommandPool(creationParams.transfer->getFamilyIndex(), pool_flags_t::RESET_COMMAND_BUFFER_BIT|pool_flags_t::TRANSIENT_BIT);
853-
if (!pool)
854-
{
855-
creationParams.utilities->getLogger()->log("Could not create command pool!", ILogger::ELL_ERROR);
856-
assert(false);
857-
}
858-
859-
if (!pool->createCommandBuffers(IGPUCommandPool::BUFFER_LEVEL::PRIMARY, 1u, &transistentCMD))
860-
{
861-
creationParams.utilities->getLogger()->log("Could not create transistent command buffer!", ILogger::ELL_ERROR);
862-
assert(false);
863-
}
864-
}
865870

866871
// Dear ImGui context
867872
IMGUI_CHECKVERSION();
868873
ImGui::CreateContext();
869874

870875
createPipeline(creationParams);
871876
createMDIBuffer(creationParams);
872-
createFontAtlasTexture(transistentCMD.get(), creationParams);
877+
878+
m_cachedCreationParams = std::move(creationParams);
879+
880+
createFontAtlasTexture(creationParams.transfer);
873881

874882
auto & io = ImGui::GetIO();
875883
io.BackendUsingLegacyKeyArrays = 0; // using AddKeyEvent() - it's new way of handling ImGUI events our backends supports
876-
877-
m_cachedCreationParams = std::move(creationParams);
878884
}
879885

880886
UI::~UI() = default;

0 commit comments

Comments
 (0)