@@ -661,7 +661,7 @@ namespace nbl::ext::imgui
661
661
if (!memory->map ({ 0ull , memoryReqs.size }, accessFlags))
662
662
logger->log (" Could not map device memory!" , system::ILogger::ELL_ERROR);
663
663
664
- m_mdi.streamingTDBufferST = core::make_smart_refctd_ptr<MDI::MULTI_ALLOC_PARAMS:: COMPOSE_T>(asset::SBufferRange<video::IGPUBuffer>{0ull , totalByteSize, std::move (buffer)}, maxStreamingBufferAllocationAlignment, minStreamingBufferAllocationSize);
664
+ m_mdi.streamingTDBufferST = core::make_smart_refctd_ptr<MDI::COMPOSE_T>(asset::SBufferRange<video::IGPUBuffer>{0ull , totalByteSize, std::move (buffer)}, maxStreamingBufferAllocationAlignment, minStreamingBufferAllocationSize);
665
665
m_mdi.streamingTDBufferST ->getBuffer ()->setObjectDebugName (" MDI Upstream Buffer" );
666
666
}
667
667
@@ -760,12 +760,17 @@ namespace nbl::ext::imgui
760
760
return std::move (retV);
761
761
}();
762
762
763
- MDI::MULTI_ALLOC_PARAMS multiAllocParams;
763
+ static constexpr auto MDI_ALLOCATION_COUNT = MDI::EBC_COUNT;
764
+ static auto MDI_ALIGNMENTS = std::to_array<typename MDI::COMPOSE_T::size_type, MDI_ALLOCATION_COUNT>({ alignof (VkDrawIndexedIndirectCommand), alignof (PerObjectData), alignof (ImDrawIdx), alignof (ImDrawVert) });
764
765
765
- multiAllocParams.alignments [MDI::EBC_DRAW_INDIRECT_STRUCTURES] = alignof (VkDrawIndexedIndirectCommand);
766
- multiAllocParams.alignments [MDI::EBC_ELEMENT_STRUCTURES] = alignof (PerObjectData);
767
- multiAllocParams.alignments [MDI::EBC_INDEX_BUFFERS] = alignof (ImDrawIdx);
768
- multiAllocParams.alignments [MDI::EBC_VERTEX_BUFFERS] = alignof (ImDrawVert);
766
+ struct MULTI_ALLOC_PARAMS
767
+ {
768
+ std::array<typename MDI::COMPOSE_T::size_type, MDI_ALLOCATION_COUNT> byteSizes = {};
769
+ std::array<typename MDI::COMPOSE_T::value_type, MDI_ALLOCATION_COUNT> offsets = {};
770
+ };
771
+
772
+ MULTI_ALLOC_PARAMS multiAllocParams;
773
+ std::fill (multiAllocParams.offsets .data (), multiAllocParams.offsets .data () + MDI_ALLOCATION_COUNT, MDI::COMPOSE_T::invalid_value);
769
774
770
775
// calculate upper bound byte size for each mdi's content
771
776
for (uint32_t i = 0 ; i < drawData->CmdListsCount ; i++)
@@ -779,34 +784,28 @@ namespace nbl::ext::imgui
779
784
}
780
785
781
786
// calculate upper bound byte size limit for mdi buffer
782
- const auto mdiBufferByteSize = [&byteSizes = multiAllocParams.byteSizes , &alignments = multiAllocParams.alignments ]() -> size_t
783
- {
784
- auto requestedByteSize = std::reduce (std::begin (byteSizes), std::end (byteSizes));
785
- auto maxAlignment = *std::max_element (std::begin (alignments), std::end (alignments));
786
- auto padding = requestedByteSize % maxAlignment; // okay I don't need it at all but lets add a few bytes
787
-
788
- return requestedByteSize + padding;
789
- }();
787
+ const auto mdiBufferByteSize = std::reduce (std::begin (multiAllocParams.byteSizes ), std::end (multiAllocParams.byteSizes ));
790
788
791
789
auto mdiBuffer = smart_refctd_ptr<IGPUBuffer>(m_mdi.streamingTDBufferST ->getBuffer ());
792
790
{
793
791
std::chrono::steady_clock::time_point timeout (std::chrono::seconds (0x45 ));
794
792
795
- const size_t unallocatedSize = m_mdi.streamingTDBufferST ->multi_allocate (timeout, MDI::MULTI_ALLOC_PARAMS::ALLOCATION_COUNT , multiAllocParams.offsets .data (), multiAllocParams.byteSizes .data (), multiAllocParams. alignments .data ());
793
+ const size_t unallocatedSize = m_mdi.streamingTDBufferST ->multi_allocate (timeout, MDI_ALLOCATION_COUNT , multiAllocParams.offsets .data (), multiAllocParams.byteSizes .data (), MDI_ALIGNMENTS .data ());
796
794
797
795
const bool ok = unallocatedSize == 0u ;
798
796
799
797
if (!ok)
800
798
{
801
799
logger->log (" Could not multi alloc mdi buffer!" , system::ILogger::ELL_ERROR);
802
800
803
- auto getOffsetStr = [&](const MDI::MULTI_ALLOC_PARAMS:: COMPOSE_T::value_type offset) -> std::string
801
+ auto getOffsetStr = [&](const MDI::COMPOSE_T::value_type offset) -> std::string
804
802
{
805
- return offset == MDI::MULTI_ALLOC_PARAMS:: COMPOSE_T::invalid_value ? " invalid_value" : std::to_string (offset);
803
+ return offset == MDI::COMPOSE_T::invalid_value ? " invalid_value" : std::to_string (offset);
806
804
};
807
805
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 ());
806
+ logger->log (" [mdi streaming buffer] = \" %s\" bytes" , system::ILogger::ELL_ERROR, std::to_string (mdiBuffer->getSize ()).c_str ());
807
+ logger->log (" [requested] = \" %s\" bytes" , system::ILogger::ELL_ERROR, std::to_string (mdiBufferByteSize).c_str ());
808
+ logger->log (" [unallocated] = \" %s\" bytes" , system::ILogger::ELL_ERROR, std::to_string (unallocatedSize).c_str ());
810
809
811
810
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
811
logger->log (" [MDI::EBC_ELEMENT_STRUCTURES offset] = \" %s\" bytes" , system::ILogger::ELL_ERROR, getOffsetStr (multiAllocParams.offsets [MDI::EBC_ELEMENT_STRUCTURES]).c_str ());
@@ -967,7 +966,9 @@ namespace nbl::ext::imgui
967
966
}
968
967
969
968
auto waitInfo = info.getFutureScratchSemaphore ();
970
- m_mdi.streamingTDBufferST ->multi_deallocate (MDI::MULTI_ALLOC_PARAMS::ALLOCATION_COUNT, multiAllocParams.offsets .data (), multiAllocParams.byteSizes .data (), waitInfo);
969
+ // logger->log("wait info semaphore value for deferred free latch \"%s\"", nbl::system::ILogger::ELL_PERFORMANCE, std::to_string(waitInfo.value).c_str());
970
+
971
+ m_mdi.streamingTDBufferST ->multi_deallocate (MDI_ALLOCATION_COUNT, multiAllocParams.offsets .data (), multiAllocParams.byteSizes .data (), waitInfo); // TODO: why does it not free my offsets with deferred latch free?
971
972
}
972
973
973
974
return true ;
0 commit comments