Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
cuda_pixel.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <cstdint>
11
12#if defined(__CUDACC__)
13 #define CUDA_PIXEL_FN __host__ __device__ inline
14#else
15 #define CUDA_PIXEL_FN inline
16#endif
17
18namespace cuda::pixel {
19
21 enum class layout_e : int {
25 };
26
28 struct rgb_t {
29 float r, g, b;
30 };
31
32 CUDA_PIXEL_FN rgb_t unpack(layout_e layout, std::uint32_t word) {
33 switch (layout) {
34 case layout_e::rgb10:
35 return {((word >> 20) & 1023u) / 1023.0f, ((word >> 10) & 1023u) / 1023.0f, (word & 1023u) / 1023.0f};
36 case layout_e::bgr10:
37 return {(word & 1023u) / 1023.0f, ((word >> 10) & 1023u) / 1023.0f, ((word >> 20) & 1023u) / 1023.0f};
38 case layout_e::bgra8:
39 default:
40 return {((word >> 16) & 255u) / 255.0f, ((word >> 8) & 255u) / 255.0f, (word & 255u) / 255.0f};
41 }
42 }
43
44 CUDA_PIXEL_FN rgb_t mix(rgb_t a, rgb_t b, float t) {
45 return {a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, a.b + (b.b - a.b) * t};
46 }
47
48 CUDA_PIXEL_FN rgb_t average(rgb_t a, rgb_t b, rgb_t c, rgb_t d) {
49 return {(a.r + b.r + c.r + d.r) * 0.25f, (a.g + b.g + c.g + d.g) * 0.25f, (a.b + b.b + c.b + d.b) * 0.25f};
50 }
51
56 struct vec4_t {
57 float x, y, z, w;
58 };
59
61 struct alignas(16) matrix_t {
62 vec4_t y, u, v;
63 float range_y[2];
64 float range_uv[2];
65 };
66
67 CUDA_PIXEL_FN float encode(const vec4_t &vec, rgb_t p) {
68 return p.r * vec.x + p.g * vec.y + p.b * vec.z + vec.w;
69 }
70
72 CUDA_PIXEL_FN std::uint32_t quantize(float value, std::uint32_t max_code) {
73 if (!(value > 0.0f)) {
74 return 0;
75 }
76 if (value >= static_cast<float>(max_code)) {
77 return max_code;
78 }
79 return static_cast<std::uint32_t>(value);
80 }
81
83 template<class sample_t>
84 CUDA_PIXEL_FN sample_t store(std::uint32_t code);
85
86 template<>
87 CUDA_PIXEL_FN std::uint8_t store<std::uint8_t>(std::uint32_t code) {
88 return static_cast<std::uint8_t>(code);
89 }
90
91 template<>
92 CUDA_PIXEL_FN std::uint16_t store<std::uint16_t>(std::uint32_t code) {
93 return static_cast<std::uint16_t>(code << 6);
94 }
95
96} // namespace cuda::pixel
std::uint32_t quantize(float value, std::uint32_t max_code)
Truncate a rounded code value into [0, max_code]; NaN becomes 0.
Definition cuda_pixel.h:72
sample_t store(std::uint32_t code)
A sample as stored in the plane: 8-bit codes as they are, P010 codes in bits 15:6.
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
@ bgr10
DRM XBGR2101010 / ABGR2101010: B in bits 29:20, G in 19:10, R in 9:0.
Definition cuda_pixel.h:24
@ rgb10
DRM XRGB2101010 / ARGB2101010: R in bits 29:20, G in 19:10, B in 9:0.
Definition cuda_pixel.h:23
Layout-compatible with video::color_t.
Definition cuda_pixel.h:61
Colour channels normalized to [0, 1].
Definition cuda_pixel.h:28