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
215 layout(location = 0) in vec2 position;
216 layout(location = 1) in vec2 texcoord;
218 layout(location = 0) out vec2 v_texcoord;
220 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
222 out 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.);
235 , bytes_per_pixel{bytes_per_pixel}
237 , filter{std::move(f)}
240 QRhiTexture::Format format;
241 int bytes_per_pixel{};
247 auto& rhi = *r.
state.rhi;
248 const auto w = decoder.width, h = decoder.height;
252 auto tex = rhi.newTexture(format, QSize{w, h}, 1, QRhiTexture::Flag{});
256 auto sampler = rhi.newSampler(
257 QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
258 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
262 samplers.push_back({sampler, tex});
271 setPixels(res, frame.data[0], frame.linesize[0]);
275 setPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
277 const auto w = decoder.width, h = decoder.height;
278 auto y_tex = samplers[0].texture;
280 QRhiTextureUploadEntry entry{
283 QRhiTextureUploadDescription desc{entry};
284 res.uploadTexture(y_tex, desc);
290 static const constexpr
auto rgb_filter = R
"_(#version 450
292 )_" SCORE_GFX_VIDEO_UNIFORMS R"_(
294 layout(binding=3) uniform sampler2D y_tex;
296 layout(location = 0) in vec2 v_texcoord;
297 layout(location = 0) out vec4 fragColor;
299 vec4 processTexture(vec4 tex) {
300 vec4 processed = tex;
307 float w = mat.texSz.x;
308 float h = mat.texSz.y;
309 int x = int(floor(v_texcoord.x * w) * 3.);
310 int y = int(v_texcoord.y * h);
311 float r = texelFetch(y_tex, ivec2(x + 0, y), 0).r;
312 float g = texelFetch(y_tex, ivec2(x + 1, y), 0).r;
313 float b = texelFetch(y_tex, ivec2(x + 2, y), 0).r;
314 fragColor = processTexture(vec4(r, g, b, 1.));
320 , filter{std::move(f)}
323 QRhiTexture::Format format;
324 int bytes_per_pixel{};
330 auto& rhi = *r.
state.rhi;
331 const auto w = decoder.width, h = decoder.height;
335 auto tex = rhi.newTexture(QRhiTexture::R8, QSize{w * 3, h}, 1, QRhiTexture::sRGB);
339 auto sampler = rhi.newSampler(
340 QRhiSampler::Nearest, QRhiSampler::Nearest, QRhiSampler::None,
341 QRhiSampler::ClampToEdge, QRhiSampler::ClampToEdge);
345 samplers.push_back({sampler, tex});
349 r.
state, vertexShader(), QString(rgb_filter).arg(filter));
355 setPixels(res, frame.data[0], frame.linesize[0]);
359 setPixels(QRhiResourceUpdateBatch& res, uint8_t* pixels,
int stride)
const noexcept
361 const auto w = decoder.width, h = decoder.height;
362 auto y_tex = samplers[0].texture;
364 QRhiTextureUploadEntry entry{
367 QRhiTextureUploadDescription desc{entry};
368 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:342
void exec(RenderList &, QRhiResourceUpdateBatch &res, AVFrame &frame) override
Decode and upload a video frame to the GPU.
Definition: RGBA.hpp:69
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:268
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition: RGBA.hpp:245
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:352
std::pair< QShader, QShader > init(RenderList &r) override
Initialize a GPUVideoDecoder.
Definition: RGBA.hpp:328