fix(linux): handle NVENC in builds without CUDA

This commit is contained in:
ReenigneArcher committed 2026-09-12 15:42:06 -04:00
1 parent dd7a1f796e
commit e596664dec
5 files changed
+72 -5

No files matched your search

+11 -1
View File
@@ -75,7 +75,17 @@ sudo mv /tmp/sunshine build/sunshine
```
##### CUDA Toolkit
Sunshine requires CUDA Toolkit for NVFBC capture. There are two caveats to CUDA:
When building Sunshine for a system with an NVIDIA GPU, install the CUDA Toolkit before configuring or compiling
Sunshine. CUDA support is selected at compile time and is used for NVFBC capture and direct GPU-memory NVENC encoding.
This applies to every source build, including builds made through the AUR or for third-party repositories such as
Omarchy. Installing the CUDA Toolkit after Sunshine was compiled does not enable CUDA support; Sunshine must be rebuilt.
> [!NOTE]
> Users installing a prebuilt package supplied by LizardByte do not need to install the CUDA Toolkit. This includes the
> Arch Linux package from LizardByte's [pacman-repo](https://github.com/LizardByte/pacman-repo), which is already built
> with CUDA support.
There are two caveats to CUDA:
1. The version installed depends on the version of GCC.
2. The version of CUDA you use will determine compatibility with various GPU generations.
+16 -3
View File
@@ -57,12 +57,20 @@ available for manual download from each GitHub release.
**CUDA Compatibility**
CUDA is used for NVFBC capture.
CUDA is used for NVFBC capture and direct GPU-memory NVENC encoding.
> [!IMPORTANT]
> CUDA support is selected when Sunshine is compiled. If you build Sunshine for an NVIDIA GPU yourself, including
> through the AUR or for a third-party repository such as Omarchy, install the CUDA Toolkit before building Sunshine.
> Installing CUDA after Sunshine has been compiled does not add CUDA support; Sunshine must be rebuilt.
>
> This requirement does not apply when installing a prebuilt package supplied by LizardByte. In particular, the
> Arch Linux package from LizardByte's [pacman-repo](https://github.com/LizardByte/pacman-repo) is already built with
> CUDA support, so its users do not need to install the CUDA Toolkit.
> [!NOTE]
> See [CUDA GPUS](https://developer.nvidia.com/cuda-gpus) to cross-reference Compute Capability to your GPU.
> The table below applies to packages provided by LizardByte. If you use an official LizardByte package, then you do not
> need to install CUDA.
> The table below applies to packages provided by LizardByte.
<table>
<caption>CUDA Compatibility</caption>
@@ -149,6 +157,11 @@ apk del sunshine
> [!CAUTION]
> Use AUR packages at your own risk.
> [!IMPORTANT]
> NVIDIA users installing Sunshine from LizardByte's pacman-repo do not need the CUDA Toolkit. If Sunshine is compiled
> locally from the AUR or by another package provider, such as Omarchy, the builder must install the CUDA Toolkit before
> compilation. Installing CUDA after the package was built cannot enable CUDA support in that package.
##### Install Prebuilt Packages
Follow the instructions at LizardByte's [pacman-repo](https://github.com/LizardByte/pacman-repo) to add
the repository. Then run the following command.
+8
View File
@@ -26,6 +26,14 @@
#ifdef SUNSHINE_BUILD_WAYLAND
namespace wl {
/**
* @brief Determine whether wlroots capture should keep frames in VRAM for the requested memory type.
*
* @param hwdevice_type Hardware device type requested for capture or encode.
* @return `true` when the requested memory type should use the wlroots VRAM path.
*/
bool use_vram_capture(platf::mem_type_e hwdevice_type);
/**
* @brief Owning pointer for a Wayland display connection.
*/
+21 -1
View File
@@ -19,6 +19,20 @@ namespace wl {
static int env_width;
static int env_height;
bool use_vram_capture(platf::mem_type_e hwdevice_type) {
if (hwdevice_type == platf::mem_type_e::vaapi) {
return true;
}
#ifdef SUNSHINE_BUILD_CUDA
if (hwdevice_type == platf::mem_type_e::cuda) {
return true;
}
#endif
return false;
}
/**
* @brief Captured frame buffer shared between capture and encode stages.
*/
@@ -488,7 +502,7 @@ namespace platf {
return nullptr;
}
if (hwdevice_type == platf::mem_type_e::vaapi || hwdevice_type == platf::mem_type_e::cuda) {
if (wl::use_vram_capture(hwdevice_type)) {
auto wlr = std::make_shared<wl::wlr_vram_t>();
if (wlr->init(hwdevice_type, display_name, config)) {
return nullptr;
@@ -497,6 +511,12 @@ namespace platf {
return wlr;
}
#ifndef SUNSHINE_BUILD_CUDA
if (hwdevice_type == platf::mem_type_e::cuda) {
BOOST_LOG(warning) << "This build does not include CUDA support. Falling back to GPU -> RAM -> GPU for NVENC."sv;
}
#endif
auto wlr = std::make_shared<wl::wlr_ram_t>();
if (wlr->init(hwdevice_type, display_name, config)) {
return nullptr;
@@ -29,4 +29,20 @@ TEST(WaylandMonitorTest, UpdatesCurrentMode) {
EXPECT_EQ(monitor.viewport.width, 2560);
EXPECT_EQ(monitor.viewport.height, 1440);
}
TEST(WaylandCaptureTest, UsesVramForVaapi) {
EXPECT_TRUE(wl::use_vram_capture(platf::mem_type_e::vaapi));
}
TEST(WaylandCaptureTest, UsesSystemMemoryForSoftwareEncoding) {
EXPECT_FALSE(wl::use_vram_capture(platf::mem_type_e::system));
}
TEST(WaylandCaptureTest, UsesVramForCudaOnlyWhenCudaSupportIsBuilt) {
#ifdef SUNSHINE_BUILD_CUDA
EXPECT_TRUE(wl::use_vram_capture(platf::mem_type_e::cuda));
#else
EXPECT_FALSE(wl::use_vram_capture(platf::mem_type_e::cuda));
#endif
}
#endif