Repository navigation
Proposed fix for the Vulkan no-op discard_texture
#10822
edTheGuy00
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
The Vulkan backend’s
discard_textureis still a no-op on trunk (source, “TODO: Current implementation no-ops”). This is the issue described in #5723 and #2038.Before opening a PR against trunk, I’d like to agree on how to handle it.
What goes wrong
When a
SurfaceTextureis dropped without being presented, wgpu callsdiscard_texture. On Vulkan, that currently does nothing, so the image remains acquired until the swapchain is destroyed. Without an extension, the only way to return it is throughvkQueuePresentKHR.The spec only guarantees that
vkAcquireNextImageKHRreturns in finite time while the application holds at most S−M images, where S is the swapchain image count and M isminImageCount(forward-progress requirements).On an Adreno device running Android/Vulkan, two discarded frames were enough to hit this with wgpu’s
minImageCount. Every subsequentget_current_texturecall timed out, and the app never presented another frame. DX12 recovers because discarding decrementsacquired_count, allowing the next acquire to return the same back buffer.Proposed fix
Keep the discarded image and return it on the next acquire.
This is the approach suggested in
wgpu_hal::Surface::discard_texturebroken on Vulkan #5723.discard_texturewould store theSurfaceTexturein the swapchain, and the next acquire would return it without callingvkAcquireNextImageKHR. It wouldn’t require any device extensions.The semaphore state should remain valid:
On reconfigure,
release_resourceswould drop the retained image before destroying the semaphores. The swapchain destruction requirement is that all uses of the image have completed (VUID-01282).Release the image directly where the maintenance extension is available.
With
VK_KHR_swapchain_maintenance1orVK_EXT_swapchain_maintenance1and theswapchainMaintenance1feature enabled, discard could callvkReleaseSwapchainImagesKHR. The image must be idle before release (release requirements).One detail to resolve is the acquire semaphore. The release reference page doesn’t say what happens to it, but
vkAcquireNextImageKHRrequires the semaphore to be unsignaled and have no pending operations before reuse (VUID-01286, VUID-01779). My plan is to consume the signal with an emptyvkQueueSubmitthat waits on the semaphore before reusing it.Approach 1 would remain the fallback.
Testing so far
I have a prototype of approach 1 on top of
v30.0.1. It fixes the hang on an Adreno device, including when the swapchain is recreated while an image is being retained. I’ll also run it with the Khronos validation layer before opening the PR.Questions
wgpu_hal::Surface::discard_texturebroken on Vulkan #5723?release_inner, which currently skips the HAL discard, or should that be a separate change?All reactions