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 12/16] vulkan/ffv1: unify encode and decode get/put primitives
Date: Wed, 14 May 2025 21:02:41 +0200
Message-ID: <20250514190253.162819-12-dev@lynne.ee> (raw)
In-Reply-To: <20250514190253.162819-1-dev@lynne.ee>

This simply makes a get_rac/put_rac_internal variant that can be
reused.
---
 libavcodec/vulkan/rangecoder.comp | 57 +++++++++----------------------
 1 file changed, 17 insertions(+), 40 deletions(-)

diff --git a/libavcodec/vulkan/rangecoder.comp b/libavcodec/vulkan/rangecoder.comp
index 9e2c5fbecf..8687b8bc3c 100644
--- a/libavcodec/vulkan/rangecoder.comp
+++ b/libavcodec/vulkan/rangecoder.comp
@@ -95,26 +95,26 @@ void renorm_encoder(inout RangeCoder c)
 }
 #endif
 
-void put_rac_direct(inout RangeCoder c, inout uint8_t state, bool bit)
+void put_rac_internal(inout RangeCoder c, const int range1, bool bit)
 {
-    int range1 = uint16_t((c.range * state) >> 8);
-
 #ifdef DEBUG
-    if (state == 0)
-        debugPrintfEXT("Error: state is zero");
     if (range1 >= c.range)
         debugPrintfEXT("Error: range1 >= c.range");
     if (range1 <= 0)
         debugPrintfEXT("Error: range1 <= 0");
 #endif
 
-    int diff = c.range - range1;
-    c.low += bit ? diff : 0;
-    c.range = bit ? range1 : diff;
+    int ranged = c.range - range1;
+    c.low += bit ? ranged : 0;
+    c.range = bit ? range1 : ranged;
 
     if (expectEXT(c.range < 0x100, false))
         renorm_encoder(c);
+}
 
+void put_rac_direct(inout RangeCoder c, inout uint8_t state, bool bit)
+{
+    put_rac_internal(c, (c.range * state) >> 8, bit);
     state = zero_one_state[(uint(bit) << 8) + state];
 }
 
@@ -126,21 +126,7 @@ void put_rac(inout RangeCoder c, uint64_t state, bool bit)
 /* Equiprobable bit */
 void put_rac_equi(inout RangeCoder c, bool bit)
 {
-    int range1 = c.range >> 1;
-
-#ifdef DEBUG
-    if (range1 >= c.range)
-        debugPrintfEXT("Error: range1 >= c.range");
-    if (range1 <= 0)
-        debugPrintfEXT("Error: range1 <= 0");
-#endif
-
-    int diff = c.range - range1;
-    c.low += bit ? diff : 0;
-    c.range = bit ? range1 : diff;
-
-    if (expectEXT(c.range < 0x100, false))
-        renorm_encoder(c);
+    put_rac_internal(c, c.range >> 1, bit);
 }
 
 void put_rac_terminate(inout RangeCoder c)
@@ -224,11 +210,9 @@ void refill(inout RangeCoder c)
     }
 }
 
-bool get_rac_direct(inout RangeCoder c, inout uint8_t state)
+bool get_rac_internal(inout RangeCoder c, const int range1)
 {
-    int range1 = c.range * state >> 8;
     int ranged = c.range - range1;
-
     bool bit = c.low >= ranged;
     c.low -= bit ? ranged : 0;
     c.range = (bit ? 0 : ranged) + (bit ? range1 : 0);
@@ -236,6 +220,12 @@ bool get_rac_direct(inout RangeCoder c, inout uint8_t state)
     if (expectEXT(c.range < 0x100, false))
         refill(c);
 
+    return bit;
+}
+
+bool get_rac_direct(inout RangeCoder c, inout uint8_t state)
+{
+    bool bit = get_rac_internal(c, c.range * state >> 8);
     state = zero_one_state[state + (bit ? 256 : 0)];
     return bit;
 }
@@ -247,18 +237,5 @@ bool get_rac(inout RangeCoder c, uint64_t state)
 
 bool get_rac_equi(inout RangeCoder c)
 {
-    int range1 = c.range >> 1;
-
-    c.range -= range1;
-
-    bool bit = c.low >= c.range;
-    if (bit) {
-        c.low -= c.range;
-        c.range = range1;
-    }
-
-    if (expectEXT(c.range < 0x100, false))
-        refill(c);
-
-    return bit;
+    return get_rac_internal(c, c.range >> 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-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2025-05-14 19:05 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 ` [FFmpeg-devel] [PATCH 04/16] ffv1enc_vulkan: unify EC code between setup and encode Lynne
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 ` Lynne [this message]
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-12-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