diff options
Diffstat (limited to 'src/quick/scenegraph/coreapi/qsgtexture.cpp')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgtexture.cpp | 102 |
1 files changed, 88 insertions, 14 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp index 31e68b9f31..57111e9e5f 100644 --- a/src/quick/scenegraph/coreapi/qsgtexture.cpp +++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp @@ -5,10 +5,11 @@ #include "qsgtexture_platform.h" #include <private/qqmlglobal_p.h> #include <private/qsgmaterialshader_p.h> +#include <private/qsgrenderer_p.h> #include <private/qquickitem_p.h> // qquickwindow_p.h cannot be included on its own due to template nonsense #include <private/qquickwindow_p.h> #include <QtCore/private/qnativeinterface_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) && defined(__GLIBC__) #define CAN_BACKTRACE_EXECINFO @@ -30,11 +31,12 @@ #ifndef QT_NO_DEBUG Q_GLOBAL_STATIC(QSet<QSGTexture *>, qsg_valid_texture_set) Q_GLOBAL_STATIC(QMutex, qsg_valid_texture_mutex) -static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK"); #endif QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(lcQsgLeak) + bool operator==(const QSGSamplerDescription &a, const QSGSamplerDescription &b) noexcept { return a.filtering == b.filtering @@ -83,8 +85,9 @@ QSGTexturePrivate::QSGTexturePrivate(QSGTexture *t) #endif #ifdef Q_OS_WIN , m_d3d11TextureAccessor(t) + , m_d3d12TextureAccessor(t) #endif -#if defined(__OBJC__) +#if QT_CONFIG(metal) , m_metalTextureAccessor(t) #endif #if QT_CONFIG(vulkan) @@ -116,7 +119,7 @@ static QHash<QSGTexture*, SGTextureTraceItem*> qt_debug_allocated_textures; inline static void qt_debug_print_texture_count() { - qDebug("Number of leaked textures: %i", qt_debug_texture_count); + qCDebug(lcQsgLeak, "Number of leaked textures: %i", qt_debug_texture_count); qt_debug_texture_count = -1; #if defined(CAN_BACKTRACE_EXECINFO) @@ -243,8 +246,6 @@ static void qt_debug_remove_texture(QSGTexture* texture) \note All classes with QSG prefix should be used solely on the scene graph's rendering thread. See \l {Scene Graph and Rendering} for more information. - - \sa {Scene Graph - Rendering FBOs} */ /*! @@ -304,7 +305,7 @@ QSGTexture::QSGTexture() : QObject(*(new QSGTexturePrivate(this))) { #ifndef QT_NO_DEBUG - if (qsg_leak_check) + if (lcQsgLeak().isDebugEnabled()) qt_debug_add_texture(this); QMutexLocker locker(qsg_valid_texture_mutex()); @@ -319,7 +320,7 @@ QSGTexture::QSGTexture(QSGTexturePrivate &dd) : QObject(dd) { #ifndef QT_NO_DEBUG - if (qsg_leak_check) + if (lcQsgLeak().isDebugEnabled()) qt_debug_add_texture(this); QMutexLocker locker(qsg_valid_texture_mutex()); @@ -333,7 +334,7 @@ QSGTexture::QSGTexture(QSGTexturePrivate &dd) QSGTexture::~QSGTexture() { #ifndef QT_NO_DEBUG - if (qsg_leak_check) + if (lcQsgLeak().isDebugEnabled()) qt_debug_remove_texture(this); QMutexLocker locker(qsg_valid_texture_mutex()); @@ -580,8 +581,6 @@ QSGTexture::WrapMode QSGTexture::verticalWrapMode() const \warning This function can only be called from the rendering thread. \since 6.0 - - \internal */ QRhiTexture *QSGTexture::rhiTexture() const { @@ -602,8 +601,6 @@ QRhiTexture *QSGTexture::rhiTexture() const \warning This function can only be called from the rendering thread. \since 6.0 - - \internal */ void QSGTexture::commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates) { @@ -686,6 +683,7 @@ namespace QNativeInterface { \inmodule QtQuick \ingroup native-interfaces \ingroup native-interfaces-qsgtexture + \inheaderfile QSGTexture \brief Provides access to and enables adopting OpenGL texture objects. \since 6.0 */ @@ -786,6 +784,7 @@ namespace QNativeInterface { \inmodule QtQuick \ingroup native-interfaces \ingroup native-interfaces-qsgtexture + \inheaderfile QSGTexture \brief Provides access to and enables adopting Direct3D 11 texture objects. \since 6.0 */ @@ -837,6 +836,78 @@ void *QSGTexturePlatformD3D11::nativeTexture() const return reinterpret_cast<void *>(quintptr(tex->nativeTexture().object)); return 0; } + +namespace QNativeInterface { +/*! + \class QNativeInterface::QSGD3D12Texture + \inmodule QtQuick + \ingroup native-interfaces + \ingroup native-interfaces-qsgtexture + \inheaderfile QSGTexture + \brief Provides access to and enables adopting Direct3D 12 texture objects. + \since 6.6 +*/ + +/*! + \fn void *QNativeInterface::QSGD3D12Texture::nativeTexture() const + \return the ID3D12Texture object. + */ + +QT_DEFINE_NATIVE_INTERFACE(QSGD3D12Texture); + +/*! + Creates a new QSGTexture wrapping an existing Direct 3D 12 \a texture object + for \a window. + + The native object is wrapped, but not owned, by the resulting QSGTexture. + The caller of the function is responsible for deleting the returned + QSGTexture, but that will not destroy the underlying native object. + + This function is currently suitable for 2D RGBA textures only. + + \warning This function will return null if the scene graph has not yet been + initialized. + + Use \a options to customize the texture attributes. Only the + TextureHasAlphaChannel and TextureHasMipmaps are taken into account here. + + \a size specifies the size in pixels. + + \a resourceState must specify the + \l{https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_resource_states}{current state} + of the texture resource. + + \note This function must be called on the scene graph rendering thread. + + \sa QQuickWindow::sceneGraphInitialized(), QSGTexture, + {Scene Graph - Metal Texture Import}, {Scene Graph - Vulkan Texture Import} + + \since 6.6 + */ +QSGTexture *QSGD3D12Texture::fromNative(void *texture, + int resourceState, + QQuickWindow *window, + const QSize &size, + QQuickWindow::CreateTextureOptions options) +{ + return QQuickWindowPrivate::get(window)->createTextureFromNativeTexture(quint64(texture), resourceState, size, options); +} +} // QNativeInterface + +int QSGTexturePlatformD3D12::nativeResourceState() const +{ + if (auto *tex = m_texture->rhiTexture()) + return tex->nativeTexture().layout; + return 0; +} + +void *QSGTexturePlatformD3D12::nativeTexture() const +{ + if (auto *tex = m_texture->rhiTexture()) + return reinterpret_cast<void *>(quintptr(tex->nativeTexture().object)); + return 0; +} + #endif // win #if defined(__OBJC__) || defined(Q_QDOC) @@ -846,6 +917,7 @@ namespace QNativeInterface { \inmodule QtQuick \ingroup native-interfaces \ingroup native-interfaces-qsgtexture + \inheaderfile QSGTexture \brief Provides access to and enables adopting Metal texture objects. \since 6.0 */ @@ -893,6 +965,7 @@ namespace QNativeInterface { \inmodule QtQuick \ingroup native-interfaces \ingroup native-interfaces-qsgtexture + \inheaderfile QSGTexture \brief Provides access to and enables adopting Vulkan image objects. \since 6.0 */ @@ -974,11 +1047,12 @@ void *QSGTexture::resolveInterface(const char *name, int revision) const #if QT_CONFIG(vulkan) QT_NATIVE_INTERFACE_RETURN_IF(QSGVulkanTexture, &dd->m_vulkanTextureAccessor); #endif -#if defined(__OBJC__) +#if QT_CONFIG(metal) QT_NATIVE_INTERFACE_RETURN_IF(QSGMetalTexture, &dd->m_metalTextureAccessor); #endif #if defined(Q_OS_WIN) QT_NATIVE_INTERFACE_RETURN_IF(QSGD3D11Texture, &dd->m_d3d11TextureAccessor); + QT_NATIVE_INTERFACE_RETURN_IF(QSGD3D12Texture, &dd->m_d3d12TextureAccessor); #endif #if QT_CONFIG(opengl) QT_NATIVE_INTERFACE_RETURN_IF(QSGOpenGLTexture, &dd->m_openglTextureAccessor); |