From: Lynne <dev@lynne.ee> To: ffmpeg-devel@ffmpeg.org Cc: Lynne <dev@lynne.ee> Subject: [FFmpeg-devel] [PATCH 09/13] vulkan: unify handling of BGR and simplify ffv1_rct Date: Mon, 10 Mar 2025 04:08:28 +0100 Message-ID: <20250310030837.60814-9-dev@lynne.ee> (raw) In-Reply-To: <20250310030837.60814-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 17a93834f3..f8fe3bec1a 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 7b0f77b076..24af8d5753 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -1478,6 +1478,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] = 1; + lut[1] = 0; + lut[2] = 2; + 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 89fc4eedc5..2a2a5916a5 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".
next prev parent reply other threads:[~2025-03-10 3:10 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-03-10 3:08 [FFmpeg-devel] [PATCH 01/13] vulkan: rename ff_vk_set_descriptor_image to ff_vk_shader_update_img Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 02/13] vulkan: add ff_vk_create_imageview Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 03/13] vulkan: copy host-mapping buffer code from hwcontext Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 04/13] vulkan: workaround BGR storage image undefined behaviour Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 05/13] vulkan_decode: support software-defined decoders Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 06/13] vulkan_decode: support multiple image views Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 07/13] vulkan_decode: adjust number of async contexts created Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 08/13] ffv1enc_vulkan: refactor shaders slightly to support sharing Lynne 2025-03-10 3:08 ` Lynne [this message] 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 10/13] ffv1dec: add support for hwaccels Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 11/13] ffv1dec: reference the current packet into the main context Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 12/13] vulkan: add ff_vk_exec_add_dep_wait_sem() Lynne 2025-03-10 3:08 ` [FFmpeg-devel] [PATCH 13/13] ffv1: add a Vulkan-based decoder Lynne 2025-03-10 3:14 ` [FFmpeg-devel] [PATCH 11/13] ffv1dec: reference the current packet into the main context Andreas Rheinhardt
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=20250310030837.60814-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