From: Lynne <dev@lynne.ee> To: ffmpeg-devel@ffmpeg.org Cc: Lynne <dev@lynne.ee> Subject: [FFmpeg-devel] [PATCH 1/6] vulkan_decode: generalize handling of slice offsets/nb Date: Mon, 31 Mar 2025 04:37:37 +0200 Message-ID: <20250331023753.285499-1-dev@lynne.ee> (raw) This allows for the upcoming refactor. --- libavcodec/vulkan_av1.c | 6 +++--- libavcodec/vulkan_decode.c | 23 ++++++----------------- libavcodec/vulkan_decode.h | 5 +++-- libavcodec/vulkan_ffv1.c | 22 ++++++++-------------- libavcodec/vulkan_h264.c | 9 +++------ libavcodec/vulkan_hevc.c | 6 +++--- 6 files changed, 26 insertions(+), 45 deletions(-) diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c index ccb88004b5..13df24a44b 100644 --- a/libavcodec/vulkan_av1.c +++ b/libavcodec/vulkan_av1.c @@ -577,9 +577,7 @@ static int vk_av1_decode_slice(AVCodecContext *avctx, err = ff_vk_decode_add_slice(avctx, vp, data + s->tile_group_info[i].tile_offset, - s->tile_group_info[i].tile_size, 0, - &ap->av1_pic_info.tileCount, - &ap->av1_pic_info.pTileOffsets); + s->tile_group_info[i].tile_size, 0); if (err < 0) return err; } @@ -616,6 +614,8 @@ static int vk_av1_end_frame(AVCodecContext *avctx) } #endif + ap->av1_pic_info.pTileOffsets = vp->slice_offsets; + ap->av1_pic_info.tileCount = vp->nb_slices; if (!ap->av1_pic_info.tileCount) return 0; diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 93aa0ce5b3..48a206e3c0 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -249,33 +249,23 @@ int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic, } int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, - const uint8_t *data, size_t size, int add_startcode, - uint32_t *nb_slices, const uint32_t **offsets) + const uint8_t *data, size_t size, int add_startcode) { FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; FFVulkanDecodeShared *ctx = dec->shared_ctx; static const uint8_t startcode_prefix[3] = { 0x0, 0x0, 0x1 }; const size_t startcode_len = add_startcode ? sizeof(startcode_prefix) : 0; - const int nb = nb_slices ? *nb_slices : 0; uint8_t *slices; - uint32_t *slice_off; FFVkBuffer *vkbuf; size_t new_size = vp->slices_size + startcode_len + size + ctx->caps.minBitstreamBufferSizeAlignment; new_size = FFALIGN(new_size, ctx->caps.minBitstreamBufferSizeAlignment); - if (offsets) { - slice_off = av_fast_realloc(dec->slice_off, &dec->slice_off_max, - (nb + 1)*sizeof(slice_off)); - if (!slice_off) - return AVERROR(ENOMEM); - - *offsets = dec->slice_off = slice_off; - - slice_off[nb] = vp->slices_size; - } + /* Should never happen */ + if (vp->nb_slices > FF_ARRAY_ELEMS(vp->slice_offsets)) + return AVERROR(EINVAL); vkbuf = vp->slices_buf ? (FFVkBuffer *)vp->slices_buf->data : NULL; if (!vkbuf || vkbuf->size < new_size) { @@ -321,9 +311,8 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, /* Slice data */ memcpy(slices + vp->slices_size + startcode_len, data, size); - if (nb_slices) - *nb_slices = nb + 1; - + vp->slice_offsets[vp->nb_slices] = vp->slices_size; + vp->nb_slices = vp->nb_slices + 1; vp->slices_size += startcode_len + size; return 0; diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h index cbd22b3591..4bd755c1f6 100644 --- a/libavcodec/vulkan_decode.h +++ b/libavcodec/vulkan_decode.h @@ -110,6 +110,8 @@ typedef struct FFVulkanDecodePicture { /* Slice data */ AVBufferRef *slices_buf; size_t slices_size; + uint32_t slice_offsets[1024]; + uint32_t nb_slices; /* Vulkan functions needed for destruction, as no other context is guaranteed to exist */ PFN_vkWaitSemaphores wait_semaphores; @@ -158,8 +160,7 @@ int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic, * Add slice data to frame. */ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, - const uint8_t *data, size_t size, int add_startcode, - uint32_t *nb_slices, const uint32_t **offsets); + const uint8_t *data, size_t size, int add_startcode); /** * Decode a frame. diff --git a/libavcodec/vulkan_ffv1.c b/libavcodec/vulkan_ffv1.c index 17bfc943d4..7eb51b0dab 100644 --- a/libavcodec/vulkan_ffv1.c +++ b/libavcodec/vulkan_ffv1.c @@ -55,8 +55,6 @@ typedef struct FFv1VulkanDecodePicture { uint32_t max_context_count; AVBufferRef *slice_offset_buf; - uint32_t *slice_offset; - int slice_num; AVBufferRef *slice_status_buf; int crc_checked; @@ -163,8 +161,6 @@ static int vk_ffv1_start_frame(AVCodecContext *avctx, int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) && !(sw_format == AV_PIX_FMT_YA8); - fp->slice_num = 0; - for (int i = 0; i < f->quant_table_count; i++) fp->max_context_count = FFMAX(f->context_count[i], fp->max_context_count); @@ -278,22 +274,20 @@ static int vk_ffv1_decode_slice(AVCodecContext *avctx, if (ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY) { FFVkBuffer *slices_buf = (FFVkBuffer *)vp->slices_buf->data; - AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 0)*sizeof(uint32_t), + AV_WN32(slice_offset->mapped_mem + (2*vp->nb_slices + 0)*sizeof(uint32_t), data - slices_buf->mapped_mem); - AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 1)*sizeof(uint32_t), + AV_WN32(slice_offset->mapped_mem + (2*vp->nb_slices + 1)*sizeof(uint32_t), size); - fp->slice_num++; + vp->nb_slices++; } else { - int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0, - &fp->slice_num, - (const uint32_t **)&fp->slice_offset); + int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0); if (err < 0) return err; - AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 0)*sizeof(uint32_t), - fp->slice_offset[fp->slice_num - 1]); - AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 1)*sizeof(uint32_t), + AV_WN32(slice_offset->mapped_mem + (2*(vp->nb_slices - 1) + 0)*sizeof(uint32_t), + vp->slice_offsets[vp->nb_slices - 1]); + AV_WN32(slice_offset->mapped_mem + (2*(vp->nb_slices - 1) + 1)*sizeof(uint32_t), size); } @@ -1280,7 +1274,7 @@ static void vk_ffv1_free_frame_priv(AVRefStructOpaque _hwctx, void *data) if (fp->crc_checked) { FFVkBuffer *slice_status = (FFVkBuffer *)fp->slice_status_buf->data; - for (int i = 0; i < fp->slice_num; i++) { + for (int i = 0; i < vp->nb_slices; i++) { uint32_t crc_res; crc_res = AV_RN32(slice_status->mapped_mem + i*sizeof(uint32_t)); if (crc_res != 0) diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c index 73aaed7f6a..af37e0800b 100644 --- a/libavcodec/vulkan_h264.c +++ b/libavcodec/vulkan_h264.c @@ -491,9 +491,7 @@ static int vk_h264_decode_slice(AVCodecContext *avctx, H264VulkanDecodePicture *hp = h->cur_pic_ptr->hwaccel_picture_private; FFVulkanDecodePicture *vp = &hp->vp; - int err = ff_vk_decode_add_slice(avctx, vp, data, size, 1, - &hp->h264_pic_info.sliceCount, - &hp->h264_pic_info.pSliceOffsets); + int err = ff_vk_decode_add_slice(avctx, vp, data, size, 1); if (err < 0) return err; @@ -541,12 +539,11 @@ static int vk_h264_end_frame(AVCodecContext *avctx) } #endif + hp->h264_pic_info.pSliceOffsets = vp->slice_offsets; + hp->h264_pic_info.sliceCount = vp->nb_slices; if (!hp->h264_pic_info.sliceCount) return 0; - if (!vp->slices_buf) - return AVERROR(EINVAL); - if (!dec->session_params && !(ctx->s.extensions & FF_VK_EXT_VIDEO_MAINTENANCE_2)) { int err = vk_h264_create_params(avctx, &dec->session_params); diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index e4a946ae0d..e95f554756 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -842,9 +842,7 @@ static int vk_hevc_decode_slice(AVCodecContext *avctx, HEVCVulkanDecodePicture *hp = h->cur_frame->hwaccel_picture_private; FFVulkanDecodePicture *vp = &hp->vp; - int err = ff_vk_decode_add_slice(avctx, vp, data, size, 1, - &hp->h265_pic_info.sliceSegmentCount, - &hp->h265_pic_info.pSliceSegmentOffsets); + int err = ff_vk_decode_add_slice(avctx, vp, data, size, 1); if (err < 0) return err; @@ -898,6 +896,8 @@ static int vk_hevc_end_frame(AVCodecContext *avctx) } #endif + hp->h265_pic_info.pSliceSegmentOffsets = vp->slice_offsets; + hp->h265_pic_info.sliceSegmentCount = vp->nb_slices; if (!hp->h265_pic_info.sliceSegmentCount) return 0; -- 2.49.0 _______________________________________________ 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 reply other threads:[~2025-03-31 2:39 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-03-31 2:37 Lynne [this message] 2025-03-31 2:37 ` [FFmpeg-devel] [PATCH 2/6] vulkan_decode: only create sequence params in end_frame Lynne 2025-03-31 2:37 ` [FFmpeg-devel] [PATCH 3/6] vulkan_decode: move temporary Vulkan structs into each codec Lynne 2025-03-31 2:37 ` [FFmpeg-devel] [PATCH 4/6] vulkan_decode: add a generic start_frame function Lynne 2025-03-31 2:37 ` [FFmpeg-devel] [PATCH 5/6] vulkan_h264: make all temporary structs temporary Lynne 2025-03-31 2:37 ` [FFmpeg-devel] [PATCH 6/6] vulkan_hevc: " 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=20250331023753.285499-1-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