63 PFN_xrGetVulkanGraphicsRequirementsKHR pfnGetVulkanGraphicsRequirementsKHR =
nullptr;
65 "xrGetVulkanGraphicsRequirementsKHR",
66 reinterpret_cast<PFN_xrVoidFunction*
>(&pfnGetVulkanGraphicsRequirementsKHR)),
69 if (!pfnGetVulkanGraphicsRequirementsKHR) {
70 qWarning(
"Could not resolve xrGetVulkanGraphicsRequirementsKHR; perhaps the OpenXR implementation does not support Vulkan?");
74 PFN_xrGetVulkanInstanceExtensionsKHR pfnGetVulkanInstanceExtensionsKHR =
nullptr;
76 "xrGetVulkanInstanceExtensionsKHR",
77 reinterpret_cast<PFN_xrVoidFunction*
>(&pfnGetVulkanInstanceExtensionsKHR)),
80 XrGraphicsRequirementsVulkanKHR graphicsRequirements{};
81 graphicsRequirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_VULKAN_KHR;
84 &graphicsRequirements),
96 extensionNames.
resize(extensionNamesSize);
101 extensionNames.
data()),
108 auto begin =
string.begin();
109 auto end =
string.end();
116 for (
auto &ext : extensions)
117 ext = stripNullChars(ext);
119 for (
auto &rhiExt : QRhiVulkanInitParams::preferredInstanceExtensions()) {
120 if (!extensions.contains(rhiExt))
121 extensions.append(rhiExt);
124 m_vulkanInstance.setExtensions(extensions);
127 const QVersionNumber supportedVersion = m_vulkanInstance.supportedApiVersion();
135 if (quickConfig.isDebugLayerEnabled())
136 m_vulkanInstance.setLayers({
"VK_LAYER_LUNARG_standard_validation" });
138 if (!m_vulkanInstance.create()) {
139 qWarning(
"Quick 3D XR: Failed to create Vulkan instance");
144 PFN_xrGetVulkanDeviceExtensionsKHR pfnGetVulkanDeviceExtensionsKHR =
nullptr;
146 "xrGetVulkanDeviceExtensionsKHR",
147 reinterpret_cast<PFN_xrVoidFunction*
>(&pfnGetVulkanDeviceExtensionsKHR)),
150 uint32_t deviceExtensionNamesSize = 0;
154 &deviceExtensionNamesSize,
158 deviceExtensionNames.
resize(deviceExtensionNamesSize);
161 deviceExtensionNamesSize,
162 &deviceExtensionNamesSize,
163 deviceExtensionNames.data()),
166 auto deviceExtensions = deviceExtensionNames.split(
' ');
167 for (
auto &ext : deviceExtensions) {
168 ext = stripNullChars(ext);
170 m_graphicsConfiguration.setDeviceExtensions(deviceExtensions);
173 PFN_xrGetVulkanGraphicsDeviceKHR pfnGetVulkanGraphicsDeviceKHR =
nullptr;
175 reinterpret_cast<PFN_xrVoidFunction*
>(&pfnGetVulkanGraphicsDeviceKHR)), instance);
177 OpenXRHelpers::checkXrResult(pfnGetVulkanGraphicsDeviceKHR(instance, systemId, m_vulkanInstance.vkInstance(), &m_vulkanPhysicalDevice), instance);
185 m_vulkanDevice = vulkanRhi->dev;
186 Q_ASSERT(m_vulkanPhysicalDevice == vulkanRhi->physDev);
187 m_vulkanCommandQueue = vulkanRhi->gfxQueue;
188 m_queueFamilyIndex = vulkanRhi->gfxQueueFamilyIdx;
190 m_graphicsBinding.instance = m_vulkanInstance.vkInstance();
191 m_graphicsBinding.physicalDevice = m_vulkanPhysicalDevice;
192 m_graphicsBinding.device = m_vulkanDevice;
193 m_graphicsBinding.queueFamilyIndex = m_queueFamilyIndex;
194 m_graphicsBinding.queueIndex = 0;
205 constexpr int64_t supportedColorSwapchainFormats[] = {
206 VK_FORMAT_B8G8R8A8_SRGB,
207 VK_FORMAT_R8G8B8A8_SRGB,
208 VK_FORMAT_B8G8R8A8_UNORM,
209 VK_FORMAT_R8G8B8A8_UNORM
212 auto swapchainFormatIt = std::find_first_of(std::begin(supportedColorSwapchainFormats),
213 std::end(supportedColorSwapchainFormats),
214 swapchainFormats.begin(),
215 swapchainFormats.end());
216 return *swapchainFormatIt;
222 QVarLengthArray<int64_t, 4> supportedDepthSwapchainFormats;
223 constexpr std::pair<int64_t, QRhiTexture::Format> nativeDepthSwapchainFormats[] = {
229 for (
const auto &
format : nativeDepthSwapchainFormats) {
231 supportedDepthSwapchainFormats.append(
format.first);
234 if (supportedDepthSwapchainFormats.isEmpty())
238 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
239 std::end(supportedDepthSwapchainFormats),
240 swapchainFormats.begin(),
241 swapchainFormats.end());
246 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
247 QVector<XrSwapchainImageVulkanKHR> swapchainImageBuffer(
count);
248 for (XrSwapchainImageVulkanKHR&
image : swapchainImageBuffer) {
249 image.type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR;
250 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*
>(&
image));
252 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
253 return swapchainImages;
258 const XrSwapchainImageBaseHeader *swapchainImage,
262 const XrSwapchainImageBaseHeader *depthSwapchainImage,
263 quint64 depthSwapchainFormat)
const
265 VkImage colorTexture =
reinterpret_cast<const XrSwapchainImageVulkanKHR*
>(swapchainImage)->
image;
267 VkFormat viewFormat = VkFormat(swapchainFormat);
268 switch (swapchainFormat) {
269 case VK_FORMAT_R8G8B8A8_SRGB:
270 viewFormat = VK_FORMAT_R8G8B8A8_UNORM;
272 case VK_FORMAT_B8G8R8A8_SRGB:
273 viewFormat = VK_FORMAT_B8G8R8A8_UNORM;
279 QQuickRenderTarget::Flags
flags;
283 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
285 VK_IMAGE_LAYOUT_UNDEFINED,
286 VkFormat(swapchainFormat),
292 if (depthSwapchainImage) {
300 case VK_FORMAT_D32_SFLOAT_S8_UINT:
301 case VK_FORMAT_D32_SFLOAT:
304 case VK_FORMAT_D16_UNORM:
308 VkImage depthImage =
reinterpret_cast<const XrSwapchainImageVulkanKHR*
>(depthSwapchainImage)->
image;
309 if (m_depthTexture && (m_depthTexture->
format() !=
format || m_depthTexture->
pixelSize() != pixelSize || m_depthTexture->
arraySize() != arraySize)) {
310 delete m_depthTexture;
311 m_depthTexture =
nullptr;
313 if (!m_depthTexture) {
QQuickRenderTarget renderTarget(const XrSwapchainSubImage &subImage, const XrSwapchainImageBaseHeader *swapchainImage, quint64 swapchainFormat, int samples, int arraySize, const XrSwapchainImageBaseHeader *depthSwapchainImage, quint64 depthSwapchainFormat) const override
Format
Specifies the texture format.
virtual bool createFrom(NativeTexture src)
Similar to create(), except that no new native textures are created.