Commit 7c0da12d authored by Laszlo Agocs's avatar Laszlo Agocs

vk: more locks for rsh

Plus add a note for Metal.

Remove and leave out threading/rsh details for now as things are not
quite clear yet when it comes to QRhis operating in parallel with
one or more shared resource.
parent 9717a48f
......@@ -224,7 +224,7 @@ QT_BEGIN_NAMESPACE
QRhiTexture::nativeHandles(). Most importantly, passing pointers in structs
and via setters does not transfer ownership.
\section3 Threading
\section3 Threading and resource sharing
A QRhi instance can be created and used on any thread but all usage must be
limited to that one single thread.
......@@ -240,12 +240,7 @@ QT_BEGIN_NAMESPACE
from \l{QRhiResource::isShareable()}{isShareable()} is usable with other
QRhi instances as well, as long as they are associated with the same
QRhiResourceSharingHost. Resources can also outlive their creating QRhi in
this case, as long as there is at least one QRhi left in the "sharing
group". When the QRhi instances live and operate on different threads,
additional synchronization may be required. When writing to resources,
additional synchronization may be required even when the QRhi instances
live on the same thread. See QRhiResourceSharingHost for further
discussion.
this case, as long as there is at least one QRhi left in the sharing group.
\sa {Qt Shader Tools}, QRhiResourceSharingHost
*/
......
......@@ -52,7 +52,10 @@ QT_BEGIN_NAMESPACE
are Managed on macOS and Shared on iOS/tvOS, and still duplicated.
"Immutable" is like "static" but with only one native buffer underneath.
Textures are Private (device local) and a host visible staging buffer is
used to upload data to them.
used to upload data to them. Does not rely on strong objects refs from
command buffers (hence uses commandBufferWithUnretainedReferences), but
does rely on automatic dependency tracking between encoders (hence no
MTLResourceHazardTrackingModeUntracked atm).
*/
#if __has_feature(objc_arc)
......
......@@ -439,6 +439,12 @@ bool QRhiVulkan::create(QRhi::Flags flags)
}
if (gfxQueueFamilyIdx != -1) {
// Will use one queue always, including when multiple QRhis use the
// same device. This has significant consequences, and cannot easily be
// changed (e.g. think pipeline barriers which create a dependency
// between commands submitted to a queue - with multiple queues
// additional synchronization would be needed)
if (!gfxQueue)
df->vkGetDeviceQueue(dev, gfxQueueFamilyIdx, 0, &gfxQueue);
......@@ -1563,7 +1569,7 @@ void QRhiVulkan::waitCommandCompletion(int frameSlot)
QRhi::FrameOpResult QRhiVulkan::beginNonWrapperFrame(QRhiSwapChain *swapChain)
{
QMutexLocker lock(rsh ? &rsh->mtx : nullptr); // externally synchronized fun for VkQueue & co.
QMutexLocker lock(rsh ? &rsh->mtx : nullptr);
QVkSwapChain *swapChainD = QRHI_RES(QVkSwapChain, swapChain);
QVkSwapChain::FrameResources &frame(swapChainD->frameRes[swapChainD->currentFrameSlot]);
......@@ -1678,7 +1684,7 @@ QRhi::FrameOpResult QRhiVulkan::beginNonWrapperFrame(QRhiSwapChain *swapChain)
QRhi::FrameOpResult QRhiVulkan::endNonWrapperFrame(QRhiSwapChain *swapChain)
{
QMutexLocker lock(rsh ? &rsh->mtx : nullptr); // externally synchronized fun for VkQueue & co.
QMutexLocker lock(rsh ? &rsh->mtx : nullptr);
Q_ASSERT(inFrame);
inFrame = false;
......@@ -1875,6 +1881,8 @@ QRhi::FrameOpResult QRhiVulkan::finish()
void QRhiVulkan::activateTextureRenderTarget(QRhiCommandBuffer *, QRhiTextureRenderTarget *rt)
{
QMutexLocker lock(rsh ? &rsh->mtx : nullptr);
QVkTextureRenderTarget *rtD = QRHI_RES(QVkTextureRenderTarget, rt);
rtD->lastActiveFrameSlot = currentFrameSlot;
rtD->d.rp->lastActiveFrameSlot = currentFrameSlot;
......@@ -1900,6 +1908,8 @@ void QRhiVulkan::activateTextureRenderTarget(QRhiCommandBuffer *, QRhiTextureRen
void QRhiVulkan::deactivateTextureRenderTarget(QRhiCommandBuffer *, QRhiTextureRenderTarget *rt)
{
QMutexLocker lock(rsh ? &rsh->mtx : nullptr);
QVkTextureRenderTarget *rtD = QRHI_RES(QVkTextureRenderTarget, rt);
// already in the right layout when the renderpass ends
const QVector<QRhiColorAttachment> colorAttachments = rtD->m_desc.colorAttachments();
......@@ -2269,6 +2279,8 @@ void QRhiVulkan::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdat
QRhiResourceUpdateBatchPrivate *ud = QRhiResourceUpdateBatchPrivate::get(resourceUpdates);
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QMutexLocker lock(rsh ? &rsh->mtx : nullptr);
for (const QRhiResourceUpdateBatchPrivate::DynamicBufferUpdate &u : ud->dynamicBufferUpdates) {
QVkBuffer *bufD = QRHI_RES(QVkBuffer, u.buf);
Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
......@@ -2706,6 +2718,8 @@ void QRhiVulkan::executeBufferHostWritesForCurrentFrame(QVkBuffer *bufD)
if (updates.isEmpty())
return;
QMutexLocker lock(rsh ? &rsh->mtx : nullptr);
Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
void *p = nullptr;
VmaAllocation a = toVmaAllocation(bufD->allocations[currentFrameSlot]);
......
event
res.sh.: example to show read/write same texture
threading with rsh with resource - more external sync needed?
event/fence for res.sh.?
advanced blend modes
gl: tex formats (texture, readback)
gl: srgb? (glEnable and co.)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment