Skip to content

Commit 70c5d58

Browse files
committed
clean more UI's subscribers, remove EUF_INLINE_UPDATE_VIA_CMDBUF from required usage buffer flags, increase minStreamingBufferAllocationSize to 32u
1 parent 738ba75 commit 70c5d58

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

include/nbl/ext/ImGui/ImGui.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class UI final : public core::IReferenceCounted
5757
bool render(nbl::video::SIntendedSubmitInfo& info, const nbl::video::IGPUDescriptorSet* const descriptorSet);
5858

5959
//! registers lambda listener in which ImGUI calls should be recorded
60-
int registerListener(std::function<void()> const& listener);
61-
bool unregisterListener(uint32_t id);
60+
std::optional<size_t> registerListener(std::function<void()> const& listener);
61+
std::optional<size_t> unregisterListener(size_t id);
6262

6363
//! sets ImGUI context, you are supposed to pass valid ImGuiContext* context
6464
void setContext(void* imguiContext);
@@ -88,14 +88,7 @@ class UI final : public core::IReferenceCounted
8888
core::smart_refctd_ptr<video::IGPUImageView> m_fontAtlasTexture;
8989

9090
MDI m_mdi;
91-
92-
// TODO: Use a signal class instead like Signal<> UIRecordSignal{};
93-
struct Subscriber
94-
{
95-
uint32_t id = 0;
96-
std::function<void()> listener = nullptr;
97-
};
98-
std::vector<Subscriber> m_subscribers{};
91+
std::vector<std::function<void()>> m_subscribers {};
9992
};
10093
}
10194

src/nbl/ext/ImGui/ImGui.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,9 @@ namespace nbl::ext::imgui
626626

627627
void UI::createMDIBuffer(nbl::core::smart_refctd_ptr<typename MDI::COMPOSE_T> _streamingMDIBuffer)
628628
{
629-
constexpr static uint32_t minStreamingBufferAllocationSize = 4u, maxStreamingBufferAllocationAlignment = 1024u * 64u, mdiBufferDefaultSize = /* 2MB */ 1024u * 1024u * 2u;
629+
constexpr static uint32_t minStreamingBufferAllocationSize = 32u, maxStreamingBufferAllocationAlignment = 1024u * 64u, mdiBufferDefaultSize = /* 2MB */ 1024u * 1024u * 2u;
630630
constexpr static auto requiredAllocateFlags = core::bitflag<IDeviceMemoryAllocation::E_MEMORY_ALLOCATE_FLAGS>(IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT);
631-
constexpr static auto requiredUsageFlags = nbl::core::bitflag(nbl::asset::IBuffer::EUF_INDIRECT_BUFFER_BIT) | nbl::asset::IBuffer::EUF_INDEX_BUFFER_BIT | nbl::asset::IBuffer::EUF_VERTEX_BUFFER_BIT | nbl::asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT | nbl::asset::IBuffer::EUF_INLINE_UPDATE_VIA_CMDBUF;
631+
constexpr static auto requiredUsageFlags = nbl::core::bitflag(nbl::asset::IBuffer::EUF_INDIRECT_BUFFER_BIT) | nbl::asset::IBuffer::EUF_INDEX_BUFFER_BIT | nbl::asset::IBuffer::EUF_VERTEX_BUFFER_BIT | nbl::asset::IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT;
632632

633633
auto getRequiredAccessFlags = [&](const core::bitflag<video::IDeviceMemoryAllocation::E_MEMORY_PROPERTY_FLAGS>& properties)
634634
{
@@ -674,7 +674,7 @@ namespace nbl::ext::imgui
674674

675675
const auto validation = std::to_array
676676
({
677-
std::make_pair(buffer->getCreationParams().usage.hasFlags(requiredUsageFlags), "MDI buffer must be created with IBuffer::EUF_INDIRECT_BUFFER_BIT | IBuffer::EUF_INDEX_BUFFER_BIT | IBuffer::EUF_VERTEX_BUFFER_BIT | IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT | IBuffer::EUF_INLINE_UPDATE_VIA_CMDBUF enabled!"),
677+
std::make_pair(buffer->getCreationParams().usage.hasFlags(requiredUsageFlags), "MDI buffer must be created with IBuffer::EUF_INDIRECT_BUFFER_BIT | IBuffer::EUF_INDEX_BUFFER_BIT | IBuffer::EUF_VERTEX_BUFFER_BIT | IBuffer::EUF_SHADER_DEVICE_ADDRESS_BIT enabled!"),
678678
std::make_pair(bool(buffer->getMemoryReqs().memoryTypeBits & m_device->getPhysicalDevice()->getUpStreamingMemoryTypeBits()), "MDI buffer must have up-streaming memory type bits enabled!"),
679679
std::make_pair(binding.memory->getAllocateFlags().hasFlags(requiredAllocateFlags), "MDI buffer's memory must be allocated with IDeviceMemoryAllocation::EMAF_DEVICE_ADDRESS_BIT enabled!"),
680680
std::make_pair(binding.memory->isCurrentlyMapped(), "MDI buffer's memory must be mapped!"), // streaming buffer contructor already validates it, but cannot assume user won't unmap its own buffer for some reason (sorry if you have just hit it)
@@ -1011,30 +1011,27 @@ namespace nbl::ext::imgui
10111011
ImGui::NewFrame();
10121012

10131013
for (auto const& subscriber : m_subscribers)
1014-
subscriber.listener();
1014+
subscriber();
10151015

10161016
return true;
10171017
}
10181018

1019-
int UI::registerListener(std::function<void()> const& listener)
1019+
std::optional<size_t> UI::registerListener(const std::function<void()>& listener)
10201020
{
10211021
assert(listener != nullptr);
1022-
static int NextId = 0;
1023-
m_subscribers.emplace_back(NextId++, listener);
1024-
return m_subscribers.back().id;
1022+
m_subscribers.emplace_back(listener);
1023+
return m_subscribers.size() - 1;
10251024
}
10261025

1027-
bool UI::unregisterListener(const uint32_t id)
1026+
std::optional<size_t> UI::unregisterListener(size_t id)
10281027
{
1029-
for (int i = m_subscribers.size() - 1; i >= 0; --i)
1028+
if (id < m_subscribers.size())
10301029
{
1031-
if (m_subscribers[i].id == id)
1032-
{
1033-
m_subscribers.erase(m_subscribers.begin() + i);
1034-
return true;
1035-
}
1030+
m_subscribers.erase(m_subscribers.begin() + id);
1031+
return id;
10361032
}
1037-
return false;
1033+
1034+
return std::nullopt;
10381035
}
10391036

10401037
void* UI::getContext()

0 commit comments

Comments
 (0)