Make dependency on cuda development files optional

This commit is contained in:
loki-47-6F-64
2021-09-22 14:17:08 +02:00
parent bb912786bd
commit d0529fb234
5 changed files with 53 additions and 36 deletions

View File

@@ -107,17 +107,28 @@ else()
option(SUNSHINE_ENABLE_DRM "Enable KMS grab if available" ON) option(SUNSHINE_ENABLE_DRM "Enable KMS grab if available" ON)
option(SUNSHINE_ENABLE_X11 "Enable X11 grab if available" ON) option(SUNSHINE_ENABLE_X11 "Enable X11 grab if available" ON)
option(SUNSHINE_ENABLE_WAYLAND "Enable building wayland specific code" ON) option(SUNSHINE_ENABLE_WAYLAND "Enable building wayland specific code" ON)
option(SUNSHINE_ENABLE_CUDA "Enable cuda specific code" ON)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 75)
endif()
enable_language(CUDA)
if(${SUNSHINE_ENABLE_X11}) if(${SUNSHINE_ENABLE_X11})
find_package(X11) find_package(X11)
else() else()
set(X11_FOUND OFF) set(X11_FOUND OFF)
endif() endif()
set(CUDA_FOUND OFF)
if(${SUNSHINE_ENABLE_CUDA})
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 75)
endif()
set(CUDA_FOUND ON)
enable_language(CUDA)
endif()
endif()
if(${SUNSHINE_ENABLE_DRM}) if(${SUNSHINE_ENABLE_DRM})
find_package(LIBDRM) find_package(LIBDRM)
find_package(LIBCAP) find_package(LIBCAP)
@@ -138,6 +149,17 @@ else()
include_directories(${X11_INCLUDE_DIR}) include_directories(${X11_INCLUDE_DIR})
list(APPEND PLATFORM_TARGET_FILES sunshine/platform/linux/x11grab.cpp) list(APPEND PLATFORM_TARGET_FILES sunshine/platform/linux/x11grab.cpp)
endif() endif()
if(CUDA_FOUND)
include_directories(third-party/nvfbc)
list(APPEND PLATFORM_TARGET_FILES
sunshine/platform/linux/cuda.cu
sunshine/platform/linux/cuda.cpp
third-party/nvfbc/NvFBC.h)
add_compile_definitions(SUNSHINE_BUILD_CUDA)
endif()
if(LIBDRM_FOUND AND LIBCAP_FOUND) if(LIBDRM_FOUND AND LIBCAP_FOUND)
add_compile_definitions(SUNSHINE_BUILD_DRM) add_compile_definitions(SUNSHINE_BUILD_DRM)
include_directories(${LIBDRM_INCLUDE_DIRS} ${LIBCAP_INCLUDE_DIRS}) include_directories(${LIBDRM_INCLUDE_DIRS} ${LIBCAP_INCLUDE_DIRS})
@@ -187,16 +209,14 @@ else()
sunshine/platform/linux/wlgrab.cpp sunshine/platform/linux/wlgrab.cpp
sunshine/platform/linux/wayland.cpp) sunshine/platform/linux/wayland.cpp)
endif() endif()
if(NOT ${X11_FOUND} AND NOT (${LIBDRM_FOUND} AND ${LIBCAP_FOUND}) AND NOT ${WAYLAND_FOUND}) if(NOT ${X11_FOUND} AND NOT (${LIBDRM_FOUND} AND ${LIBCAP_FOUND}) AND NOT ${WAYLAND_FOUND} AND NOT ${})
message(FATAL_ERROR "Couldn't find either x11, wayland or (libdrm and libcap)") message(FATAL_ERROR "Couldn't find either x11, wayland, cuda or (libdrm and libcap)")
endif() endif()
list(APPEND PLATFORM_TARGET_FILES list(APPEND PLATFORM_TARGET_FILES
sunshine/platform/linux/publish.cpp sunshine/platform/linux/publish.cpp
sunshine/platform/linux/vaapi.h sunshine/platform/linux/vaapi.h
sunshine/platform/linux/vaapi.cpp sunshine/platform/linux/vaapi.cpp
sunshine/platform/linux/cuda.cu
sunshine/platform/linux/cuda.cpp
sunshine/platform/linux/cuda.h sunshine/platform/linux/cuda.h
sunshine/platform/linux/graphics.h sunshine/platform/linux/graphics.h
sunshine/platform/linux/graphics.cpp sunshine/platform/linux/graphics.cpp
@@ -211,8 +231,7 @@ else()
third-party/glad/include/EGL/eglplatform.h third-party/glad/include/EGL/eglplatform.h
third-party/glad/include/KHR/khrplatform.h third-party/glad/include/KHR/khrplatform.h
third-party/glad/include/glad/gl.h third-party/glad/include/glad/gl.h
third-party/glad/include/glad/egl.h third-party/glad/include/glad/egl.h)
third-party/nvfbc/NvFBC.h)
list(APPEND PLATFORM_LIBRARIES list(APPEND PLATFORM_LIBRARIES
dl dl
@@ -224,8 +243,7 @@ else()
include_directories( include_directories(
/usr/include/libevdev-1.0 /usr/include/libevdev-1.0
third-party/nv-codec-headers/include third-party/nv-codec-headers/include
third-party/glad/include third-party/glad/include)
third-party/nvfbc)
if(NOT DEFINED SUNSHINE_EXECUTABLE_PATH) if(NOT DEFINED SUNSHINE_EXECUTABLE_PATH)
set(SUNSHINE_EXECUTABLE_PATH "sunshine") set(SUNSHINE_EXECUTABLE_PATH "sunshine")

View File

@@ -14,7 +14,6 @@ extern "C" {
#include "sunshine/main.h" #include "sunshine/main.h"
#include "sunshine/utility.h" #include "sunshine/utility.h"
#include "wayland.h" #include "wayland.h"
#include "x11grab.h"
#define SUNSHINE_STRINGVIEW_HELPER(x) x##sv #define SUNSHINE_STRINGVIEW_HELPER(x) x##sv
#define SUNSHINE_STRINGVIEW(x) SUNSHINE_STRINGVIEW_HELPER(x) #define SUNSHINE_STRINGVIEW(x) SUNSHINE_STRINGVIEW_HELPER(x)

View File

@@ -1,10 +1,14 @@
#ifndef SUNSHINE_PLATFORM_CUDA_H #if !defined(SUNSHINE_PLATFORM_CUDA_H) && defined(SUNSHINE_BUILD_CUDA)
#define SUNSHINE_PLATFORM_CUDA_H #define SUNSHINE_PLATFORM_CUDA_H
#ifndef __NVCC__ #include <vector>
#include <memory>
#include <optional>
#include "sunshine/platform/common.h" namespace platf {
#include "x11grab.h" class hwdevice_t;
class img_t;
}
namespace cuda { namespace cuda {
namespace nvfbc { namespace nvfbc {
@@ -14,12 +18,6 @@ std::shared_ptr<platf::hwdevice_t> make_hwdevice(int width, int height, bool vra
int init(); int init();
} // namespace cuda } // namespace cuda
#else
namespace platf {
class img_t;
}
#endif
typedef struct cudaArray *cudaArray_t; typedef struct cudaArray *cudaArray_t;
#if !defined(__CUDACC__) #if !defined(__CUDACC__)

View File

@@ -141,9 +141,9 @@ std::string get_mac_address(const std::string_view &address) {
} }
enum class source_e { enum class source_e {
// #ifdef SUNSHINE_BUILD_CUDA #ifdef SUNSHINE_BUILD_CUDA
NVFBC, NVFBC,
// #endif #endif
#ifdef SUNSHINE_BUILD_WAYLAND #ifdef SUNSHINE_BUILD_WAYLAND
WAYLAND, WAYLAND,
#endif #endif
@@ -156,14 +156,14 @@ enum class source_e {
}; };
static source_e source; static source_e source;
// #ifdef SUNSHINE_BUILD_CUDA #ifdef SUNSHINE_BUILD_CUDA
std::vector<std::string> nvfbc_display_names(); std::vector<std::string> nvfbc_display_names();
std::shared_ptr<display_t> nvfbc_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate); std::shared_ptr<display_t> nvfbc_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate);
bool verify_nvfbc() { bool verify_nvfbc() {
return !nvfbc_display_names().empty(); return !nvfbc_display_names().empty();
} }
// #endif #endif
#ifdef SUNSHINE_BUILD_WAYLAND #ifdef SUNSHINE_BUILD_WAYLAND
std::vector<std::string> wl_display_names(); std::vector<std::string> wl_display_names();
@@ -194,10 +194,10 @@ bool verify_x11() {
std::vector<std::string> display_names() { std::vector<std::string> display_names() {
switch(source) { switch(source) {
// #ifdef SUNSHINE_BUILD_CUDA #ifdef SUNSHINE_BUILD_CUDA
case source_e::NVFBC: case source_e::NVFBC:
return nvfbc_display_names(); return nvfbc_display_names();
// #endif #endif
#ifdef SUNSHINE_BUILD_WAYLAND #ifdef SUNSHINE_BUILD_WAYLAND
case source_e::WAYLAND: case source_e::WAYLAND:
return wl_display_names(); return wl_display_names();
@@ -217,10 +217,10 @@ std::vector<std::string> display_names() {
std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &display_name, int framerate) { std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
switch(source) { switch(source) {
// #ifdef SUNSHINE_BUILD_CUDA #ifdef SUNSHINE_BUILD_CUDA
case source_e::NVFBC: case source_e::NVFBC:
return nvfbc_display(hwdevice_type, display_name, framerate); return nvfbc_display(hwdevice_type, display_name, framerate);
// #endif #endif
#ifdef SUNSHINE_BUILD_WAYLAND #ifdef SUNSHINE_BUILD_WAYLAND
case source_e::WAYLAND: case source_e::WAYLAND:
return wl_display(hwdevice_type, display_name, framerate); return wl_display(hwdevice_type, display_name, framerate);
@@ -249,7 +249,7 @@ std::unique_ptr<deinit_t> init() {
window_system = window_system_e::WAYLAND; window_system = window_system_e::WAYLAND;
} }
#endif #endif
#if defined(SUNSHINE_BUILD_X11) // || defined(SUNSHINE_BUILD_CUDA) #if defined(SUNSHINE_BUILD_X11) || defined(SUNSHINE_BUILD_CUDA)
if(std::getenv("DISPLAY") && window_system != window_system_e::WAYLAND) { if(std::getenv("DISPLAY") && window_system != window_system_e::WAYLAND) {
if(std::getenv("WAYLAND_DISPLAY")) { if(std::getenv("WAYLAND_DISPLAY")) {
BOOST_LOG(warning) << "Wayland detected, yet sunshine will use X11 for screencasting, screencasting will only work on XWayland applications"sv; BOOST_LOG(warning) << "Wayland detected, yet sunshine will use X11 for screencasting, screencasting will only work on XWayland applications"sv;
@@ -258,13 +258,13 @@ std::unique_ptr<deinit_t> init() {
window_system = window_system_e::X11; window_system = window_system_e::X11;
} }
#endif #endif
// #ifdef SUNSHINE_BUILD_CUDA #ifdef SUNSHINE_BUILD_CUDA
if(verify_nvfbc()) { if(verify_nvfbc()) {
BOOST_LOG(info) << "Using nvFBC for screencasting"sv; BOOST_LOG(info) << "Using nvFBC for screencasting"sv;
source = source_e::NVFBC; source = source_e::NVFBC;
goto found_source; goto found_source;
} }
// #endif #endif
#ifdef SUNSHINE_BUILD_WAYLAND #ifdef SUNSHINE_BUILD_WAYLAND
if(verify_wl()) { if(verify_wl()) {
BOOST_LOG(info) << "Using Wayland for screencasting"sv; BOOST_LOG(info) << "Using Wayland for screencasting"sv;

View File

@@ -20,11 +20,11 @@
#include "sunshine/main.h" #include "sunshine/main.h"
#include "sunshine/task_pool.h" #include "sunshine/task_pool.h"
#include "cuda.h"
#include "graphics.h" #include "graphics.h"
#include "misc.h" #include "misc.h"
#include "vaapi.h" #include "vaapi.h"
#include "x11grab.h" #include "x11grab.h"
#include "cuda.h"
using namespace std::literals; using namespace std::literals;
@@ -517,9 +517,11 @@ struct x11_attr_t : public display_t {
return va::make_hwdevice(width, height, false); return va::make_hwdevice(width, height, false);
} }
#ifdef SUNSHINE_BUILD_CUDA
if(mem_type == mem_type_e::cuda) { if(mem_type == mem_type_e::cuda) {
return cuda::make_hwdevice(width, height, false); return cuda::make_hwdevice(width, height, false);
} }
#endif
return std::make_shared<hwdevice_t>(); return std::make_shared<hwdevice_t>();
} }