Sunshine latest
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 class avcodec_encode_device_t;
20 class 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, height;
73 int offsetX, offsetY;
74 };
75
76 class tex_t {
77 public:
78 static std::optional<tex_t> make(int height, int pitch);
79
80 tex_t();
81 tex_t(tex_t &&);
82
83 tex_t &operator=(tex_t &&other);
84
85 ~tex_t();
86
87 int copy(std::uint8_t *src, int height, int pitch);
88
89 cudaArray_t array;
90
91 struct texture {
92 cudaTextureObject_t point;
93 cudaTextureObject_t linear;
94 } texture;
95 };
96
97 class sws_t {
98 public:
99 sws_t() = default;
100 sws_t(int in_width, int in_height, int out_width, int out_height, int pitch, int threadsPerBlock, ptr_t &&color_matrix);
101
108 static std::optional<sws_t> make(int in_width, int in_height, int out_width, int out_height, int pitch);
109
110 // Converts loaded image into a CUDevicePtr
111 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);
112 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);
113
114 void apply_colorspace(const video::sunshine_colorspace_t &colorspace);
115
116 int load_ram(platf::img_t &img, cudaArray_t array);
117
118 ptr_t color_matrix;
119
120 int threadsPerBlock;
121
122 viewport_t viewport;
123
124 float scale;
125 };
126} // namespace cuda
127
128#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:489
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:347
Definition video_colorspace.h:20
Declarations for colorspace functions.