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 v2 09/12] vulkan: unify handling of BGR and simplify ffv1_rct
Date: Mon, 24 Feb 2025 09:04:22 +0100
Message-ID: <20250224080434.5632-9-dev@lynne.ee> (raw)
In-Reply-To: <20250224080434.5632-1-dev@lynne.ee>

---
 libavcodec/ffv1_vulkan.h            |  1 +
 libavcodec/ffv1enc_vulkan.c         |  2 ++
 libavcodec/vulkan/ffv1_enc_rct.comp | 17 ++++++-------
 libavutil/vulkan.c                  | 38 +++++++++++++++++++++++++++++
 libavutil/vulkan.h                  |  6 +++++
 5 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/libavcodec/ffv1_vulkan.h b/libavcodec/ffv1_vulkan.h
index 0da6dc2d33..599afae66e 100644
--- a/libavcodec/ffv1_vulkan.h
+++ b/libavcodec/ffv1_vulkan.h
@@ -37,6 +37,7 @@ int ff_ffv1_vk_init_crc_table_data(FFVulkanContext *s,
                                    FFVkBuffer *vkb, FFV1Context *f);
 
 typedef struct FFv1VkRCTParameters {
+    int fmt_lut[4];
     int offset;
     uint8_t bits;
     uint8_t planar_rgb;
diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c
index 88801ca8e6..225d478fb7 100644
--- a/libavcodec/ffv1enc_vulkan.c
+++ b/libavcodec/ffv1enc_vulkan.c
@@ -264,6 +264,7 @@ static int run_rct(AVCodecContext *avctx, FFVkExecContext *exec,
                       (ff_vk_count_images((AVVkFrame *)enc_in->data[0]) > 1),
         .transparency = f->transparency,
     };
+    ff_vk_set_perm(src_hwfc->sw_format, pd.fmt_lut);
     ff_vk_shader_update_push_const(&fv->s, exec, &fv->rct,
                                    VK_SHADER_STAGE_COMPUTE_BIT,
                                    0, sizeof(pd), &pd);
@@ -1157,6 +1158,7 @@ static int init_rct_shader(AVCodecContext *avctx, FFVkSPIRVCompiler *spv)
     GLSLD(ff_source_common_comp);
 
     GLSLC(0, layout(push_constant, scalar) uniform pushConstants {             );
+    GLSLC(1,    ivec4 fmt_lut;                                                 );
     GLSLC(1,    int offset;                                                    );
     GLSLC(1,    uint8_t bits;                                                  );
     GLSLC(1,    uint8_t planar_rgb;                                            );
diff --git a/libavcodec/vulkan/ffv1_enc_rct.comp b/libavcodec/vulkan/ffv1_enc_rct.comp
index a615381c90..b611f4be98 100644
--- a/libavcodec/vulkan/ffv1_enc_rct.comp
+++ b/libavcodec/vulkan/ffv1_enc_rct.comp
@@ -22,17 +22,14 @@
 
 ivec4 load_components(ivec2 pos)
 {
-    if (planar_rgb == 0)
-        return ivec4(imageLoad(src[0], pos));
+    ivec4 pix = ivec4(imageLoad(src[0], pos));
+    if (planar_rgb != 0) {
+        for (int i = 1; i < (3 + transparency); i++)
+            pix[i] = int(imageLoad(src[i], pos)[0]);
+    }
 
-    ivec4 pix;
-    for (int i = 0; i < (3 + transparency); i++)
-        pix[i] = int(imageLoad(src[i], pos)[0]);
-
-    /* Swizzle out the difference */
-    if (bits > 8 && bits < 16 && transparency == 0)
-        return pix.bgra;
-    return pix.brga;
+    return ivec4(pix[fmt_lut[0]], pix[fmt_lut[1]],
+                 pix[fmt_lut[2]], pix[fmt_lut[3]]);
 }
 
 void bypass_sample(ivec2 pos)
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 40ca737422..26d7e9e600 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1468,6 +1468,44 @@ int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
     return 0;
 }
 
+void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4])
+{
+    switch (pix_fmt) {
+    case AV_PIX_FMT_BGRA:
+    case AV_PIX_FMT_BGR0:
+    case AV_PIX_FMT_BGR565:
+    case AV_PIX_FMT_X2BGR10:
+        lut[0] = 2;
+        lut[1] = 1;
+        lut[2] = 0;
+        lut[3] = 3;
+        return;
+    case AV_PIX_FMT_GBRAP:
+    case AV_PIX_FMT_GBRP:
+    case AV_PIX_FMT_GBRAP10:
+    case AV_PIX_FMT_GBRAP12:
+    case AV_PIX_FMT_GBRAP14:
+    case AV_PIX_FMT_GBRAP16:
+    case AV_PIX_FMT_GBRP10:
+    case AV_PIX_FMT_GBRP12:
+    case AV_PIX_FMT_GBRP14:
+    case AV_PIX_FMT_GBRP16:
+    case AV_PIX_FMT_GBRPF32:
+    case AV_PIX_FMT_GBRAPF32:
+        lut[0] = 2;
+        lut[1] = 0;
+        lut[2] = 1;
+        lut[3] = 3;
+        return;
+    default:
+        lut[0] = 0;
+        lut[1] = 1;
+        lut[2] = 2;
+        lut[3] = 3;
+        return;
+    }
+}
+
 const char *ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt,
                                  enum FFVkShaderRepFormat rep_fmt)
 {
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 327ce2b286..1be432ed5e 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -371,6 +371,12 @@ const char *ff_vk_ret2str(VkResult res);
  */
 int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt);
 
+/**
+ * Since storage images may not be swizzled, we have to do this in the
+ * shader itself. This fills in a lookup table to do it.
+ */
+void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4]);
+
 /**
  * Get the aspect flag for a plane from an image.
  */
-- 
2.47.2
_______________________________________________
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-02-24  8:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24  8:04 [FFmpeg-devel] [PATCH v2 01/12] ffv1enc_vulkan: disable autodetection of async_depth Lynne
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 02/12] vulkan: add ff_vk_create_imageview Lynne
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 03/12] vulkan: copy host-mapping buffer code from hwcontext Lynne
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 04/12] vulkan_decode: support software-defined decoders Lynne
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 05/12] vulkan_decode: support multiple image views Lynne
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 06/12] hwcontext_vulkan: enable read/write without storage Lynne
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 07/12] vulkan: workaround BGR storage image undefined behaviour Lynne
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 08/12] ffv1enc_vulkan: refactor shaders slightly to support sharing Lynne
2025-02-24  8:04 ` Lynne [this message]
2025-02-24  8:04 ` [FFmpeg-devel] [PATCH v2 10/12] ffv1dec: add support for hwaccels Lynne
2025-02-24  8:05 ` [FFmpeg-devel] [PATCH v2 11/12] ffv1dec: reference the current packet into the main context Lynne
2025-02-24  8:05   ` [FFmpeg-devel] [PATCH v2 12/12] ffv1dec_vulkan: add a Vulkan compute-based hardware decoding implementation 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=20250224080434.5632-9-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