Files
ffmpeg/libavcodec/vulkan/ffv1_dec_rct.comp
Lynne 6bad55eb17 ffv1: add a Vulkan-based decoder
This patch adds a fully-featured level 3 and 4 decoder for FFv1,
supporting Golomb and all Range coding variants, all pixel formats,
and all features, except for the newly added floating-point formats.

On a 6000 Ada, for 3840x2160 bgr0 content at 50Mbps (standard desktop
recording), it is able to do 400fps.
An Alder Lake with 24 threads can barely do 100fps.
2025-03-17 08:51:23 +01:00

89 lines
2.8 KiB
Plaintext

/*
* FFv1 codec
*
* Copyright (c) 2025 Lynne <dev@lynne.ee>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
void bypass_block(in SliceContext sc)
{
ivec2 start = ivec2(gl_LocalInvocationID) + sc.slice_pos;
ivec2 end = sc.slice_pos + sc.slice_dim;
for (uint y = start.y; y < end.y; y += gl_WorkGroupSize.y) {
for (uint x = start.x; x < end.x; x += gl_WorkGroupSize.x) {
ivec2 pos = ivec2(x, y);
ivec4 pix;
for (int i = 0; i < color_planes; i++)
pix[i] = int(imageLoad(src[i], pos)[0]);
imageStore(dst[0], pos, pix);
if (planar_rgb != 0) {
for (int i = 1; i < color_planes; i++)
imageStore(dst[i], pos, ivec4(pix[i]));
}
}
}
}
void transform_sample(ivec2 pos, ivec2 rct_coef)
{
ivec4 pix;
pix.r = int(imageLoad(src[2], pos)[0]);
pix.g = int(imageLoad(src[0], pos)[0]);
pix.b = int(imageLoad(src[1], pos)[0]);
if (transparency != 0)
pix.a = int(imageLoad(src[3], pos)[0]);
pix.b -= offset;
pix.r -= offset;
pix.g -= (pix.b*rct_coef.y + pix.r*rct_coef.x) >> 2;
pix.b += pix.g;
pix.r += pix.g;
pix = ivec4(pix[fmt_lut[0]], pix[fmt_lut[1]],
pix[fmt_lut[2]], pix[fmt_lut[3]]);
imageStore(dst[0], pos, pix);
if (planar_rgb != 0) {
for (int i = 1; i < color_planes; i++)
imageStore(dst[i], pos, ivec4(pix[i]));
}
}
void transform_block(in SliceContext sc)
{
const ivec2 rct_coef = sc.slice_rct_coef;
const ivec2 start = ivec2(gl_LocalInvocationID) + sc.slice_pos;
const ivec2 end = sc.slice_pos + sc.slice_dim;
for (uint y = start.y; y < end.y; y += gl_WorkGroupSize.y)
for (uint x = start.x; x < end.x; x += gl_WorkGroupSize.x)
transform_sample(ivec2(x, y), rct_coef);
}
void main()
{
const uint slice_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x;
if (slice_ctx[slice_idx].slice_coding_mode == 1)
bypass_block(slice_ctx[slice_idx]);
else
transform_block(slice_ctx[slice_idx]);
}