Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsd3d11rhitextureimporter_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QWINDOWSD3D11RHITEXTUREIMPORTER_P_H
4#define QWINDOWSD3D11RHITEXTUREIMPORTER_P_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include <QtMultimedia/qtmultimediaexports.h>
18#include <QtMultimedia/qvideoframeformat.h>
19#include <QtMultimedia/private/qhwvideobuffer_p.h>
20#include <QtMultimedia/private/qwindowsd3d11planesplitter_p.h>
21#include <QtMultimedia/private/qwindowsd3d11texturebridge_p.h>
22#if QT_CONFIG(opengl)
23# include <QtMultimedia/private/qmultimedia_gl_support_p.h>
24#endif
25
26#include <QtCore/qobject.h>
27#include <QtCore/qsize.h>
28#include <QtCore/private/qcomptr_p.h>
29#include <QtCore/private/quniquehandle_p.h>
30
31#include <d3d11.h>
32#include <d3d11_1.h>
33
34#include <atomic>
35#include <memory>
36#include <vector>
37
38QT_BEGIN_NAMESPACE
39
40class QRhi;
41
42namespace QtMultimediaPrivate {
43
44#if QT_CONFIG(opengl)
46{
47public:
48 WglDxDeviceDeleter() = default;
50 void operator()(HANDLE device) const noexcept
51 {
54 }
55
56private:
57 BOOL(WINAPI *m_closeFn)(HANDLE) = nullptr;
58};
59
61{
62 using Type = HANDLE;
63 static Type invalidValue() noexcept { return nullptr; }
64};
66
68{
69public:
70 WglDxObjectDeleter() = default;
73 {
74 }
75 void operator()(HANDLE object) const noexcept
76 {
79 }
80
81private:
82 HANDLE m_device = nullptr;
84};
85
87
88// A D3D11 texture that stays registered with WGL_NV_DX_interop2 as long as it is reused.
90{
92 GlTextureHandle glTexture; // GL name that 'texture' is registered to
93 WglDxObjectHandle registration; // must be destroyed before 'glTexture'
94
95 void reset()
96 {
99 texture.Reset();
100 }
101};
102#endif
103
104class Q_MULTIMEDIA_EXPORT QWindowsD3D11RhiTextureImporter
105{
106public:
109
111
112 static bool isRhiBackendSupported(QRhi &);
113
114 /** Returns whether a texture of the given pixel format can be imported into 'rhi'. On
115 * D3D12 and OpenGL, multi-plane formats must be splittable by QWindowsD3D11PlaneSplitter. */
117
118 /** 'pixelFormat' is only consulted on D3D12 and OpenGL, to route multi-plane textures
119 * through QWindowsD3D11PlaneSplitter. Returns null on failure. */
124
125private:
126 // Textures that D3D12 imports are unwrapped from. A texture stays unwrapped until the handles
127 // of its frame are destroyed, and must neither be unwrapped again nor written to before that,
128 // so every frame in flight gets a texture of its own. Released textures are reused.
130 {
131 public:
132 struct Texture
133 {
135 // Set while the handles of a frame use the texture.
137 };
138
140
141 private:
143 };
144
148 const QSize &frameSize,
160
161 QWindowsD3D11TextureBridge m_bridge; // D3D11 import, and single-plane D3D12/OpenGL import
162 QWindowsD3D11TextureBridge m_bridge2; // second plane of a split multi-plane D3D12 import
163 std::unique_ptr<QWindowsD3D11PlaneSplitter> m_planeSplitter; // bound to m_planeSplitterDevice
164 ComPtr<ID3D11Device> m_planeSplitterDevice; // device m_planeSplitter was created for
165
167 D3D12OutputTexturePool m_d3d12OutputPool; // used with m_bridge
168 D3D12OutputTexturePool m_d3d12OutputPool2; // used with m_bridge2
169
170#if QT_CONFIG(opengl)
174 const QSize &frameSize,
176 void releaseGLInterop();
177
178 // OpenGL interop (WGL_NV_DX_interop2). Order matters
180 WglDxInteropSlot m_glInteropSlot; // single-plane import, or first plane when split
181 WglDxInteropSlot m_glInteropSlot2; // second plane when split
182 std::unique_ptr<QObject> m_glCleanupContext; // context object for the cleanup connection
183#endif
184};
185
186} // namespace QtMultimediaPrivate
187
188QT_END_NAMESPACE
189
190#endif // QWINDOWSD3D11RHITEXTUREIMPORTER_P_H