21bool QOpenXRGraphicsD3D12::isExtensionSupported(
const QVector<XrExtensionProperties> &extensions)
const
23 for (
const auto &extension : extensions) {
24 if (!strcmp(XR_KHR_D3D12_ENABLE_EXTENSION_NAME,
25 extension.extensionName))
44bool QOpenXRGraphicsD3D12::setupGraphics(
const XrInstance &instance, XrSystemId &systemId,
const QQuickGraphicsConfiguration &)
46 PFN_xrGetD3D12GraphicsRequirementsKHR pfnGetD3D12GraphicsRequirementsKHR =
nullptr;
48 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetD3D12GraphicsRequirementsKHR)),
51 if (!pfnGetD3D12GraphicsRequirementsKHR) {
52 qWarning(
"Could not resolve xrGetD3D12GraphicsRequirementsKHR; perhaps the OpenXR implementation does not support D3D12?");
56 OpenXRHelpers::checkXrResult(pfnGetD3D12GraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
61bool QOpenXRGraphicsD3D12::finializeGraphics(QRhi *rhi)
63 const QRhiD3D12NativeHandles *d3d12Rhi =
static_cast<
const QRhiD3D12NativeHandles *>(rhi->nativeHandles());
64 m_graphicsBinding.device =
reinterpret_cast<ID3D12Device*>(d3d12Rhi->dev);
65 m_graphicsBinding.queue =
reinterpret_cast<ID3D12CommandQueue*>(d3d12Rhi->commandQueue);
72int64_t QOpenXRGraphicsD3D12::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 QOpenXRGraphicsD3D12::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*> QOpenXRGraphicsD3D12::allocateSwapchainImages(
int count, XrSwapchain swapchain)
107 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
108 QVector<XrSwapchainImageD3D12KHR> swapchainImageBuffer(count);
109 for (XrSwapchainImageD3D12KHR& image : swapchainImageBuffer) {
110 image.type = XR_TYPE_SWAPCHAIN_IMAGE_D3D12_KHR;
111 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
113 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
114 return swapchainImages;
118QQuickRenderTarget QOpenXRGraphicsD3D12::renderTarget(
const XrSwapchainSubImage &subImage,
119 const XrSwapchainImageBaseHeader *swapchainImage,
120 quint64 swapchainFormat,
123 const XrSwapchainImageBaseHeader *depthSwapchainImage,
124 quint64 depthSwapchainFormat)
const
126 ID3D12Resource*
const colorTexture =
reinterpret_cast<
const XrSwapchainImageD3D12KHR*>(swapchainImage)->texture;
128 DXGI_FORMAT viewFormat = DXGI_FORMAT(swapchainFormat);
129 switch (swapchainFormat) {
130 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
131 viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
133 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
134 viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
140 QQuickRenderTarget::Flags flags;
142 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
144 return QQuickRenderTarget::fromD3D12Texture(colorTexture,
148 QSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height),
155 Q_UNUSED(depthSwapchainImage);
156 Q_UNUSED(depthSwapchainFormat);
160void QOpenXRGraphicsD3D12::setupWindow(QQuickWindow *quickWindow)
162 quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromAdapter(m_graphicsRequirements.adapterLuid.LowPart,
163 m_graphicsRequirements.adapterLuid.HighPart,
164 m_graphicsRequirements.minFeatureLevel));