@@ -636,12 +636,6 @@ namespace nbl::ext::imgui
636
636
637
637
ImGui::Render (); // note it doesn't touch GPU or graphics API at all, its an internal ImGUI call to update & prepare the data for rendering so we can call GetDrawData()
638
638
639
- struct
640
- {
641
- const uint64_t oldie;
642
- uint64_t newie;
643
- } scratchSemaphoreCounters = { .oldie = info.scratchSemaphore .value , .newie = 0u };
644
-
645
639
auto * commandBuffer = info.getScratchCommandBuffer ();
646
640
647
641
ImGuiIO& io = ImGui::GetIO ();
@@ -760,6 +754,9 @@ namespace nbl::ext::imgui
760
754
// retry, second attempt cull frees and execute deferred memory deallocation of offsets no longer in use
761
755
unallocatedSize = m_mdi.streamingTDBufferST ->multi_allocate (timeout, MDI_ALLOCATION_COUNT, multiAllocParams.offsets .data (), multiAllocParams.byteSizes .data (), MDI_ALIGNMENTS.data ());
762
756
757
+ // still no? then we will try suballocating smaller pieces of memory due to possible fragmentation issues & upstream in nice loop (if we get to a point when suballocation could not cover whole 1 sub draw call then we need to submit overflow & rerecord stuff + repeat)
758
+ // that's TODO but first a small test for not tightly packed index + vertex buffer
759
+
763
760
if (unallocatedSize != 0u )
764
761
{
765
762
m_creationParams.utilities ->getLogger ()->log (" Could not multi alloc mdi buffer!" , system::ILogger::ELL_ERROR);
@@ -778,7 +775,7 @@ namespace nbl::ext::imgui
778
775
m_creationParams.utilities ->getLogger ()->log (" [MDI::EBC_INDEX_BUFFERS offset] = \" %s\" bytes" , system::ILogger::ELL_ERROR, getOffsetStr (multiAllocParams.offsets [MDI::EBC_INDEX_BUFFERS]).c_str ());
779
776
m_creationParams.utilities ->getLogger ()->log (" [MDI::EBC_VERTEX_BUFFERS offset] = \" %s\" bytes" , system::ILogger::ELL_ERROR, getOffsetStr (multiAllocParams.offsets [MDI::EBC_VERTEX_BUFFERS]).c_str ());
780
777
781
- exit (0x45 ); // TODO: handle OOB memory requests, probably need to extend the mdi buffer/let user pass more size at init
778
+ exit (0x45 );
782
779
}
783
780
}
784
781
@@ -791,12 +788,17 @@ namespace nbl::ext::imgui
791
788
auto binding = mdiBuffer->getBoundMemory ();
792
789
assert (binding.memory ->isCurrentlyMapped ());
793
790
794
- auto * const indirectsMappedPointer = reinterpret_cast <VkDrawIndexedIndirectCommand*>(reinterpret_cast <uint8_t *>(m_mdi.streamingTDBufferST ->getBufferPointer ()) + multiAllocParams.offsets [MDI::EBC_DRAW_INDIRECT_STRUCTURES]);
795
- auto * const elementsMappedPointer = reinterpret_cast <PerObjectData*>(reinterpret_cast <uint8_t *>(m_mdi.streamingTDBufferST ->getBufferPointer ()) + multiAllocParams.offsets [MDI::EBC_ELEMENT_STRUCTURES]);
796
- auto * indicesMappedPointer = reinterpret_cast <ImDrawIdx*>(reinterpret_cast <uint8_t *>(m_mdi.streamingTDBufferST ->getBufferPointer ()) + multiAllocParams.offsets [MDI::EBC_INDEX_BUFFERS]);
797
- auto * verticesMappedPointer = reinterpret_cast <ImDrawVert*>(reinterpret_cast <uint8_t *>(m_mdi.streamingTDBufferST ->getBufferPointer ()) + multiAllocParams.offsets [MDI::EBC_VERTEX_BUFFERS]);
791
+ auto * const mdiData = reinterpret_cast <uint8_t *>(m_mdi.streamingTDBufferST ->getBufferPointer ());
798
792
799
- size_t globalIOffset = {}, globalVOffset = {}, drawID = {};
793
+ auto * const indirectsMappedPointer = reinterpret_cast <VkDrawIndexedIndirectCommand*>(mdiData + multiAllocParams.offsets [MDI::EBC_DRAW_INDIRECT_STRUCTURES]);
794
+ auto * const elementsMappedPointer = reinterpret_cast <PerObjectData*>(mdiData + multiAllocParams.offsets [MDI::EBC_ELEMENT_STRUCTURES]);
795
+ auto * const indicesMappedPointer = reinterpret_cast <ImDrawIdx*>(mdiData + multiAllocParams.offsets [MDI::EBC_INDEX_BUFFERS]);
796
+ auto * const verticesMappedPointer = reinterpret_cast <ImDrawVert*>(mdiData + multiAllocParams.offsets [MDI::EBC_VERTEX_BUFFERS]);
797
+
798
+ const auto indexObjectGlobalOffset = indicesMappedPointer - reinterpret_cast <ImDrawIdx*>(mdiData);
799
+ const auto vertexObjectGlobalOffset = verticesMappedPointer - reinterpret_cast <ImDrawVert*>(mdiData);
800
+
801
+ size_t cmdListIndexOffset = {}, cmdListVertexOffset = {}, drawID = {};
800
802
801
803
for (int n = 0 ; n < drawData->CmdListsCount ; n++)
802
804
{
@@ -811,11 +813,17 @@ namespace nbl::ext::imgui
811
813
auto * indirect = indirectsMappedPointer + drawID;
812
814
auto * element = elementsMappedPointer + drawID;
813
815
814
- indirect->firstIndex = pcmd->IdxOffset + globalIOffset;
815
816
indirect->firstInstance = drawID; // use base instance as draw ID
816
817
indirect->indexCount = pcmd->ElemCount ;
817
818
indirect->instanceCount = 1u ;
818
- indirect->vertexOffset = pcmd->VtxOffset + globalVOffset;
819
+
820
+ indirect->firstIndex = pcmd->IdxOffset + cmdListIndexOffset;
821
+ indirect->vertexOffset = pcmd->VtxOffset + cmdListVertexOffset;
822
+
823
+ // TEST: I think this could be illegal in vulkan explaining why I get weird flickering but valid scene still I see (the geometry seems to be OK),
824
+ // could try BDA to get vertex + index instead and this is valid for sure
825
+ // indirect->firstIndex = indexObjectGlobalOffset + pcmd->IdxOffset + cmdListIndexOffset;
826
+ // indirect->vertexOffset = vertexObjectGlobalOffset + pcmd->VtxOffset + cmdListVertexOffset;
819
827
820
828
const auto scissor = clip.getScissor (clipRectangle);
821
829
@@ -837,21 +845,29 @@ namespace nbl::ext::imgui
837
845
}
838
846
839
847
// update mdi's vertex & index buffers
840
- ::memcpy (indicesMappedPointer + globalIOffset , cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof (ImDrawIdx));
841
- ::memcpy (verticesMappedPointer + globalVOffset , cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof (ImDrawVert));
848
+ ::memcpy (indicesMappedPointer + cmdListIndexOffset , cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof (ImDrawIdx));
849
+ ::memcpy (verticesMappedPointer + cmdListVertexOffset , cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof (ImDrawVert));
842
850
843
- globalIOffset += cmd_list->IdxBuffer .Size ;
844
- globalVOffset += cmd_list->VtxBuffer .Size ;
851
+ cmdListIndexOffset += cmd_list->IdxBuffer .Size ;
852
+ cmdListVertexOffset += cmd_list->VtxBuffer .Size ;
845
853
}
854
+
855
+ // TEST: flush
856
+ // const ILogicalDevice::MappedMemoryRange memoryRange(binding.memory, 0ull, binding.memory->getAllocationSize());
857
+ // m_creationParams.utilities->getLogicalDevice()->flushMappedMemoryRanges(1u, &memoryRange);
846
858
}
847
859
848
860
auto * rawPipeline = pipeline.get ();
849
861
commandBuffer->bindGraphicsPipeline (rawPipeline);
850
862
commandBuffer->bindDescriptorSets (EPBP_GRAPHICS, rawPipeline->getLayout (), 0 , 1 , &descriptorSet);
863
+
864
+ const auto offset = mdiBuffer->getBoundMemory ().offset ;
851
865
{
852
866
const asset::SBufferBinding<const video::IGPUBuffer> binding =
853
867
{
854
868
.offset = multiAllocParams.offsets [MDI::EBC_INDEX_BUFFERS],
869
+ // TEST: start of MDI buffer
870
+ // .offset = offset, // 0u
855
871
.buffer = smart_refctd_ptr (mdiBuffer)
856
872
};
857
873
@@ -866,6 +882,8 @@ namespace nbl::ext::imgui
866
882
const asset::SBufferBinding<const video::IGPUBuffer> bindings[] =
867
883
{{
868
884
.offset = multiAllocParams.offsets [MDI::EBC_VERTEX_BUFFERS],
885
+ // TEST: start of MDI buffer
886
+ // .offset = offset, // 0u
869
887
.buffer = smart_refctd_ptr (mdiBuffer)
870
888
}};
871
889
@@ -922,17 +940,6 @@ namespace nbl::ext::imgui
922
940
};
923
941
924
942
commandBuffer->drawIndexedIndirect (binding, drawCount, sizeof (VkDrawIndexedIndirectCommand));
925
-
926
- scratchSemaphoreCounters.newie = info.scratchSemaphore .value ;
927
-
928
- if (scratchSemaphoreCounters.newie != scratchSemaphoreCounters.oldie )
929
- {
930
- const auto overflows = scratchSemaphoreCounters.newie - scratchSemaphoreCounters.oldie ;
931
- m_creationParams.utilities ->getLogger ()->log (" %d overflows when rendering UI!\n " , nbl::system::ILogger::ELL_PERFORMANCE, overflows);
932
-
933
- // TODO: handle them?
934
- exit (0x45 );
935
- }
936
943
}
937
944
938
945
return true ;
0 commit comments