2#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
21 static const constexpr auto frag = R
"_(#version 450
23)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
25layout(binding=3) uniform sampler2D y_tex;
26layout(binding=4) uniform sampler2D a_tex;
28layout(location = 0) in vec2 v_texcoord;
29layout(location = 0) out vec4 fragColor;
33vec4 processTexture(vec4 tex) {
34 vec4 processed = convert_to_rgb(tex);
40 // UYVY packs U0 Y0 V0 Y1 into RGBA as x=U0 y=Y0 z=V0 w=Y1, so the texture
41 // is half the width of the picture and each texel is two pixels.
42 float colIndex = floor(v_texcoord.x * mat.texSz.x);
43 float oddCol = mod(colIndex, 2.0);
45 vec2 tc = score_tc(v_texcoord);
46 vec2 dxInput = 0.5 * vec2(1.0 / mat.texSz.x, 0.0);
48 float oddY = texture(y_tex, tc - dxInput).w;
49 float evenY = texture(y_tex, tc + dxInput).y;
50 float y = mix(evenY, oddY, oddCol);
51 vec2 uv = texture(y_tex, tc).xz;
53 // The alpha plane is full resolution, so it samples at the picture
54 // coordinate rather than the half-width one.
55 float a = texture(a_tex, tc).r;
57 vec4 rgb = processTexture(vec4(y, uv.x, uv.y, 1.));
58 fragColor = vec4(rgb.rgb, a);
71 auto& rhi = *r.
state.rhi;
72 const auto w = decoder.width, h = decoder.height;
74 auto mkSampler = [&] {
75 auto sampler = rhi.newSampler(
76 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
77 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
83 auto tex = rhi.newTexture(QRhiTexture::RGBA8, {w / 2, h}, 1, QRhiTexture::Flag{});
85 samplers.push_back({mkSampler(), tex});
88 auto tex = rhi.newTexture(QRhiTexture::R8, {w, h}, 1, QRhiTexture::Flag{});
90 samplers.push_back({mkSampler(), tex});
94 r.
state, vertexShader(), QString(frag).arg(
"").arg(colorMatrix(decoder)));
97 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
100 const auto [rows, offset] = planeRows(decoder, frame, decoder.height);
102 frame.data[0], decoder.width / 2, rows, 4, frame.linesize[0]);
103 sub.setDestinationTopLeft({0, offset});
104 res.uploadTexture(samplers[0].texture, QRhiTextureUploadDescription{{0, 0, sub}});
107 const auto [rows, offset] = planeRows(decoder, frame, decoder.height);
109 frame.data[1], decoder.width, rows, 1, frame.linesize[1]);
110 sub.setDestinationTopLeft({0, offset});
111 res.uploadTexture(samplers[1].texture, QRhiTextureUploadDescription{{0, 0, sub}});
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:137
static QRhiTextureSubresourceUploadDescription createTextureUpload(uint8_t *pixels, int w, int h, int bytesPerPixel, int stride)
Utility method to create a QRhiTextureSubresourceUploadDescription.
Definition GPUVideoDecoder.cpp:22
List of nodes to be rendered to an output.
Definition RenderList.hpp:33
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:259
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag, int multiViewCount)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:1303
NDI UYVA: a UYVY 4:2:2 plane, then a full-resolution alpha plane.
Definition UYVA.hpp:20
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition UYVA.hpp:69
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition UYVA.hpp:97