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
qopenxrgraphics_d3d12.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
6
#
include
"qopenxrgraphics_d3d12_p.h"
7
8
#
include
"qopenxrhelpers_p.h"
9
10
#
include
<
QtQuick
/
QQuickWindow
>
11
#
include
<
QtQuick
/
QQuickGraphicsDevice
>
12
13
#
include
<
rhi
/
qrhi
.
h
>
14
15
QT_BEGIN_NAMESPACE
16
17
QOpenXRGraphicsD3D12::QOpenXRGraphicsD3D12()
18
{
19
m_graphicsBinding.type = XR_TYPE_GRAPHICS_BINDING_D3D12_KHR;
20
m_graphicsRequirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_D3D12_KHR;
21
}
22
23
bool
QOpenXRGraphicsD3D12::initialize(
const
QVector<XrExtensionProperties> &extensions)
24
{
25
return
hasExtension(extensions, XR_KHR_D3D12_ENABLE_EXTENSION_NAME);
26
}
27
28
QVector<
const
char
*> QOpenXRGraphicsD3D12::getRequiredExtensions()
const
29
{
30
return
{ XR_KHR_D3D12_ENABLE_EXTENSION_NAME };
31
}
32
33
34
const
XrBaseInStructure *QOpenXRGraphicsD3D12::handle()
const
35
{
36
return
reinterpret_cast
<
const
XrBaseInStructure*>(&m_graphicsBinding);
37
}
38
39
40
bool
QOpenXRGraphicsD3D12::setupGraphics(
const
XrInstance &instance, XrSystemId &systemId,
const
QQuickGraphicsConfiguration &)
41
{
42
PFN_xrGetD3D12GraphicsRequirementsKHR pfnGetD3D12GraphicsRequirementsKHR =
nullptr
;
43
OpenXRHelpers
::
checkXrResult
(xrGetInstanceProcAddr(instance,
"xrGetD3D12GraphicsRequirementsKHR"
,
44
reinterpret_cast
<PFN_xrVoidFunction*>(&pfnGetD3D12GraphicsRequirementsKHR)),
45
instance);
46
47
if
(!pfnGetD3D12GraphicsRequirementsKHR) {
48
qWarning(
"Could not resolve xrGetD3D12GraphicsRequirementsKHR; perhaps the OpenXR implementation does not support D3D12?"
);
49
return
false
;
50
}
51
52
OpenXRHelpers
::
checkXrResult
(pfnGetD3D12GraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
53
instance);
54
return
true
;
55
}
56
57
bool
QOpenXRGraphicsD3D12::finializeGraphics(QRhi *rhi)
58
{
59
const
QRhiD3D12NativeHandles *d3d12Rhi =
static_cast
<
const
QRhiD3D12NativeHandles *>(rhi->nativeHandles());
60
m_graphicsBinding.device =
reinterpret_cast
<ID3D12Device*>(d3d12Rhi->dev);
61
m_graphicsBinding.queue =
reinterpret_cast
<ID3D12CommandQueue*>(d3d12Rhi->commandQueue);
62
m_rhi = rhi;
63
64
return
true
;
65
}
66
67
68
int64_t QOpenXRGraphicsD3D12::colorSwapchainFormat(
const
QVector<int64_t> &swapchainFormats)
const
69
{
70
// List of supported color swapchain formats.
71
constexpr
DXGI_FORMAT supportedColorSwapchainFormats[] = {
72
DXGI_FORMAT_B8G8R8A8_UNORM_SRGB,
73
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
74
DXGI_FORMAT_B8G8R8A8_UNORM,
75
DXGI_FORMAT_R8G8B8A8_UNORM
76
};
77
78
auto
swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
79
std::end(supportedColorSwapchainFormats),
80
swapchainFormats.begin(),
81
swapchainFormats.end());
82
83
return
*swapchainFormatIt;
84
}
85
86
int64_t QOpenXRGraphicsD3D12::depthSwapchainFormat(
const
QVector<int64_t> &swapchainFormats)
const
87
{
88
// in order of preference
89
constexpr
int64_t supportedDepthSwapchainFormats[] = {
90
DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
91
DXGI_FORMAT_D32_FLOAT,
92
DXGI_FORMAT_D16_UNORM
93
};
94
95
return
*std::find_first_of(std::begin(supportedDepthSwapchainFormats),
96
std::end(supportedDepthSwapchainFormats),
97
swapchainFormats.begin(),
98
swapchainFormats.end());
99
}
100
101
QVector<XrSwapchainImageBaseHeader*> QOpenXRGraphicsD3D12::allocateSwapchainImages(
int
count, XrSwapchain swapchain)
102
{
103
QVector<XrSwapchainImageBaseHeader*> swapchainImages;
104
QVector<XrSwapchainImageD3D12KHR> swapchainImageBuffer(count);
105
for
(XrSwapchainImageD3D12KHR& image : swapchainImageBuffer) {
106
image.type = XR_TYPE_SWAPCHAIN_IMAGE_D3D12_KHR;
107
swapchainImages.push_back(
reinterpret_cast
<XrSwapchainImageBaseHeader*>(&image));
108
}
109
m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
110
return
swapchainImages;
111
}
112
113
114
QQuickRenderTarget QOpenXRGraphicsD3D12::renderTarget(
const
XrSwapchainSubImage &subImage,
115
const
XrSwapchainImageBaseHeader *swapchainImage,
116
quint64 swapchainFormat,
117
int
samples,
118
int
arraySize,
119
const
XrSwapchainImageBaseHeader *depthSwapchainImage,
120
quint64 depthSwapchainFormat)
const
121
{
122
ID3D12Resource*
const
colorTexture =
reinterpret_cast
<
const
XrSwapchainImageD3D12KHR*>(swapchainImage)->texture;
123
124
DXGI_FORMAT viewFormat = DXGI_FORMAT(swapchainFormat);
125
switch
(swapchainFormat) {
126
case
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
127
viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
128
break
;
129
case
DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
130
viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
131
break
;
132
default
:
133
break
;
134
}
135
136
QQuickRenderTarget::Flags flags;
137
if
(samples > 1)
138
flags |= QQuickRenderTarget::Flag::MultisampleResolve;
139
140
return
QQuickRenderTarget::fromD3D12Texture(colorTexture,
141
0,
142
swapchainFormat,
143
viewFormat,
144
QSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height),
145
samples,
146
arraySize,
147
flags);
148
149
// No depthSwapchainImage support because ResolveDepthStencil will be
150
// unsupported with D3D11/12 no matter what.
151
Q_UNUSED(depthSwapchainImage);
152
Q_UNUSED(depthSwapchainFormat);
153
}
154
155
156
void
QOpenXRGraphicsD3D12::setupWindow(QQuickWindow *quickWindow)
157
{
158
quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromAdapter(m_graphicsRequirements.adapterLuid.LowPart,
159
m_graphicsRequirements.adapterLuid.HighPart,
160
m_graphicsRequirements.minFeatureLevel));
161
}
162
163
QT_END_NAMESPACE
OpenXRHelpers
Definition
qopenxrhelpers_p.h:30
OpenXRHelpers::checkXrResult
bool checkXrResult(XrResult result, XrInstance instance)
Definition
qopenxrhelpers.cpp:19
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtquick3d
src
xr
quick3dxr
openxr
qopenxrgraphics_d3d12.cpp
Generated on
for Qt by
1.18.0