38bool QOpenXRGraphicsD3D11::setupGraphics(
const XrInstance &instance, XrSystemId &systemId,
const QQuickGraphicsConfiguration &)
40 PFN_xrGetD3D11GraphicsRequirementsKHR pfnGetD3D11GraphicsRequirementsKHR =
nullptr;
42 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetD3D11GraphicsRequirementsKHR)),
45 if (!pfnGetD3D11GraphicsRequirementsKHR) {
46 qWarning(
"Could not resolve xrGetD3D11GraphicsRequirementsKHR; perhaps the OpenXR implementation does not support D3D11?");
51 OpenXRHelpers::checkXrResult(pfnGetD3D11GraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
56bool QOpenXRGraphicsD3D11::finializeGraphics(QRhi *rhi)
58 const QRhiD3D11NativeHandles *d3d11Rhi =
static_cast<
const QRhiD3D11NativeHandles *>(rhi->nativeHandles());
59 m_graphicsBinding.device =
reinterpret_cast<ID3D11Device*>(d3d11Rhi->dev);
66int64_t QOpenXRGraphicsD3D11::colorSwapchainFormat(
const QVector<int64_t> &swapchainFormats)
const
69 constexpr DXGI_FORMAT supportedColorSwapchainFormats[] = {
70 DXGI_FORMAT_B8G8R8A8_UNORM_SRGB,
71 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
72 DXGI_FORMAT_B8G8R8A8_UNORM,
73 DXGI_FORMAT_R8G8B8A8_UNORM
76 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
77 std::end(supportedColorSwapchainFormats),
78 swapchainFormats.begin(),
79 swapchainFormats.end());
81 return *swapchainFormatIt;
84int64_t QOpenXRGraphicsD3D11::depthSwapchainFormat(
const QVector<int64_t> &swapchainFormats)
const
87 constexpr int64_t supportedDepthSwapchainFormats[] = {
88 DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
89 DXGI_FORMAT_D32_FLOAT,
93 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
94 std::end(supportedDepthSwapchainFormats),
95 swapchainFormats.begin(),
96 swapchainFormats.end());
99QVector<XrSwapchainImageBaseHeader*> QOpenXRGraphicsD3D11::allocateSwapchainImages(
int count, XrSwapchain swapchain)
101 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
102 QVector<XrSwapchainImageD3D11KHR> swapchainImageBuffer(count);
103 for (XrSwapchainImageD3D11KHR& image : swapchainImageBuffer) {
104 image.type = XR_TYPE_SWAPCHAIN_IMAGE_D3D11_KHR;
105 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
107 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
108 return swapchainImages;
112QQuickRenderTarget QOpenXRGraphicsD3D11::renderTarget(
const XrSwapchainSubImage &subImage,
113 const XrSwapchainImageBaseHeader *swapchainImage,
114 quint64 swapchainFormat,
117 const XrSwapchainImageBaseHeader *depthSwapchainImage,
118 quint64 depthSwapchainFormat)
const
120 ID3D11Texture2D*
const colorTexture =
reinterpret_cast<
const XrSwapchainImageD3D11KHR*>(swapchainImage)->texture;
125 DXGI_FORMAT viewFormat = DXGI_FORMAT(swapchainFormat);
126 switch (swapchainFormat) {
127 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
128 viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
130 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
131 viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
138 qWarning(
"Qt Quick 3D XR: The D3D11 integration has no support for multiview");
140 QQuickRenderTarget::Flags flags;
142 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
144 return QQuickRenderTarget::fromD3D11Texture(colorTexture,
146 QSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height),
152 Q_UNUSED(depthSwapchainImage);
153 Q_UNUSED(depthSwapchainFormat);
157void QOpenXRGraphicsD3D11::setupWindow(QQuickWindow *quickWindow)
159 quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromAdapter(m_graphicsRequirements.adapterLuid.LowPart,
160 m_graphicsRequirements.adapterLuid.HighPart,
161 m_graphicsRequirements.minFeatureLevel));