Skip to content

Commit f3df85d

Browse files
make CResizableSurface work with concurrently shared sources, untested obviously
1 parent 88df1f8 commit f3df85d

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

examples_tests

include/nbl/video/IQueue.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class IQueue : public core::Interface, public core::Unmovable
4444
inline core::bitflag<CREATE_FLAGS> getFlags() const { return m_flags; }
4545
inline uint32_t getFamilyIndex() const { return m_familyIndex; }
4646
inline float getPriority() const { return m_priority; }
47-
47+
#if 0
4848
// When dealing with external/foreign queues treat `other` as nullptr
49-
inline bool needsOwnershipTransfer(const IQueue* other) const
49+
inline bool needsOwnershipTransfer(const IQueue* other) const // TODO: move into IDeviceMemoryBacked
5050
{
5151
if (!other)
5252
return true;
@@ -57,7 +57,7 @@ class IQueue : public core::Interface, public core::Unmovable
5757
// TODO: take into account concurrent sharing indices, but then we'll need to remember the concurrent sharing family indices
5858
return true;
5959
}
60-
60+
#endif
6161

6262
// for renderdoc and friends
6363
virtual bool startCapture() = 0;

include/nbl/video/utilities/CResizableSurface.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ class NBL_API2 IResizableSurface : public ISimpleManagedSurface
127127
// So CAN'T USE `acquireNextImage` for frame pacing, it was bad Vulkan practice anyway!
128128
inline bool present(std::unique_lock<std::mutex>&& acquireLock, const SPresentInfo& presentInfo)
129129
{
130+
if (!presentInfo)
131+
return false;
132+
130133
std::unique_lock<std::mutex> guard;
131134
if (acquireLock)
132135
guard = std::move(acquireLock);
@@ -136,8 +139,11 @@ class NBL_API2 IResizableSurface : public ISimpleManagedSurface
136139
assert(presentInfo.pPresentSemaphoreWaitValue!=m_lastPresent.pPresentSemaphoreWaitValue);
137140
}
138141
// The only thing we want to do under the mutex, is just enqueue a triple buffer present and a swapchain present, its not a lot.
139-
// Only acquire ownership if the Present queue is different to the current one.
140-
return present_impl(presentInfo,getAssignedQueue()->getFamilyIndex()!=presentInfo.mostRecentFamilyOwningSource);
142+
// Only acquire ownership if the Present queue is different to the current one and not concurrent sharing
143+
bool needFamilyOwnershipTransfer = getAssignedQueue()->getFamilyIndex()!=presentInfo.mostRecentFamilyOwningSource;
144+
if (presentInfo.source.image->getCachedCreationParams().isConcurrentSharing()) // in reality should also return false if the assigned queue is NOT in the Concurrent Sharing Set
145+
needFamilyOwnershipTransfer = false;
146+
return present_impl(presentInfo,needFamilyOwnershipTransfer);
141147
}
142148

143149
// Call this when you want to recreate the swapchain with new extents
@@ -163,13 +169,15 @@ class NBL_API2 IResizableSurface : public ISimpleManagedSurface
163169

164170
// The triple present enqueue operations are fast enough to be done under a mutex, this is safer on some platforms. You need to "race to present" to avoid a flicker.
165171
// Queue family ownership acquire not needed, done by the the very first present when `m_lastPresentSource` wasset.
166-
return present_impl({{m_lastPresent},getAssignedQueue()->getFamilyIndex()},false);
172+
return present_impl({m_lastPresent},false);
167173
}
168174

169175
protected:
170176
using ISimpleManagedSurface::ISimpleManagedSurface;
171177
virtual inline ~IResizableSurface()
172178
{
179+
// stop any calls into explicit resizes
180+
std::unique_lock guard(m_swapchainResourcesMutex);
173181
static_cast<ICallback*>(m_cb)->setSwapchainRecreator(nullptr);
174182
}
175183

@@ -294,7 +302,7 @@ class NBL_API2 IResizableSurface : public ISimpleManagedSurface
294302
}
295303

296304
//
297-
inline bool present_impl(const SPresentInfo& presentInfo, const bool acquireOwnership)
305+
inline bool present_impl(const SCachedPresentInfo& presentInfo, const bool acquireOwnership)
298306
{
299307
// irrecoverable or bad input
300308
if (!presentInfo || !getSwapchainResources())

0 commit comments

Comments
 (0)