Skip to content

feat(nvenc): support for split frame encoding on GPUs with 2+ nvenc blocks#4892

Open
andygrundman wants to merge 2 commits intoLizardByte:masterfrom
andygrundman:andyg.nvenc-split-frame-encoding
Open

feat(nvenc): support for split frame encoding on GPUs with 2+ nvenc blocks#4892
andygrundman wants to merge 2 commits intoLizardByte:masterfrom
andygrundman:andyg.nvenc-split-frame-encoding

Conversation

@andygrundman
Copy link
Contributor

Description

This PR adds new option split_frame_encoding with options disabled, enabled, and driver_decides. The majority of the changes are from #3061 .

When NV_ENC_CAPS_NUM_ENCODER_ENGINES > 1, these options set init_params.splitEncodeMode to NV_ENC_SPLIT_DISABLE_MODE, NV_ENC_SPLIT_AUTO_FORCED_MODE, or NV_ENC_SPLIT_AUTO_MODE respectively.

The encoder options string in the log will show sfe or sfe-auto when nvenc count > 1 and split_frame_encoding is not set to disabled.

This also bumps build-deps in order to pull in ffmpeg 8.1 and nvenc SDK 13.0. (ffmpeg is not used when encoding with nvenc but is needed here due to the fact that ffmpeg owns third-party/nv-codec-headers/include/ffnvcodec/nvEncodeAPI.h by including it in the prebuilt ffmpeg binary that comes from build-deps.)

cc @ns6089 @Nonary

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@ns6089
Copy link
Contributor

ns6089 commented Mar 23, 2026

Currently sunshine supports every nvidia gpu with nvenc ever made, and dropping runtime support for nvenc-11.0 (or more specifically nvenc-11.1) will cut off the ones for which the drivers stopped being updated years ago. Personally I'm indifferent about how sunshine will want to handle this, but you will get bug reports.

@andygrundman
Copy link
Contributor Author

andygrundman commented Mar 23, 2026

Currently sunshine supports every nvidia gpu with nvenc ever made, and dropping runtime support for nvenc-11.0 (or more specifically nvenc-11.1) will cut off the ones for which the drivers stopped being updated years ago. Personally I'm indifferent about how sunshine will want to handle this, but you will get bug reports.

You are probably right, but what cards are we talking about here? I have a GTX 1070 which has been EOL'ed recently and runs driver version 580 with SDK 13.0 (this is in Linux). NVENC goes back to the 600 series, so the issue is cards from 600-900? Wikipedia says NVENC 1st gen was used on all those cards with Maxwell 1000 series getting 2nd gen with HEVC. Do we support cards that old?

I don't want to break anything, and I admit I did take the easy route here. But I'm also not worried about supporting people who choose to run older drivers (in this case they would have to be MUCH older drivers since 13.0 shipped in Jan 2025). It's sometimes smart to avoid the current Nvidia driver, but choosing to be a year out of date, probably on Windows 10, I find it hard to understand the mindset. Maybe these users are ok running an older Sunshine too.

@andygrundman andygrundman force-pushed the andyg.nvenc-split-frame-encoding branch from 49d784c to ed602e0 Compare March 23, 2026 06:27
@ns6089
Copy link
Contributor

ns6089 commented Mar 23, 2026

NVENC goes back to the 600 series, so the issue is cards from 600-900? Wikipedia says NVENC 1st gen was used on all those cards with Maxwell 1000 series getting 2nd gen with HEVC. Do we support cards that old?

Yes, current sunshine does support them, on Windows at least. And you're going to have the same dilemma for every future version of nvenc sdk, unless dynamic sdk version selection is implemented. But to repeat myself, both paths are somewhat viable (even though one is superior) and I don't have a strong opinion regarding which one sunshine ends up going for.

@andygrundman
Copy link
Contributor Author

Yes, current sunshine does support them, on Windows at least. And you're going to have the same dilemma for every future version of nvenc sdk, unless dynamic sdk version selection is implemented. But to repeat myself, both paths are somewhat viable (even though one is superior) and I don't have a strong opinion regarding which one sunshine ends up going for.

