Skip to content

Commit 99c52f0

Browse files
Make ILogicalDevice::blockForSemaphores also purge the queue drop lists
1 parent 0c91901 commit 99c52f0

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

include/nbl/video/CThreadSafeQueueAdapter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ class CThreadSafeQueueAdapter final : public IQueue
5959
return originalQueue->waitIdle();
6060
}
6161

62-
inline uint32_t cullResources() override
62+
inline uint32_t cullResources(const ISemaphore* sema=nullptr) override
6363
{
6464
std::lock_guard g(m);
65-
return originalQueue->cullResources();
65+
return originalQueue->cullResources(sema);
6666
}
6767

6868
inline IQueue* getUnderlyingQueue() const

include/nbl/video/ILogicalDevice.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,26 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
157157

158158
//! Semaphore Stuff
159159
virtual core::smart_refctd_ptr<ISemaphore> createSemaphore(const uint64_t initialValue) = 0;
160+
// Waits for max timeout amout of time for the semaphores to reach a specific counter value
161+
// DOES NOT implicitly trigger Queue-refcount-resource release because of two reasons:
162+
// - the events may trigger loads of resource releases causing extra processing, whereas our `timeout` could be quite small
163+
// - the event handlers use `waitForSemaphores` themselves so don't want infinite recursion here
160164
virtual ISemaphore::WAIT_RESULT waitForSemaphores(const std::span<const ISemaphore::SWaitInfo> infos, const bool waitAll, const uint64_t timeout) = 0;
161165
// Forever waiting variant if you're confident that the fence will eventually be signalled
166+
// Does implicitly trigger Queue-refcount-resource-release
162167
inline ISemaphore::WAIT_RESULT blockForSemaphores(const std::span<const ISemaphore::SWaitInfo> infos, const bool waitAll=true)
163168
{
164169
using retval_t = ISemaphore::WAIT_RESULT;
165170
if (!infos.empty())
166171
{
167172
auto waitStatus = retval_t::TIMEOUT;
168-
while (waitStatus== retval_t::TIMEOUT)
173+
while (waitStatus==retval_t::TIMEOUT)
174+
{
169175
waitStatus = waitForSemaphores(infos,waitAll,999999999ull);
176+
for (const auto& info : infos)
177+
for (const auto& queue : *m_queues)
178+
queue->cullResources(info.semaphore);
179+
}
170180
return waitStatus;
171181
}
172182
return retval_t::SUCCESS;

include/nbl/video/IQueue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class IQueue : public core::Interface, public core::Unmovable
108108
NBL_API2 virtual RESULT waitIdle();
109109
// You can call this to force an early check on whether past submits have completed and hasten when the refcount gets dropped.
110110
// Normally its the next call to `submit` that polls the event timeline for completions.
111-
NBL_API2 virtual uint32_t cullResources();
111+
// If you want to only check a particular semaphore's timeline, then set `sema` to non nullptr.
112+
NBL_API2 virtual uint32_t cullResources(const ISemaphore* sema=nullptr);
112113

113114
// we cannot derive from IBackendObject because we can't derive from IReferenceCounted
114115
inline const ILogicalDevice* getOriginDevice() const {return m_originDevice;}

src/nbl/video/IQueue.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,16 @@ auto IQueue::waitIdle() -> RESULT
110110
return retval;
111111
}
112112

113-
uint32_t IQueue::cullResources()
113+
uint32_t IQueue::cullResources(const ISemaphore* sema)
114114
{
115+
if (sema)
116+
{
117+
const auto& timelines = m_submittedResources->getTimelines();
118+
auto found = timelines.find(sema);
119+
if (found==timelines.end())
120+
return 0;
121+
return found->handler->poll().eventsLeft;
122+
}
115123
return m_submittedResources->poll().eventsLeft;
116124
}
117125

0 commit comments

Comments
 (0)