Sunshine v2026.319.132152
Self-hosted game stream host for Moonlight.
cuda.h
Go to the documentation of this file.
1
5#pragma once
6
7#if defined(SUNSHINE_BUILD_CUDA)
8 // standard includes
9 #include <cstdint>
10 #include <memory>
11 #include <optional>
12 #include <string>
13 #include <vector>
14
15 // local includes
16 #include "src/video_colorspace.h"
17
18namespace platf {
19 struct avcodec_encode_device_t;
20 struct img_t;
21} // namespace platf
22
23namespace cuda {
24
25 namespace nvfbc {
26 std::vector<std::string> display_names();
27 }
28
29 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_encode_device(int width, int height, bool vram);
30
39 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_gl_encode_device(int width, int height, int offset_x, int offset_y);
40
41 int init();
42} // namespace cuda
43
44typedef struct cudaArray *cudaArray_t;
45
46 #if !defined(__CUDACC__)
47typedef struct CUstream_st *cudaStream_t;
48typedef unsigned long long cudaTextureObject_t;
49 #else /* defined(__CUDACC__) */
50typedef __location__(device_builtin) struct CUstream_st *cudaStream_t;
51typedef __location__(device_builtin) unsigned long long cudaTextureObject_t;
52 #endif /* !defined(__CUDACC__) */
53
54namespace cuda {
55
56 class freeCudaPtr_t {
57 public:
58 void operator()(void *ptr);
59 };
60
61 class freeCudaStream_t {
62 public:
63 void operator()(cudaStream_t ptr);
64 };
65
66 using ptr_t = std::unique_ptr<void, freeCudaPtr_t>;
67 using stream_t = std::unique_ptr<CUstream_st, freeCudaStream_t>;
68
69 stream_t make_stream(int flags = 0);
70
71 struct viewport_t {
72 int width;
73 int height;
74 int offsetX;
75 int offsetY;
76 };
77
78 class tex_t {
79 public:
80 static std::optional<tex_t> make(int height, int pitch);
81
82 tex_t();
83 tex_t(tex_t &&);
84
85 tex_t &operator=(tex_t &&other);
86
87 ~tex_t();
88
89 int copy(std::uint8_t *src, int height, int pitch);
90
91 cudaArray_t array;
92
93 struct texture {
94 cudaTextureObject_t point;
95 cudaTextureObject_t linear;
96 } texture;
97 };
98
99 class sws_t {
100 public:
101 sws_t() = default;
102 sws_t(int in_width, int in_height, int out_width, int out_height, int pitch, int threadsPerBlock, ptr_t &&color_matrix);
103
110 static std::optional<sws_t> make(int in_width, int in_height, int out_width, int out_height, int pitch);
111
112 // Converts loaded image into a CUDevicePtr
113 int convert(std::uint8_t *Y, std::uint8_t *UV, std::uint32_t pitchY, std::uint32_t pitchUV, cudaTextureObject_t texture, stream_t::pointer stream);
114 int convert(std::uint8_t *Y, std::uint8_t *UV, std::uint32_t pitchY, std::uint32_t pitchUV, cudaTextureObject_t texture, stream_t::pointer stream, const viewport_t &viewport);
115
116 void apply_colorspace(const video::sunshine_colorspace_t &colorspace);
117
118 int load_ram(platf::img_t &img, cudaArray_t array);
119
120 ptr_t color_matrix;
121
122 int threadsPerBlock;
123
124 viewport_t viewport;
125
126 float scale;
127 };
128} // namespace cuda
129
130#endif
std::unique_ptr< platf::avcodec_encode_device_t > make_avcodec_gl_encode_device(int width, int height, int offset_x, int offset_y)
Create a GL->CUDA encoding device for consuming captured dmabufs.
Definition cuda.cpp:492
std::unique_ptr< platf::deinit_t > init(const std::filesystem::path &persistence_filepath, const config::video_t &video_config)
Initialize the implementation and perform the initial state recovery (if needed).
Definition display_device.cpp:704
Definition common.h:369
Definition video_colorspace.h:20
Declarations for colorspace functions.