Skip to content

feat(linux/glad): implement EGL_IMG_context_priority#4857

Merged
ReenigneArcher merged 1 commit intoLizardByte:masterfrom
psyke83:glad_priority
Mar 22, 2026
Merged

feat(linux/glad): implement EGL_IMG_context_priority#4857
ReenigneArcher merged 1 commit intoLizardByte:masterfrom
psyke83:glad_priority

Conversation

@psyke83
Copy link
Copy Markdown
Contributor

@psyke83 psyke83 commented Mar 16, 2026

Description

Resolves encoding throttling during high GPU usage:

  • Try to create EGL context with high priority if supported.
  • Set CAP_SYS_NICE capability (needed for AMDGPU/NVIDIA drivers at minumum).
  • This will not work for Flatpak, AppImage or Portal capture due to the
    CAP_SYS_NICE capability not being available.

Currently has no effect on AMDGPU with Flatpak, AppImage and/or with
Portal capture. Other GPUs may behave differently.

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

@psyke83 psyke83 marked this pull request as ready for review March 16, 2026 02:27
@psyke83
Copy link
Copy Markdown
Contributor Author

psyke83 commented Mar 16, 2026

Pinging @inkatail to test a possible alternative to async_depth modification. Vulkan encoding won't be affected by this PR, but it may help resolve VAAPI encoder throttling during high GPU usage.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 16, 2026

Bundle Report

Bundle size has no change ✅

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 0% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.46%. Comparing base (0d3be0b) to head (b9bf74f).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/linux/graphics.cpp 0.00% 30 Missing and 3 partials ⚠️
src/platform/linux/portalgrab.cpp 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4857      +/-   ##
==========================================
- Coverage   18.50%   18.46%   -0.04%     
==========================================
  Files         107      107              
  Lines       22448    22477      +29     
  Branches     9970     9990      +20     
==========================================
- Hits         4153     4151       -2     
- Misses      14360    15008     +648     
+ Partials     3935     3318     -617     
Flag Coverage Δ
Archlinux 12.24% <0.00%> (-0.03%) ⬇️
FreeBSD-14.3-aarch64 ?
FreeBSD-14.3-amd64 14.07% <0.00%> (-0.01%) ⬇️
Homebrew-ubuntu-22.04 14.60% <0.00%> (-0.04%) ⬇️
Linux-AppImage 12.74% <0.00%> (-0.03%) ⬇️
Windows-AMD64 14.98% <ø> (ø)
Windows-ARM64 13.39% <ø> (ø)
macOS-arm64 19.11% <ø> (ø)
macOS-x86_64 18.49% <ø> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
src/platform/linux/portalgrab.cpp 3.37% <0.00%> (-0.01%) ⬇️
src/platform/linux/graphics.cpp 2.26% <0.00%> (-0.12%) ⬇️

... and 20 files with indirect coverage changes

@inkatail
Copy link
Copy Markdown

Pinging @inkatail to test a possible alternative to async_depth modification. Vulkan encoding won't be affected by this PR, but it may help resolve VAAPI encoder throttling during high GPU usage.

@psyke83 Unfortunately, this PR doesn't seem to improve it at least for me, logs seem to report that the Priority is HIGH but in games the performance is still weird

@psyke83 psyke83 marked this pull request as draft March 16, 2026 14:18
@psyke83
Copy link
Copy Markdown
Contributor Author

psyke83 commented Mar 16, 2026

Thanks for testing. I'll convert this to draft until I can test some more.

@inkatail I happen to have the same GPU as you; can you suggest the exact in-game settings that can reproduce the issue in ETS2? I have the game but never played it, so I might need some guidance on what scenario to load, etc.

@Romanychev
Copy link
Copy Markdown

Could you help me with the problem?

GPU performance drop tied to stream framerate on Linux #4567

@psyke83 psyke83 marked this pull request as ready for review March 16, 2026 14:51
@psyke83
Copy link
Copy Markdown
Contributor Author

psyke83 commented Mar 16, 2026

@Romanychev

I refreshed the PR to try setting realtime priority as well. I can't test this as the AMD drivers don't support this extension, but you could give it a try. I'm not sure how the nvenc encoder pipeline interacts with EGL.

If you don't see EGL Context Priority: REALTIME logged, more changes (setting CAP_SYS_NICE) might be needed. Realtime might also cause Sunshine to hang your system, so be careful.

@inkatail
Copy link
Copy Markdown

Thanks for testing. I'll convert this to draft until I can test some more.

