FFmpeg
Loading...
Searching...
No Matches
vulkan_ffv1.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 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 "ffv1.h"
25#include "ffv1_vulkan.h"
26#include "libavutil/mem.h"
27
28#define RGB_LINECACHE 2
29
30extern const unsigned char ff_ffv1_dec_setup_comp_spv_data[];
31extern const unsigned int ff_ffv1_dec_setup_comp_spv_len;
32
33extern const unsigned char ff_ffv1_dec_reset_comp_spv_data[];
34extern const unsigned int ff_ffv1_dec_reset_comp_spv_len;
35
36extern const unsigned char ff_ffv1_dec_reset_golomb_comp_spv_data[];
37extern const unsigned int ff_ffv1_dec_reset_golomb_comp_spv_len;
38
39extern const unsigned char ff_ffv1_dec_comp_spv_data[];
40extern const unsigned int ff_ffv1_dec_comp_spv_len;
41
42extern const unsigned char ff_ffv1_dec_rgb_comp_spv_data[];
43extern const unsigned int ff_ffv1_dec_rgb_comp_spv_len;
44
45extern const unsigned char ff_ffv1_dec_golomb_comp_spv_data[];
46extern const unsigned int ff_ffv1_dec_golomb_comp_spv_len;
47
48extern const unsigned char ff_ffv1_dec_rgb_golomb_comp_spv_data[];
49extern const unsigned int ff_ffv1_dec_rgb_golomb_comp_spv_len;
50
51extern const unsigned char ff_ffv1_dec_rgb_float_comp_spv_data[];
52extern const unsigned int ff_ffv1_dec_rgb_float_comp_spv_len;
53
54extern const unsigned char ff_ffv1_dec_rgb_float_golomb_comp_spv_data[];
55extern const unsigned int ff_ffv1_dec_rgb_float_golomb_comp_spv_len;
56
57extern const unsigned char ff_ffv1_dec_bayer_comp_spv_data[];
58extern const unsigned int ff_ffv1_dec_bayer_comp_spv_len;
59
60extern const unsigned char ff_ffv1_dec_bayer_golomb_comp_spv_data[];
61extern const unsigned int ff_ffv1_dec_bayer_golomb_comp_spv_len;
62
64 .codec_id = AV_CODEC_ID_FFV1,
65 .queue_flags = VK_QUEUE_COMPUTE_BIT,
66};
67
70
75
78 uint32_t *slice_offset;
81
82 /* The context-less free callback waits for the decode before reading
83 * back the slice feedback */
84 PFN_vkWaitSemaphores wait_semaphores;
86
100
102 const AVBufferRef *buffer_ref,
103 av_unused const uint8_t *buffer,
104 av_unused uint32_t size)
105{
106 int err;
109 FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
110 FFV1Context *f = avctx->priv_data;
111
112 FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
113 FFVulkanDecodePicture *vp = &fp->vp;
114
116 enum AVPixelFormat sw_format = hwfc->sw_format;
117
118 int max_contexts;
119 int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
120 !(sw_format == AV_PIX_FMT_YA8);
121
122 fp->slice_num = 0;
123
124 max_contexts = 0;
125 for (int i = 0; i < f->quant_table_count; i++)
126 max_contexts = FFMAX(f->context_count[i], max_contexts);
127
128 /* Allocate slice buffer data */
129 if (f->ac == AC_GOLOMB_RICE)
130 fp->plane_state_size = 8;
131 else
133
134 fp->plane_state_size *= max_contexts;
135 fp->slice_state_size = fp->plane_state_size*f->plane_count;
136
137 fp->slice_data_size = 256; /* Overestimation for the SliceContext struct */
140
141 fp->crc_checked = f->ec && (avctx->err_recognition & AV_EF_CRCCHECK);
142
143 /* The context-less free callback needs these device functions, which
144 * prepare_frame_sdr() used to set. vp->sem is kept for the next
145 * non-keyframe's wait and the free callback's CRC readback. */
146 fp->wait_semaphores = ctx->s.vkfn.WaitSemaphores;
147 vp->invalidate_memory_ranges = ctx->s.vkfn.InvalidateMappedMemoryRanges;
148
149 /* Host map the input slices data if supported */
150 if (ctx->s.extensions & FF_VK_EXT_EXTERNAL_HOST_MEMORY)
151 ff_vk_host_map_buffer(&ctx->s, &vp->slices_buf, buffer_ref->data,
152 VK_WHOLE_SIZE, buffer_ref,
153 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
154 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
155
156 /* Allocate slice state data */
157 if (f->picture.f->flags & AV_FRAME_FLAG_KEY) {
159 &fp->slice_state,
160 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
161 NULL, f->slice_count*fp->slice_state_size,
162 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
163 if (err < 0)
164 return err;
165 } else {
166 FFv1VulkanDecodePicture *fpl = f->hwaccel_last_picture_private;
167
168 /* The previous frame's setup may have failed partway */
169 if (!fpl || !fpl->slice_state)
170 return AVERROR_INVALIDDATA;
171
173 }
174
175 /* Allocate slice offsets/status buffer */
178 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
179 NULL, 2*(2*f->slice_count*sizeof(uint32_t)),
180 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
181 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
182 if (err < 0)
183 return err;
184
185 /* Allocate slice offsets/status buffer (note, for integer+remap, we don't need it) */
186 if (f->version >=4 && f->micro_version >= 9 &&
189 &fp->slice_fltmap_buf,
190 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
191 NULL, 65536*4*f->slice_count*sizeof(uint32_t),
192 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
193 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
194 /* A megabyte per slice; fall back if there is no BAR space left */
195 if (err < 0)
197 &fp->slice_fltmap_buf,
198 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
199 NULL, 65536*4*f->slice_count*sizeof(uint32_t),
200 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
201 if (err < 0)
202 return err;
203 }
204
205 /* Create a temporaty frame for RGB */
206 if (is_rgb) {
208 if (!vp->dpb_frame)
209 return AVERROR(ENOMEM);
210
212 vp->dpb_frame, 0);
213 if (err < 0)
214 return err;
215 }
216
217 return 0;
218}
219
221 const uint8_t *data,
222 uint32_t size)
223{
224 FFV1Context *f = avctx->priv_data;
225
226 FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
227 FFVulkanDecodePicture *vp = &fp->vp;
228
229 FFVkBuffer *slice_offset = fp->slice_feedback_buf;
230 FFVkBuffer *slices_buf = vp->slices_buf;
231
232 if (slices_buf && slices_buf->host_ref) {
233 AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 0)*sizeof(uint32_t),
234 data - slices_buf->mapped_mem);
235 AV_WN32(slice_offset->mapped_mem + (2*fp->slice_num + 1)*sizeof(uint32_t),
236 size);
237
238 fp->slice_num++;
239 } else {
240 int err = ff_vk_decode_add_slice(avctx, vp, data, size, 0,
241 &fp->slice_num,
242 (const uint32_t **)&fp->slice_offset);
243 if (err < 0)
244 return err;
245
246 AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 0)*sizeof(uint32_t),
247 fp->slice_offset[fp->slice_num - 1]);
248 AV_WN32(slice_offset->mapped_mem + (2*(fp->slice_num - 1) + 1)*sizeof(uint32_t),
249 size);
250 }
251
252 return 0;
253}
254
256{
257 int err;
260 FFVulkanFunctions *vk = &ctx->s.vkfn;
261
262 FFV1Context *f = avctx->priv_data;
263 FFv1VulkanDecodeContext *fv = ctx->sd_ctx;
264
266 enum AVPixelFormat sw_format = hwfc->sw_format;
267
268 int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
269 !(sw_format == AV_PIX_FMT_YA8);
270 int color_planes = av_pix_fmt_desc_get(avctx->sw_pix_fmt)->nb_components;
271
272 FFv1VulkanDecodePicture *fp = f->hwaccel_picture_private;
273 FFVulkanDecodePicture *vp = &fp->vp;
274
275 FFVkBuffer *slices_buf = vp->slices_buf;
276 FFVkBuffer *slice_state = fp->slice_state;
277 FFVkBuffer *slice_feedback = fp->slice_feedback_buf;
278 FFVkBuffer *fltmap_buf = NULL;
279 if (fp->slice_fltmap_buf)
280 fltmap_buf = fp->slice_fltmap_buf;
281
282 VkImageView output_views[AV_NUM_DATA_POINTERS];
283 VkImageView rct_image_views[AV_NUM_DATA_POINTERS];
284
285 VkImageMemoryBarrier2 img_bar[37];
286 int nb_img_bar = 0;
287 VkBufferMemoryBarrier2 buf_bar[8];
288 int nb_buf_bar = 0;
289
290 FFVkExecContext *exec = ff_vk_exec_get(&ctx->s, &ctx->exec_pool);
291 ff_vk_exec_start(&ctx->s, exec);
292
293 /* Prepare deps */
294 RET(ff_vk_exec_add_dep_frame(&ctx->s, exec, f->picture.f,
295 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
296 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
297
298 err = ff_vk_exec_mirror_sem_value(&ctx->s, exec, &vp->sem, &vp->sem_value,
299 f->picture.f);
300 if (err < 0)
301 return err;
302
303 /* Exec-owned output views (vp->sem is still mirrored above, for the next
304 * frame's dependency and the free callback's CRC readback). */
305 RET(ff_vk_create_imageviews(&ctx->s, exec, output_views, f->picture.f,
307
308 if (is_rgb) {
309 RET(ff_vk_create_imageviews(&ctx->s, exec, rct_image_views,
312 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
313 VK_PIPELINE_STAGE_2_CLEAR_BIT));
314 }
315
316 if (!(f->picture.f->flags & AV_FRAME_FLAG_KEY)) {
317 FFv1VulkanDecodePicture *fpl = f->hwaccel_last_picture_private;
318 FFVulkanDecodePicture *vpl = &fpl->vp;
319
320 /* Wait on the previous frame, if its decode was ever submitted */
321 if (vpl->sem)
322 ff_vk_exec_add_dep_wait_sem(&ctx->s, exec, vpl->sem, vpl->sem_value,
323 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT);
324 }
325
329
330 if (fp->slice_fltmap_buf)
332
333 AVVkFrame *vkf = (AVVkFrame *)f->picture.f->data[0];
334 for (int i = 0; i < ff_vk_count_images(vkf); i++) {
335 vkf->layout[i] = VK_IMAGE_LAYOUT_UNDEFINED;
336 vkf->access[i] = VK_ACCESS_2_NONE;
337 }
338
339 /* Setup shader */
341 1, 0, 0,
342 slice_state,
343 0, fp->slice_data_size*f->slice_count,
344 VK_FORMAT_UNDEFINED);
346 1, 1, 0,
347 slice_feedback,
348 0, 2*f->slice_count*sizeof(uint32_t),
349 VK_FORMAT_UNDEFINED);
351 1, 2, 0,
352 slice_feedback,
353 2*f->slice_count*sizeof(uint32_t),
354 VK_WHOLE_SIZE,
355 VK_FORMAT_UNDEFINED);
356 /* The binding is statically used by the shader, so it must always hold
357 * a valid buffer. */
359 1, 3, 0,
360 fltmap_buf ? fltmap_buf : slice_feedback,
361 0,
362 VK_WHOLE_SIZE,
363 VK_FORMAT_UNDEFINED);
364
365 ff_vk_exec_bind_shader(&ctx->s, exec, &fv->setup);
366
367 FFv1ShaderParams pd = {
368 .slice_data = slices_buf->address,
369
370 .img_size[0] = f->picture.f->width,
371 .img_size[1] = f->picture.f->height,
372
373 .plane_state_size = fp->plane_state_size,
374 .key_frame = f->picture.f->flags & AV_FRAME_FLAG_KEY,
375 .crcref = f->crcref,
376 .micro_version = f->micro_version,
377 .remap_allowed = !!fltmap_buf,
378 };
379
380 for (int i = 0; i < f->quant_table_count; i++) {
381 pd.context_count[i] = f->context_count[i];
382 pd.extend_lookup[i] = f->quant_tables[i][3][127] ||
383 f->quant_tables[i][4][127];
384 }
385
386 /* For some reason the C FFv1 encoder/decoder treats these differently */
387 if (sw_format == AV_PIX_FMT_GBRP10 || sw_format == AV_PIX_FMT_GBRP12 ||
388 sw_format == AV_PIX_FMT_GBRP14)
389 memcpy(pd.fmt_lut, (int [4]) { 2, 1, 0, 3 }, 4*sizeof(int));
390 else
391 ff_vk_set_perm(sw_format, pd.fmt_lut, 0);
392
394 VK_SHADER_STAGE_COMPUTE_BIT,
395 0, sizeof(FFv1ShaderParams), &pd);
396
397 vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices, 1);
398
399 if (is_rgb) {
400 vkf = (AVVkFrame *)vp->dpb_frame->data[0];
401 for (int i = 0; i < 4; i++) {
402 vkf->layout[i] = VK_IMAGE_LAYOUT_UNDEFINED;
403 vkf->access[i] = VK_ACCESS_2_NONE;
404 }
405
406 ff_vk_frame_barrier(&ctx->s, exec, vp->dpb_frame, img_bar, &nb_img_bar,
407 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
408 VK_PIPELINE_STAGE_2_CLEAR_BIT,
409 VK_ACCESS_2_TRANSFER_WRITE_BIT,
410 VK_IMAGE_LAYOUT_GENERAL,
411 VK_QUEUE_FAMILY_IGNORED);
412
413 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
414 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
415 .pImageMemoryBarriers = img_bar,
416 .imageMemoryBarrierCount = nb_img_bar,
417 .pBufferMemoryBarriers = buf_bar,
418 .bufferMemoryBarrierCount = nb_buf_bar,
419 });
420 nb_img_bar = 0;
421 nb_buf_bar = 0;
422
423 /* The intermediate frame has 4 planes (GBRAP16/32). Clear all of
424 * them since the bayer decoder uses all four. */
425 int n_dec_planes = f->bayer ? 4 : color_planes;
426 for (int i = 0; i < n_dec_planes; i++)
427 vk->CmdClearColorImage(exec->buf, vkf->img[i], VK_IMAGE_LAYOUT_GENERAL,
428 &((VkClearColorValue) { 0 }),
429 1, &((VkImageSubresourceRange) {
430 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
431 .levelCount = 1,
432 .layerCount = 1,
433 }));
434 }
435
436 /* Sync between setup and reset shaders */
437 ff_vk_buf_barrier(buf_bar[nb_buf_bar++], slice_state,
438 COMPUTE_SHADER_BIT, SHADER_STORAGE_READ_BIT,
439 SHADER_STORAGE_WRITE_BIT,
440 COMPUTE_SHADER_BIT, SHADER_STORAGE_READ_BIT, NONE_KHR,
441 0, fp->slice_data_size*f->slice_count);
442
443 /* Probability data barrier for P-frames */
444 if (!(f->picture.f->flags & AV_FRAME_FLAG_KEY))
445 ff_vk_buf_barrier(buf_bar[nb_buf_bar++], slice_state,
446 COMPUTE_SHADER_BIT, SHADER_STORAGE_READ_BIT,
447 SHADER_STORAGE_WRITE_BIT,
448 COMPUTE_SHADER_BIT, SHADER_STORAGE_WRITE_BIT, NONE_KHR,
449 fp->slice_data_size*f->slice_count, VK_WHOLE_SIZE);
450
451 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
452 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
453 .pImageMemoryBarriers = img_bar,
454 .imageMemoryBarrierCount = nb_img_bar,
455 .pBufferMemoryBarriers = buf_bar,
456 .bufferMemoryBarrierCount = nb_buf_bar,
457 });
458 nb_buf_bar = 0;
459 nb_img_bar = 0;
460
461 /* Reset shader */
463 1, 0, 0,
464 slice_state,
465 0, fp->slice_data_size*f->slice_count,
466 VK_FORMAT_UNDEFINED);
468 1, 1, 0,
469 slice_state,
470 f->slice_count*fp->slice_data_size,
471 VK_WHOLE_SIZE,
472 VK_FORMAT_UNDEFINED);
473
474 ff_vk_exec_bind_shader(&ctx->s, exec, &fv->reset);
476 VK_SHADER_STAGE_COMPUTE_BIT,
477 0, sizeof(FFv1ShaderParams), &pd);
478
479 vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices,
480 f->plane_count);
481
482 /* Sync probabilities between reset and decode shaders */
483 ff_vk_buf_barrier(buf_bar[nb_buf_bar++], slice_state,
484 COMPUTE_SHADER_BIT, SHADER_STORAGE_WRITE_BIT, NONE_KHR,
485 COMPUTE_SHADER_BIT, SHADER_STORAGE_READ_BIT,
486 SHADER_STORAGE_WRITE_BIT,
487 fp->slice_data_size*f->slice_count, VK_WHOLE_SIZE);
488
489 /* Input frame barrier */
490 ff_vk_frame_barrier(&ctx->s, exec, f->picture.f, img_bar, &nb_img_bar,
491 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
492 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
493 VK_ACCESS_SHADER_WRITE_BIT |
494 (!is_rgb ? VK_ACCESS_SHADER_READ_BIT : 0),
495 VK_IMAGE_LAYOUT_GENERAL,
496 VK_QUEUE_FAMILY_IGNORED);
497 if (is_rgb)
498 ff_vk_frame_barrier(&ctx->s, exec, vp->dpb_frame, img_bar, &nb_img_bar,
499 VK_PIPELINE_STAGE_2_CLEAR_BIT,
500 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
501 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
502 VK_IMAGE_LAYOUT_GENERAL,
503 VK_QUEUE_FAMILY_IGNORED);
504
505 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
506 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
507 .pImageMemoryBarriers = img_bar,
508 .imageMemoryBarrierCount = nb_img_bar,
509 .pBufferMemoryBarriers = buf_bar,
510 .bufferMemoryBarrierCount = nb_buf_bar,
511 });
512 nb_img_bar = 0;
513 nb_buf_bar = 0;
514
515 /* Decode */
517 1, 0, 0,
518 slice_state,
519 0, fp->slice_data_size*f->slice_count,
520 VK_FORMAT_UNDEFINED);
522 1, 1, 0,
523 slice_feedback,
524 0, 2*f->slice_count*sizeof(uint32_t),
525 VK_FORMAT_UNDEFINED);
527 1, 2, 0,
528 slice_feedback,
529 2*f->slice_count*sizeof(uint32_t),
530 VK_WHOLE_SIZE,
531 VK_FORMAT_UNDEFINED);
533 1, 3, 0,
534 slice_state,
535 f->slice_count*fp->slice_data_size,
536 VK_WHOLE_SIZE,
537 VK_FORMAT_UNDEFINED);
538
539 AVFrame *decode_dst = is_rgb ? vp->dpb_frame : f->picture.f;
540 VkImageView *decode_dst_view = is_rgb ? rct_image_views : output_views;
542 decode_dst, decode_dst_view,
543 1, 4,
544 VK_IMAGE_LAYOUT_GENERAL,
545 VK_NULL_HANDLE);
546 if (is_rgb)
548 f->picture.f, output_views,
549 1, 5,
550 VK_IMAGE_LAYOUT_GENERAL,
551 VK_NULL_HANDLE);
552 if (fltmap_buf)
554 1, 6, 0,
555 fltmap_buf,
556 0,
557 VK_WHOLE_SIZE,
558 VK_FORMAT_UNDEFINED);
559
560 ff_vk_exec_bind_shader(&ctx->s, exec, &fv->decode);
562 VK_SHADER_STAGE_COMPUTE_BIT,
563 0, sizeof(FFv1ShaderParams), &pd);
564
565 vk->CmdDispatch(exec->buf, f->num_h_slices, f->num_v_slices, 1);
566
567 err = ff_vk_exec_submit(&ctx->s, exec);
568 if (err < 0)
569 return err;
570
571 /* We don't need the temporary frame after decoding */
573
574fail:
575 return 0;
576}
577
579 FFVkExecPool *pool, FFVulkanShader *shd,
580 VkSpecializationInfo *sl)
581{
582 int err;
583
584 ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
585 (uint32_t []) { 1, 1, 1 }, 0);
586
588 VK_SHADER_STAGE_COMPUTE_BIT);
589
590 const FFVulkanDescriptorSetBinding desc_set_const[] = {
591 { /* rangecoder_buf */
592 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
593 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
594 },
595 { /* crc_ieee_buf */
596 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
597 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
598 },
599 };
600 ff_vk_shader_add_descriptor_set(s, shd, desc_set_const, 2, 1);
601
602 const FFVulkanDescriptorSetBinding desc_set[] = {
603 { /* slice_data_buf */
604 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
605 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
606 },
607 { /* slice_offsets_buf */
608 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
609 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
610 },
611 { /* slice_status_buf */
612 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
613 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
614 },
615 { /* fltmap_buf */
616 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
617 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
618 },
619 };
620 ff_vk_shader_add_descriptor_set(s, shd, desc_set, 4, 0);
621
625
626 RET(ff_vk_shader_register_exec(s, pool, shd));
627
628fail:
629 return err;
630}
631
633 FFVkExecPool *pool, FFVulkanShader *shd,
634 VkSpecializationInfo *sl, int ac)
635{
636 int err;
637 int wg_dim = FFMIN(s->props.properties.limits.maxComputeWorkGroupSize[0], 1024);
638
639 ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
640 (uint32_t []) { wg_dim, 1, 1 }, 0);
641
643 VK_SHADER_STAGE_COMPUTE_BIT);
644
645 const FFVulkanDescriptorSetBinding desc_set_const[] = {
646 { /* rangecoder_buf */
647 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
648 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
649 },
650 };
651 ff_vk_shader_add_descriptor_set(s, shd, desc_set_const, 1, 1);
652
653 const FFVulkanDescriptorSetBinding desc_set[] = {
654 { /* slice_data_buf */
655 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
656 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
657 },
658 { /* slice_state_buf */
659 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
660 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
661 },
662 };
663 ff_vk_shader_add_descriptor_set(s, shd, desc_set, 2, 0);
664
665 if (ac == AC_GOLOMB_RICE)
669 else
673
674 RET(ff_vk_shader_register_exec(s, pool, shd));
675
676fail:
677 return err;
678}
679
681 FFVkExecPool *pool, FFVulkanShader *shd,
682 AVHWFramesContext *dec_frames_ctx,
683 AVHWFramesContext *out_frames_ctx,
684 VkSpecializationInfo *sl, int ac, int rgb,
685 int bayer)
686{
687 int err;
688
689 uint32_t wg_x = ac != AC_GOLOMB_RICE ? CONTEXT_SIZE : 1;
690 ff_vk_shader_load(shd, VK_SHADER_STAGE_COMPUTE_BIT, sl,
691 (uint32_t []) { wg_x, 1, 1 }, 0);
692
694 VK_SHADER_STAGE_COMPUTE_BIT);
695
696 const FFVulkanDescriptorSetBinding desc_set_const[] = {
697 { /* rangecoder_buf */
698 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
699 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
700 },
701 { /* quant_buf */
702 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
703 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
704 },
705 };
706 ff_vk_shader_add_descriptor_set(s, shd, desc_set_const, 2, 1);
707
708 const FFVulkanDescriptorSetBinding desc_set[] = {
709 { /* slice_data_buf */
710 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
711 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
712 },
713 { /* slice_offsets_buf */
714 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
715 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
716 },
717 { /* slice_status_buf */
718 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
719 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
720 },
721 { /* slice_state_buf */
722 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
723 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
724 },
725 { /* dec */
726 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
727 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
728 .elems = av_pix_fmt_count_planes(dec_frames_ctx->sw_format),
729 },
730 { /* dst */
731 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
732 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
733 .elems = av_pix_fmt_count_planes(out_frames_ctx->sw_format),
734 },
735 { /* fltmap_buf */
736 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
737 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
738 },
739 };
740 /* Detect a float output from the pixfmt descriptor instead of f->flt:
741 * the encoder side does not (yet) write f->flt to the extradata, so the
742 * parsed value is unreliable for some v4m4+ streams. The descriptor's
743 * FLOAT flag is set by the pixfmt selection logic and is accurate */
744 int is_float = !!(av_pix_fmt_desc_get(out_frames_ctx->sw_format)->flags &
746
747 /* Bindings 5 (dst) and 6 (fltmap_buf) are conditional */
748 ff_vk_shader_add_descriptor_set(s, shd, desc_set,
749 5 + rgb + (is_float && !bayer),
750 0);
751
752 if (bayer) {
753 if (ac == AC_GOLOMB_RICE)
754 ff_vk_shader_link(s, shd,
757 else
758 ff_vk_shader_link(s, shd,
761 } else if (is_float) {
762 if (ac == AC_GOLOMB_RICE)
763 ff_vk_shader_link(s, shd,
766 else
767 ff_vk_shader_link(s, shd,
770 } else if (ac == AC_GOLOMB_RICE) {
771 if (rgb)
772 ff_vk_shader_link(s, shd,
775 else
776 ff_vk_shader_link(s, shd,
779 } else {
780 if (rgb)
781 ff_vk_shader_link(s, shd,
784 else
785 ff_vk_shader_link(s, shd,
788 }
789
790 RET(ff_vk_shader_register_exec(s, pool, shd));
791
792fail:
793 return err;
794}
795
797 AVBufferRef **dst, enum AVPixelFormat sw_format)
798{
799 int err;
800 AVHWFramesContext *frames_ctx;
801 AVVulkanFramesContext *vk_frames;
802 FFV1Context *f = avctx->priv_data;
803
804 *dst = av_hwframe_ctx_alloc(s->device_ref);
805 if (!(*dst))
806 return AVERROR(ENOMEM);
807
808 frames_ctx = (AVHWFramesContext *)((*dst)->data);
809 frames_ctx->format = AV_PIX_FMT_VULKAN;
810 frames_ctx->sw_format = sw_format;
811 frames_ctx->width = s->frames->width;
812 frames_ctx->height = f->num_v_slices*RGB_LINECACHE;
813
814 vk_frames = frames_ctx->hwctx;
815 vk_frames->tiling = VK_IMAGE_TILING_OPTIMAL;
816 vk_frames->img_flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
817 vk_frames->usage = VK_IMAGE_USAGE_STORAGE_BIT |
818 VK_IMAGE_USAGE_TRANSFER_DST_BIT;
819
820 err = av_hwframe_ctx_init(*dst);
821 if (err < 0) {
822 av_log(avctx, AV_LOG_ERROR,
823 "Unable to initialize frame pool with format %s: %s\n",
824 av_get_pix_fmt_name(sw_format), av_err2str(err));
826 return err;
827 }
828
829 return 0;
830}
831
850
852{
853 int err;
854 FFV1Context *f = avctx->priv_data;
858
859 if (f->version < 3)
860 return AVERROR(ENOTSUP);
861
862 /* Streams with a low amount of slices will usually be much slower
863 * to decode, so warn the user. Use the slice structure from the
864 * extradata: slice_count is only set during frame decoding. */
865 if (f->num_h_slices * f->num_v_slices < 16)
866 av_log(avctx, AV_LOG_WARNING, "Stream has a low number of slices (%i), "
867 "decoding may be very slow\n", f->num_h_slices * f->num_v_slices);
868
869 err = ff_vk_decode_init(avctx);
870 if (err < 0)
871 return err;
872 ctx = dec->shared_ctx;
873
874 fv = ctx->sd_ctx = av_mallocz(sizeof(*fv));
875 if (!fv) {
876 err = AVERROR(ENOMEM);
877 goto fail;
878 }
879
880 ctx->sd_ctx_free = &vk_decode_ffv1_uninit;
881
883 AVHWFramesContext *dctx = hwfc;
884 enum AVPixelFormat sw_format = hwfc->sw_format;
885 int is_rgb = !(f->colorspace == 0 && sw_format != AV_PIX_FMT_YA8) &&
886 !(sw_format == AV_PIX_FMT_YA8);
887
888 /* Intermediate frame pool for RCT */
889 if (is_rgb) {
893 }
894
895 SPEC_LIST_CREATE(sl, 15, 15*sizeof(uint32_t))
896 ff_ffv1_vk_set_common_sl(avctx, f, sl, sw_format);
897
898 if (RGB_LINECACHE != 2)
899 SPEC_LIST_ADD(sl, 0, 32, RGB_LINECACHE);
900
901 if (f->ec && !!(avctx->err_recognition & AV_EF_CRCCHECK))
902 SPEC_LIST_ADD(sl, 1, 32, 1);
903
904 /* Setup shader */
905 RET(init_setup_shader(f, &ctx->s, &ctx->exec_pool, &fv->setup, sl));
906
907 /* Reset shader */
908 RET(init_reset_shader(f, &ctx->s, &ctx->exec_pool, &fv->reset, sl, f->ac));
909
910 /* Decode shaders */
911 RET(init_decode_shader(f, &ctx->s, &ctx->exec_pool, &fv->decode,
912 dctx, hwfc, sl, f->ac, is_rgb, f->bayer));
913
914 /* Init static data */
916
917 /* Update setup global descriptors */
918 RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
919 &fv->setup, 0, 0, 0,
920 &fv->consts_buf,
921 256*sizeof(uint32_t), 512*sizeof(uint8_t),
922 VK_FORMAT_UNDEFINED));
923 RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
924 &fv->setup, 0, 1, 0,
925 &fv->consts_buf,
926 0, 256*sizeof(uint32_t),
927 VK_FORMAT_UNDEFINED));
928
929 /* Update decode global descriptors */
930 RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
931 &fv->decode, 0, 0, 0,
932 &fv->consts_buf,
933 256*sizeof(uint32_t), 512*sizeof(uint8_t),
934 VK_FORMAT_UNDEFINED));
935 RET(ff_vk_shader_update_desc_buffer(&ctx->s, &ctx->exec_pool.contexts[0],
936 &fv->decode, 0, 1, 0,
937 &fv->consts_buf,
938 256*sizeof(uint32_t) + 512*sizeof(uint8_t),
939 VK_WHOLE_SIZE,
940 VK_FORMAT_UNDEFINED));
941
942fail:
943 return err;
944}
945
947{
948 AVHWDeviceContext *dev_ctx = _hwctx.nc;
949 AVVulkanDeviceContext *hwctx = dev_ctx->hwctx;
950
952 FFVulkanDecodePicture *vp = &fp->vp;
953
954 /* The feedback below is read back on the host: wait for the decode.
955 * The generic free path no longer waits for anything. */
956 if (vp->sem) {
957 VkSemaphoreWaitInfo sem_wait = {
958 .sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO,
959 .pSemaphores = &vp->sem,
960 .pValues = &vp->sem_value,
961 .semaphoreCount = 1,
962 };
963 fp->wait_semaphores(hwctx->act_dev, &sem_wait, UINT64_MAX);
964 }
965
966 ff_vk_decode_free_frame(dev_ctx, vp);
967
968 /* No feedback to read if setup failed or the decode was never submitted */
969 if (fp->slice_feedback_buf && vp->sem) {
970 FFVkBuffer *slice_feedback = fp->slice_feedback_buf;
971 uint8_t *ssp = slice_feedback->mapped_mem + 2*fp->slice_num*sizeof(uint32_t);
972
973 /* Invalidate slice/output data if needed */
974 if (!(slice_feedback->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
975 VkMappedMemoryRange invalidate_data = {
976 .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
977 .memory = slice_feedback->mem,
978 .offset = 0,
979 .size = 2*fp->slice_num*sizeof(uint32_t),
980 };
982 1, &invalidate_data);
983 }
984
985 int slice_error_cnt = 0;
986 int crc_mismatch_cnt = 0;
987 uint32_t max_overread = 0;
988 for (int i = 0; i < fp->slice_num; i++) {
989 uint32_t crc_res = 0;
990 if (fp->crc_checked)
991 crc_res = AV_RN32(ssp + 2*i*sizeof(uint32_t) + 0);
992 uint32_t overread = AV_RN32(ssp + 2*i*sizeof(uint32_t) + 4);
993 max_overread = FFMAX(overread, max_overread);
994 slice_error_cnt += !!overread;
995 crc_mismatch_cnt += !!crc_res;
996 }
997 if (slice_error_cnt || crc_mismatch_cnt)
998 av_log(dev_ctx, AV_LOG_ERROR, "Decode status: %i slices overread (%i bytes max), "
999 "%i CRCs mismatched\n",
1000 slice_error_cnt, max_overread, crc_mismatch_cnt);
1001 }
1002
1005}
1006
1008 .p.name = "ffv1_vulkan",
1009 .p.type = AVMEDIA_TYPE_VIDEO,
1010 .p.id = AV_CODEC_ID_FFV1,
1011 .p.pix_fmt = AV_PIX_FMT_VULKAN,
1012 .start_frame = &vk_ffv1_start_frame,
1013 .decode_slice = &vk_ffv1_decode_slice,
1014 .end_frame = &vk_ffv1_end_frame,
1015 .free_frame_priv = &vk_ffv1_free_frame_priv,
1016 .frame_priv_data_size = sizeof(FFv1VulkanDecodePicture),
1018 .update_thread_context = &ff_vk_update_thread_context,
1020 .frame_params = &ff_vk_frame_params,
1021 .priv_data_size = sizeof(FFVulkanDecodeContext),
1023};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define f(width, name)
Definition cbs_vp8.c:236
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition defs.h:48
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
FF Video Codec 1 (a lossless codec)
#define CONTEXT_SIZE
Definition ffv1.h:45
#define AC_GOLOMB_RICE
Definition ffv1.h:52
int ff_ffv1_vk_init_consts(FFVulkanContext *s, FFVkBuffer *vkb, FFV1Context *f)
Definition ffv1_vulkan.c:85
void ff_ffv1_vk_set_common_sl(AVCodecContext *avctx, FFV1Context *f, VkSpecializationInfo *sl, enum AVPixelFormat sw_format)
Definition ffv1_vulkan.c:24
#define RGB_LINECACHE
#define AV_NUM_DATA_POINTERS
Definition frame.h:473
#define fail
Definition test.h:479
@ AV_CODEC_ID_FFV1
Definition codec_id.h:83
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:139
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition frame.h:687
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ 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_ffv1_vulkan_hwaccel
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition hwcontext.c:337
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition hwcontext.c:263
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition hwcontext.c:506
#define AV_WN32(p, v)
#define AV_RN32(p)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define av_unused
Definition attributes.h:164
void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4], int inv)
Since storage images may not be swizzled, we have to do this in the shader itself.
Definition vulkan.c:1526
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:2542
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:2070
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:2373
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition vulkan.c:1443
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
Definition vulkan.c:1230
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:2027
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
Definition vulkan.c:599
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:1958
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
Definition vulkan.c:2614
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Definition vulkan.c:2407
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
Definition vulkan.c:571
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
Definition vulkan.c:881
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
Definition vulkan.c:2591
void ff_vk_exec_move_dep_refstruct(FFVulkanContext *s, FFVkExecContext *e, void *obj)
Definition vulkan.c:694
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:2555
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:1352
void ff_vk_exec_add_dep_refstruct(FFVulkanContext *s, FFVkExecContext *e, void *obj)
Execution dependency management.
Definition vulkan.c:687
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:1256
int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *dst, uint64_t *dst_val, AVFrame *f)
Definition vulkan.c:856
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:2267
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
Definition vulkan.c:777
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:2581
void ff_vk_exec_add_dep_wait_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore sem, uint64_t val, VkPipelineStageFlagBits2 stage)
Definition vulkan.c:735
#define FFMIN(a, b)
Definition macros.h:49
#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:149
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3380
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition pixdesc.h:158
#define AV_PIX_FMT_GBRAP16
Definition pixfmt.h:571
#define AV_PIX_FMT_GBRAP32
Definition pixfmt.h:572
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:564
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:565
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition pixfmt.h:379
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition pixfmt.h:140
#define AV_PIX_FMT_GBRP14
Definition pixfmt.h:566
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:120
void * av_refstruct_ref(void *obj)
Create a new reference to an object managed via this API, i.e.
Definition refstruct.c:140
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
Definition refstruct.h:292
#define sem_wait(psem)
Definition semaphore.h:27
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:650
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition avcodec.h:1471
struct AVCodecInternal * internal
Private context used for internal data.
Definition avcodec.h:478
void * priv_data
Definition avcodec.h:470
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition avcodec.h:1416
void * hwaccel_priv_data
hwaccel-specific private data
Definition internal.h:130
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition hwcontext.h:63
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition hwcontext.h:88
This struct describes a set or pool of "hardware" frames (i.e.
Definition hwcontext.h:118
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition hwcontext.h:200
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
Definition hwcontext.h:153
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition hwcontext.h:213
int width
The allocated dimensions of the frames in this pool.
Definition hwcontext.h:220
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
Definition pixdesc.h:94
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:183
VkImageLayout layout[AV_NUM_DATA_POINTERS]
VkAccessFlagBits2 access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkDevice act_dev
Active device.
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
VkImageTiling tiling
Controls the tiling of allocated frames.
VkImageCreateFlags img_flags
Flags to set during image creation.
VkImageUsageFlagBits usage
Defines extra usage of output frames.
VkDeviceAddress address
Definition vulkan.h:99
VkMemoryPropertyFlagBits flags
Definition vulkan.h:97
AVBufferRef * host_ref
Definition vulkan.h:111
VkDeviceMemory mem
Definition vulkan.h:96
uint8_t * mapped_mem
Definition vulkan.h:103
VkCommandBuffer buf
Definition vulkan.h:139
FFVulkanDecodeShared * shared_ctx
PFN_vkInvalidateMappedMemoryRanges invalidate_memory_ranges
uint16_t context_count[8]
Definition ffv1_vulkan.h:37
uint32_t extend_lookup[8]
Definition ffv1_vulkan.h:36
FFVulkanShader reset
Definition vulkan_ffv1.c:91
AVRefStructPool * slice_fltmap_pool
Definition vulkan_ffv1.c:97
FFVulkanShader setup
Definition vulkan_ffv1.c:90
AVRefStructPool * slice_feedback_pool
Definition vulkan_ffv1.c:98
FFVulkanShader decode
Definition vulkan_ffv1.c:92
AVBufferRef * intermediate_frames_ref
Definition vulkan_ffv1.c:88
AVRefStructPool * slice_state_pool
Definition vulkan_ffv1.c:96
FFVkBuffer * slice_fltmap_buf
Definition vulkan_ffv1.c:76
PFN_vkWaitSemaphores wait_semaphores
Definition vulkan_ffv1.c:84
FFVulkanDecodePicture vp
Definition vulkan_ffv1.c:69
FFVkBuffer * slice_feedback_buf
Definition vulkan_ffv1.c:77
FFVkBuffer * slice_state
Definition vulkan_ffv1.c:71
Definition rpzaenc.c:60
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static AVFormatContext * ctx
Definition movenc.c:49
static char buffer[20]
Definition seek.c:32
int size
RefStruct is an API for creating reference-counted objects with minimal overhead.
Definition refstruct.h:58
#define ff_vk_buf_barrier(dst, vkb, s_stage, s_access, s_access2, d_stage, d_access, d_access2, offs, bsz)
Definition vulkan.h:562
@ FF_VK_REP_NATIVE
Definition vulkan.h:429
#define RET(x)
Definition vulkan.h:37
#define SPEC_LIST_ADD(name, idx, val_bits, val)
Definition vulkan.h:55
#define SPEC_LIST_CREATE(name, max_length, max_size)
Definition vulkan.h:45
static int ff_vk_count_images(AVVkFrame *f)
Definition vulkan.h:346
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.
static int vk_ffv1_end_frame(AVCodecContext *avctx)
const unsigned int ff_ffv1_dec_rgb_golomb_comp_spv_len
static int vk_ffv1_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
static int vk_decode_ffv1_init(AVCodecContext *avctx)
const unsigned char ff_ffv1_dec_setup_comp_spv_data[]
const unsigned int ff_ffv1_dec_bayer_golomb_comp_spv_len
const unsigned char ff_ffv1_dec_comp_spv_data[]
const unsigned char ff_ffv1_dec_golomb_comp_spv_data[]
const unsigned int ff_ffv1_dec_comp_spv_len
static void vk_ffv1_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
const unsigned int ff_ffv1_dec_rgb_float_comp_spv_len
const unsigned int ff_ffv1_dec_reset_golomb_comp_spv_len
const unsigned char ff_ffv1_dec_bayer_golomb_comp_spv_data[]
static int vk_ffv1_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
const unsigned int ff_ffv1_dec_bayer_comp_spv_len
const FFVulkanDecodeDescriptor ff_vk_dec_ffv1_desc
Definition vulkan_ffv1.c:63
const unsigned int ff_ffv1_dec_reset_comp_spv_len
const unsigned int ff_ffv1_dec_setup_comp_spv_len
const unsigned char ff_ffv1_dec_reset_comp_spv_data[]
static void vk_decode_ffv1_uninit(FFVulkanDecodeShared *ctx)
const unsigned int ff_ffv1_dec_golomb_comp_spv_len
static int init_reset_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd, VkSpecializationInfo *sl, int ac)
const unsigned char ff_ffv1_dec_bayer_comp_spv_data[]
const unsigned char ff_ffv1_dec_reset_golomb_comp_spv_data[]
const unsigned int ff_ffv1_dec_rgb_float_golomb_comp_spv_len
static int init_decode_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd, AVHWFramesContext *dec_frames_ctx, AVHWFramesContext *out_frames_ctx, VkSpecializationInfo *sl, int ac, int rgb, int bayer)
const unsigned char ff_ffv1_dec_rgb_comp_spv_data[]
const unsigned char ff_ffv1_dec_rgb_float_comp_spv_data[]
const unsigned char ff_ffv1_dec_rgb_float_golomb_comp_spv_data[]
static int init_indirect(AVCodecContext *avctx, FFVulkanContext *s, AVBufferRef **dst, enum AVPixelFormat sw_format)
const unsigned int ff_ffv1_dec_rgb_comp_spv_len
const unsigned char ff_ffv1_dec_rgb_golomb_comp_spv_data[]
static int init_setup_shader(FFV1Context *f, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd, VkSpecializationInfo *sl)
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY