diff --git a/CMakeLists.txt b/CMakeLists.txt index 62d8b435..c96b1bbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,11 +351,14 @@ list(APPEND SUNSHINE_EXTERNAL_LIBRARIES ${PLATFORM_LIBRARIES}) add_compile_options("$<$:${SUNSHINE_COMPILE_OPTIONS}>") +add_compile_options("$<$:-std=c++17>") add_compile_options("$<$:${SUNSHINE_COMPILE_OPTIONS}>") foreach(flag IN LISTS SUNSHINE_COMPILE_OPTIONS) add_compile_options($<$:-Xcompiler=${flag}>) endforeach() +add_compile_options($<$:-Xcompiler=-std=c++14>) +add_compile_options($<$:-std=c++14>) list(APPEND SUNSHINE_DEFINITIONS SUNSHINE_ASSETS_DIR="${SUNSHINE_ASSETS_DIR}") list(APPEND SUNSHINE_DEFINITIONS SUNSHINE_CONFIG_DIR="${SUNSHINE_CONFIG_DIR}") @@ -363,4 +366,4 @@ list(APPEND SUNSHINE_DEFINITIONS SUNSHINE_DEFAULT_DIR="${SUNSHINE_DEFAULT_DIR}") add_executable(sunshine ${SUNSHINE_TARGET_FILES}) target_link_libraries(sunshine ${SUNSHINE_EXTERNAL_LIBRARIES}) target_compile_definitions(sunshine PUBLIC ${SUNSHINE_DEFINITIONS}) -set_target_properties(sunshine PROPERTIES CXX_STANDARD 17) \ No newline at end of file +# set_target_properties(sunshine PROPERTIES CXX_STANDARD 17) \ No newline at end of file diff --git a/sunshine/platform/linux/cuda.cpp b/sunshine/platform/linux/cuda.cpp index b15104a5..8a25eb27 100644 --- a/sunshine/platform/linux/cuda.cpp +++ b/sunshine/platform/linux/cuda.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -29,7 +30,7 @@ namespace cuda { constexpr auto cudaDevAttrMaxThreadsPerBlock = (CUdevice_attribute)1; constexpr auto cudaDevAttrMaxThreadsPerMultiProcessor = (CUdevice_attribute)39; -void pass_error(const std::string_view &sv, const char *name, const char *description) { +void pass_error(const std::string &sv, const char *name, const char *description) { BOOST_LOG(error) << sv << name << ':' << description; } @@ -276,7 +277,7 @@ public: return *this; } - static std::optional make() { + static std::unique_ptr make() { NVFBC_CREATE_HANDLE_PARAMS params { NVFBC_CREATE_HANDLE_PARAMS_VER }; handle_t handle; @@ -284,12 +285,12 @@ public: if(status) { BOOST_LOG(error) << "Failed to create session: "sv << handle.last_error(); - return std::nullopt; + return nullptr; } handle.handle_flags[SESSION_HANDLE] = true; - return std::move(handle); + return std::make_unique(std::move(handle)); } const char *last_error() { diff --git a/sunshine/platform/linux/cuda.cu b/sunshine/platform/linux/cuda.cu index 49f088f8..e93f7d9f 100644 --- a/sunshine/platform/linux/cuda.cu +++ b/sunshine/platform/linux/cuda.cu @@ -1,15 +1,11 @@ -// #include +#include #include #include #include -#include -#include #include "cuda.h" -using namespace std::literals; - -#define SUNSHINE_STRINGVIEW_HELPER(x) x##sv +#define SUNSHINE_STRINGVIEW_HELPER(x) x #define SUNSHINE_STRINGVIEW(x) SUNSHINE_STRINGVIEW_HELPER(x) #define CU_CHECK(x, y) \ @@ -21,14 +17,9 @@ using namespace std::literals; #define CU_CHECK_PTR(x, y) \ if(check((x), SUNSHINE_STRINGVIEW(y ": "))) return nullptr; -#define CU_CHECK_OPT(x, y) \ - if(check((x), SUNSHINE_STRINGVIEW(y ": "))) return std::nullopt; - #define CU_CHECK_IGNORE(x, y) \ check((x), SUNSHINE_STRINGVIEW(y ": ")) -using namespace std::literals; - //////////////////// Special desclarations /** * NVCC segfaults when including @@ -83,8 +74,8 @@ inline T div_align(T l, T r) { return (l + r - 1) / r; } -void pass_error(const std::string_view &sv, const char *name, const char *description); -inline static int check(cudaError_t result, const std::string_view &sv) { +void pass_error(const std::string &sv, const char *name, const char *description); +inline static int check(cudaError_t result, const std::string &sv) { if(result) { auto name = cudaGetErrorName(result); auto description = cudaGetErrorString(result); @@ -174,11 +165,11 @@ int tex_t::copy(std::uint8_t *src, int height, int pitch) { return 0; } -std::optional tex_t::make(int height, int pitch) { +std::unique_ptr tex_t::make(int height, int pitch) { tex_t tex; auto format = cudaCreateChannelDesc(); - CU_CHECK_OPT(cudaMallocArray(&tex.array, &format, pitch, height, cudaArrayDefault), "Couldn't allocate cuda array"); + CU_CHECK_PTR(cudaMallocArray(&tex.array, &format, pitch, height, cudaArrayDefault), "Couldn't allocate cuda array"); cudaResourceDesc res {}; res.resType = cudaResourceTypeArray; @@ -192,13 +183,13 @@ std::optional tex_t::make(int height, int pitch) { std::fill_n(std::begin(desc.addressMode), 2, cudaAddressModeClamp); - CU_CHECK_OPT(cudaCreateTextureObject(&tex.texture.point, &res, &desc, nullptr), "Couldn't create cuda texture that uses point interpolation"); + CU_CHECK_PTR(cudaCreateTextureObject(&tex.texture.point, &res, &desc, nullptr), "Couldn't create cuda texture that uses point interpolation"); desc.filterMode = cudaFilterModeLinear; - CU_CHECK_OPT(cudaCreateTextureObject(&tex.texture.linear, &res, &desc, nullptr), "Couldn't create cuda texture that uses linear interpolation"); + CU_CHECK_PTR(cudaCreateTextureObject(&tex.texture.linear, &res, &desc, nullptr), "Couldn't create cuda texture that uses linear interpolation"); - return std::move(tex); + return std::make_unique(std::move(tex)); } tex_t::tex_t() : array {}, texture { INVALID_TEXTURE } {} @@ -255,18 +246,18 @@ sws_t::sws_t(int in_width, int in_height, int out_width, int out_height, int pit scale = 1.0f / scalar; } -std::optional sws_t::make(int in_width, int in_height, int out_width, int out_height, int pitch) { +std::unique_ptr sws_t::make(int in_width, int in_height, int out_width, int out_height, int pitch) { cudaDeviceProp props; int device; - CU_CHECK_OPT(cudaGetDevice(&device), "Couldn't get cuda device"); - CU_CHECK_OPT(cudaGetDeviceProperties(&props, device), "Couldn't get cuda device properties"); + CU_CHECK_PTR(cudaGetDevice(&device), "Couldn't get cuda device"); + CU_CHECK_PTR(cudaGetDeviceProperties(&props, device), "Couldn't get cuda device properties"); auto ptr = make_ptr(); if(!ptr) { - return std::nullopt; + return nullptr; } - return std::make_optional(in_width, in_height, out_width, out_height, pitch, props.maxThreadsPerMultiProcessor / props.maxBlocksPerMultiProcessor, std::move(ptr)); + return std::make_unique(in_width, in_height, out_width, out_height, pitch, props.maxThreadsPerMultiProcessor / props.maxBlocksPerMultiProcessor, std::move(ptr)); } int sws_t::convert(std::uint8_t *Y, std::uint8_t *UV, std::uint32_t pitchY, std::uint32_t pitchUV, cudaTextureObject_t texture) { diff --git a/sunshine/platform/linux/cuda.h b/sunshine/platform/linux/cuda.h index 5811379f..e46b4759 100644 --- a/sunshine/platform/linux/cuda.h +++ b/sunshine/platform/linux/cuda.h @@ -3,7 +3,7 @@ #include #include -#include +#include namespace platf { class hwdevice_t; @@ -42,7 +42,7 @@ struct viewport_t { class tex_t { public: - static std::optional make(int height, int pitch); + static std::unique_ptr make(int height, int pitch); tex_t(); tex_t(tex_t &&); @@ -72,7 +72,7 @@ public: * * pitch -- The size of a single row of pixels in bytes */ - static std::optional make(int in_width, int in_height, int out_width, int out_height, int pitch); + static std::unique_ptr make(int in_width, int in_height, int out_width, int out_height, int pitch); // Converts loaded image into a CUDevicePtr int convert(std::uint8_t *Y, std::uint8_t *UV, std::uint32_t pitchY, std::uint32_t pitchUV, cudaTextureObject_t texture);