1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

vulkan_ffv1: pipe through slice decoding status

This commit is contained in:
Lynne
2025-05-06 11:53:12 +02:00
parent cb8f4b675d
commit 7b45d9c5fd
5 changed files with 52 additions and 18 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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,

View File

@ -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;
/**

View File

@ -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);
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);
}
/* 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);
}
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);