diff options
author | Lynne <dev@lynne.ee> | 2025-05-06 11:53:12 +0200 |
---|---|---|
committer | Lynne <dev@lynne.ee> | 2025-05-20 19:53:02 +0900 |
commit | 7b45d9c5fdce010bbd00be1fb506685f6885a35b (patch) | |
tree | fcd311496e60a659c540ddabfdc749d2da897e7a /libavcodec/vulkan_ffv1.c | |
parent | cb8f4b675d1e1074ddb6fe2bbb965933fb9e3571 (diff) | |
download | ffmpeg-7b45d9c5fdce010bbd00be1fb506685f6885a35b.tar.gz |
vulkan_ffv1: pipe through slice decoding status
Diffstat (limited to 'libavcodec/vulkan_ffv1.c')
-rw-r--r-- | libavcodec/vulkan_ffv1.c | 60 |
1 files changed, 43 insertions, 17 deletions
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)); @@ -896,6 +901,14 @@ static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, .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, .dimensions = 2, @@ -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); |