40bool QOpenXRGraphicsD3D12::setupGraphics(
const XrInstance &instance, XrSystemId &systemId,
const QQuickGraphicsConfiguration &)
42 PFN_xrGetD3D12GraphicsRequirementsKHR pfnGetD3D12GraphicsRequirementsKHR =
nullptr;
43 OpenXRHelpers::checkXrResult(xrGetInstanceProcAddr(instance,
"xrGetD3D12GraphicsRequirementsKHR",
44 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetD3D12GraphicsRequirementsKHR)),
47 if (!pfnGetD3D12GraphicsRequirementsKHR) {
48 qWarning(
"Could not resolve xrGetD3D12GraphicsRequirementsKHR; perhaps the OpenXR implementation does not support D3D12?");
52 OpenXRHelpers::checkXrResult(pfnGetD3D12GraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
57bool QOpenXRGraphicsD3D12::finializeGraphics(QRhi *rhi)
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);
68int64_t QOpenXRGraphicsD3D12::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 QOpenXRGraphicsD3D12::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*> QOpenXRGraphicsD3D12::allocateSwapchainImages(
int count, XrSwapchain swapchain)
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));
109 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
110 return swapchainImages;
114QQuickRenderTarget QOpenXRGraphicsD3D12::renderTarget(
const XrSwapchainSubImage &subImage,
115 const XrSwapchainImageBaseHeader *swapchainImage,
116 quint64 swapchainFormat,
119 const XrSwapchainImageBaseHeader *depthSwapchainImage,
120 quint64 depthSwapchainFormat)
const
122 ID3D12Resource*
const colorTexture =
reinterpret_cast<
const XrSwapchainImageD3D12KHR*>(swapchainImage)->texture;
124 DXGI_FORMAT viewFormat = DXGI_FORMAT(swapchainFormat);
125 switch (swapchainFormat) {
126 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
127 viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
129 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
130 viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
136 QQuickRenderTarget::Flags flags;
138 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
140 return QQuickRenderTarget::fromD3D12Texture(colorTexture,
144 QSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height),
151 Q_UNUSED(depthSwapchainImage);
152 Q_UNUSED(depthSwapchainFormat);
156void QOpenXRGraphicsD3D12::setupWindow(QQuickWindow *quickWindow)
158 quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromAdapter(m_graphicsRequirements.adapterLuid.LowPart,
159 m_graphicsRequirements.adapterLuid.HighPart,
160 m_graphicsRequirements.minFeatureLevel));