-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(nvenc): implement async encode #3629
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3629 +/- ##
==========================================
- Coverage 11.62% 11.61% -0.01%
==========================================
Files 93 92 -1
Lines 17319 17333 +14
Branches 8085 8096 +11
==========================================
Hits 2014 2014
+ Misses 14710 12832 -1878
- Partials 595 2487 +1892
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Might be related to this? #3411 |
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
I encountered the NVENC hang again (this time during resolution change). With the fix here, we didn't hang inside the Full stack
To allow the encoder thread to continue to make forward progress in that case, I've added a simple async teardown codepath for NVENC that moves destruction to a separate thread. Reducing the amount of non-trivial work done on the encoder thread is generally a good idea, but I made it an opt-in thing because some encoders may make assumptions that they will be constructed and destructed on the same thread (or that there will only ever be one instance of an encoder). I haven't successfully reproduced the issue again to confirm there's not some other hang hiding yet. |
Description
This PR implements the Asynchronous Mode of NVENC encoding using an event handle on Windows. This implementation is unlikely to have performance gains (or losses) because it's still a 1:1 single thread encoding loop.
However, this seems to resolve the encoder hangs I've seen when navigating through the NVIDIA app while streaming. If anyone else is regularly experiencing those, I'd appreciate testing this to see if it also resolves the hangs for them too.
When I was debugging the Sunshine hang when the NVIDIA app was running, I saw our encoder thread stuck deep inside the GPU driver waiting in
NtGdiDdDDIWaitForSynchronizationObjectFromCpu()
forever. Based on my analysis of NvEncodeAPI64.dll in Ghidra and debugging Sunshine under WinDbg, the codepath which hangs appears to only be exercised withNV_ENC_LOCK_BITSTREAM::doNotWait == 0
, so async mode sidesteps the driver bug.Screenshot
Issues Fixed or Closed
Type of Change
.github/...
)Checklist