Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Lynne <dev@lynne.ee>
To: ffmpeg-devel@ffmpeg.org
Cc: Lynne <dev@lynne.ee>
Subject: [FFmpeg-devel] [PATCH 04/16] ffv1enc_vulkan: unify EC code between setup and encode
Date: Wed, 14 May 2025 21:02:33 +0200
Message-ID: <20250514190253.162819-4-dev@lynne.ee> (raw)
In-Reply-To: <20250514190253.162819-1-dev@lynne.ee>

---
 libavcodec/ffv1enc_vulkan.c           |  1 +
 libavcodec/vulkan/ffv1_enc.comp       |  7 -------
 libavcodec/vulkan/ffv1_enc_setup.comp | 10 +++++-----
 libavcodec/vulkan/rangecoder.comp     | 23 +++++++++++------------
 4 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c
index d78ba3aca8..956463e932 100644
--- a/libavcodec/ffv1enc_vulkan.c
+++ b/libavcodec/ffv1enc_vulkan.c
@@ -976,6 +976,7 @@ static int init_setup_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv)
     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);
+    av_bprintf(&shd->src, "#define FULL_RENORM\n");
 
     desc_set = (FFVulkanDescriptorSetBinding []) {
         {
diff --git a/libavcodec/vulkan/ffv1_enc.comp b/libavcodec/vulkan/ffv1_enc.comp
index 7f8c831efa..a3c22f7459 100644
--- a/libavcodec/vulkan/ffv1_enc.comp
+++ b/libavcodec/vulkan/ffv1_enc.comp
@@ -63,13 +63,6 @@ ivec2 get_pred(readonly uimage2D pred, ivec2 sp, ivec2 off, int comp, int sw, ui
 }
 
 #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)
 {
diff --git a/libavcodec/vulkan/ffv1_enc_setup.comp b/libavcodec/vulkan/ffv1_enc_setup.comp
index d395770ba8..6f21e47523 100644
--- a/libavcodec/vulkan/ffv1_enc_setup.comp
+++ b/libavcodec/vulkan/ffv1_enc_setup.comp
@@ -50,18 +50,18 @@ void init_slice(out SliceContext sc, const uint slice_idx)
 void put_usymbol(inout RangeCoder c, uint v)
 {
     bool is_nil = (v == 0);
-    put_rac(c, state[0], is_nil);
+    put_rac_direct(c, state[0], is_nil);
     if (is_nil)
         return;
 
     const int e = findMSB(v);
 
     for (int i = 0; i < e; i++)
-        put_rac(c, state[1 + min(i, 9)], true);
-    put_rac(c, state[1 + min(e, 9)], false);
+        put_rac_direct(c, state[1 + min(i, 9)], true);
+    put_rac_direct(c, state[1 + min(e, 9)], false);
 
     for (int i = e - 1; i >= 0; i--)
-        put_rac(c, state[22 + min(i, 9)], bool(bitfieldExtract(v, i, 1)));
+        put_rac_direct(c, state[22 + min(i, 9)], bool(bitfieldExtract(v, i, 1)));
 }
 
 void write_slice_header(inout SliceContext sc)
@@ -83,7 +83,7 @@ void write_slice_header(inout SliceContext sc)
     put_usymbol(sc.c, sar.y);
 
     if (version >= 4) {
-        put_rac(sc.c, state[0], sc.slice_reset_contexts);
+        put_rac_direct(sc.c, state[0], sc.slice_reset_contexts);
         put_usymbol(sc.c, sc.slice_coding_mode);
         if (sc.slice_coding_mode != 1 && colorspace == 1) {
             put_usymbol(sc.c, sc.slice_rct_coef.y);
diff --git a/libavcodec/vulkan/rangecoder.comp b/libavcodec/vulkan/rangecoder.comp
index 1db42e1dc9..badc65293f 100644
--- a/libavcodec/vulkan/rangecoder.comp
+++ b/libavcodec/vulkan/rangecoder.comp
@@ -31,8 +31,9 @@ struct RangeCoder {
     uint8_t outstanding_byte;
 };
 
+#ifdef FULL_RENORM
 /* Full renorm version that can handle outstanding_byte == 0xFF */
-void renorm_encoder_full(inout RangeCoder c)
+void renorm_encoder(inout RangeCoder c)
 {
     int bs_cnt = 0;
     u8buf bytestream = u8buf(c.bytestream);
@@ -62,6 +63,8 @@ void renorm_encoder_full(inout RangeCoder c)
     c.low = bitfieldInsert(0, c.low, 8, 8);
 }
 
+#else
+
 /* Cannot deal with outstanding_byte == -1 in the name of speed */
 void renorm_encoder(inout RangeCoder c)
 {
@@ -90,8 +93,9 @@ void renorm_encoder(inout RangeCoder c)
     for (int i = 1; i < oc; i++)
         bs[i].v = fill;
 }
+#endif
 
-void put_rac_direct(inout RangeCoder c, uint8_t state, bool bit)
+void put_rac_direct(inout RangeCoder c, inout uint8_t state, bool bit)
 {
     int range1 = uint16_t((c.range * state) >> 8);
 
@@ -111,21 +115,16 @@ void put_rac_direct(inout RangeCoder c, uint8_t state, bool bit)
     } else {
         c.range  = diff;
     }
-}
 
-void put_rac_norenorm(inout RangeCoder c, uint64_t state, bool bit)
-{
-    put_rac_direct(c, u8buf(state).v, bit);
+    if (c.range < 0x100)
+        renorm_encoder(c);
 
-    u8buf(state).v = zero_one_state[(uint(bit) << 8) + u8buf(state).v];
+    state = zero_one_state[(uint(bit) << 8) + state];
 }
 
-void put_rac(inout RangeCoder c, inout uint8_t state, bool bit)
+void put_rac(inout RangeCoder c, uint64_t state, bool bit)
 {
-    put_rac_direct(c, state, bit);
-    if (c.range < 0x100)
-        renorm_encoder_full(c);
-    state = zero_one_state[(uint(bit) << 8) + state];
+    put_rac_direct(c, u8buf(state).v, bit);
 }
 
 /* Equiprobable bit */
-- 
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-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2025-05-14 19:03 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-14 19:02 [FFmpeg-devel] [PATCH 01/16] ffv1enc_vulkan: merge all encoder variants into one file Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 02/16] vulkan/ffv1: synchronize get_pred implementations between encoder and decoder Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 03/16] ffv1enc_vulkan: get rid of temporary data for the setup shader Lynne
2025-05-14 19:02 ` Lynne [this message]
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 05/16] ffv1enc_vulkan: minor EC optimizations Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 06/16] ffv1enc_vulkan: switch to 2-line cache, unify prediction code Lynne
2025-05-23 14:38   ` [FFmpeg-devel] [PATCH] ffv1enc_vulkan: fix array overflow Jerome Martinez
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 07/16] ffv1_common: minor RGB optimization Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 08/16] ffv1enc_vulkan: use ff_get_encode_buffer Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 09/16] vulkan_ffv1: fix PCM + cached symbol reader Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 10/16] ffv1enc_vulkan: implement the cached EC writer from the decoder Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 11/16] ffv1enc_vulkan: implement RCT search for level >= 4 Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 12/16] vulkan/ffv1: unify encode and decode get/put primitives Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 13/16] vulkan_ffv1: pipe through slice decoding status Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 14/16] vulkan: enable VK_KHR_shader_subgroup_rotate Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 15/16] hwcontext_vulkan: correct image transfer usage flags Lynne
2025-05-14 19:02 ` [FFmpeg-devel] [PATCH 16/16] hwcontext_vulkan: only try exporting DMABUF memory on !WIN32 and only for DMABUF tiling Lynne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250514190253.162819-4-dev@lynne.ee \
    --to=dev@lynne.ee \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git