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 constexpr int64_t supportedDepthSwapchainFormats[] = {
223 VK_FORMAT_D24_UNORM_S8_UINT,
224 VK_FORMAT_D32_SFLOAT_S8_UINT,
225 VK_FORMAT_D32_SFLOAT,
230 return *std::find_first_of(std::begin(supportedDepthSwapchainFormats),
231 std::end(supportedDepthSwapchainFormats),
232 swapchainFormats.begin(),
233 swapchainFormats.end());
238 QVector<XrSwapchainImageBaseHeader*> swapchainImages;
239 QVector<XrSwapchainImageVulkanKHR> swapchainImageBuffer(
count);
240 for (XrSwapchainImageVulkanKHR&
image : swapchainImageBuffer) {
241 image.type = XR_TYPE_SWAPCHAIN_IMAGE_VULKAN_KHR;
242 swapchainImages.push_back(
reinterpret_cast<XrSwapchainImageBaseHeader*
>(&
image));
244 m_swapchainImageBuffer.insert(swapchain, swapchainImageBuffer);
245 return swapchainImages;
250 const XrSwapchainImageBaseHeader *swapchainImage,
254 const XrSwapchainImageBaseHeader *depthSwapchainImage,
255 quint64 depthSwapchainFormat)
const
257 VkImage colorTexture =
reinterpret_cast<const XrSwapchainImageVulkanKHR*
>(swapchainImage)->
image;
259 VkFormat viewFormat = VkFormat(swapchainFormat);
260 switch (swapchainFormat) {
261 case VK_FORMAT_R8G8B8A8_SRGB:
262 viewFormat = VK_FORMAT_R8G8B8A8_UNORM;
264 case VK_FORMAT_B8G8R8A8_SRGB:
265 viewFormat = VK_FORMAT_B8G8R8A8_UNORM;
271 QQuickRenderTarget::Flags
flags;
275 const QSize pixelSize(subImage.imageRect.extent.width, subImage.imageRect.extent.height);
277 VK_IMAGE_LAYOUT_UNDEFINED,
278 VkFormat(swapchainFormat),
284 if (depthSwapchainImage) {
292 case VK_FORMAT_D32_SFLOAT_S8_UINT:
293 case VK_FORMAT_D32_SFLOAT:
296 case VK_FORMAT_D16_UNORM:
300 VkImage depthImage =
reinterpret_cast<const XrSwapchainImageVulkanKHR*
>(depthSwapchainImage)->
image;
301 if (m_depthTexture && (m_depthTexture->
format() !=
format || m_depthTexture->
pixelSize() != pixelSize || m_depthTexture->
arraySize() != arraySize)) {
302 delete m_depthTexture;
303 m_depthTexture =
nullptr;
305 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.