Skip to content

Commit 4fbf379

Browse files
committed
move MULTI_ALLOC_PARAMS to cpp, make mdi the alignment array constexpr, add more logs (+ tmp logs) - I have issue with deferred offset memory deallocation, it doesn't execute (maybe because of my wait semaphore?)
1 parent 839f38f commit 4fbf379

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

include/nbl/ext/ImGui/ImGui.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class UI final : public core::IReferenceCounted
4646

4747
struct MDI
4848
{
49+
using COMPOSE_T = nbl::video::StreamingTransientDataBufferST<nbl::core::allocator<uint8_t>>;
50+
4951
enum E_BUFFER_CONTENT : uint8_t
5052
{
5153
EBC_DRAW_INDIRECT_STRUCTURES,
@@ -56,18 +58,7 @@ class UI final : public core::IReferenceCounted
5658
EBC_COUNT,
5759
};
5860

59-
struct MULTI_ALLOC_PARAMS
60-
{
61-
static constexpr auto ALLOCATION_COUNT = EBC_COUNT;
62-
63-
using COMPOSE_T = nbl::video::StreamingTransientDataBufferST<nbl::core::allocator<uint8_t>>;
64-
65-
std::array<typename COMPOSE_T::value_type, ALLOCATION_COUNT> alignments = {};
66-
std::array<typename COMPOSE_T::size_type, ALLOCATION_COUNT> byteSizes = {};
67-
std::array<typename COMPOSE_T::value_type, ALLOCATION_COUNT> offsets = { COMPOSE_T::invalid_value, COMPOSE_T::invalid_value, COMPOSE_T::invalid_value, COMPOSE_T::invalid_value };
68-
};
69-
70-
nbl::core::smart_refctd_ptr<typename MULTI_ALLOC_PARAMS::COMPOSE_T> streamingTDBufferST; // composed buffer layout is [Draw Indirect structures] [Element structures] [Index buffers] [Vertex Buffers]
61+
nbl::core::smart_refctd_ptr<typename COMPOSE_T> streamingTDBufferST; // composed buffer layout is [EBC_DRAW_INDIRECT_STRUCTURES] [EBC_ELEMENT_STRUCTURES] [EBC_INDEX_BUFFERS] [EBC_VERTEX_BUFFERS]
7162
};
7263

7364
MDI m_mdi;

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ namespace nbl::ext::imgui
661661
if (!memory->map({ 0ull, memoryReqs.size }, accessFlags))
662662
logger->log("Could not map device memory!", system::ILogger::ELL_ERROR);
663663

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);
665665
m_mdi.streamingTDBufferST->getBuffer()->setObjectDebugName("MDI Upstream Buffer");
666666
}
667667

@@ -760,12 +760,17 @@ namespace nbl::ext::imgui
760760
return std::move(retV);
761761
}();
762762

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) });
764765

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);
769774

770775
// calculate upper bound byte size for each mdi's content
771776
for (uint32_t i = 0; i < drawData->CmdListsCount; i++)
@@ -779,34 +784,28 @@ namespace nbl::ext::imgui
779784
}
780785

781786
// 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));
790788

791789
auto mdiBuffer = smart_refctd_ptr<IGPUBuffer>(m_mdi.streamingTDBufferST->getBuffer());
792790
{
793791
std::chrono::steady_clock::time_point timeout(std::chrono::seconds(0x45));
794792

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());
796794

797795
const bool ok = unallocatedSize == 0u;
798796

799797
if (!ok)
800798
{
801799
logger->log("Could not multi alloc mdi buffer!", system::ILogger::ELL_ERROR);
802800

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
804802
{
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);
806804
};
807805

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());
810809

811810
logger->log("[MDI::EBC_DRAW_INDIRECT_STRUCTURES offset] = \"%s\" bytes", system::ILogger::ELL_ERROR, getOffsetStr(multiAllocParams.offsets[MDI::EBC_DRAW_INDIRECT_STRUCTURES]).c_str());
812811
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
967966
}
968967

969968
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?
971972
}
972973

973974
return true;

0 commit comments

Comments
 (0)