Skip to content

Conversation

@Nonary
Copy link

@Nonary Nonary commented Jul 12, 2025

Description

This pull request introduces Windows Game Capture (WGC) support to Sunshine via a dedicated helper process, along with a reusable IPC framework for inter-process communication.

  • The helper process runs in the interactive user session, uses WGC APIs to capture frames, and shares texture handles with the Sunshine service through the new IPC framework.

Motivation and Benefits

Sunshine currently relies on DXGI for screen capture on Windows, which works well but has limitations in headless service mode, frame pacing consistency, and compatibility with features like Xbox Game Bar. WGC addresses these by providing a more robust, game-optimized capture API.

Key benefits include:

  • Headless service compatibility: Sunshine can run as a background service while still accessing interactive-session APIs via the helper.
  • Game Bar integration: Overlays and features from Xbox Game Bar remain functional during streaming.
  • Extensible IPC: The new framework enables secure communication with subprocesses, paving the way for future enhancements like isolated Web API or capture modules.
  • Seamless fallback: Users will be able to still respond to UAC as well as login without any workarounds, it swaps between DXGI and WGC seamlessly.
  • Self healing: If the capture crashes or deadlocks, the main process will re-initialize without disconnecting the current stream.

Implementation Overview

Area Details Impact
Process Model Introduces sunshine_wgc_capture.exe as a subprocess launched by the Sunshine service. Separates privileges for better security and enables sunshine to use WGC even when running as a service.
IPC Framework Adds a bidirectional IPC layer for handle sharing and commands. Reusable for future multi-process features (e.g., offloading Web API or other helpers).
Capture Logic Defaults to WGC with runtime checks for availability; falls back to DXGI as needed. No configuration required once stable, handles edge cases automatically.

Development Status

  • Proof-of-concept: WGC capture working in helper process with IPC handle transfer.
  • Proper IPC Protocol: Add basic security controls to the IPC such as anonymous pipes, validation and ACL.
  • WGC while running as System: WGC can now run when Sunshine is running as system.
  • Auto Swap DXGI/WGC: WGC capture now supports UAC/Login screens with automated capture swapping.
  • Optimizations: Remove the micro stuttering and frame pacing issues caused by the capture.
  • RAII: Migrate the new code to use RAII for disposal to minimize risk of memory leaks and errors.
  • Refactor: The code contains a lot of duplication, excessive logging and inconsistent styling. It's best to fix the code once everything has been shown to work.

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

@ReenigneArcher ReenigneArcher added roadmap This PR closes a roadmap entry ai PR has signs of heavy ai usage (either indicated by user or assumed) labels Jul 17, 2025
@Nonary Nonary closed this Jul 18, 2025
@Nonary
Copy link
Author

Nonary commented Jul 18, 2025

I had closed it because I suspect it might be another few weeks before this one is fully polished and ready to go. It did not mean I was stopping the work entirely. I had planned on doing a re-submit once the polish was completed, however after some discussions with RA we both agreed its best to put it back in draft.

So to clarify, this is still planned and I am working on it… but I have been getting my ass kicked the past week on this one. I try one thing and the entire thing breaks.

The code is mostly working as-is right now, just quality wise it is not that great.

I really had hoped to get this in a reviewable state much sooner, but I am really struggling getting that down.

Nonary added 15 commits July 26, 2025 21:57
- Introduced `sunshine_wgc_helper.cpp` to handle Windows Graphics Capture.
- Removed the old `shared_memory.cpp` as its functionality is integrated into the new helper.
- Created a simple test program `test_wgc_ipc.cpp` to verify the IPC implementation.
- Updated `CMakeLists.txt` to include the new helper executable and its dependencies.
- Added unit tests for process handling and shared memory functionality.
- Implemented integration tests for the display IPC to ensure proper initialization and error handling.
- Enhanced existing tests for robustness and added deadlock protection.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
117 New issues
2 Security Hotspots
117 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

@Nonary Nonary closed this Aug 12, 2025
@cringegnere
Copy link

Kudos for your work! Btw it looks like you closed it again by mistake

@mspeedo
Copy link

mspeedo commented Aug 12, 2025

Thanks for great work, I've been testing this (wgc variable) for a while with Moonlight VRR client at 120fps and stream smoothness after last commit [refactor pointer usage] now seems to be on par with ddx capture method. Host processing latency is lower up to 1 ms in comparison to ddx.

@Nonary
Copy link
Author

Nonary commented Aug 12, 2025

Kudos for your work! Btw it looks like you closed it again by mistake

Good morning, due to disagreements with owner the PR actually was intentionally closed. I'm not sure if I'm going to be banned yet but that's typically what he will do as next step.

@ReenigneArcher
Copy link
Member

Don't blame me... You had a disagreement with yourself at 3am, again. Last time you were banned because you started cussing at me. If you start that again, yes you will be banned.

@Nonary
Copy link
Author

Nonary commented Aug 12, 2025

I'm just saying that because you've banned everyone else who's disagreed with you in the past. But thanks for clearing that up

@ReenigneArcher
Copy link
Member

You have absolutely no idea who has been banned or why, so stop spewing misinformation.

I've never banned anyone who I disagreed with. I've only ever banned spammers and people who can't act professional and follow the code of conduct. https://github.com/LizardByte/.github/blob/master/CODE_OF_CONDUCT.md

@Nonary
Copy link
Author

Nonary commented Sep 24, 2025

I am re-opening this if Sunshine decides to inherit it or not. It does not matter to me. I maintain my own fork now; however, WGC still has major benefits for users, so I am open to having it reviewed again.

I have been testing it for a few months now and haven't had issues so its pretty much stable as is.

@Nonary Nonary reopened this Sep 24, 2025
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
117 New issues
2 Security Hotspots
117 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

@ReenigneArcher
Copy link
Member

This is unlikely to get merged in it's current state, some things that can be done to improve the chances.

A. Fix sonar warnings (rebase needed to actually view the current ones)
B. Add tests and cover the new code as well as possible
C. if splitting the logging into a ton of new files is actually necessary then it should be divided into a logging subdirectory
D. Breaking this down into smaller, more manageable/reviewable PRs would make this immensely easier

@Nonary
Copy link
Author

Nonary commented Oct 31, 2025

This is unlikely to get merged in it's current state, some things that can be done to improve the chances.

A. Fix sonar warnings (rebase needed to actually view the current ones) B. Add tests and cover the new code as well as possible C. if splitting the logging into a ton of new files is actually necessary then it should be divided into a logging subdirectory D. Breaking this down into smaller, more manageable/reviewable PRs would make this immensely easier

A. Not going to happen, SonarQube is a complete waste of time and resources and 99% of the “issues” is more of an opinion rather than an actual serious issue. This code has been working for months without crashes and is fine, any sonar warning is entirely pointless.

B. Also unrealistic, this is low level code and would be challenging to write tests for because its would only work on the Windows Environment.

C. Fixing the split log issue is easy, we can just add more compiler switches to null-out the extra logging code.

D. Also unlikely going to happen, splitting a complex feature into multiple smaller PR’s is much worse than having it all together.

How can anyone test code in the PR if for example it is not complete? If I make a smaller PR that makes the capture process, but does not include anything else, the entire PR is pointless and also cannot be tested because you need more than just that code to see it function.

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

Labels

ai PR has signs of heavy ai usage (either indicated by user or assumed) roadmap This PR closes a roadmap entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows.Graphics.Capture does not work with service model Stream Freezes with high VRAM utilization (and does not recover)

5 participants