40bool QOpenXRGraphicsD3D11::setupGraphics(
const XrInstance &instance, XrSystemId &systemId,
const QQuickGraphicsConfiguration &)
42 PFN_xrGetD3D11GraphicsRequirementsKHR pfnGetD3D11GraphicsRequirementsKHR =
nullptr;
43 OpenXRHelpers::checkXrResult(xrGetInstanceProcAddr(instance,
"xrGetD3D11GraphicsRequirementsKHR",
44 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetD3D11GraphicsRequirementsKHR)),
47 if (!pfnGetD3D11GraphicsRequirementsKHR) {
48 qWarning(
"Could not resolve xrGetD3D11GraphicsRequirementsKHR; perhaps the OpenXR implementation does not support D3D11?");
53 OpenXRHelpers::checkXrResult(pfnGetD3D11GraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
58bool QOpenXRGraphicsD3D11::finializeGraphics(QRhi *rhi)
60 const QRhiD3D11NativeHandles *d3d11Rhi =
static_cast<
const QRhiD3D11NativeHandles *>(rhi->nativeHandles());
61 m_graphicsBinding.device =
reinterpret_cast<ID3D11Device*>(d3d11Rhi->dev);
68int64_t QOpenXRGraphicsD3D11::colorSwapchainFormat(
const QVector<int64_t> &swapchainFormats)
const
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
78 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
79 std::end(supportedColorSwapchainFormats),
80 swapchainFormats.begin(),
81 swapchainFormats.end());
83 return *swapchainFormatIt;
86int64_t QOpenXRGraphicsD3D11::depthSwapchainFormat(
const QVector<int64_t> &swapchainFormats)
const
89 constexpr int64_t supportedDepthSwapchainFormats[] = {
90 DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
91 DXGI_FORMAT_D32_FLOAT,
95 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
96 std::end(supportedDepthSwapchainFormats),
97 swapchainFormats.begin(),
98 swapchainFormats.end());
101QVector<XrSwapchainImageBaseHeader*> QOpenXRGraphicsD3D11::allocateSwapchainImages(
int count, XrSwapchain swapchain)
103 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
104 QVector<XrSwapchainImageD3D11KHR> swapchainImageBuffer(count);
105 for (XrSwapchainImageD3D11KHR& image : swapchainImageBuffer) {
106 image.type = XR_TYPE_SWAPCHAIN_IMAGE_D3D11_KHR;
107 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
109 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
110 return swapchainImages;
114QQuickRenderTarget QOpenXRGraphicsD3D11::renderTarget(
const XrSwapchainSubImage &subImage,
115 const XrSwapchainImageBaseHeader *swapchainImage,
116 quint64 swapchainFormat,
119 const XrSwapchainImageBaseHeader *depthSwapchainImage,
120 quint64 depthSwapchainFormat)
const
122 ID3D11Texture2D*
const colorTexture =
reinterpret_cast<
const XrSwapchainImageD3D11KHR*>(swapchainImage)->texture;
127 DXGI_FORMAT viewFormat = DXGI_FORMAT(swapchainFormat);
128 switch (swapchainFormat) {
129 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
130 viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
132 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
133 viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
140 qWarning(
"Qt Quick 3D XR: The D3D11 integration has no support for multiview");
142 QQuickRenderTarget::Flags flags;
144 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
146 return QQuickRenderTarget::fromD3D11Texture(colorTexture,
148 QSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height),
154 Q_UNUSED(depthSwapchainImage);
155 Q_UNUSED(depthSwapchainFormat);
159void QOpenXRGraphicsD3D11::setupWindow(QQuickWindow *quickWindow)
161 quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromAdapter(m_graphicsRequirements.adapterLuid.LowPart,
162 m_graphicsRequirements.adapterLuid.HighPart,
163 m_graphicsRequirements.minFeatureLevel));