21bool QOpenXRGraphicsD3D11::isExtensionSupported(
const QVector<XrExtensionProperties> &extensions)
const
23 for (
const auto &extension : extensions) {
24 if (!strcmp(XR_KHR_D3D11_ENABLE_EXTENSION_NAME,
25 extension.extensionName))
44bool QOpenXRGraphicsD3D11::setupGraphics(
const XrInstance &instance, XrSystemId &systemId,
const QQuickGraphicsConfiguration &)
46 PFN_xrGetD3D11GraphicsRequirementsKHR pfnGetD3D11GraphicsRequirementsKHR =
nullptr;
48 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetD3D11GraphicsRequirementsKHR)),
51 if (!pfnGetD3D11GraphicsRequirementsKHR) {
52 qWarning(
"Could not resolve xrGetD3D11GraphicsRequirementsKHR; perhaps the OpenXR implementation does not support D3D11?");
57 OpenXRHelpers::checkXrResult(pfnGetD3D11GraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
62bool QOpenXRGraphicsD3D11::finializeGraphics(QRhi *rhi)
64 const QRhiD3D11NativeHandles *d3d11Rhi =
static_cast<
const QRhiD3D11NativeHandles *>(rhi->nativeHandles());
65 m_graphicsBinding.device =
reinterpret_cast<ID3D11Device*>(d3d11Rhi->dev);
72int64_t QOpenXRGraphicsD3D11::colorSwapchainFormat(
const QVector<int64_t> &swapchainFormats)
const
75 constexpr DXGI_FORMAT supportedColorSwapchainFormats[] = {
76 DXGI_FORMAT_B8G8R8A8_UNORM_SRGB,
77 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
78 DXGI_FORMAT_B8G8R8A8_UNORM,
79 DXGI_FORMAT_R8G8B8A8_UNORM
82 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
83 std::end(supportedColorSwapchainFormats),
84 swapchainFormats.begin(),
85 swapchainFormats.end());
87 return *swapchainFormatIt;
90int64_t QOpenXRGraphicsD3D11::depthSwapchainFormat(
const QVector<int64_t> &swapchainFormats)
const
93 constexpr int64_t supportedDepthSwapchainFormats[] = {
94 DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
95 DXGI_FORMAT_D32_FLOAT,
99 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
100 std::end(supportedDepthSwapchainFormats),
101 swapchainFormats.begin(),
102 swapchainFormats.end());
105QVector<XrSwapchainImageBaseHeader*> QOpenXRGraphicsD3D11::allocateSwapchainImages(
int count, XrSwapchain swapchain)
107 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
108 QVector<XrSwapchainImageD3D11KHR> swapchainImageBuffer(count);
109 for (XrSwapchainImageD3D11KHR& image : swapchainImageBuffer) {
110 image.type = XR_TYPE_SWAPCHAIN_IMAGE_D3D11_KHR;
111 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
113 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
114 return swapchainImages;
118QQuickRenderTarget QOpenXRGraphicsD3D11::renderTarget(
const XrSwapchainSubImage &subImage,
119 const XrSwapchainImageBaseHeader *swapchainImage,
120 quint64 swapchainFormat,
123 const XrSwapchainImageBaseHeader *depthSwapchainImage,
124 quint64 depthSwapchainFormat)
const
126 ID3D11Texture2D*
const colorTexture =
reinterpret_cast<
const XrSwapchainImageD3D11KHR*>(swapchainImage)->texture;
131 DXGI_FORMAT viewFormat = DXGI_FORMAT(swapchainFormat);
132 switch (swapchainFormat) {
133 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
134 viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
136 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
137 viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
144 qWarning(
"Qt Quick 3D XR: The D3D11 integration has no support for multiview");
146 QQuickRenderTarget::Flags flags;
148 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
150 return QQuickRenderTarget::fromD3D11Texture(colorTexture,
152 QSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height),
158 Q_UNUSED(depthSwapchainImage);
159 Q_UNUSED(depthSwapchainFormat);
163void QOpenXRGraphicsD3D11::setupWindow(QQuickWindow *quickWindow)
165 quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromAdapter(m_graphicsRequirements.adapterLuid.LowPart,
166 m_graphicsRequirements.adapterLuid.HighPart,
167 m_graphicsRequirements.minFeatureLevel));