Sunshine v2025.118.151840
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
10
11 #include <cstdint>
12 #include <memory>
13 #include <optional>
14 #include <string>
15 #include <vector>
16
17namespace platf {
18 class avcodec_encode_device_t;
19 class img_t;
20} // namespace platf
21
22namespace cuda {
23
24 namespace nvfbc {
25 std::vector<std::string>
26 display_names();
27 }
28 std::unique_ptr<platf::avcodec_encode_device_t>
29 make_avcodec_encode_device(int width, int height, bool vram);
30
39 std::unique_ptr<platf::avcodec_encode_device_t>
40 make_avcodec_gl_encode_device(int width, int height, int offset_x, int offset_y);
41
42 int
43 init();
44} // namespace cuda
45
46typedef struct cudaArray *cudaArray_t;
47
48 #if !defined(__CUDACC__)
49typedef struct CUstream_st *cudaStream_t;
50typedef unsigned long long cudaTextureObject_t;
51 #else /* defined(__CUDACC__) */
52typedef __location__(device_builtin) struct CUstream_st *cudaStream_t;
53typedef __location__(device_builtin) unsigned long long cudaTextureObject_t;
54 #endif /* !defined(__CUDACC__) */
55
56namespace cuda {
57
58 class freeCudaPtr_t {
59 public:
60 void
61 operator()(void *ptr);
62 };
63
64 class freeCudaStream_t {
65 public:
66 void
67 operator()(cudaStream_t ptr);
68 };
69
70 using ptr_t = std::unique_ptr<void, freeCudaPtr_t>;
71 using stream_t = std::unique_ptr<CUstream_st, freeCudaStream_t>;
72
73 stream_t
74 make_stream(int flags = 0);
75
76 struct viewport_t {
77 int width, height;
78 int offsetX, offsetY;
79 };
80
81 class tex_t {
82 public:
83 static std::optional<tex_t>
84 make(int height, int pitch);
85
86 tex_t();
87 tex_t(tex_t &&);
88
89 tex_t &
90 operator=(tex_t &&other);
91
92 ~tex_t();
93
94 int
95 copy(std::uint8_t *src, int height, int pitch);
96
97 cudaArray_t array;
98
99 struct texture {
100 cudaTextureObject_t point;
101 cudaTextureObject_t linear;
102 } texture;
103 };
104
105 class sws_t {
106 public:
107 sws_t() = default;
108 sws_t(int in_width, int in_height, int out_width, int out_height, int pitch, int threadsPerBlock, ptr_t &&color_matrix);
109
116 static std::optional<sws_t>
117 make(int in_width, int in_height, int out_width, int out_height, int pitch);
118
119 // Converts loaded image into a CUDevicePtr
120 int
121 convert(std::uint8_t *Y, std::uint8_t *UV, std::uint32_t pitchY, std::uint32_t pitchUV, cudaTextureObject_t texture, stream_t::pointer stream);
122 int
123 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);
124
125 void
126 apply_colorspace(const video::sunshine_colorspace_t &colorspace);
127
128 int
129 load_ram(platf::img_t &img, cudaArray_t array);
130
131 ptr_t color_matrix;
132
133 int threadsPerBlock;
134
135 viewport_t viewport;
136
137 float scale;
138 };
139} // namespace cuda
140
141#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:508
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:721
Definition common.h:341
Definition video_colorspace.h:20
Declarations for colorspace functions.