@@ -665,14 +665,28 @@ namespace nbl::ext::imgui
665
665
m_mdi.streamingTDBufferST ->getBuffer ()->setObjectDebugName (" MDI Upstream Buffer" );
666
666
}
667
667
668
- bool UI::render (IGPUCommandBuffer* commandBuffer , const IGPUDescriptorSet* const descriptorSet)
668
+ bool UI::render (SIntendedSubmitInfo& info , const IGPUDescriptorSet* const descriptorSet)
669
669
{
670
+ if (!info.valid ())
671
+ {
672
+ logger->log (" Invalid SIntendedSubmitInfo!" , system::ILogger::ELL_ERROR);
673
+ return false ;
674
+ }
675
+
676
+ struct
677
+ {
678
+ const uint64_t oldie;
679
+ uint64_t newie;
680
+ } scratchSemaphoreCounters = { .oldie = info.scratchSemaphore .value , .newie = 0u };
681
+
682
+ auto * commandBuffer = info.getScratchCommandBuffer ();
683
+
670
684
ImGuiIO& io = ImGui::GetIO ();
671
685
672
686
if (!io.Fonts ->IsBuilt ())
673
687
{
674
688
logger->log (" Font atlas not built! It is generally built by the renderer backend. Missing call to renderer _NewFrame() function? e.g. ImGui_ImplOpenGL3_NewFrame()." , system::ILogger::ELL_ERROR);
675
- assert ( false ) ;
689
+ return false ;
676
690
}
677
691
678
692
auto const * drawData = ImGui::GetDrawData ();
@@ -774,6 +788,7 @@ namespace nbl::ext::imgui
774
788
return requestedByteSize + padding;
775
789
}();
776
790
791
+ auto mdiBuffer = smart_refctd_ptr<IGPUBuffer>(m_mdi.streamingTDBufferST ->getBuffer ());
777
792
{
778
793
std::chrono::steady_clock::time_point timeout (std::chrono::seconds (0x45 ));
779
794
@@ -785,23 +800,23 @@ namespace nbl::ext::imgui
785
800
{
786
801
logger->log (" Could not multi alloc mdi buffer!" , system::ILogger::ELL_ERROR);
787
802
788
- auto callback = [&](const std::string_view section, const MDI::MULTI_ALLOC_PARAMS::COMPOSE_T::value_type offset)
803
+ auto getOffsetStr = [&](const MDI::MULTI_ALLOC_PARAMS::COMPOSE_T::value_type offset) -> std::string
789
804
{
790
- std::string value = offset == MDI::MULTI_ALLOC_PARAMS::COMPOSE_T::invalid_value ? " invalid_value" : std::to_string (offset);
791
- logger->log (" %s offset = %s" , system::ILogger::ELL_ERROR, section.data (), value.c_str ());
805
+ return offset == MDI::MULTI_ALLOC_PARAMS::COMPOSE_T::invalid_value ? " invalid_value" : std::to_string (offset);
792
806
};
793
807
794
- callback (" MDI::EBC_DRAW_INDIRECT_STRUCTURES" , multiAllocParams.offsets [MDI::EBC_DRAW_INDIRECT_STRUCTURES]);
795
- callback (" MDI::EBC_ELEMENT_STRUCTURES" , multiAllocParams.offsets [MDI::EBC_ELEMENT_STRUCTURES]);
796
- callback (" MDI::EBC_INDEX_BUFFERS" , multiAllocParams.offsets [MDI::EBC_INDEX_BUFFERS]);
797
- callback (" MDI::EBC_VERTEX_BUFFERS" , multiAllocParams.offsets [MDI::EBC_VERTEX_BUFFERS]);
808
+ logger->log (" [mdi streaming buffer size] = \" %s\" bytes" , system::ILogger::ELL_ERROR, std::to_string (mdiBuffer->getSize ()).c_str ());
809
+ logger->log (" [unallocated size] = \" %s\" bytes" , system::ILogger::ELL_ERROR, std::to_string (unallocatedSize).c_str ());
810
+
811
+ logger->log (" [MDI::EBC_DRAW_INDIRECT_STRUCTURES offset] = \" %s\" bytes" , system::ILogger::ELL_ERROR, getOffsetStr (multiAllocParams.offsets [MDI::EBC_DRAW_INDIRECT_STRUCTURES]).c_str ());
812
+ logger->log (" [MDI::EBC_ELEMENT_STRUCTURES offset] = \" %s\" bytes" , system::ILogger::ELL_ERROR, getOffsetStr (multiAllocParams.offsets [MDI::EBC_ELEMENT_STRUCTURES]).c_str ());
813
+ logger->log (" [MDI::EBC_INDEX_BUFFERS offset] = \" %s\" bytes" , system::ILogger::ELL_ERROR, getOffsetStr (multiAllocParams.offsets [MDI::EBC_INDEX_BUFFERS]).c_str ());
814
+ logger->log (" [MDI::EBC_VERTEX_BUFFERS offset] = \" %s\" bytes" , system::ILogger::ELL_ERROR, getOffsetStr (multiAllocParams.offsets [MDI::EBC_VERTEX_BUFFERS]).c_str ());
798
815
799
- exit (0x45 ); // TODO: handle overflows, unallocatedSize tells how much is missing
816
+ exit (0x45 ); // TODO: handle OOB memory requests
800
817
}
801
818
}
802
819
803
- auto mdiBuffer = smart_refctd_ptr<IGPUBuffer>(m_mdi.streamingTDBufferST ->getBuffer ());
804
-
805
820
const uint32_t drawCount = multiAllocParams.byteSizes [MDI::EBC_DRAW_INDIRECT_STRUCTURES] / sizeof (VkDrawIndexedIndirectCommand);
806
821
{
807
822
auto binding = mdiBuffer->getBoundMemory ();
@@ -817,12 +832,6 @@ namespace nbl::ext::imgui
817
832
auto * indicesMappedPointer = reinterpret_cast <ImDrawIdx*>(reinterpret_cast <uint8_t *>(m_mdi.streamingTDBufferST ->getBufferPointer ()) + multiAllocParams.offsets [MDI::EBC_INDEX_BUFFERS]);
818
833
auto * verticesMappedPointer = reinterpret_cast <ImDrawVert*>(reinterpret_cast <uint8_t *>(m_mdi.streamingTDBufferST ->getBufferPointer ()) + multiAllocParams.offsets [MDI::EBC_VERTEX_BUFFERS]);
819
834
820
- /*
821
- IMGUI Render command lists. We merged all buffers into a single one so we
822
- maintain our own offset into them, we pre-loop to get request data for
823
- MDI buffer alocation request/update.
824
- */
825
-
826
835
size_t globalIOffset = {}, globalVOffset = {}, drawID = {};
827
836
828
837
for (int n = 0 ; n < drawData->CmdListsCount ; n++)
@@ -945,9 +954,22 @@ namespace nbl::ext::imgui
945
954
};
946
955
947
956
commandBuffer->drawIndexedIndirect (binding, drawCount, sizeof (VkDrawIndexedIndirectCommand));
948
- }
949
- assert (m_mdi.streamingTDBufferST ->getBuffer ()); // make sure no drop
950
957
958
+ scratchSemaphoreCounters.newie = info.scratchSemaphore .value ;
959
+
960
+ if (scratchSemaphoreCounters.newie != scratchSemaphoreCounters.oldie )
961
+ {
962
+ const auto overflows = scratchSemaphoreCounters.newie - scratchSemaphoreCounters.oldie ;
963
+ logger->log (" %d overflows when rendering UI!\n " , nbl::system::ILogger::ELL_PERFORMANCE, overflows);
964
+
965
+ // TODO: handle them?
966
+ exit (0x45 );
967
+ }
968
+
969
+ auto waitInfo = info.getFutureScratchSemaphore ();
970
+ m_mdi.streamingTDBufferST ->multi_deallocate (MDI::MULTI_ALLOC_PARAMS::ALLOCATION_COUNT, multiAllocParams.offsets .data (), multiAllocParams.byteSizes .data (), waitInfo);
971
+ }
972
+
951
973
return true ;
952
974
}
953
975
0 commit comments