ValveSoftware / openvr

OpenVR SDK
http://steamvr.com
BSD 3-Clause "New" or "Revised" License
6.02k stars 1.27k forks source link

SteamVR violates the OpenXR standard when using a single swapchain with array layers #1822

Open amini-allight opened 3 months ago

amini-allight commented 3 months ago

When you construct an application that uses a single XrSwapchain with two array layers, one for each eye, SteamVR will emit a Vulkan validation error with every frame (provided validation layers are enabled). The error message reads

vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer expects VkImage (subresource: aspectMask 0x1 array layer 1, mip level 0) to be in layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL.

This originates from a call to vkQueueSubmit somewhere inside of SteamVR, not the application code. It occurs because SteamVR is expecting the second array layer to be in layout VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL. This violates the OpenXR standard which states in section 12.20 on the XR_KHR_vulkan_enable extension that:

When an application releases a swapchain image by calling xrReleaseSwapchainImage, in a session created using XrGraphicsBindingVulkanKHR, the OpenXR runtime must interpret the image as:

• Having a memory layout compatible with VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL for color images, or VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL for depth images.

I have written a demo program where this issue can be turned on and off by toggling between a single or dual swapchain setup, available on my GitLab here along with usage instructions and a description of its internal functionality.

Rectus commented 3 months ago

IIRC it has that behavior even without array layers, both with Vulkan and DirectX 12.

amini-allight commented 3 months ago

With a single swapchain or dual?

Rectus commented 3 months ago

It's been a while, I think I mostly tested with dual under DX12. I don't think there has been any instance where I've attached the debugger and not having it spammed with the layout errors.

amini-allight commented 3 months ago

It did also used to spam the console with performance warnings (2 per frame) about performing operations on images in VK_IMAGE_LAYOUT_GENERAL but those got fixed at some point.