Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
cuda.h
Go to the documentation of this file.
1
5#pragma once
6
7#if defined(HERMES_BUILD_CUDA)
8 // standard includes
9 #include <cstddef>
10 #include <cstdint>
11 #include <memory>
12 #include <optional>
13 #include <string>
14 #include <vector>
15
16 // local includes
17 #include "cuda_pixel.h"
18 #include "src/video_colorspace.h"
19
20namespace platf {
22 struct img_t;
23} // namespace platf
24
25namespace cuda {
26
27 namespace nvfbc {
28 std::vector<std::string> display_names();
29 }
30
39 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_encode_device(int width, int height, bool vram, pixel::layout_e layout = pixel::layout_e::bgra8);
40
49 std::unique_ptr<platf::avcodec_encode_device_t> make_avcodec_gl_encode_device(int width, int height, int offset_x, int offset_y);
50
51 int init();
52
64 void *alloc_host(std::size_t size);
65
67 void free_host(void *ptr);
68} // namespace cuda
69
70typedef struct cudaArray *cudaArray_t;
71
72 #if !defined(__CUDACC__)
73typedef struct CUstream_st *cudaStream_t;
74typedef unsigned long long cudaTextureObject_t;
75 #else /* defined(__CUDACC__) */
76typedef __location__(device_builtin) struct CUstream_st *cudaStream_t;
77typedef __location__(device_builtin) unsigned long long cudaTextureObject_t;
78 #endif /* !defined(__CUDACC__) */
79
80namespace cuda {
81
82 class freeCudaPtr_t {
83 public:
84 void operator()(void *ptr);
85 };
86
87 class freeCudaStream_t {
88 public:
89 void operator()(cudaStream_t ptr);
90 };
91
92 using ptr_t = std::unique_ptr<void, freeCudaPtr_t>;
93 using stream_t = std::unique_ptr<CUstream_st, freeCudaStream_t>;
94
95 stream_t make_stream(int flags = 0);
96
97 struct viewport_t {
98 int width, height;
99 int offsetX, offsetY;
100 };
101
102 class tex_t {
103 public:
111 static std::optional<tex_t> make(int height, int pitch, pixel::layout_e layout = pixel::layout_e::bgra8);
112
113 tex_t();
114 tex_t(tex_t &&);
115
116 tex_t &operator=(tex_t &&other);
117
118 ~tex_t();
119
120 int copy(std::uint8_t *src, int height, int pitch);
121
122 cudaArray_t array;
123 pixel::layout_e layout {pixel::layout_e::bgra8};
124
125 struct texture {
126 cudaTextureObject_t point;
127 cudaTextureObject_t linear;
128 } texture;
129 };
130
131 class sws_t {
132 public:
133 sws_t() = default;
134 sws_t(int in_width, int in_height, int out_width, int out_height, int pitch, int threadsPerBlock, ptr_t &&color_matrix);
135
142 static std::optional<sws_t> make(int in_width, int in_height, int out_width, int out_height, int pitch);
143
148 static std::optional<sws_t> make(int in_width, int in_height, int out_width, int out_height, int pitch, pixel::layout_e layout, int output_bits);
149
150 // Converts loaded image into a CUDevicePtr
151 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);
152 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);
153
154 void apply_colorspace(const video::sunshine_colorspace_t &colorspace);
155
156 int load_ram(platf::img_t &img, cudaArray_t array);
157
158 ptr_t color_matrix;
159
162 ptr_t code_matrix;
163
164 pixel::layout_e layout {pixel::layout_e::bgra8};
165 int output_bits {8};
166
168 bool linear {false};
169
170 int threadsPerBlock;
171
172 viewport_t viewport;
173
174 float scale;
175 };
176} // namespace cuda
177
178#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:612
Pixel decoding and YUV encoding shared by the CUDA converter and its host-side tests.
layout_e
How the 32-bit little-endian words of a CPU-copied frame hold their channels.
Definition cuda_pixel.h:21
@ bgra8
DRM XRGB8888 / ARGB8888: bytes B, G, R, X.
Definition cuda_pixel.h:22
Declarations for colorspace functions.