38bool QOpenXRGraphicsD3D12::setupGraphics(
const XrInstance &instance, XrSystemId &systemId,
const QQuickGraphicsConfiguration &)
40 PFN_xrGetD3D12GraphicsRequirementsKHR pfnGetD3D12GraphicsRequirementsKHR =
nullptr;
42 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetD3D12GraphicsRequirementsKHR)),
45 if (!pfnGetD3D12GraphicsRequirementsKHR) {
46 qWarning(
"Could not resolve xrGetD3D12GraphicsRequirementsKHR; perhaps the OpenXR implementation does not support D3D12?");
50 OpenXRHelpers::checkXrResult(pfnGetD3D12GraphicsRequirementsKHR(instance, systemId, &m_graphicsRequirements),
55bool QOpenXRGraphicsD3D12::finializeGraphics(QRhi *rhi)
57 const QRhiD3D12NativeHandles *d3d12Rhi =
static_cast<
const QRhiD3D12NativeHandles *>(rhi->nativeHandles());
58 m_graphicsBinding.device =
reinterpret_cast<ID3D12Device*>(d3d12Rhi->dev);
59 m_graphicsBinding.queue =
reinterpret_cast<ID3D12CommandQueue*>(d3d12Rhi->commandQueue);
66int64_t QOpenXRGraphicsD3D12::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 QOpenXRGraphicsD3D12::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*> QOpenXRGraphicsD3D12::allocateSwapchainImages(
int count, XrSwapchain swapchain)
101 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
102 QVector<XrSwapchainImageD3D12KHR> swapchainImageBuffer(count);
103 for (XrSwapchainImageD3D12KHR& image : swapchainImageBuffer) {
104 image.type = XR_TYPE_SWAPCHAIN_IMAGE_D3D12_KHR;
105 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*>(&image));
107 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
108 return swapchainImages;
112QQuickRenderTarget QOpenXRGraphicsD3D12::renderTarget(
const XrSwapchainSubImage &subImage,
113 const XrSwapchainImageBaseHeader *swapchainImage,
114 quint64 swapchainFormat,
117 const XrSwapchainImageBaseHeader *depthSwapchainImage,
118 quint64 depthSwapchainFormat)
const
120 ID3D12Resource*
const colorTexture =
reinterpret_cast<
const XrSwapchainImageD3D12KHR*>(swapchainImage)->texture;
122 DXGI_FORMAT viewFormat = DXGI_FORMAT(swapchainFormat);
123 switch (swapchainFormat) {
124 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
125 viewFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
127 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
128 viewFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
134 QQuickRenderTarget::Flags flags;
136 flags |= QQuickRenderTarget::Flag::MultisampleResolve;
138 return QQuickRenderTarget::fromD3D12Texture(colorTexture,
142 QSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height),
149 Q_UNUSED(depthSwapchainImage);
150 Q_UNUSED(depthSwapchainFormat);
154void QOpenXRGraphicsD3D12::setupWindow(QQuickWindow *quickWindow)
156 quickWindow->setGraphicsDevice(QQuickGraphicsDevice::fromAdapter(m_graphicsRequirements.adapterLuid.LowPart,
157 m_graphicsRequirements.adapterLuid.HighPart,
158 m_graphicsRequirements.minFeatureLevel));