Commit 55af90ad authored by Laszlo Agocs's avatar Laszlo Agocs

Introduce (but don't yet implement) QRhiResourceSharingHost

parent 9ffcb7d4
...@@ -333,6 +333,17 @@ QT_BEGIN_NAMESPACE ...@@ -333,6 +333,17 @@ QT_BEGIN_NAMESPACE
\class QRhiInitParams \class QRhiInitParams
\inmodule QtRhi \inmodule QtRhi
\brief Base class for backend-specific initialization parameters. \brief Base class for backend-specific initialization parameters.
Contains fields that are relevant to all backends.
\l resourceSharingHost is set to null by default. Setting it to an actual
QRhiResourceSharingHost instance is optional. When set, it causes the QRhi
to share either the graphics device, or, in case of OpenGL, use a context
that shares resources, with all other QRhi instances that have the same
QRhiResourceSharingHost set in their QRhiInitParams. This makes the
underlying graphics resources of QRhiResource subclasses such as
QRhiTexture visible to all the QRhi instances that use the same
QRhiResourceSharingHost.
*/ */
/*! /*!
...@@ -2499,6 +2510,64 @@ quint32 QRhiImplementation::approxByteSizeForTexture(QRhiTexture::Format format, ...@@ -2499,6 +2510,64 @@ quint32 QRhiImplementation::approxByteSizeForTexture(QRhiTexture::Format format,
return approxSize; return approxSize;
} }
/*!
\class QRhiResourceSharingHost
\inmodule QtRhi
\brief Enables resource sharing and synchronization between QRhi instances.
When a QRhi is created with QRhiInitParams::resourceSharingHost set, it
causes the QRhi to share either the graphics device, or, in case of OpenGL,
use a context that shares resources, with all other QRhi instances that
have the same QRhiResourceSharingHost set in their QRhiInitParams.
Sharing the same device means that when two or more QRhi instances have the
same QhiResourceSharingHost set, there will only be one native graphics
device object, such as, \c VkDevice, \c MTLDevice, or \c ID3D11Device,
created, and that device will be available as long as the
QRhiResourceSharingHost is alive, thus avoiding lifetime and ownership
issues.
This makes the underlying graphics resources of QRhiResource subclasses
such as QRhiTexture available to all the QRhi instances that use the same
QRhiResourceSharingHost.
With some backends the resource sharing host has more tasks than merely
facilitating the reuse of the device objects. With Direct3D 11 for example,
it also performs synchronizing submission to the device context (of which
there is only one, regardless of the number of threads submitting to it).
\note There is no further synchronization performed for resources like
buffers or textures. If the QRhi instances operate on different threads, it
is up to those threads to ensure the QRhiResource usages on the threads
are done as appropriate for the underlying graphics APIs.
\note The QRhiResourceSharingHost can be created on a thread that is
different than the threads on which the associated QRhi instances will be
created. It is however up to the application to organize those threads in a
way that the construction and destruction of the QRhiResourceSharingHost is
performed (and completed) before and after all associated QRhi instances
and created and destroyed, respectively.
*/
/*!
Constructs a new QRhiResourceSharingHost.
*/
QRhiResourceSharingHost::QRhiResourceSharingHost()
: d(new QRhiResourceSharingHostPrivate)
{
}
/*!
Destructor.
\note Destroying a QRhiResourceSharingHost before all the associated QRhi
instances are destroyed is not allowed and will lead to undefined behavior.
*/
QRhiResourceSharingHost::~QRhiResourceSharingHost()
{
delete d;
}
/*! /*!
\internal \internal
*/ */
......
...@@ -60,6 +60,7 @@ class QRhiResourceUpdateBatch; ...@@ -60,6 +60,7 @@ class QRhiResourceUpdateBatch;
class QRhiResourceUpdateBatchPrivate; class QRhiResourceUpdateBatchPrivate;
class QRhiProfiler; class QRhiProfiler;
class QRhiShaderResourceBindingPrivate; class QRhiShaderResourceBindingPrivate;
class QRhiResourceSharingHostPrivate;
class Q_RHI_EXPORT QRhiColorClearValue class Q_RHI_EXPORT QRhiColorClearValue
{ {
...@@ -1110,8 +1111,20 @@ private: ...@@ -1110,8 +1111,20 @@ private:
Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiResourceUpdateBatch::TexturePrepareFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiResourceUpdateBatch::TexturePrepareFlags)
class Q_RHI_EXPORT QRhiResourceSharingHost
{
public:
QRhiResourceSharingHost();
~QRhiResourceSharingHost();
private:
Q_DISABLE_COPY(QRhiResourceSharingHost)
QRhiResourceSharingHostPrivate *d;
};
struct Q_RHI_EXPORT QRhiInitParams struct Q_RHI_EXPORT QRhiInitParams
{ {
QRhiResourceSharingHost *resourceSharingHost = nullptr;
}; };
class Q_RHI_EXPORT QRhi class Q_RHI_EXPORT QRhi
......
...@@ -362,6 +362,11 @@ private: ...@@ -362,6 +362,11 @@ private:
int curBinding = -1; int curBinding = -1;
}; };
class Q_RHI_PRIVATE_EXPORT QRhiResourceSharingHostPrivate
{
public:
};
QT_END_NAMESPACE QT_END_NAMESPACE
#endif #endif
...@@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE ...@@ -68,7 +68,7 @@ QT_BEGIN_NAMESPACE
QRhiSwapChain will target is passed in as well. QRhiSwapChain will target is passed in as well.
\badcode \badcode
fallbackSurface = QRhiGles2InitParams::newFallbackSurface(); QOffscreenSurface *fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
QRhiGles2InitParams params; QRhiGles2InitParams params;
params.fallbackSurface = fallbackSurface; params.fallbackSurface = fallbackSurface;
params.window = window; params.window = window;
......
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