Makes it easier to work with, despite the heavy ifdeffery. --- libavcodec/ffv1enc_vulkan.c | 21 +-- libavcodec/vulkan/Makefile | 4 +- libavcodec/vulkan/ffv1_enc.comp | 240 ++++++++++++++++++++++++- libavcodec/vulkan/ffv1_enc_ac.comp | 83 --------- libavcodec/vulkan/ffv1_enc_common.comp | 101 ----------- libavcodec/vulkan/ffv1_enc_rgb.comp | 83 --------- libavcodec/vulkan/ffv1_enc_vlc.comp | 112 ------------ 7 files changed, 244 insertions(+), 400 deletions(-) delete mode 100644 libavcodec/vulkan/ffv1_enc_ac.comp delete mode 100644 libavcodec/vulkan/ffv1_enc_common.comp delete mode 100644 libavcodec/vulkan/ffv1_enc_rgb.comp delete mode 100644 libavcodec/vulkan/ffv1_enc_vlc.comp
diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c index 42a98a5efa..f4b54b8375 100644 --- a/libavcodec/ffv1enc_vulkan.c +++ b/libavcodec/ffv1enc_vulkan.c @@ -114,13 +114,9 @@ extern const char *ff_source_rangecoder_comp; extern const char *ff_source_ffv1_vlc_comp; extern const char *ff_source_ffv1_common_comp; extern const char *ff_source_ffv1_reset_comp; -extern const char *ff_source_ffv1_enc_common_comp; extern const char *ff_source_ffv1_enc_rct_comp; -extern const char *ff_source_ffv1_enc_vlc_comp; -extern const char *ff_source_ffv1_enc_ac_comp; extern const char *ff_source_ffv1_enc_setup_comp; extern const char *ff_source_ffv1_enc_comp; -extern const char *ff_source_ffv1_enc_rgb_comp; typedef struct FFv1VkParameters { VkDeviceAddress slice_state; @@ -961,6 +957,9 @@ static void define_shared_code(AVCodecContext *avctx, FFVulkanShader *shd) av_bprintf(&shd->src, "#define GOLOMB\n" ); } + if (fv->is_rgb) + av_bprintf(&shd->src, "#define RGB\n"); + GLSLF(0, #define TYPE int%i_t ,smp_bits); GLSLF(0, #define VTYPE2 i%ivec2 ,smp_bits); GLSLF(0, #define VTYPE3 i%ivec3 ,smp_bits); @@ -1260,7 +1259,6 @@ static int init_encode_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) { int err; VulkanEncodeFFv1Context *fv = avctx->priv_data; - FFV1Context *f = &fv->ctx; FFVulkanShader *shd = &fv->enc; FFVulkanDescriptorSetBinding *desc_set; @@ -1344,18 +1342,7 @@ static int init_encode_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv) }; RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 3, 0, 0)); - /* Assemble the shader body */ - GLSLD(ff_source_ffv1_enc_common_comp); - - if (f->ac == AC_GOLOMB_RICE) - GLSLD(ff_source_ffv1_enc_vlc_comp); - else - GLSLD(ff_source_ffv1_enc_ac_comp); - - if (fv->is_rgb) - GLSLD(ff_source_ffv1_enc_rgb_comp); - else - GLSLD(ff_source_ffv1_enc_comp); + GLSLD(ff_source_ffv1_enc_comp); RET(spv->compile_shader(&fv->s, spv, shd, &spv_data, &spv_len, "main", &spv_opaque)); diff --git a/libavcodec/vulkan/Makefile b/libavcodec/vulkan/Makefile index feb5d2ea51..4bbcb38c6a 100644 --- a/libavcodec/vulkan/Makefile +++ b/libavcodec/vulkan/Makefile @@ -6,10 +6,8 @@ clean:: OBJS-$(CONFIG_FFV1_VULKAN_ENCODER) += vulkan/common.o \ vulkan/rangecoder.o vulkan/ffv1_vlc.o \ vulkan/ffv1_common.o vulkan/ffv1_reset.o \ - vulkan/ffv1_enc_common.o \ vulkan/ffv1_enc_rct.o vulkan/ffv1_enc_setup.o \ - vulkan/ffv1_enc_vlc.o vulkan/ffv1_enc_ac.o \ - vulkan/ffv1_enc.o vulkan/ffv1_enc_rgb.o + vulkan/ffv1_enc.o OBJS-$(CONFIG_FFV1_VULKAN_HWACCEL) += vulkan/common.o \ vulkan/rangecoder.o vulkan/ffv1_vlc.o \ diff --git a/libavcodec/vulkan/ffv1_enc.comp b/libavcodec/vulkan/ffv1_enc.comp index 4b851fd711..9854ecad51 100644 --- a/libavcodec/vulkan/ffv1_enc.comp +++ b/libavcodec/vulkan/ffv1_enc.comp @@ -20,12 +20,186 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +ivec2 get_diff(ivec2 pos, ivec2 off, int p, int comp, int sw, int bits) +{ + const ivec2 yoff_border1 = off.x == 0 ? ivec2(1, -1) : ivec2(0, 0); + const ivec2 yoff_border2 = off.x == 1 ? ivec2(1, -1) : ivec2(0, 0); + + TYPE top2 = TYPE(0); + if (off.y > 1) + top2 = TYPE(imageLoad(src[p], pos + ivec2(0, -2))[comp]); + + VTYPE3 top = VTYPE3(TYPE(0), + TYPE(0), + TYPE(0)); + if (off.y > 0 && off != ivec2(0, 1)) + top[0] = TYPE(imageLoad(src[p], pos + ivec2(-1, -1) + yoff_border1)[comp]); + if (off.y > 0) { + top[1] = TYPE(imageLoad(src[p], pos + ivec2(0, -1))[comp]); + top[2] = TYPE(imageLoad(src[p], pos + ivec2(min(1, sw - off.x - 1), -1))[comp]); + } + + VTYPE3 cur = VTYPE3(TYPE(0), + TYPE(0), + imageLoad(src[p], pos)[comp]); + if (off.x > 0 && off != ivec2(1, 0)) + cur[0] = TYPE(imageLoad(src[p], pos + ivec2(-2, 0) + yoff_border2)[comp]); + if (off != ivec2(0, 0)) + cur[1] = TYPE(imageLoad(src[p], pos + ivec2(-1, 0) + yoff_border1)[comp]); + + /* context, diff */ + ivec2 d = ivec2(get_context(VTYPE2(cur), top, top2, context_model), + cur[2] - predict(cur[1], VTYPE2(top))); + + if (d[0] < 0) + d = -d; + + d[1] = fold(d[1], bits); + + return d; +} + +#ifndef GOLOMB +void put_rac(inout RangeCoder c, uint64_t state, bool bit) +{ + put_rac_norenorm(c, state, bit); + if (c.range < 0x100) + renorm_encoder(c); +} + +/* Note - only handles signed values */ +void put_symbol(inout RangeCoder c, uint64_t state, int v) +{ + bool is_nil = (v == 0); + put_rac(c, state, is_nil); + if (is_nil) + return; + + const int a = abs(v); + const int e = findMSB(a); + + state += 1; + for (int i = 0; i < e; i++) + put_rac(c, state + min(i, 9), true); + put_rac(c, state + min(e, 9), false); + + state += 21; + for (int i = e - 1; i >= 0; i--) + put_rac(c, state + min(i, 9), bool(bitfieldExtract(a, i, 1))); + + put_rac(c, state - 11 + min(e, 10), v < 0); +} + +void encode_line_pcm(inout SliceContext sc, int y, int p, int comp, + int bits) +{ + ivec2 sp = sc.slice_pos; + int w = sc.slice_dim.x; + if (p > 0 && p < 3) { + w >>= chroma_shift.x; + sp >>= chroma_shift; + } + + for (int x = 0; x < w; x++) { + uint v = imageLoad(src[p], (sp + ivec2(x, y)))[comp]; + for (int i = (bits - 1); i >= 0; i--) + put_rac_equi(sc.c, bool(bitfieldExtract(v, i, 1))); + } +} + +void encode_line(inout SliceContext sc, uint64_t state, + int y, int p, int comp, int bits, const int run_index) +{ + ivec2 sp = sc.slice_pos; + + int w = sc.slice_dim.x; + if (p > 0 && p < 3) { + w >>= chroma_shift.x; + sp >>= chroma_shift; + } + + for (int x = 0; x < w; x++) { + const ivec2 d = get_diff(sp + ivec2(x, y), ivec2(x, y), p, comp, w, bits); + put_symbol(sc.c, state + CONTEXT_SIZE*d[0], d[1]); + } +} + +#else /* GOLOMB */ + +void encode_line(inout SliceContext sc, uint64_t state, + int y, int p, int comp, int bits, inout int run_index) +{ + ivec2 sp = sc.slice_pos; + + int w = sc.slice_dim.x; + if (p > 0 && p < 3) { + w >>= chroma_shift.x; + sp >>= chroma_shift; + } + + int run_count = 0; + bool run_mode = false; + + for (int x = 0; x < w; x++) { + ivec2 d = get_diff(sp + ivec2(x, y), ivec2(x, y), p, comp, w, bits); + + if (d[0] == 0) + run_mode = true; + + if (run_mode) { + if (d[1] != 0) { + /* A very unlikely loop */ + while (run_count >= 1 << log2_run[run_index]) { + run_count -= 1 << log2_run[run_index]; + run_index++; + put_bits(sc.pb, 1, 1); + } + + put_bits(sc.pb, 1 + log2_run[run_index], run_count); + if (run_index != 0) + run_index--; + run_count = 0; + run_mode = false; + if (d[1] > 0) + d[1]--; + } else { + run_count++; + } + } + + if (!run_mode) { + VlcState sb = VlcState(state + VLC_STATE_SIZE*d[0]); + Symbol sym = get_vlc_symbol(sb, d[1], bits); + put_bits(sc.pb, sym.bits, sym.val); + } + } + + if (run_mode) { + while (run_count >= (1 << log2_run[run_index])) { + run_count -= 1 << log2_run[run_index]; + run_index++; + put_bits(sc.pb, 1, 1); + } + + if (run_count > 0) + put_bits(sc.pb, 1, 1); + } +} +#endif + void encode_slice(inout SliceContext sc, const uint slice_idx) { +#ifndef RGB int bits = bits_per_raw_sample; +#else + int bits = 9; + if (bits != 8 || sc.slice_coding_mode != 0) + bits = bits_per_raw_sample + int(sc.slice_coding_mode != 1); +#endif #ifndef GOLOMB if (sc.slice_coding_mode == 1) { +#ifndef RGB for (int c = 0; c < components; c++) { int h = sc.slice_dim.y; @@ -39,12 +213,22 @@ void encode_slice(inout SliceContext sc, const uint slice_idx) for (int y = 0; y < h; y++) encode_line_pcm(sc, y, p, comp, bits); } +#else + for (int y = 0; y < sc.slice_dim.y; y++) { + encode_line_pcm(sc, y, 0, 1, bits); + encode_line_pcm(sc, y, 0, 2, bits); + encode_line_pcm(sc, y, 0, 0, bits); + if (transparency == 1) + encode_line_pcm(sc, y, 0, 3, bits); + } +#endif } else #endif { uint64_t slice_state_off = uint64_t(slice_state) + slice_idx*plane_state_size*codec_planes; +#ifndef RGB for (int c = 0; c < components; c++) { int run_index = 0; @@ -62,13 +246,67 @@ void encode_slice(inout SliceContext sc, const uint slice_idx) if (c != 1) slice_state_off += plane_state_size; } +#else + int run_index = 0; + for (int y = 0; y < sc.slice_dim.y; y++) { + encode_line(sc, slice_state_off + plane_state_size*0, + y, 0, 1, bits, run_index); + encode_line(sc, slice_state_off + plane_state_size*1, + y, 0, 2, bits, run_index); + encode_line(sc, slice_state_off + plane_state_size*1, + y, 0, 0, bits, run_index); + if (transparency == 1) + encode_line(sc, slice_state_off + plane_state_size*2, + y, 0, 3, bits, run_index); + } +#endif + } +} + +void finalize_slice(inout SliceContext sc, const uint slice_idx) +{ +#ifdef GOLOMB + uint32_t enc_len = sc.hdr_len + flush_put_bits(sc.pb); +#else + uint32_t enc_len = rac_terminate(sc.c); +#endif + + u8buf bs = u8buf(sc.c.bytestream_start); + + /* Append slice length */ + u8vec4 enc_len_p = unpack8(enc_len); + bs[enc_len + 0].v = enc_len_p.z; + bs[enc_len + 1].v = enc_len_p.y; + bs[enc_len + 2].v = enc_len_p.x; + enc_len += 3; + + /* Calculate and write CRC */ + if (ec != 0) { + bs[enc_len].v = uint8_t(0); + enc_len++; + + uint32_t crc = crcref; + for (int i = 0; i < enc_len; i++) + crc = crc_ieee[(crc & 0xFF) ^ uint32_t(bs[i].v)] ^ (crc >> 8); + + if (crcref != 0x00000000) + crc ^= 0x8CD88196; + + u8vec4 crc_p = unpack8(crc); + bs[enc_len + 0].v = crc_p.x; + bs[enc_len + 1].v = crc_p.y; + bs[enc_len + 2].v = crc_p.z; + bs[enc_len + 3].v = crc_p.w; + enc_len += 4; } - finalize_slice(sc, slice_idx); + slice_results[slice_idx*2 + 0] = enc_len; + slice_results[slice_idx*2 + 1] = uint64_t(bs) - uint64_t(out_data); } void main(void) { const uint slice_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x; encode_slice(slice_ctx[slice_idx], slice_idx); + finalize_slice(slice_ctx[slice_idx], slice_idx); } diff --git a/libavcodec/vulkan/ffv1_enc_ac.comp b/libavcodec/vulkan/ffv1_enc_ac.comp deleted file mode 100644 index 0bbf58c5dd..0000000000 --- a/libavcodec/vulkan/ffv1_enc_ac.comp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2024 Lynne <d...@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 put_rac(inout RangeCoder c, uint64_t state, bool bit) -{ - put_rac_norenorm(c, state, bit); - if (c.range < 0x100) - renorm_encoder(c); -} - -/* Note - only handles signed values */ -void put_symbol(inout RangeCoder c, uint64_t state, int v) -{ - bool is_nil = (v == 0); - put_rac(c, state, is_nil); - if (is_nil) - return; - - const int a = abs(v); - const int e = findMSB(a); - - state += 1; - for (int i = 0; i < e; i++) - put_rac(c, state + min(i, 9), true); - put_rac(c, state + min(e, 9), false); - - state += 21; - for (int i = e - 1; i >= 0; i--) - put_rac(c, state + min(i, 9), bool(bitfieldExtract(a, i, 1))); - - put_rac(c, state - 11 + min(e, 10), v < 0); -} - -void encode_line_pcm(inout SliceContext sc, int y, int p, int comp, - int bits) -{ - ivec2 sp = sc.slice_pos; - int w = sc.slice_dim.x; - if (p > 0 && p < 3) { - w >>= chroma_shift.x; - sp >>= chroma_shift; - } - - for (int x = 0; x < w; x++) { - uint v = imageLoad(src[p], (sp + ivec2(x, y)))[comp]; - for (int i = (bits - 1); i >= 0; i--) - put_rac_equi(sc.c, bool(bitfieldExtract(v, i, 1))); - } -} - -void encode_line(inout SliceContext sc, uint64_t state, - int y, int p, int comp, int bits, const int run_index) -{ - ivec2 sp = sc.slice_pos; - - int w = sc.slice_dim.x; - if (p > 0 && p < 3) { - w >>= chroma_shift.x; - sp >>= chroma_shift; - } - - for (int x = 0; x < w; x++) { - const ivec2 d = get_diff(sp + ivec2(x, y), ivec2(x, y), p, comp, w, bits); - put_symbol(sc.c, state + CONTEXT_SIZE*d[0], d[1]); - } -} diff --git a/libavcodec/vulkan/ffv1_enc_common.comp b/libavcodec/vulkan/ffv1_enc_common.comp deleted file mode 100644 index 62c0624b0e..0000000000 --- a/libavcodec/vulkan/ffv1_enc_common.comp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * FFv1 codec - * - * Copyright (c) 2024 Lynne <d...@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 - */ - -ivec2 get_diff(ivec2 pos, ivec2 off, int p, int comp, int sw, int bits) -{ - const ivec2 yoff_border1 = off.x == 0 ? ivec2(1, -1) : ivec2(0, 0); - const ivec2 yoff_border2 = off.x == 1 ? ivec2(1, -1) : ivec2(0, 0); - - TYPE top2 = TYPE(0); - if (off.y > 1) - top2 = TYPE(imageLoad(src[p], pos + ivec2(0, -2))[comp]); - - VTYPE3 top = VTYPE3(TYPE(0), - TYPE(0), - TYPE(0)); - if (off.y > 0 && off != ivec2(0, 1)) - top[0] = TYPE(imageLoad(src[p], pos + ivec2(-1, -1) + yoff_border1)[comp]); - if (off.y > 0) { - top[1] = TYPE(imageLoad(src[p], pos + ivec2(0, -1))[comp]); - top[2] = TYPE(imageLoad(src[p], pos + ivec2(min(1, sw - off.x - 1), -1))[comp]); - } - - VTYPE3 cur = VTYPE3(TYPE(0), - TYPE(0), - imageLoad(src[p], pos)[comp]); - if (off.x > 0 && off != ivec2(1, 0)) - cur[0] = TYPE(imageLoad(src[p], pos + ivec2(-2, 0) + yoff_border2)[comp]); - if (off != ivec2(0, 0)) - cur[1] = TYPE(imageLoad(src[p], pos + ivec2(-1, 0) + yoff_border1)[comp]); - - /* context, diff */ - ivec2 d = ivec2(get_context(VTYPE2(cur), top, top2, context_model), - cur[2] - predict(cur[1], VTYPE2(top))); - - if (d[0] < 0) - d = -d; - - d[1] = fold(d[1], bits); - - return d; -} - -void finalize_slice(inout SliceContext sc, const uint slice_idx) -{ -#ifdef GOLOMB - uint32_t enc_len = sc.hdr_len + flush_put_bits(sc.pb); -#else - uint32_t enc_len = rac_terminate(sc.c); -#endif - - u8buf bs = u8buf(sc.c.bytestream_start); - - /* Append slice length */ - u8vec4 enc_len_p = unpack8(enc_len); - bs[enc_len + 0].v = enc_len_p.z; - bs[enc_len + 1].v = enc_len_p.y; - bs[enc_len + 2].v = enc_len_p.x; - enc_len += 3; - - /* Calculate and write CRC */ - if (ec != 0) { - bs[enc_len].v = uint8_t(0); - enc_len++; - - uint32_t crc = crcref; - for (int i = 0; i < enc_len; i++) - crc = crc_ieee[(crc & 0xFF) ^ uint32_t(bs[i].v)] ^ (crc >> 8); - - if (crcref != 0x00000000) - crc ^= 0x8CD88196; - - u8vec4 crc_p = unpack8(crc); - bs[enc_len + 0].v = crc_p.x; - bs[enc_len + 1].v = crc_p.y; - bs[enc_len + 2].v = crc_p.z; - bs[enc_len + 3].v = crc_p.w; - enc_len += 4; - } - - slice_results[slice_idx*2 + 0] = enc_len; - slice_results[slice_idx*2 + 1] = uint64_t(bs) - uint64_t(out_data); -} diff --git a/libavcodec/vulkan/ffv1_enc_rgb.comp b/libavcodec/vulkan/ffv1_enc_rgb.comp deleted file mode 100644 index c176d94e8b..0000000000 --- a/libavcodec/vulkan/ffv1_enc_rgb.comp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * FFv1 codec - * - * Copyright (c) 2024 Lynne <d...@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 encode_slice_rgb(inout SliceContext sc, const uint slice_idx) -{ - int bits = 9; - if (bits != 8 || sc.slice_coding_mode != 0) - bits = bits_per_raw_sample + int(sc.slice_coding_mode != 1); - - int run_index = 0; - -#ifndef GOLOMB - if (sc.slice_coding_mode == 1) { - if (transparency == 1) { - for (int y = 0; y < sc.slice_dim.y; y++) { - encode_line_pcm(sc, y, 0, 1, bits); - encode_line_pcm(sc, y, 0, 2, bits); - encode_line_pcm(sc, y, 0, 0, bits); - encode_line_pcm(sc, y, 0, 3, bits); - } - } else { - for (int y = 0; y < sc.slice_dim.y; y++) { - encode_line_pcm(sc, y, 0, 1, bits); - encode_line_pcm(sc, y, 0, 2, bits); - encode_line_pcm(sc, y, 0, 0, bits); - } - } - } else -#endif - { - uint64_t slice_state_off = uint64_t(slice_state) + - slice_idx*plane_state_size*codec_planes; - - if (transparency == 1) { - for (int y = 0; y < sc.slice_dim.y; y++) { - encode_line(sc, slice_state_off + plane_state_size*0, - y, 0, 1, bits, run_index); - encode_line(sc, slice_state_off + plane_state_size*1, - y, 0, 2, bits, run_index); - encode_line(sc, slice_state_off + plane_state_size*1, - y, 0, 0, bits, run_index); - encode_line(sc, slice_state_off + plane_state_size*2, - y, 0, 3, bits, run_index); - } - } else { - for (int y = 0; y < sc.slice_dim.y; y++) { - encode_line(sc, slice_state_off + plane_state_size*0, - y, 0, 1, bits, run_index); - encode_line(sc, slice_state_off + plane_state_size*1, - y, 0, 2, bits, run_index); - encode_line(sc, slice_state_off + plane_state_size*1, - y, 0, 0, bits, run_index); - } - } - } - - finalize_slice(sc, slice_idx); -} - -void main(void) -{ - const uint slice_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x; - encode_slice_rgb(slice_ctx[slice_idx], slice_idx); -} diff --git a/libavcodec/vulkan/ffv1_enc_vlc.comp b/libavcodec/vulkan/ffv1_enc_vlc.comp deleted file mode 100644 index 7a4d39e307..0000000000 --- a/libavcodec/vulkan/ffv1_enc_vlc.comp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * FFv1 codec - * - * Copyright (c) 2024 Lynne <d...@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 - */ - -struct RLEState { - int count; - int diff; - int index; - bool mode; -}; - -void calc_new_state(inout RLEState state, int context) -{ - if (context == 0) - state.mode = false; - - if (!state.mode) - return; - - if (state.diff > 0) { - while (state.count >= (1 << log2_run[state.index])) { - state.count -= 1 << log2_run[state.index]; - state.index++; - } - if (state.index > 0) - state.index--; - state.count = 0; - state.mode = false; - if (state.diff > 0) - state.diff--; - } else { - state.count++; - } -} - -void encode_line(inout SliceContext sc, uint64_t state, - int y, int p, int comp, int bits, inout int run_index) -{ - ivec2 sp = sc.slice_pos; - - int w = sc.slice_dim.x; - if (p > 0 && p < 3) { - w >>= chroma_shift.x; - sp >>= chroma_shift; - } - - int run_count = 0; - bool run_mode = false; - - for (int x = 0; x < w; x++) { - ivec2 d = get_diff(sp + ivec2(x, y), ivec2(x, y), p, comp, w, bits); - - if (d[0] == 0) - run_mode = true; - - if (run_mode) { - if (d[1] != 0) { - /* A very unlikely loop */ - while (run_count >= 1 << log2_run[run_index]) { - run_count -= 1 << log2_run[run_index]; - run_index++; - put_bits(sc.pb, 1, 1); - } - - put_bits(sc.pb, 1 + log2_run[run_index], run_count); - if (run_index != 0) - run_index--; - run_count = 0; - run_mode = false; - if (d[1] > 0) - d[1]--; - } else { - run_count++; - } - } - - if (!run_mode) { - VlcState sb = VlcState(state + VLC_STATE_SIZE*d[0]); - Symbol sym = get_vlc_symbol(sb, d[1], bits); - put_bits(sc.pb, sym.bits, sym.val); - } - } - - if (run_mode) { - while (run_count >= (1 << log2_run[run_index])) { - run_count -= 1 << log2_run[run_index]; - run_index++; - put_bits(sc.pb, 1, 1); - } - - if (run_count > 0) - put_bits(sc.pb, 1, 1); - } -} -- 2.49.0.395.g12beb8f557c _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".