@inkatail I happen to have the same GPU as you; can you suggest the exact in-game settings that can reproduce the issue in ETS2? I have the game but never played it, so I might need some guidance on what scenario to load, etc.

@psyke83 All I changed in graphics settings was using the Ultra preset, then for testing I were just driving around cities cause they are pretty intensive to run, I were also testing in the Driving Academy (which is basically a tutorial for ETS).

@psyke83
Copy link
Copy Markdown
Contributor Author

psyke83 commented Mar 17, 2026

@inkatail Please retest the latest version that adds CAP_SYS_NICE support. I was able to reproduce the lag in ETS2 that's now fixed by the PR, but only under specific conditions:

  • Using distro package only (no Flatpak or AppImage)
  • Not using Portal capture

Basically, VAAPI + KMS is currently the only confirmed working case on AMD.

@Romanychev

The NVIDIA drivers might not need CAP_SYS_NICE to increase the priority, so Flatpak, AppImage and Portal may work/benefit from this change as well as the distro packages.

@ReenigneArcher
Copy link
Copy Markdown
Member

@psyke83 I will wait to merge until I get the go-ahead from you.

@inkatail
Copy link
Copy Markdown

@inkatail Please retest the latest version that adds CAP_SYS_NICE support. I was able to reproduce the lag in ETS2 that's now fixed by the PR, but only under specific conditions:

* Using distro package only (no Flatpak or AppImage)

* Not using Portal capture

Basically, VAAPI + KMS is currently the only confirmed working case on AMD.

@Romanychev

The NVIDIA drivers might not need CAP_SYS_NICE to increase the priority, so Flatpak, AppImage and Portal may work/benefit from this change as well as the distro packages.

@psyke83 Did another test, now with CAP_SYS_NICE on VA-API + KMS and it indeed seems to fix the issue properly now.

@psyke83
Copy link
Copy Markdown
Contributor Author

psyke83 commented Mar 17, 2026

@psyke83 I will wait to merge until I get the go-ahead from you.

I think we should get some feedback from NVIDIA users. It may be risky to set realtime due to the risk of hangs. Aside from that, I'm investigating whether it's possible to make this work with Portal, but I suppose that can be refined in a later PR.

@psyke83 psyke83 changed the title fix(linux/glad): implement EGL_IMG_context_priority support fix(linux/glad): add EGL_IMG_context_priority & EGL_NV_context_priority_realtime Mar 17, 2026
@psyke83 psyke83 force-pushed the glad_priority branch 2 times, most recently from 1879f4e to fd9d3ae Compare March 17, 2026 19:36
@psyke83 psyke83 changed the title fix(linux/glad): add EGL_IMG_context_priority & EGL_NV_context_priority_realtime feat(linux/glad): add EGL_IMG_context_priority & EGL_NV_context_priority_realtime Mar 17, 2026
@ReenigneArcher
Copy link
Copy Markdown
Member

I think we should get some feedback from NVIDIA users. It may be risky to set realtime due to the risk of hangs. Aside from that, I'm investigating whether it's possible to make this work with Portal, but I suppose that can be refined in a later PR.

Doesn't look like there were any volunteers on discord

@psyke83 psyke83 marked this pull request as draft March 21, 2026 17:40
@psyke83
Copy link
Copy Markdown
Contributor Author

psyke83 commented Mar 21, 2026

To be safe, I'll partially revert the realtime changes and just try setting HIGH for everyone. I'm also still investigating ways to make this work with Portal. Will update the PR soon.

Resolves encoding throttling during high GPU usage:
* Try to create EGL context with high priority if supported.
* Set CAP_SYS_NICE capability (needed for AMDGPU/NVIDIA drivers at minumum).
* This will not work for Flatpak, AppImage or Portal capture due to the
  CAP_SYS_NICE capability not being available.
@sonarqubecloud
Copy link
Copy Markdown

@psyke83 psyke83 changed the title feat(linux/glad): add EGL_IMG_context_priority & EGL_NV_context_priority_realtime feat(linux/glad): implement EGL_IMG_context_priority Mar 21, 2026
@psyke83 psyke83 marked this pull request as ready for review March 21, 2026 21:30
@psyke83
Copy link
Copy Markdown
Contributor Author

psyke83 commented Mar 21, 2026

This should be good to go.

@ReenigneArcher ReenigneArcher merged commit ae8adfd into LizardByte:master Mar 22, 2026
72 of 73 checks passed
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.

Inconsistent FPS in Certain Games

4 participants