Go to the documentation of this file.
35 .queue_flags = VK_QUEUE_COMPUTE_BIT,
83 VK_WHOLE_SIZE, buffer_ref,
84 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
85 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
94 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
95 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
97 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
98 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
141 if (slices_buf && slices_buf->
host_ref) {
185 VkImageMemoryBarrier2 img_bar[8];
187 VkBufferMemoryBarrier2 buf_bar[2];
198 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
199 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
211 vkf->
layout[0] = VK_IMAGE_LAYOUT_UNDEFINED;
212 vkf->
access[0] = VK_ACCESS_2_NONE;
215 img_bar, &nb_img_bar,
216 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
217 VK_PIPELINE_STAGE_2_CLEAR_BIT,
218 VK_ACCESS_2_TRANSFER_WRITE_BIT,
219 VK_IMAGE_LAYOUT_GENERAL,
220 VK_QUEUE_FAMILY_IGNORED);
221 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
222 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
223 .pImageMemoryBarriers = img_bar,
224 .imageMemoryBarrierCount = nb_img_bar,
230 vk->CmdClearColorImage(exec->
buf, vkf->
img[
i],
231 VK_IMAGE_LAYOUT_GENERAL,
232 &((VkClearColorValue) { 0 }),
233 1, &((VkImageSubresourceRange) {
234 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
241 VK_PIPELINE_STAGE_2_CLEAR_BIT,
242 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
243 VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
244 VK_IMAGE_LAYOUT_GENERAL,
245 VK_QUEUE_FAMILY_IGNORED);
246 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
247 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
248 .pImageMemoryBarriers = img_bar,
249 .imageMemoryBarrierCount = nb_img_bar,
255 VK_BUFFER_USAGE_TRANSFER_DST_BIT |
256 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
258 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
261 vk->CmdFillBuffer(exec->
buf, coeff_buf->
buf, 0, VK_WHOLE_SIZE, 0);
263 buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
264 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
265 .srcStageMask = VK_PIPELINE_STAGE_2_CLEAR_BIT,
266 .srcAccessMask = VK_ACCESS_2_TRANSFER_WRITE_BIT,
267 .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
268 .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT |
269 VK_ACCESS_2_SHADER_STORAGE_READ_BIT,
270 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
271 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
272 .buffer = coeff_buf->
buf,
273 .size = VK_WHOLE_SIZE,
275 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
276 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
277 .pBufferMemoryBarriers = buf_bar,
278 .bufferMemoryBarrierCount = nb_buf_bar,
286 .log2_chroma_sub = {
desc->log2_chroma_w,
desc->log2_chroma_h },
287 .components =
desc->nb_components,
295 VK_IMAGE_LAYOUT_GENERAL,
300 0, frame_data_buf->
size,
301 VK_FORMAT_UNDEFINED);
304 coeff_buf, 0, coeff_buf->
size,
305 VK_FORMAT_UNDEFINED);
309 VK_SHADER_STAGE_COMPUTE_BIT,
312 vk->CmdDispatch(exec->
buf,
314 desc->nb_components);
317 buf_bar[nb_buf_bar++] = (VkBufferMemoryBarrier2) {
318 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
319 .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
320 .srcAccessMask = VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
321 .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
322 .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT,
323 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
324 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
325 .buffer = coeff_buf->
buf,
326 .size = VK_WHOLE_SIZE,
328 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
329 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
330 .pBufferMemoryBarriers = buf_bar,
331 .bufferMemoryBarrierCount = nb_buf_bar,
339 VK_IMAGE_LAYOUT_GENERAL,
344 0, frame_data_buf->
size,
345 VK_FORMAT_UNDEFINED);
348 coeff_buf, 0, coeff_buf->
size,
349 VK_FORMAT_UNDEFINED);
353 VK_SHADER_STAGE_COMPUTE_BIT,
358 int idct_cx = 0, idct_by = 0;
360 int sw = (
comp == 0) ? 0 :
desc->log2_chroma_w;
361 int sh = (
comp == 0) ? 0 :
desc->log2_chroma_h;
362 int bx = (avctx->
coded_width + (1 << (3 + sw)) - 1) >> (3 + sw);
363 int by = (avctx->
coded_height + (1 << (3 + sh)) - 1) >> (3 + sh);
364 idct_cx =
FFMAX(idct_cx, (bx + 7) >> 3);
365 idct_by =
FFMAX(idct_by, by);
367 vk->CmdDispatch(exec->
buf, idct_cx, idct_by,
desc->nb_components);
374 return err < 0 ? err : 0;
385 (uint32_t []) { 1, 1, 1 }, 0);
387 VK_SHADER_STAGE_COMPUTE_BIT);
392 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
394 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
397 .name =
"frame_data_buf",
398 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
399 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
402 .name =
"coeffs_out_buf",
403 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
404 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
429 const double idct_8_scales[8] = {
430 cos(4.0*
M_PI/16.0) / 2.0, cos(1.0*
M_PI/16.0) / 2.0,
431 cos(2.0*
M_PI/16.0) / 2.0, cos(3.0*
M_PI/16.0) / 2.0,
432 cos(4.0*
M_PI/16.0) / 2.0, cos(5.0*
M_PI/16.0) / 2.0,
433 cos(6.0*
M_PI/16.0) / 2.0, cos(7.0*
M_PI/16.0) / 2.0,
435 for (
int i = 0;
i < 64;
i++)
440 (uint32_t []) { 32, 2, 1 }, 0);
442 VK_SHADER_STAGE_COMPUTE_BIT);
447 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
448 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
452 .name =
"frame_data_buf",
453 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
454 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
457 .name =
"coeffs_in_buf",
458 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
459 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
516 apvvk->
coeff_size += (size_t)(cw >> sx) * (ch >> sy);
544 .
p.
name =
"apv_vulkan",
const FFVulkanDecodeDescriptor ff_vk_dec_apv_desc
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void * priv_data
Internal codec-specific data.
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
FFVulkanDecodeShared * shared_ctx
RefStruct is an API for creating reference-counted objects with minimal overhead.
static int vk_apv_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
AVHWAccel p
The public AVHWAccel.
APVRawTile tile[APV_MAX_TILE_COUNT]
AVRefStructPool * frame_data_pool
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.
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
#define SPEC_LIST_ADD(name, idx, val_bits, val)
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
APVDerivedTileInfo tile_info
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
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.
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)
#define HWACCEL_CAP_THREAD_SAFE
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
const unsigned int ff_apv_decode_comp_spv_len
static void vk_apv_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
APVRawFrameHeader frame_header
static int init_idct_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
static int init_decode_shader(AVCodecContext *avctx, FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
static AVFormatContext * ctx
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
APVRawFrame * cur_raw_frame
void ff_vk_exec_move_dep_refstruct(FFVulkanContext *s, FFVkExecContext *e, void *obj)
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.
const unsigned char ff_apv_decode_comp_spv_data[]
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
uint8_t nb_components
The number of components each pixel has, (1-4)
void ff_vk_decode_free_frame(AVHWDeviceContext *dev_ctx, FFVulkanDecodePicture *vp)
Free a frame and its state.
struct AVCodecInternal * internal
Private context used for internal data.
uint8_t q_matrix[APV_MAX_NUM_COMP][APV_TR_SIZE][APV_TR_SIZE]
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
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.
#define SPEC_LIST_CREATE(name, max_length, max_size)
VkAccessFlagBits2 access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
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...
APVRawTileHeader tile_header
static int vk_decode_apv_init(AVCodecContext *avctx)
static int vk_apv_end_frame(AVCodecContext *avctx)
int(* init)(AVBSFContext *ctx)
const FFHWAccel ff_apv_vulkan_hwaccel
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.
void * hwaccel_priv_data
hwaccel-specific private data
#define i(width, name, range_min, range_max)
#define AV_NUM_DATA_POINTERS
FFVkBuffer * frame_data_buf
FrameData * frame_data(AVFrame *frame)
Get our axiliary frame data attached to the frame, allocating it if needed.
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.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
const char * name
Name of the hardware accelerated codec.
VkDeviceAddress tile_data
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
uint16_t row_starts[APV_MAX_TILE_ROWS+1]
static void vk_decode_apv_uninit(FFVulkanDecodeShared *ctx)
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int vk_apv_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
const unsigned char ff_apv_idct_comp_spv_data[]
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
This struct describes a set or pool of "hardware" frames (i.e.
void ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular)
Add descriptor to a shader.
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.
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.
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
const unsigned int ff_apv_idct_comp_spv_len
main external API structure.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have update_thread_context() run it in the next thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. Use ff_thread_get_buffer()(or ff_progress_frame_get_buffer() in case you have inter-frame dependencies and use the ProgressFrame API) to allocate frame buffers. Call ff_progress_frame_report() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
uint16_t col_starts[APV_MAX_TILE_COLS+1]
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Synchronize the contexts between 2 threads.
int coded_width
Bitstream width / height, may be different from width/height e.g.
VkImageLayout layout[AV_NUM_DATA_POINTERS]
A reference to a data buffer.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
CodedBitstreamContext * cbc
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
static int ff_vk_count_images(AVVkFrame *f)
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
void * hwaccel_picture_private
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
AVRefStructPool * coeff_pool
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.
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.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.