2#include <Gfx/Graph/decoders/GPUVideoDecoder.hpp>
4#include <libavformat/avformat.h>
11 static const constexpr auto rgb_filter = R
"_(#version 450
13)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
15 layout(binding=3) uniform sampler2D y_tex;
17 layout(location = 0) in vec2 v_texcoord;
18 layout(location = 0) out vec4 fragColor;
20 vec4 processTexture(vec4 tex) {
28 fragColor = processTexture(texture(y_tex, v_texcoord));
35 , bytes_per_pixel{bytes_per_pixel}
37 , filter{std::move(f)}
40 QRhiTexture::Format format;
41 int bytes_per_pixel{};
47 auto& rhi = *r.
state.rhi;
48 const auto w = decoder.width, h = decoder.height;
52 auto tex = rhi.newTexture(format, QSize{w, h}, 1, QRhiTexture::Flag{});
56 auto sampler = rhi.newSampler(
57 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
58 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
62 samplers.push_back({sampler, tex});
66 r.
state, vertexShader(), QString(rgb_filter).arg(filter));
69 void exec(
RenderList&, QRhiResourceUpdateBatch& res, AVFrame& frame)
override
72 setPixels(res, frame.data[0], frame.linesize[0]);
76 setPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
78 const auto w = decoder.width, h = decoder.height;
79 auto y_tex = samplers[0].texture;
81 QRhiTextureUploadEntry entry{
84 QRhiTextureUploadDescription desc{entry};
85 res.uploadTexture(y_tex, desc);
91 static const constexpr auto rgb_filter = R
"_(#version 450
93)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
96 layout(location = 0) in vec2 v_texcoord;
97 layout(location = 0) out vec4 fragColor;
99 vec4 processTexture(vec4 tex) {
100 vec4 processed = tex;
109 fragColor = processTexture(tex);
113 QRhiTexture::Format fmt, int bytes_per_pixel, QString planes,
116 , bytes_per_pixel{bytes_per_pixel}
119 , filter{std::move(f)}
122 QRhiTexture::Format format;
123 int bytes_per_pixel{};
130 auto& rhi = *r.
state.rhi;
131 const auto w = decoder.width, h = decoder.height;
133 QString samplers_code;
134 QString read_texture_code;
136 const int binding_orig = 3;
137 for(
int i = 0; i < planes.size(); i++)
139 samplers_code += QString(
140 " layout(binding=%1) uniform sampler2D tconst mat4 "
141 "colorspace_matrix = %2;;\n")
142 .arg(binding_orig + i)
144 read_texture_code += QString(
145 " tex.%1 = texture(tconst mat4 colorspace_matrix = "
146 "%2;, v_texcoord).r;\n")
151 auto tex = rhi.newTexture(format, QSize{w, h}, 1, QRhiTexture::Flag{});
155 auto sampler = rhi.newSampler(
156 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
157 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
161 samplers.push_back({sampler, tex});
165 r.
state, vertexShader(),
166 QString(rgb_filter).arg(samplers_code).arg(filter).arg(read_texture_code));
172 for(
int i = 0; i < planes.size(); i++)
174 setPixels(res, samplers[i].texture, frame.data[i], frame.linesize[i]);
179 QRhiResourceUpdateBatch& res, QRhiTexture* tex, uint8_t* pixels,
180 int stride)
const noexcept
182 const auto w = decoder.width, h = decoder.height;
184 QRhiTextureUploadEntry entry{
187 QRhiTextureUploadDescription desc{entry};
188 res.uploadTexture(tex, desc);
194 static const constexpr auto rgb_filter = R
"_(#version 450
196)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
198 layout(binding=3) uniform sampler2DRect y_tex;
200 layout(location = 0) in vec2 v_texcoord;
201 layout(location = 0) out vec4 fragColor;
203 vec4 processTexture(vec4 tex) {
204 vec4 processed = tex;
211 fragColor = processTexture(texture(y_tex, v_texcoord));
214 static constexpr const char* vertex = R
"_(#version 450
215layout(location = 0) in vec2 position;
216layout(location = 1) in vec2 texcoord;
218layout(location = 0) out vec2 v_texcoord;
220)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
222out gl_PerVertex { vec4 gl_Position; };
226 v_texcoord = texcoord * mat.texSz.xy;
227 gl_Position = renderer.clipSpaceCorrMatrix * vec4(position.x * mat.scale.x, position.y * mat.scale.y, 0.0, 1.);
228#if defined(QSHADER_HLSL) || defined(QSHADER_MSL)
229 gl_Position.y = - gl_Position.y;
238 , bytes_per_pixel{bytes_per_pixel}
240 , filter{std::move(f)}
243 QRhiTexture::Format format;
244 int bytes_per_pixel{};
250 auto& rhi = *r.
state.rhi;
251 const auto w = decoder.width, h = decoder.height;
255 auto tex = rhi.newTexture(format, QSize{w, h}, 1, QRhiTexture::Flag{});
259 auto sampler = rhi.newSampler(
260 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
261 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
265 samplers.push_back({sampler, tex});
274 setPixels(res, frame.data[0], frame.linesize[0]);
278 setPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
280 const auto w = decoder.width, h = decoder.height;
281 auto y_tex = samplers[0].texture;
283 QRhiTextureUploadEntry entry{
286 QRhiTextureUploadDescription desc{entry};
287 res.uploadTexture(y_tex, desc);
293 static const constexpr auto rgb_filter = R
"_(#version 450
295)_" SCORE_GFX_VIDEO_UNIFORMS R"_(
297 layout(binding=3) uniform sampler2D y_tex;
299 layout(location = 0) in vec2 v_texcoord;
300 layout(location = 0) out vec4 fragColor;
302 vec4 processTexture(vec4 tex) {
303 vec4 processed = tex;
310 float w = mat.texSz.x;
311 float h = mat.texSz.y;
312 int x = int(floor(v_texcoord.x * w) * 3.);
313 int y = int(v_texcoord.y * h);
314 float r = texelFetch(y_tex, ivec2(x + 0, y), 0).r;
315 float g = texelFetch(y_tex, ivec2(x + 1, y), 0).r;
316 float b = texelFetch(y_tex, ivec2(x + 2, y), 0).r;
317 fragColor = processTexture(vec4(r, g, b, 1.));
323 , filter{std::move(f)}
326 QRhiTexture::Format format;
327 int bytes_per_pixel{};
333 auto& rhi = *r.
state.rhi;
334 const auto w = decoder.width, h = decoder.height;
338 auto tex = rhi.newTexture(QRhiTexture::R8, QSize{w * 3, h}, 1, QRhiTexture::sRGB);
342 auto sampler = rhi.newSampler(
343 QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
344 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
348 samplers.push_back({sampler, tex});
352 r.
state, vertexShader(), QString(rgb_filter).arg(filter));
358 setPixels(res, frame.data[0], frame.linesize[0]);
362 setPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
364 const auto w = decoder.width, h = decoder.height;
365 auto y_tex = samplers[0].texture;
367 QRhiTextureUploadEntry entry{
370 QRhiTextureUploadDescription desc{entry};
371 res.uploadTexture(y_tex, desc);
Processes and renders a video frame on the GPU.
Definition GPUVideoDecoder.hpp:43
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:19
RenderState & state
RenderState corresponding to this RenderList.
Definition RenderList.hpp:89
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:12
std::pair< QShader, QShader > makeShaders(const RenderState &v, QString vert, QString frag)
Get a pair of compiled vertex / fragment shaders from GLSL 4.5 sources.
Definition score-plugin-gfx/Gfx/Graph/Utils.cpp:390
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition RGBA.hpp:45
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition RGBA.hpp:69
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition RGBA.hpp:271
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition RGBA.hpp:248
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition RGBA.hpp:169
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition RGBA.hpp:128
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition RGBA.hpp:355
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition RGBA.hpp:331