Conversation
Use semaphores to ensure ordering correctness using different queues
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When capturing a Vulkan application, specifically when the graphics and present queues are not identical, it is insufficient to rely on memory barriers alone.
When working across queues, as some applications may, semaphores are required to handle cross-queue synchronization, and ensure that capture happens strictly after rendering has completed.
An example of what I was able to see without change is shown in the attached image.

When the graphics and present queues are not identical, capturing has a race. A barrier in the presentation queue won't synchronize the work done in the graphics queue, since it only asserts an ordering on work in the same queue, so commands may still be executing in the graphics queue at the moment we take the capture (which happens on the present queue).
Before this change, capture submission did not wait on a semaphore. The changes here assert an ordering from graphics -> capture -> present using OBS-owned semaphores to prevent mid-draw artifacts, and are indexed on each swapchain image rather than logical frame to ensure that each is protected accordingly. Capture submission now waits for rendering to complete.
Motivation and Context
Vulkan applications with separate graphics/present queues were being captured with artifacts like those I have shown above. To be clear, this is not an visible when graphics/present happen in the same queue. While I didn't see any open tickets for this specifically, I was able to unearth this ticket that seemed to exhibit some of the same issues I was having. I made sure I was using an up-to-date driver first, then I enabled verbose validation and saw a host of messages when capturing/previewing regarding sync hazards (write racing write, and present after write), like in the tagged issue. That same issue mentions "...improper synchronization, resulting in OBS grabbing the image sometimes at the wrong interval (mid program write)", which is ultimately what I observed happening, and is addressed in this PR.
How Has This Been Tested?
Hardware: NVIDIA GeForce RTX 2070 / Ryzen 7 5800x
OS Version: Microsoft Windows 11 Home / Version 10.0.26200
Graphics Driver Version: GeForce Game Ready Driver 616.92
I've tested it over the last week by running (each step against both altered/unaltered hook dll):
The changes are isolated to the Vulkan
graphics-hookdll. I've tested in both x64 Debug and x64 Release, and left the applications running for several minutes.For my renderer, I forced both same and separate graphics/present queues. Artifacts were no longer showing, both through the preview window, as well as in the output file after recording a small clip. I also did not see any
SYNC-HAZARD-WRITE-RACING-WRITEorSYNC-HAZARD-PRESENT-AFTER-WRITEafter this change. I forced a number of swapchain recreations (to make sure that the recreation works with the new locks) and continued the capture.Types of changes
Checklist: