OBS just uses a single DirectX context when using jim-nvenc (see below). This is the recommendation Nvidia gives in their Video SDK samples (https://developer.nvidia.com/video_codec_sdk/downloads/v11-1-5, Nvidia Developer account necessary for download)
At Nvidia, we performed benchmarks that showed that following the recommended API usage would increase game FPS (on average by 1.5% on the 5 tested games. We shared detailed results with OBS core devs in discord earlier).
The disadvantage of using separate contexts are:
more GPU context switches
more overhead for sharing the textures (e.g. synchronization between different DirectX contexts)
extra shared textures are needed (two extra texture copies from and to the shared textures, unnecessary VRAM usage)
increased code code complexity for setting additional up the DirectX contexts, textures and implementing the interop between the contexts. Reusing the gs_device and the gs_* subsystem would allow to reduce the amount of code in jim-nvenc and also make it trivial to implement https://github.com/obsproject/obs-studio/pull/4974 with gs_device_get_obj.
We can help you to fix this problem. Please let us know whether you would be interested in such a change!
Steps to Reproduce
Bug does not become apparent at runtime, but hurts game performance. To check whether that was really the case we performed benchmark using only a single context which improved performance.
Operating System Info
Windows 11
Other OS
No response
OBS Studio Version
Git
OBS Studio Version (Other)
No response
OBS Studio Log URL
https://obsproject.com/logs/l3JZQfAboldVzSMe
OBS Studio Crash Log URL
No response
Expected Behavior
OBS just uses a single DirectX context when using jim-nvenc (see below). This is the recommendation Nvidia gives in their Video SDK samples (https://developer.nvidia.com/video_codec_sdk/downloads/v11-1-5, Nvidia Developer account necessary for download)
Current Behavior
jim-nvenc, like other GPU encoders, creates a dedicated DirectX context (https://github.com/obsproject/obs-studio/blob/master/plugins/obs-ffmpeg/jim-nvenc.c#L290-L340) that is not shared with the rendering context. This does not follow the recommendation in the official samples https://developer.nvidia.com/video_codec_sdk/downloads/v11-1-5 (Nvidia developer account necessary for download) where GPU encoding is performed using the same context shared with rendering.
At Nvidia, we performed benchmarks that showed that following the recommended API usage would increase game FPS (on average by 1.5% on the 5 tested games. We shared detailed results with OBS core devs in discord earlier).
The disadvantage of using separate contexts are:
gs_device
and thegs_*
subsystem would allow to reduce the amount of code in jim-nvenc and also make it trivial to implement https://github.com/obsproject/obs-studio/pull/4974 withgs_device_get_obj
.We can help you to fix this problem. Please let us know whether you would be interested in such a change!
Steps to Reproduce
Bug does not become apparent at runtime, but hurts game performance. To check whether that was really the case we performed benchmark using only a single context which improved performance.
Anything else we should know?
No response