Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
38
QT_BEGIN_NAMESPACE
39
40
class
QRhi;
41
42
namespace
QtMultimediaPrivate
{
43
44
#
if
QT_CONFIG
(
opengl
)
45
class
WglDxDeviceDeleter
46
{
47
public
:
48
WglDxDeviceDeleter
() =
default
;
49
explicit
WglDxDeviceDeleter
(
BOOL
(
WINAPI
*
closeFn
)(
HANDLE
)) :
m_closeFn
(
closeFn
) { }
50
void
operator
()(
HANDLE
device
)
const
noexcept
51
{
52
Q_ASSERT
(
m_closeFn
);
53
m_closeFn
(
device
);
54
}
55
56
private
:
57
BOOL
(
WINAPI
*
m_closeFn
)(
HANDLE
) =
nullptr
;
58
};
59
60
struct
WglDxDeviceHandleTraits
61
{
62
using
Type
=
HANDLE
;
63
static
Type
invalidValue
()
noexcept
{
return
nullptr
; }
64
};
65
using
WglDxDeviceHandle
=
QUniqueHandle
<
WglDxDeviceHandleTraits
,
WglDxDeviceDeleter
>;
66
67
class
WglDxObjectDeleter
68
{
69
public
:
70
WglDxObjectDeleter
() =
default
;
71
WglDxObjectDeleter
(
HANDLE
device
,
BOOL
(
WINAPI
*
unregisterFn
)(
HANDLE
,
HANDLE
))
72
:
m_device
(
device
),
m_unregisterFn
(
unregisterFn
)
73
{
74
}
75
void
operator
()(
HANDLE
object
)
const
noexcept
76
{
77
Q_ASSERT
(
m_unregisterFn
);
78
m_unregisterFn
(
m_device
,
object
);
79
}
80
81
private
:
82
HANDLE
m_device
=
nullptr
;
83
BOOL
(
WINAPI
*
m_unregisterFn
)(
HANDLE
,
HANDLE
) =
nullptr
;
84
};
85
86
using
WglDxObjectHandle
=
QUniqueHandle
<
WglDxDeviceHandleTraits
,
WglDxObjectDeleter
>;
87
88
// A D3D11 texture that stays registered with WGL_NV_DX_interop2 as long as it is reused.
89
struct
WglDxInteropSlot
90
{
91
ComPtr
<
ID3D11Texture2D
>
texture
;
92
GlTextureHandle
glTexture
;
// GL name that 'texture' is registered to
93
WglDxObjectHandle
registration
;
// must be destroyed before 'glTexture'
94
95
void
reset
()
96
{
97
registration
.
reset
();
98
glTexture
.
reset
();
99
texture
.
Reset
();
100
}
101
};
102
#
endif
103
104
class
Q_MULTIMEDIA_EXPORT
QWindowsD3D11RhiTextureImporter
105
{
106
public
:
107
QWindowsD3D11RhiTextureImporter
();
108
~
QWindowsD3D11RhiTextureImporter
();
109
110
Q_DISABLE_COPY_MOVE
(
QWindowsD3D11RhiTextureImporter
)
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. */
116
static
bool
isPixelFormatSupportedByRhiBackend
(
QRhi
&,
QVideoFrameFormat
::
PixelFormat
);
117
118
/** 'pixelFormat' is only consulted on D3D12 and OpenGL, to route multi-plane textures
119
* through QWindowsD3D11PlaneSplitter. Returns null on failure. */
120
QVideoFrameTexturesHandlesUPtr
121
importTexture
(
QRhi
&,
ID3D11Device
*
srcDevice
,
ID3D11DeviceContext
*
srcContext
,
122
const
ComPtr
<
ID3D11Texture2D
> &
texture
,
const
QSize
&
frameSize
,
123
QVideoFrameFormat
::
PixelFormat
pixelFormat
,
UINT
subresourceIndex
= 0);
124
125
private
:
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.
129
class
D3D12OutputTexturePool
130
{
131
public
:
132
struct
Texture
133
{
134
ComPtr
<
ID3D11Texture2D
>
texture
;
135
// Set while the handles of a frame use the texture.
136
std
::
shared_ptr
<
std
::
atomic_bool
>
inUse
;
137
};
138
139
Texture
acquire
(
ID3D11Device
*
device
,
const
D3D11_TEXTURE2D_DESC
&
desc
);
140
141
private
:
142
std
::
vector
<
Texture
>
m_textures
;
143
};
144
145
QVideoFrameTexturesHandlesUPtr
importTextureD3D11
(
QRhi
&,
ID3D11Device
*
srcDevice
,
146
ID3D11DeviceContext
*
srcContext
,
147
const
ComPtr
<
ID3D11Texture2D
> &
texture
,
148
const
QSize
&
frameSize
,
149
UINT
subresourceIndex
);
150
QVideoFrameTexturesHandlesUPtr
importTextureD3D12
(
QRhi
&,
ID3D11Device
*
srcDevice
,
151
ID3D11DeviceContext
*
srcContext
,
152
const
ComPtr
<
ID3D11Texture2D
> &
texture
,
153
const
QSize
&
frameSize
,
UINT
subresourceIndex
,
154
QWindowsD3D11TextureBridge
&
bridge
,
155
D3D12OutputTexturePool
&
outputPool
);
156
QVideoFrameTexturesHandlesUPtr
157
importSplitPlanes
(
QRhi
&
rhi
,
ID3D11Device
*
srcDevice
,
ID3D11DeviceContext
*
srcContext
,
158
const
ComPtr
<
ID3D11Texture2D
> &
texture
,
const
QSize
&
frameSize
,
159
QVideoFrameFormat
::
PixelFormat
pixelFormat
,
UINT
subresourceIndex
);
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
166
ComPtr
<
ID3D11Device
>
m_d3d11on12Device
;
167
D3D12OutputTexturePool
m_d3d12OutputPool
;
// used with m_bridge
168
D3D12OutputTexturePool
m_d3d12OutputPool2
;
// used with m_bridge2
169
170
#
if
QT_CONFIG
(
opengl
)
171
QVideoFrameTexturesHandlesUPtr
importTextureOpenGL
(
QRhi
&
rhi
,
ID3D11Device
*
srcDevice
,
172
ID3D11DeviceContext
*
srcContext
,
173
const
ComPtr
<
ID3D11Texture2D
> &
texture
,
174
const
QSize
&
frameSize
,
175
WglDxInteropSlot
&
interopSlot
);
176
void
releaseGLInterop
();
177
178
// OpenGL interop (WGL_NV_DX_interop2). Order matters
179
WglDxDeviceHandle
m_glInteropDevice
;
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
188
QT_END_NAMESPACE
189
190
#
endif
// QWINDOWSD3D11RHITEXTUREIMPORTER_P_H
QtMultimediaPrivate::QWindowsD3D11RhiTextureImporter
Definition
qwindowsd3d11rhitextureimporter_p.h:105
QtMultimediaPrivate::impl
Definition
qaudiosystem_p.h:257
qtmultimedia
src
multimedia
windows
qwindowsd3d11rhitextureimporter_p.h
Generated on
for Qt by
1.18.0