--- 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-requ...@ffmpeg.org with subject "unsubscribe".