From: Lynne <dev@lynne.ee> To: ffmpeg-devel@ffmpeg.org Cc: Lynne <dev@lynne.ee> Subject: [FFmpeg-devel] [PATCH 13/16] vulkan_ffv1: pipe through slice decoding status Date: Wed, 14 May 2025 21:02:42 +0200 Message-ID: <20250514190253.162819-13-dev@lynne.ee> (raw) In-Reply-To: <20250514190253.162819-1-dev@lynne.ee> --- libavcodec/vulkan/ffv1_dec.comp | 4 ++ libavcodec/vulkan/ffv1_dec_setup.comp | 4 +- libavcodec/vulkan_decode.c | 1 + libavcodec/vulkan_decode.h | 1 + libavcodec/vulkan_ffv1.c | 60 +++++++++++++++++++-------- 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/libavcodec/vulkan/ffv1_dec.comp b/libavcodec/vulkan/ffv1_dec.comp index e73b3f1dc0..1d33b32c6b 100644 --- a/libavcodec/vulkan/ffv1_dec.comp +++ b/libavcodec/vulkan/ffv1_dec.comp @@ -291,4 +291,8 @@ void main(void) { const uint slice_idx = gl_WorkGroupID.y*gl_NumWorkGroups.x + gl_WorkGroupID.x; decode_slice(slice_ctx[slice_idx], slice_idx); + + uint32_t status = corrupt ? uint32_t(corrupt) : overread; + if (status != 0) + slice_status[2*slice_idx + 1] = status; } diff --git a/libavcodec/vulkan/ffv1_dec_setup.comp b/libavcodec/vulkan/ffv1_dec_setup.comp index a27a878927..671f28e7e7 100644 --- a/libavcodec/vulkan/ffv1_dec_setup.comp +++ b/libavcodec/vulkan/ffv1_dec_setup.comp @@ -133,6 +133,8 @@ void main(void) for (int i = 0; i < slice_size; i++) crc = crc_ieee[(crc & 0xFF) ^ uint32_t(bs[i].v)] ^ (crc >> 8); - slice_crc_mismatch[slice_idx] = crc; + slice_status[2*slice_idx + 0] = crc; } + + slice_status[2*slice_idx + 1] = corrupt ? uint32_t(corrupt) : overread; } diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index f1313c8409..7310ba1547 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -142,6 +142,7 @@ static void init_frame(FFVulkanDecodeContext *dec, FFVulkanDecodePicture *vkpic) vkpic->destroy_image_view = vk->DestroyImageView; vkpic->wait_semaphores = vk->WaitSemaphores; + vkpic->invalidate_memory_ranges = vk->InvalidateMappedMemoryRanges; } int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic, diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h index cbd22b3591..bf6506f280 100644 --- a/libavcodec/vulkan_decode.h +++ b/libavcodec/vulkan_decode.h @@ -114,6 +114,7 @@ typedef struct FFVulkanDecodePicture { /* Vulkan functions needed for destruction, as no other context is guaranteed to exist */ PFN_vkWaitSemaphores wait_semaphores; PFN_vkDestroyImageView destroy_image_view; + PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges; } FFVulkanDecodePicture; /** diff --git a/libavcodec/vulkan_ffv1.c b/libavcodec/vulkan_ffv1.c index efbf5fa953..c839f4c387 100644 --- a/libavcodec/vulkan_ffv1.c +++ b/libavcodec/vulkan_ffv1.c @@ -221,7 +221,7 @@ static int vk_ffv1_start_frame(AVCodecContext *avctx, &fp->slice_status_buf, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT, - NULL, f->slice_count*sizeof(uint32_t), + NULL, 2*f->slice_count*sizeof(uint32_t), VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); if (err < 0) @@ -408,7 +408,7 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx) ff_vk_shader_update_desc_buffer(&ctx->s, exec, &fv->setup, 1, 2, 0, slice_status, - 0, f->slice_count*sizeof(uint32_t), + 0, 2*f->slice_count*sizeof(uint32_t), VK_FORMAT_UNDEFINED); ff_vk_exec_bind_shader(&ctx->s, exec, &fv->setup); @@ -538,10 +538,15 @@ static int vk_ffv1_end_frame(AVCodecContext *avctx) 1, 1, VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE); + ff_vk_shader_update_desc_buffer(&ctx->s, exec, decode_shader, + 1, 2, 0, + slice_status, + 0, 2*f->slice_count*sizeof(uint32_t), + VK_FORMAT_UNDEFINED); if (is_rgb) ff_vk_shader_update_img_array(&ctx->s, exec, decode_shader, f->picture.f, vp->view.out, - 1, 2, + 1, 3, VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE); @@ -700,8 +705,8 @@ static int init_setup_shader(FFV1Context *f, FFVulkanContext *s, .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, .stages = VK_SHADER_STAGE_COMPUTE_BIT, .mem_quali = "writeonly", - .buf_content = "uint32_t slice_crc_mismatch", - .buf_elems = f->max_slice_count, + .buf_content = "uint32_t slice_status", + .buf_elems = 2*f->max_slice_count, }, }; RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0, 0)); @@ -895,6 +900,14 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format), .stages = VK_SHADER_STAGE_COMPUTE_BIT, }, + { + .name = "slice_status_buf", + .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, + .stages = VK_SHADER_STAGE_COMPUTE_BIT, + .mem_quali = "writeonly", + .buf_content = "uint32_t slice_status", + .buf_elems = 2*f->max_slice_count, + }, { .name = "dst", .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, @@ -906,7 +919,7 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, .stages = VK_SHADER_STAGE_COMPUTE_BIT, }, }; - RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2 + rgb, 0, 0)); + RET(ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3 + rgb, 0, 0)); GLSLD(ff_source_ffv1_dec_comp); @@ -1114,22 +1127,35 @@ fail: static void vk_ffv1_free_frame_priv(AVRefStructOpaque _hwctx, void *data) { - AVHWDeviceContext *hwctx = _hwctx.nc; + AVHWDeviceContext *dev_ctx = _hwctx.nc; + AVVulkanDeviceContext *hwctx = dev_ctx->hwctx; FFv1VulkanDecodePicture *fp = data; FFVulkanDecodePicture *vp = &fp->vp; + FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data; - ff_vk_decode_free_frame(hwctx, vp); + ff_vk_decode_free_frame(dev_ctx, vp); + + /* Invalidate slice/output data if needed */ + if (!(slice_status->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) { + VkMappedMemoryRange invalidate_data = { + .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE, + .memory = slice_status->mem, + .offset = 0, + .size = 2*fp->slice_num*sizeof(uint32_t), + }; + vp->invalidate_memory_ranges(hwctx->act_dev, + 1, &invalidate_data); + } - if (fp->crc_checked) { - FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data; - for (int i = 0; i < fp->slice_num; i++) { - uint32_t crc_res; - crc_res = AV_RN32(slice_status->mapped_mem + i*sizeof(uint32_t)); - if (crc_res != 0) - av_log(hwctx, AV_LOG_ERROR, "CRC mismatch in slice %i, res: 0x%x\n", - i, crc_res); - } + for (int i = 0; i < fp->slice_num; i++) { + uint32_t crc_res = 0; + if (fp->crc_checked) + crc_res = AV_RN32(slice_status->mapped_mem + 2*i*sizeof(uint32_t) + 0); + uint32_t status = AV_RN32(slice_status->mapped_mem + 2*i*sizeof(uint32_t) + 4); + if (status || crc_res) + av_log(dev_ctx, AV_LOG_ERROR, "Slice %i status: 0x%x, CRC 0x%x\n", + i, status, crc_res); } av_buffer_unref(&vp->slices_buf); -- 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".
next prev 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 ` [FFmpeg-devel] [PATCH 12/16] vulkan/ffv1: unify encode and decode get/put primitives Lynne 2025-05-14 19:02 ` Lynne [this message] 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-13-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