I am coming around to this concern a bit more after thinking about it, because a bug report that someone is stuck with software encoding without a good workaround really sucks.

Do you think the approach you used in #3061 is still applicable? I notice you removed the min_struct_version(), I assume this is the older way that back-compat was handled? How well did that work? What led you to need to replace it for 12.1?

I worry that supporting so many versions makes it difficult to test properly. Do you have any tips on testing older versions? Thanks for all your work on this issue.

@andygrundman andygrundman marked this pull request as draft March 23, 2026 10:50
@andygrundman andygrundman marked this pull request as ready for review March 23, 2026 16:31
@andygrundman andygrundman force-pushed the andyg.nvenc-split-frame-encoding branch from 0999b1f to efac4f9 Compare March 23, 2026 16:40
@ReenigneArcher ReenigneArcher changed the title feat(nvenc): support for split frame encoding on GPUs with 2+ nvenc blocks. Ported from #3061 feat(nvenc): support for split frame encoding on GPUs with 2+ nvenc blocks Mar 23, 2026
@andygrundman andygrundman force-pushed the andyg.nvenc-split-frame-encoding branch from efac4f9 to 6066365 Compare March 23, 2026 18:18
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 New issues
2 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@codecov
Copy link

codecov bot commented Mar 23, 2026

Bundle Report

Changes will increase total bundle size by 1.23kB (0.16%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
sunshine-esm 784.11kB 1.23kB (0.16%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: sunshine-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/Notification-*.js 537 bytes 356.26kB 0.15%
assets/config-*.js 695 bytes 67.39kB 1.04%

Files in assets/Notification-*.js:

  • ./src_assets/common/assets/web/public/assets/locale/en.json → Total Size: 38.67kB

Files in assets/config-*.js:

  • ./src_assets/common/assets/web/configs/tabs/encoders/NvidiaNvencEncoder.vue → Total Size: 9.06kB

  • ./src_assets/common/assets/web/config.html → Total Size: 0 bytes

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 0% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.35%. Comparing base (3e06afa) to head (6066365).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/nvenc/nvenc_base.cpp 0.00% 29 Missing and 1 partial ⚠️
src/config.cpp 0.00% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4892      +/-   ##
==========================================
- Coverage   18.46%   17.35%   -1.12%     
==========================================
  Files         107       72      -35     
  Lines       22524    15233    -7291     
  Branches    10019     7215    -2804     
==========================================
- Hits         4159     2643    -1516     
+ Misses      15988    11718    -4270     
+ Partials     2377      872    -1505     
Flag Coverage Δ
Archlinux 12.20% <0.00%> (-0.02%) ⬇️
FreeBSD-14.3-aarch64 ?
FreeBSD-14.3-amd64 14.01% <0.00%> (-0.02%) ⬇️
Homebrew-ubuntu-22.04 14.59% <0.00%> (-0.02%) ⬇️
Linux-AppImage 12.70% <0.00%> (-0.02%) ⬇️
Windows-AMD64 ?
Windows-ARM64 ?
macOS-arm64 ?
macOS-x86_64 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/nvenc/nvenc_base.h 0.00% <ø> (ø)
src/config.cpp 3.28% <0.00%> (+0.09%) ⬆️
src/nvenc/nvenc_base.cpp 0.00% <0.00%> (-1.61%) ⬇️

... and 61 files with indirect coverage changes

Copy link
Member

@ReenigneArcher ReenigneArcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ns6089 Would supporting all these versions also mean that FFmpeg also needs to be build with all these versions simultaneously?

Split the encoding of each video frame over multiple NVENC hardware units.
Significantly reduces encoding latency with a marginal compression efficiency penalty.
This option is ignored if your GPU has a singular NVENC unit.
@note{This option only applies when using NVENC [encoder](#encoderhttpslocalhost47990configencoder) with HEVC or AV1.}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@note{This option only applies when using NVENC [encoder](#encoderhttpslocalhost47990configencoder) with HEVC or AV1.}
@note{This option only applies when using NVENC [encoder](#encoder) with HEVC or AV1.}

This should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants