This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 6f4cef26df78aed84ce6e82e3cc861a8a5b0aa00
Author:     Lynne <[email protected]>
AuthorDate: Wed Feb 4 11:47:39 2026 +0100
Commit:     Lynne <[email protected]>
CommitDate: Thu Feb 19 19:42:28 2026 +0100

    ffv1enc_vulkan: convert reset shader to compile-time SPIR-V generation
---
 libavcodec/ffv1_vulkan.h                           |  11 ---
 libavcodec/ffv1enc_vulkan.c                        | 110 ++++++---------------
 libavcodec/vulkan/Makefile                         |   6 +-
 ...ec_reset.comp.glsl => ffv1_enc_reset.comp.glsl} |   0
 ...b.comp.glsl => ffv1_enc_reset_golomb.comp.glsl} |   2 +-
 libavcodec/vulkan/ffv1_reset.comp                  |  57 -----------
 6 files changed, 37 insertions(+), 149 deletions(-)

diff --git a/libavcodec/ffv1_vulkan.h b/libavcodec/ffv1_vulkan.h
index 5dfd12c3c6..8ec50ca3f1 100644
--- a/libavcodec/ffv1_vulkan.h
+++ b/libavcodec/ffv1_vulkan.h
@@ -56,15 +56,4 @@ typedef struct FFv1ShaderParams {
     int micro_version;
 } FFv1ShaderParams;
 
-typedef struct FFv1VkResetParameters {
-    uint32_t context_count[MAX_QUANT_TABLES];
-    VkDeviceAddress slice_state;
-    uint32_t plane_state_size;
-    uint8_t codec_planes;
-    uint8_t key_frame;
-    uint8_t version;
-    uint8_t micro_version;
-    uint8_t padding[1];
-} FFv1VkResetParameters;
-
 #endif /* AVCODEC_FFV1_VULKAN_H */
diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c
index 933f2e6609..8eac6d47eb 100644
--- a/libavcodec/ffv1enc_vulkan.c
+++ b/libavcodec/ffv1enc_vulkan.c
@@ -110,10 +110,15 @@ extern const char *ff_source_common_comp;
 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_setup_comp;
 extern const char *ff_source_ffv1_enc_comp;
 
+extern const unsigned char ff_ffv1_enc_reset_comp_spv_data[];
+extern const unsigned int ff_ffv1_enc_reset_comp_spv_len;
+
+extern const unsigned char ff_ffv1_enc_reset_golomb_comp_spv_data[];
+extern const unsigned int ff_ffv1_enc_reset_golomb_comp_spv_len;
+
 extern const unsigned char ff_ffv1_enc_rct_search_comp_spv_data[];
 extern const unsigned int ff_ffv1_enc_rct_search_comp_spv_len;
 
@@ -537,25 +542,17 @@ static int vulkan_encode_ffv1_submit_frame(AVCodecContext 
*avctx,
     nb_buf_bar = 0;
 
     /* Run reset shader */
-    FFv1VkResetParameters pd_reset;
     ff_vk_shader_update_desc_buffer(&fv->s, exec, &fv->reset,
                                     1, 0, 0,
                                     slice_data_buf,
                                     0, slice_data_size*f->slice_count,
                                     VK_FORMAT_UNDEFINED);
-    ff_vk_exec_bind_shader(&fv->s, exec, &fv->reset);
-    pd_reset = (FFv1VkResetParameters) {
-        .slice_state = slice_data_buf->address + f->slice_count*256,
-        .plane_state_size = plane_state_size,
-        .codec_planes = f->plane_count,
-        .key_frame = f->key_frame,
-    };
-    for (int i = 0; i < f->quant_table_count; i++)
-        pd_reset.context_count[i] = f->context_count[i];
 
+    ff_vk_exec_bind_shader(&fv->s, exec, &fv->reset);
     ff_vk_shader_update_push_const(&fv->s, exec, &fv->reset,
                                    VK_SHADER_STAGE_COMPUTE_BIT,
-                                   0, sizeof(pd_reset), &pd_reset);
+                                   0, sizeof(FFv1ShaderParams), &pd);
+
     vk->CmdDispatch(exec->buf, fv->ctx.num_h_slices, fv->ctx.num_v_slices,
                     f->plane_count);
 
@@ -1096,91 +1093,48 @@ fail:
     return err;
 }
 
-static int init_reset_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv)
+static int init_reset_shader(AVCodecContext *avctx, VkSpecializationInfo *sl)
 {
     int err;
     VulkanEncodeFFv1Context *fv = avctx->priv_data;
-    FFV1Context *f = &fv->ctx;
     FFVulkanShader *shd = &fv->reset;
-    FFVulkanDescriptorSetBinding *desc_set;
 
-    uint8_t *spv_data;
-    size_t spv_len;
-    void *spv_opaque = NULL;
     int wg_dim = 
FFMIN(fv->s.props.properties.limits.maxComputeWorkGroupSize[0], 1024);
 
-    RET(ff_vk_shader_init(&fv->s, shd, "ffv1_reset",
-                          VK_SHADER_STAGE_COMPUTE_BIT,
-                          (const char *[]) { "GL_EXT_buffer_reference",
-                                             "GL_EXT_buffer_reference2" }, 2,
-                          wg_dim, 1, 1,
-                          0));
-
-    /* Common codec header */
-    GLSLD(ff_source_common_comp);
+    ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
+                      (uint32_t []) { wg_dim, 1, 1 }, 0);
 
-    GLSLC(0, layout(push_constant, scalar) uniform pushConstants {             
);
-    GLSLF(1,    uint context_count[%i];                                        
,MAX_QUANT_TABLES);
-    GLSLC(1,    u8buf slice_state;                                             
);
-    GLSLC(1,    uint plane_state_size;                                         
);
-    GLSLC(1,    uint8_t codec_planes;                                          
);
-    GLSLC(1,    uint8_t key_frame;                                             
);
-    GLSLC(1,    uint8_t version;                                               
);
-    GLSLC(1,    uint8_t micro_version;                                         
);
-    GLSLC(1,    uint8_t padding[1];                                            
);
-    GLSLC(0, };                                                                
);
-    ff_vk_shader_add_push_const(shd, 0, sizeof(FFv1VkResetParameters),
+    ff_vk_shader_add_push_const(shd, 0, sizeof(FFv1ShaderParams),
                                 VK_SHADER_STAGE_COMPUTE_BIT);
 
-    av_bprintf(&shd->src, "#define MAX_QUANT_TABLES %i\n", MAX_QUANT_TABLES);
-    av_bprintf(&shd->src, "#define MAX_CONTEXT_INPUTS %i\n", 
MAX_CONTEXT_INPUTS);
-    av_bprintf(&shd->src, "#define MAX_QUANT_TABLE_SIZE %i\n", 
MAX_QUANT_TABLE_SIZE);
-
-    desc_set = (FFVulkanDescriptorSetBinding []) {
-        {
-            .name        = "rangecoder_static_buf",
-            .type        = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
-            .stages      = VK_SHADER_STAGE_COMPUTE_BIT,
-            .mem_layout  = "scalar",
-            .buf_content = "uint8_t zero_one_state[512];",
-        },
-        {
-            .name        = "quant_buf",
-            .type        = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
-            .stages      = VK_SHADER_STAGE_COMPUTE_BIT,
-            .mem_layout  = "scalar",
-            .buf_content = "int16_t quant_table[MAX_QUANT_TABLES]"
-                           "[MAX_CONTEXT_INPUTS][MAX_QUANT_TABLE_SIZE];",
+    const FFVulkanDescriptorSetBinding desc_set_const[] = {
+        { /* rangecoder_buf */
+            .type   = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
+            .stages = VK_SHADER_STAGE_COMPUTE_BIT,
         },
     };
-    RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 2, 1, 0));
-
-    define_shared_code(avctx, shd);
+    ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set_const, 1, 1, 0);
 
-    desc_set = (FFVulkanDescriptorSetBinding []) {
-        {
-            .name        = "slice_data_buf",
-            .type        = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
-            .mem_quali   = "readonly",
-            .stages      = VK_SHADER_STAGE_COMPUTE_BIT,
-            .buf_content = "SliceContext slice_ctx",
-            .buf_elems   = f->max_slice_count,
+    const FFVulkanDescriptorSetBinding desc_set[] = {
+        { /* slice_data_buf */
+            .type   = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
+            .stages = VK_SHADER_STAGE_COMPUTE_BIT,
         },
     };
-    RET(ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 1, 0, 0));
+    ff_vk_shader_add_descriptor_set(&fv->s, shd, desc_set, 1, 0, 0);
 
-    GLSLD(ff_source_ffv1_reset_comp);
-
-    RET(spv->compile_shader(&fv->s, spv, shd, &spv_data, &spv_len, "main",
-                            &spv_opaque));
-    RET(ff_vk_shader_link(&fv->s, shd, spv_data, spv_len, "main"));
+    if (fv->ctx.ac == AC_GOLOMB_RICE)
+        RET(ff_vk_shader_link(&fv->s, shd,
+                              ff_ffv1_enc_reset_golomb_comp_spv_data,
+                              ff_ffv1_enc_reset_golomb_comp_spv_len, "main"));
+    else
+        RET(ff_vk_shader_link(&fv->s, shd,
+                              ff_ffv1_enc_reset_comp_spv_data,
+                              ff_ffv1_enc_reset_comp_spv_len, "main"));
 
     RET(ff_vk_shader_register_exec(&fv->s, &fv->exec_pool, shd));
 
 fail:
-    if (spv_opaque)
-        spv->free_shader(spv, &spv_opaque);
-
     return err;
 }
 
@@ -1539,7 +1493,7 @@ static av_cold int vulkan_encode_ffv1_init(AVCodecContext 
*avctx)
     }
 
     /* Init reset shader */
-    err = init_reset_shader(avctx, spv);
+    err = init_reset_shader(avctx, sl);
     if (err < 0) {
         spv->uninit(&spv);
         return err;
diff --git a/libavcodec/vulkan/Makefile b/libavcodec/vulkan/Makefile
index 79b5facc51..72cfeb7fd2 100644
--- a/libavcodec/vulkan/Makefile
+++ b/libavcodec/vulkan/Makefile
@@ -3,10 +3,12 @@ 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_common.o \
                                        vulkan/ffv1_enc_setup.o 
vulkan/ffv1_enc.o
 
-OBJS-$(CONFIG_FFV1_VULKAN_ENCODER) += vulkan/ffv1_enc_rct_search.comp.spv.o
+OBJS-$(CONFIG_FFV1_VULKAN_ENCODER) += vulkan/ffv1_enc_reset.comp.spv.o \
+                                      vulkan/ffv1_enc_reset_golomb.comp.spv.o \
+                                      vulkan/ffv1_enc_rct_search.comp.spv.o
 
 OBJS-$(CONFIG_FFV1_VULKAN_HWACCEL) += vulkan/ffv1_dec_setup.comp.spv.o \
                                       vulkan/ffv1_dec_reset.comp.spv.o \
diff --git a/libavcodec/vulkan/ffv1_dec_reset.comp.glsl 
b/libavcodec/vulkan/ffv1_enc_reset.comp.glsl
similarity index 100%
copy from libavcodec/vulkan/ffv1_dec_reset.comp.glsl
copy to libavcodec/vulkan/ffv1_enc_reset.comp.glsl
diff --git a/libavcodec/vulkan/ffv1_dec_golomb.comp.glsl 
b/libavcodec/vulkan/ffv1_enc_reset_golomb.comp.glsl
similarity index 96%
copy from libavcodec/vulkan/ffv1_dec_golomb.comp.glsl
copy to libavcodec/vulkan/ffv1_enc_reset_golomb.comp.glsl
index 4de62a4888..277f88c6c3 100644
--- a/libavcodec/vulkan/ffv1_dec_golomb.comp.glsl
+++ b/libavcodec/vulkan/ffv1_enc_reset_golomb.comp.glsl
@@ -24,4 +24,4 @@
 #extension GL_GOOGLE_include_directive : require
 
 #define GOLOMB
-#include "ffv1_dec.comp.glsl"
+#include "ffv1_enc_reset.comp.glsl"
diff --git a/libavcodec/vulkan/ffv1_reset.comp 
b/libavcodec/vulkan/ffv1_reset.comp
deleted file mode 100644
index cfb7dcc444..0000000000
--- a/libavcodec/vulkan/ffv1_reset.comp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * FFv1 codec
- *
- * Copyright (c) 2024 Lynne <[email protected]>
- *
- * 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 main(void)
-{
-    const uint slice_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + 
gl_WorkGroupID.x;
-
-    if (key_frame == 0 &&
-        slice_ctx[slice_idx].slice_reset_contexts == false)
-        return;
-
-    const uint8_t qidx = 
slice_ctx[slice_idx].quant_table_idx[gl_WorkGroupID.z];
-    uint contexts = context_count[qidx];
-    uint64_t slice_state_off = uint64_t(slice_state) +
-                               slice_idx*plane_state_size*codec_planes;
-
-#ifdef GOLOMB
-    uint64_t start = slice_state_off +
-                     (gl_WorkGroupID.z*(plane_state_size/VLC_STATE_SIZE) + 
gl_LocalInvocationID.x)*VLC_STATE_SIZE;
-    for (uint x = gl_LocalInvocationID.x; x < contexts; x += 
gl_WorkGroupSize.x) {
-        VlcState sb = VlcState(start);
-        sb.drift     =  int16_t(0);
-        sb.error_sum = uint16_t(4);
-        sb.bias      =   int8_t(0);
-        sb.count     =  uint8_t(1);
-        start += gl_WorkGroupSize.x*VLC_STATE_SIZE;
-    }
-#else
-    uint64_t start = slice_state_off +
-                     gl_WorkGroupID.z*plane_state_size +
-                     (gl_LocalInvocationID.x << 2 /* dwords */); /* Bytes */
-    uint count_total = contexts*(CONTEXT_SIZE /* bytes */ >> 2 /* dwords */);
-    for (uint x = gl_LocalInvocationID.x; x < count_total; x += 
gl_WorkGroupSize.x) {
-        u32buf(start).v = 0x80808080;
-        start += gl_WorkGroupSize.x*(CONTEXT_SIZE >> 3 /* 1/8th of context */);
-    }
-#endif
-}

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to