FFmpeg
Loading...
Searching...
No Matches
vulkan_apv.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Lynne <dev@lynne.ee>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "vulkan_decode.h"
22#include "hwaccel_internal.h"
23
24#include "apv_decode.h"
25#include "libavutil/mem.h"
26
27extern const unsigned char ff_apv_decode_comp_spv_data[];
28extern const unsigned int ff_apv_decode_comp_spv_len;
29
30extern const unsigned char ff_apv_idct_comp_spv_data[];
31extern const unsigned int ff_apv_idct_comp_spv_len;
32
34 .codec_id = AV_CODEC_ID_APV,
35 .queue_flags = VK_QUEUE_COMPUTE_BIT,
36};
37
45
46typedef struct APVVulkanDecodeContext {
49
51
52 /* Flat per-frame coefficient buffer: entropy writes it, the iDCT reads it,
53 * instead of bouncing coefficients through the output image. */
55 size_t coeff_size;
57
58typedef struct DecodePushData {
59 VkDeviceAddress tile_data;
60 int tile_count[2];
65
67 const AVBufferRef *buffer_ref,
68 av_unused const uint8_t *buffer,
69 av_unused uint32_t size)
70{
71 int err;
72 APVDecodeContext *apv = avctx->priv_data;
75 APVVulkanDecodeContext *apvvk = ctx->sd_ctx;
76
78 FFVulkanDecodePicture *vp = &apvvp->vp;
79
80 /* Host map the input tile data if supported */
81 if (ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY)
82 ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, buffer_ref->data,
83 VK_WHOLE_SIZE, buffer_ref,
84 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
85 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
86
87 /* Allocate frame data buffer */
88 int fd_size = (2*4*APV_MAX_TILE_COUNT)*APV_MAX_NUM_COMP +
91
93 &apvvp->frame_data_buf,
94 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
95 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
96 NULL, fd_size,
97 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
98 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
99 if (err < 0)
100 return err;
101
102 /* Frame data */
104 uint8_t *fd = frame_data->mapped_mem;
105
106 fd += 2*4*APV_MAX_TILE_COUNT*APV_MAX_NUM_COMP; /* Tile offsets go first */
107
108 /* per-component qmatrix and QPs */
109 for (int i = 0; i < APV_MAX_NUM_COMP; i++)
110 memcpy(fd + 64*i,
112 64);
113 fd += 64*APV_MAX_NUM_COMP;
114
115 for (int i = 0; i < APV_MAX_NUM_COMP; i++) {
116 for (int j = 0; j < APV_MAX_TILE_COUNT; j++)
117 fd[j] = apv->cur_raw_frame->tile[j].tile_header.tile_qp[i];
118 fd += APV_MAX_TILE_COUNT;
119 }
120
121 /* tile col/row offset */
122 memcpy(fd, apv->tile_info.col_starts, (APV_MAX_TILE_COLS+1)*2);
123 fd += (APV_MAX_TILE_COLS+1)*2;
124 memcpy(fd, apv->tile_info.row_starts, (APV_MAX_TILE_ROWS+1)*2);
125
126 return 0;
127}
128
130 const uint8_t *data,
131 uint32_t size)
132{
133 APVDecodeContext *apv = avctx->priv_data;
134
136 FFVulkanDecodePicture *vp = &apvvp->vp;
137
139 FFVkBuffer *slices_buf = vp->slices_buf;
140
141 if (slices_buf && slices_buf->host_ref) {
142 AV_WN32(frame_data->mapped_mem + (2*apvvp->tile_num + 0)*sizeof(uint32_t),
143 data - slices_buf->mapped_mem);
144 AV_WN32(frame_data->mapped_mem + (2*apvvp->tile_num + 1)*sizeof(uint32_t),
145 size);
146
147 apvvp->tile_num++;
148 } else {
149 int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
150 &apvvp->tile_num,
151 (const uint32_t **)&apvvp->frame_data);
152 if (err < 0)
153 return err;
154
155 AV_WN32(frame_data->mapped_mem + (2*(apvvp->tile_num - 1) + 0)*sizeof(uint32_t),
156 apvvp->frame_data[apvvp->tile_num - 1]);
157 AV_WN32(frame_data->mapped_mem + (2*(apvvp->tile_num - 1) + 1)*sizeof(uint32_t),
158 size);
159 }
160
161 return 0;
162}
163
165{
166 int err;
167 APVDecodeContext *apv = avctx->priv_data;
168 const CodedBitstreamAPVContext *apv_cbc = apv->cbc->priv_data;
171 APVVulkanDecodeContext *apvvk = ctx->sd_ctx;
172 FFVulkanFunctions *vk = &ctx->s.vkfn;
173
175 FFVulkanDecodePicture *vp = &apvvp->vp;
176
177 FFVkBuffer *slices_buf = vp->slices_buf;
178 FFVkBuffer *frame_data_buf = apvvp->frame_data_buf;
179 FFVkBuffer *coeff_buf = NULL;
180
182 enum AVPixelFormat sw_format = hwfc->sw_format;
183 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(sw_format);
184
185 VkImageMemoryBarrier2 img_bar[8];
186 int nb_img_bar = 0;
187 VkBufferMemoryBarrier2 buf_bar[2];
188 int nb_buf_bar = 0;
189
190 FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool);
191 err = ff_vk_exec_start(&ctx->s, exec);
192 if (err < 0)
193 return err;
194
195 /* Make sure the buffer is flushed */
196 RET(ff_vk_flush_buffer(&ctx->s, frame_data_buf, 0, frame_data_buf->size, 1));
197
198 /* Prepare deps */
200 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
201 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
202
203 /* Exec-owned output views: freed on exec recycle, so releasing a picture
204 * needs no blocking wait. No mirror_sem: nothing consumes vp->sem here. */
205 VkImageView views[AV_NUM_DATA_POINTERS];
206 RET(ff_vk_create_imageviews(&ctx->s, exec, views, apv->output_frame,
208
211
212 AVVkFrame *vkf = (AVVkFrame *)apv->output_frame->data[0];
213 vkf->layout[0] = VK_IMAGE_LAYOUT_UNDEFINED;
214 vkf->access[0] = VK_ACCESS_2_NONE;
215
216 /* The IDCT shader writes every sample of the coded area, so the frame
217 * does not need to be cleared first. */
218 ff_vk_frame_barrier(&ctx->s, exec, apv->output_frame, img_bar, &nb_img_bar,
219 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
220 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
221 VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
222 VK_IMAGE_LAYOUT_GENERAL,
223 VK_QUEUE_FAMILY_IGNORED);
224 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
225 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
226 .pImageMemoryBarriers = img_bar,
227 .imageMemoryBarrierCount = nb_img_bar,
228 });
229 nb_img_bar = 0;
230
231 /* Zero-filled first, since entropy writes only the nonzero coefficients. */
232 err = ff_vk_get_pooled_buffer(&ctx->s, &apvvk->coeff_pool, &coeff_buf,
233 VK_BUFFER_USAGE_TRANSFER_DST_BIT |
234 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
235 NULL, apvvk->coeff_size,
236 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
237 if (err < 0)
238 return err;
239 vk->CmdFillBuffer(exec->buf, coeff_buf->buf, 0, VK_WHOLE_SIZE, 0);
240
241 buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
242 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
243 .srcStageMask = VK_PIPELINE_STAGE_2_CLEAR_BIT,
244 .srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT,
245 .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
246 .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT |
247 VK_ACCESS_2_SHADER_STORAGE_READ_BIT,
248 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
249 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
250 .buffer = coeff_buf->buf,
251 .size = VK_WHOLE_SIZE,
252 };
253 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
254 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
255 .pBufferMemoryBarriers = buf_bar,
256 .bufferMemoryBarrierCount = nb_buf_bar,
257 });
258 nb_buf_bar = 0;
259
260 /* Setup push data */
262 .tile_data = slices_buf->address,
263 .tile_count = { apv->tile_info.tile_cols, apv->tile_info.tile_rows },
264 .log2_chroma_sub = { desc->log2_chroma_w, desc->log2_chroma_h },
265 .components = desc->nb_components,
266 .bit_depth = apv_cbc->bit_depth,
267 };
268
269 /* Decoding */
270 ff_vk_shader_update_img_array(&ctx->s, exec, &apvvk->decode,
271 apv->output_frame, views,
272 0, 0,
273 VK_IMAGE_LAYOUT_GENERAL,
274 VK_NULL_HANDLE);
275 ff_vk_shader_update_desc_buffer(&ctx->s, exec, &apvvk->decode,
276 0, 1, 0,
277 frame_data_buf,
278 0, frame_data_buf->size,
279 VK_FORMAT_UNDEFINED);
280 ff_vk_shader_update_desc_buffer(&ctx->s, exec, &apvvk->decode,
281 0, 2, 0,
282 coeff_buf, 0, coeff_buf->size,
283 VK_FORMAT_UNDEFINED);
284
285 ff_vk_exec_bind_shader(&ctx->s, exec, &apvvk->decode);
286 ff_vk_shader_update_push_const(&ctx->s, exec, &apvvk->decode,
287 VK_SHADER_STAGE_COMPUTE_BIT,
288 0, sizeof(pd), &pd);
289
290 vk->CmdDispatch(exec->buf,
292 desc->nb_components);
293
294 /* Wait for the coefficient writes before the iDCT reads them */
295 buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
296 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
297 .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
298 .srcAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
299 .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
300 .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT,
301 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
302 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
303 .buffer = coeff_buf->buf,
304 .size = VK_WHOLE_SIZE,
305 };
306 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
307 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
308 .pBufferMemoryBarriers = buf_bar,
309 .bufferMemoryBarrierCount = nb_buf_bar,
310 });
311 nb_buf_bar = 0;
312
313 /* iDCT */
314 ff_vk_shader_update_img_array(&ctx->s, exec, &apvvk->idct,
315 apv->output_frame, views,
316 0, 0,
317 VK_IMAGE_LAYOUT_GENERAL,
318 VK_NULL_HANDLE);
319 ff_vk_shader_update_desc_buffer(&ctx->s, exec, &apvvk->idct,
320 0, 1, 0,
321 frame_data_buf,
322 0, frame_data_buf->size,
323 VK_FORMAT_UNDEFINED);
324 ff_vk_shader_update_desc_buffer(&ctx->s, exec, &apvvk->idct,
325 0, 2, 0,
326 coeff_buf, 0, coeff_buf->size,
327 VK_FORMAT_UNDEFINED);
328
329 ff_vk_exec_bind_shader(&ctx->s, exec, &apvvk->idct);
330 ff_vk_shader_update_push_const(&ctx->s, exec, &apvvk->idct,
331 VK_SHADER_STAGE_COMPUTE_BIT,
332 0, sizeof(pd), &pd);
333
334 /* one workgroup per group of 8 horizontally adjacent transform blocks,
335 * in the luma basis coords, in case a block is OOB writes/reads are ignored */
336 int idct_cx = 0, idct_by = 0;
337 for (int comp = 0; comp < desc->nb_components; comp++) {
338 int sw = (comp == 0) ? 0 : desc->log2_chroma_w;
339 int sh = (comp == 0) ? 0 : desc->log2_chroma_h;
340 int bx = (avctx->coded_width + (1 << (3 + sw)) - 1) >> (3 + sw);
341 int by = (avctx->coded_height + (1 << (3 + sh)) - 1) >> (3 + sh);
342 idct_cx = FFMAX(idct_cx, (bx + 7) >> 3);
343 idct_by = FFMAX(idct_by, by);
344 }
345 vk->CmdDispatch(exec->buf, idct_cx, idct_by, desc->nb_components);
346
347 ff_vk_exec_move_dep_refstruct(&ctx->s, exec, &coeff_buf);
348 err = ff_vk_exec_submit(&ctx->s, exec);
349 if (err < 0)
350 return err;
351
352 return 0;
353
354fail:
355 ff_vk_exec_discard(&ctx->s, exec);
356 av_refstruct_unref(&coeff_buf);
357 return err;
358}
359
361 FFVkExecPool *pool, FFVulkanShader *shd)
362{
363 int err;
364 AVHWFramesContext *dec_frames_ctx;
365 dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
366
367 ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, NULL,
368 (uint32_t []) { 1, 1, 1 }, 0);
370 VK_SHADER_STAGE_COMPUTE_BIT);
371
372 const FFVulkanDescriptorSetBinding desc_set[] = {
373 {
374 .name = "dst",
375 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
376 .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
377 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
378 },
379 {
380 .name = "frame_data_buf",
381 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
382 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
383 },
384 {
385 .name = "coeffs_out_buf",
386 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
387 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
388 }
389 };
390 ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0);
391
395
396 RET(ff_vk_shader_register_exec(s, pool, shd));
397
398fail:
399 return err;
400}
401
403 FFVkExecPool *pool, FFVulkanShader *shd)
404{
405 int err;
406 AVHWFramesContext *dec_frames_ctx;
407 dec_frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data;
408
409 ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, NULL,
410 (uint32_t []) { 32, 2, 1 }, 0);
412 VK_SHADER_STAGE_COMPUTE_BIT);
413
414 FFVulkanDescriptorSetBinding desc_set[] = {
415 {
416 .name = "dst",
417 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
418 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
419 .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
420 },
421 {
422 .name = "frame_data_buf",
423 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
424 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
425 },
426 {
427 .name = "coeffs_in_buf",
428 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
429 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
430 },
431 };
432 ff_vk_shader_add_descriptor_set(s, shd, desc_set, 3, 0);
433
436 ff_apv_idct_comp_spv_len, "main"));
437
438 RET(ff_vk_shader_register_exec(s, pool, shd));
439
440fail:
441 return err;
442}
443
445{
446 APVVulkanDecodeContext *apvvk = ctx->sd_ctx;
447
448 ff_vk_shader_free(&ctx->s, &apvvk->decode);
449 ff_vk_shader_free(&ctx->s, &apvvk->idct);
450
453
454 av_freep(&apvvk);
455}
456
458{
459 int err;
461
462 err = ff_vk_decode_init(avctx);
463 if (err < 0)
464 return err;
465
467 APVVulkanDecodeContext *apvvk = ctx->sd_ctx = av_mallocz(sizeof(*apvvk));
468 if (!apvvk) {
469 err = AVERROR(ENOMEM);
470 goto fail;
471 }
472
473 ctx->sd_ctx_free = &vk_decode_apv_uninit;
474
475 /* Size the flat coefficient buffer: one int16 per sample of the
476 * MB-aligned coded area, summed over components. */
477 {
478 const AVPixFmtDescriptor *pd =
480 int cw = FFALIGN(avctx->coded_width, 16);
481 int ch = FFALIGN(avctx->coded_height, 16);
482 apvvk->coeff_size = 0;
483 for (int i = 0; i < pd->nb_components; i++) {
484 int sx = (i == 1 || i == 2) ? pd->log2_chroma_w : 0;
485 int sy = (i == 1 || i == 2) ? pd->log2_chroma_h : 0;
486 apvvk->coeff_size += (size_t)(cw >> sx) * (ch >> sy);
487 }
488 apvvk->coeff_size *= sizeof(int16_t);
489 }
490
491 RET(init_decode_shader(avctx, &ctx->s, &ctx->exec_pool,
492 &apvvk->decode));
493
494 RET(init_idct_shader(avctx, &ctx->s, &ctx->exec_pool,
495 &apvvk->idct));
496
497fail:
498 return err;
499}
500
502{
503 AVHWDeviceContext *dev_ctx = _hwctx.nc;
504
506 FFVulkanDecodePicture *vp = &apvvp->vp;
507
508 ff_vk_decode_free_frame(dev_ctx, vp);
509
511}
512
514 .p.name = "apv_vulkan",
515 .p.type = AVMEDIA_TYPE_VIDEO,
516 .p.id = AV_CODEC_ID_APV,
517 .p.pix_fmt = AV_PIX_FMT_VULKAN,
518 .start_frame = &vk_apv_start_frame,
519 .decode_slice = &vk_apv_decode_slice,
520 .end_frame = &vk_apv_end_frame,
521 .free_frame_priv = &vk_apv_free_frame_priv,
522 .frame_priv_data_size = sizeof(APVVulkanDecodePicture),
524 .update_thread_context = &ff_vk_update_thread_context,
526 .frame_params = &ff_vk_frame_params,
527 .priv_data_size = sizeof(FFVulkanDecodeContext),
529};
static AVFormatContext * ctx
#define APV_MAX_NUM_COMP
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:613
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
Definition ffmpeg.c:491
#define AV_NUM_DATA_POINTERS
Definition frame.h:480
#define fail
Definition test.h:479
@ AV_CODEC_ID_APV
Definition codec_id.h:323
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
#define HWACCEL_CAP_THREAD_SAFE
const struct FFHWAccel ff_apv_vulkan_hwaccel
Definition vulkan_apv.c:513
#define AV_WN32(p, v)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
@ APV_MAX_TILE_COUNT
Definition apv.h:77
@ APV_MAX_TILE_COLS
Definition apv.h:75
@ APV_MAX_TILE_ROWS
Definition apv.h:76
#define av_unused
Definition attributes.h:164
void ff_vk_shader_update_img_array(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, AVFrame *f, VkImageView *views, int set, int binding, VkImageLayout layout, VkSampler sampler)
Update a descriptor in a buffer with an image array.
Definition vulkan.c:2711
int ff_vk_shader_load(FFVulkanShader *shd, VkPipelineStageFlags stage, VkSpecializationInfo *spec, uint32_t wg_size[3], uint32_t required_subgroup_size)
Initialize a shader object.
Definition vulkan.c:2283
void ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular)
Add descriptor to a shader.
Definition vulkan.c:2542
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition vulkan.c:1635
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags2 src_stage, VkPipelineStageFlags2 dst_stage, VkAccessFlagBits2 new_access, VkImageLayout new_layout, uint32_t new_qf)
Definition vulkan.c:2237
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition vulkan.c:668
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, VkImageView views[AV_NUM_DATA_POINTERS], AVFrame *f, enum FFVkShaderRepFormat rep_fmt)
Create an imageview and add it as a dependency to an execution.
Definition vulkan.c:2215
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition vulkan.c:2778
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Definition vulkan.c:2576
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition vulkan.c:630
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:991
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition vulkan.c:2760
void ff_vk_exec_move_dep_refstruct(FFVulkanContext *s, FFVkExecContext *e, void *obj)
Definition vulkan.c:794
int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, int set, int bind, int elem, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len, VkFormat fmt)
Update a descriptor in a buffer with a buffer.
Definition vulkan.c:2724
int ff_vk_host_map_buffer(FFVulkanContext *s, FFVkBuffer **dst, uint8_t *src_data, VkDeviceSize size, const AVBufferRef *src_buf, VkBufferUsageFlags usage)
Maps a system RAM buffer into a Vulkan buffer.
Definition vulkan.c:1544
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVRefStructPool **buf_pool, FFVkBuffer **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.
Definition vulkan.c:1448
int ff_vk_flush_buffer(FFVulkanContext *s, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize mem_size, int flush)
Flush or invalidate a single buffer, with a given size and offset.
Definition vulkan.c:1349
void ff_vk_exec_discard(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:771
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, const char *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
Definition vulkan.c:2446
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition vulkan.c:889
void ff_vk_shader_update_push_const(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
Update push constant in a shader.
Definition vulkan.c:2750
const char * desc
Definition libsvtav1.c:83
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
Memory handling functions.
const char data[16]
Definition mxf.c:155
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3524
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition pixfmt.h:379
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition refstruct.c:121
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
Definition refstruct.h:292
APVRawFrame * cur_raw_frame
Definition apv_decode.h:141
CodedBitstreamContext * cbc
Definition apv_decode.h:136
APVDerivedTileInfo tile_info
Definition apv_decode.h:140
void * hwaccel_picture_private
Definition apv_decode.h:145
AVFrame * output_frame
Definition apv_decode.h:144
uint16_t col_starts[APV_MAX_TILE_COLS+1]
Definition apv_decode.h:131
uint16_t row_starts[APV_MAX_TILE_ROWS+1]
Definition apv_decode.h:132
APVRawQuantizationMatrix quantization_matrix
Definition cbs_apv.h:78
APVRawFrameHeader frame_header
Definition cbs_apv.h:103
APVRawTile tile[APV_MAX_TILE_COUNT]
Definition cbs_apv.h:105
uint8_t q_matrix[APV_MAX_NUM_COMP][APV_TR_SIZE][APV_TR_SIZE]
Definition cbs_apv.h:57
uint8_t tile_qp[APV_MAX_NUM_COMP]
Definition cbs_apv.h:89
APVRawTileHeader tile_header
Definition cbs_apv.h:94
FFVulkanShader decode
Definition vulkan_apv.c:47
AVRefStructPool * coeff_pool
Definition vulkan_apv.c:54
AVRefStructPool * frame_data_pool
Definition vulkan_apv.c:50
FFVulkanShader idct
Definition vulkan_apv.c:48
FFVulkanDecodePicture vp
Definition vulkan_apv.c:39
FFVkBuffer * frame_data_buf
Definition vulkan_apv.c:41
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:651
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition avcodec.h:1477
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:620
struct AVCodecInternal * internal
Private context used for internal data.
Definition avcodec.h:478
void * priv_data
Definition avcodec.h:470
void * hwaccel_priv_data
hwaccel-specific private data
Definition internal.h:130
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:500
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition pixdesc.h:71
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:184
VkImageLayout layout[AV_NUM_DATA_POINTERS]
VkAccessFlagBits2 access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
void * priv_data
Internal codec-specific data.
Definition cbs.h:247
VkDeviceAddress tile_data
Definition vulkan_apv.c:59
int tile_count[2]
Definition vulkan_apv.c:60
int log2_chroma_sub[2]
Definition vulkan_apv.c:61
VkBuffer buf
Definition vulkan.h:95
VkDeviceAddress address
Definition vulkan.h:99
size_t size
Definition vulkan.h:98
AVBufferRef * host_ref
Definition vulkan.h:111
uint8_t * mapped_mem
Definition vulkan.h:103
VkCommandBuffer buf
Definition vulkan.h:142
FFVulkanDecodeShared * shared_ctx
Definition format.c:918
#define av_mallocz(s)
#define av_freep(p)
static char buffer[20]
Definition seek.c:33
int size
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
@ FF_VK_REP_NATIVE
Definition vulkan.h:440
#define RET(x)
Definition vulkan.h:37
const unsigned char ff_apv_decode_comp_spv_data[]
static int vk_apv_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
Definition vulkan_apv.c:129
static void vk_decode_apv_uninit(FFVulkanDecodeShared *ctx)
Definition vulkan_apv.c:444
const unsigned char ff_apv_idct_comp_spv_data[]
static int vk_decode_apv_init(AVCodecContext *avctx)
Definition vulkan_apv.c:457
static int init_idct_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Definition vulkan_apv.c:402
const FFVulkanDecodeDescriptor ff_vk_dec_apv_desc
Definition vulkan_apv.c:33
static void vk_apv_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
Definition vulkan_apv.c:501
static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Definition vulkan_apv.c:360
static int vk_apv_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
Definition vulkan_apv.c:66
static int vk_apv_end_frame(AVCodecContext *avctx)
Definition vulkan_apv.c:164
const unsigned int ff_apv_idct_comp_spv_len
const unsigned int ff_apv_decode_comp_spv_len
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Synchronize the contexts between 2 threads.
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
Initialize hw_frames_ctx with the parameters needed to decode the stream using the parameters from av...
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)
Add slice data to frame.
void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp)
Free a frame and its state.
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY