Loading...
Searching...
No Matches
GPUVideoEncoder.hpp
1#pragma once
2#include <Gfx/Graph/RenderList.hpp>
3#include <Gfx/Graph/RenderState.hpp>
4#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
6
7namespace score::gfx
8{
9
30{
31 virtual ~GPUVideoEncoder() = default;
32
41 virtual void init(
42 QRhi& rhi, const RenderState& state, QRhiTexture* inputRGBA, int width, int height,
43 const QString& colorConversion)
44 = 0;
45
48 virtual void exec(QRhi& rhi, QRhiCommandBuffer& cb) = 0;
49
51 virtual int planeCount() const = 0;
52
54 virtual const QRhiReadbackResult& readback(int plane) const = 0;
55
60 virtual QRhiTexture* outputTexture() const noexcept { return nullptr; }
61
65 virtual void setReadbackEnabled(bool) noexcept {}
66
68 virtual void release() = 0;
69
74 static constexpr const char* vertex_shader = R"_(#version 450
75 layout(location = 0) out vec2 v_texcoord;
76 out gl_PerVertex { vec4 gl_Position; };
77 void main() {
78 vec2 pos = vec2(
79 float((gl_VertexIndex & 1) * 4 - 1),
80 float((gl_VertexIndex & 2) * 2 - 1)
81 );
82 v_texcoord = pos * 0.5 + 0.5;
83 gl_Position = vec4(pos, 0.0, 1.0);
84 }
85 )_";
86
91 static constexpr const char* rgb_to_yuv_glsl = R"_(
92 const vec3 yuv_offset = vec3(0.0, 0.5, 0.5);
93 vec3 rgb_to_yuv(vec3 rgb) {
94 return vec3(
95 dot(rgb, vec3( 0.2126, 0.7152, 0.0722)),
96 dot(rgb, vec3(-0.1146, -0.3854, 0.5 )),
97 dot(rgb, vec3( 0.5, -0.4542, -0.0458))
98 ) + yuv_offset;
99 }
100 )_";
101
103 static constexpr const char* y_flip_glsl = R"_(
104 vec2 flip_y(vec2 tc) {
105 // Only OpenGL. The rest of the engine puts its geometry through
106 // renderer.clipSpaceCorrMatrix, which negates Y on Vulkan; this pass draws
107 // a hardcoded triangle in raw NDC and does not, so the correction it needs
108 // is not the same one. Flipping on Vulkan as well handed libav, GStreamer,
109 // NDI and every other consumer an upside-down picture.
110 #if defined(QSHADER_SPIRV) || defined(QSHADER_MSL) || defined(QSHADER_HLSL)
111 return tc;
112 #else
113 return vec2(tc.x, 1.0 - tc.y);
114 #endif
115 }
116 )_";
117};
118
119} // namespace score::gfx
GPU shader generation for RGB->YUV color space conversion (output/encoding).
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Base class for GPU-side video format conversion (RGBA to YUV).
Definition GPUVideoEncoder.hpp:30
static constexpr const char * y_flip_glsl
Fragment shader Y-flip: on GL, flip v_texcoord.y. On Metal/HLSL, no flip.
Definition GPUVideoEncoder.hpp:103
static constexpr const char * vertex_shader
Definition GPUVideoEncoder.hpp:74
static constexpr const char * rgb_to_yuv_glsl
Definition GPUVideoEncoder.hpp:91
virtual const QRhiReadbackResult & readback(int plane) const =0
Get the readback result for a given plane. Valid after endOffscreenFrame.
virtual void setReadbackEnabled(bool) noexcept
Definition GPUVideoEncoder.hpp:65
virtual void exec(QRhi &rhi, QRhiCommandBuffer &cb)=0
virtual int planeCount() const =0
Number of readback planes (1 for UYVY, 2 for NV12, 3 for I420).
virtual void init(QRhi &rhi, const RenderState &state, QRhiTexture *inputRGBA, int width, int height, const QString &colorConversion)=0
virtual QRhiTexture * outputTexture() const noexcept
Definition GPUVideoEncoder.hpp:60
virtual void release()=0
Release all GPU resources.
Global state associated to a rendering context.
Definition RenderState.hpp:37