Go to the documentation of this file.
34 .queue_flags = VK_QUEUE_COMPUTE_BIT,
84 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
85 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT);
90 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
91 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT,
93 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
94 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
155 VkImageMemoryBarrier2 img_bar[8];
163 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
164 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
177 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
178 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
179 VK_ACCESS_2_TRANSFER_WRITE_BIT,
180 VK_IMAGE_LAYOUT_GENERAL,
181 VK_QUEUE_FAMILY_IGNORED);
183 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
184 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
185 .pImageMemoryBarriers = img_bar,
186 .imageMemoryBarrierCount = nb_img_bar,
194 VK_IMAGE_LAYOUT_GENERAL,
202 .pkt_data = slices_buf->
address,
203 .frame_size[0] = avctx->
width,
204 .frame_size[1] = avctx->
height,
205 .tile_size[0] = prr->
tw,
206 .tile_size[1] = prr->
th,
208 memcpy(pd_decode.
qmat, prr->
qmat, 64);
210 VK_SHADER_STAGE_COMPUTE_BIT,
211 0,
sizeof(pd_decode), &pd_decode);
229 int parallel_rows = 1;
233 void *spv_opaque =
NULL;
235 if (
s->props.properties.limits.maxComputeWorkGroupInvocations < 512 ||
236 s->props.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
240 VK_SHADER_STAGE_COMPUTE_BIT,
241 (
const char *[]) {
"GL_EXT_buffer_reference",
242 "GL_EXT_buffer_reference2",
243 "GL_EXT_null_initializer" }, 3,
244 parallel_rows ? 8 : 1 ,
250 GLSLC(0, #define PARALLEL_ROWS );
261 GLSLC(0,
layout(push_constant, scalar) uniform pushConstants { );
263 GLSLC(1, u8buf pkt_data; );
265 GLSLC(1, uvec2 tile_size; );
266 GLSLC(1, uint8_t qmat[64]; );
270 VK_SHADER_STAGE_COMPUTE_BIT);
275 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
277 .mem_quali =
"writeonly",
279 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
286 .
name =
"dct_scale_buf",
287 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
288 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
289 .mem_layout =
"scalar",
290 .buf_content =
"float idct_8x8_scales[64];",
294 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
295 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
296 .mem_layout =
"scalar",
297 .buf_content =
"uint8_t scan[64];",
301 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
302 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
303 .mem_layout =
"scalar",
304 .buf_content =
"uint8_t dc_cb[13];",
308 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
309 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
310 .mem_layout =
"scalar",
311 .buf_content =
"int16_t ac_cb[95];",
315 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
316 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
317 .mem_layout =
"scalar",
318 .buf_content =
"int16_t rn_cb[28];",
322 .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
323 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
324 .mem_layout =
"scalar",
325 .buf_content =
"int16_t ln_cb[15];",
389 size_t cb_size[5] = {
398 size_t ua =
ctx->s.props.properties.limits.minUniformBufferOffsetAlignment;
399 cb_offset[0] = 64*
sizeof(
float) + 64*
sizeof(uint8_t);
400 cb_offset[1] = cb_offset[0] +
FFALIGN(cb_size[0], ua);
401 cb_offset[2] = cb_offset[1] +
FFALIGN(cb_size[1], ua);
402 cb_offset[3] = cb_offset[2] +
FFALIGN(cb_size[2], ua);
403 cb_offset[4] = cb_offset[3] +
FFALIGN(cb_size[3], ua);
406 64*
sizeof(
float) + 64*
sizeof(uint8_t) + cb_offset[4] + 256,
408 VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
409 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
410 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
411 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
413 uint8_t *uniform_buf;
417 float *dct_scale_buf = (
float *)uniform_buf;
418 double idct_8_scales[8] = {
419 cos(4.0*
M_PI/16.0) / 2.0,
420 cos(1.0*
M_PI/16.0) / 2.0,
421 cos(2.0*
M_PI/16.0) / 2.0,
422 cos(3.0*
M_PI/16.0) / 2.0,
423 cos(4.0*
M_PI/16.0) / 2.0,
424 cos(5.0*
M_PI/16.0) / 2.0,
425 cos(6.0*
M_PI/16.0) / 2.0,
426 cos(7.0*
M_PI/16.0) / 2.0,
428 for (
int i = 0;
i < 64;
i++)
429 dct_scale_buf[
i] = (
float)(idct_8_scales[
i >> 3] *
430 idct_8_scales[
i & 7]);
433 uint8_t *scan_buf = uniform_buf + 64*
sizeof(
float);
434 for (
int i = 0;
i < 64;
i++)
435 scan_buf[prr->
scan[
i]] =
i;
450 for (
int i = 0;
i < 2;
i++) {
455 VK_FORMAT_UNDEFINED));
459 64*
sizeof(
float), 64*
sizeof(uint8_t),
460 VK_FORMAT_UNDEFINED));
461 for (
int j = 0; j < 4; j++)
465 cb_offset[j], cb_size[j],
466 VK_FORMAT_UNDEFINED));
486 .
p.
name =
"prores_raw_vulkan",
int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
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
static void vk_decode_prores_raw_uninit(FFVulkanDecodeShared *ctx)
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name, VkPipelineStageFlags stage, const char *extensions[], int nb_extensions, int lg_x, int lg_y, int lg_z, uint32_t required_subgroup_size)
Initialize a shader object, with a specific set of extensions, type+bind, local group size,...
int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic, FFVulkanDecodePicture *vkpic, int is_current, enum FFVkShaderRepFormat rep_fmt, int alloc_dpb)
Software-defined decoder version of ff_vk_decode_prepare_frame.
uint8_t * data
The data buffer.
FFVulkanDecodeShared * shared_ctx
RefStruct is an API for creating reference-counted objects with minimal overhead.
AVHWAccel p
The public AVHWAccel.
static void vk_prores_raw_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
struct FFVulkanDecodePicture::@319 view
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
const int16_t ff_prores_raw_ln_cb[LN_CB_MAX+1]
@ 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)
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.
#define HWACCEL_CAP_THREAD_SAFE
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
int ff_vk_host_map_buffer(FFVulkanContext *s, AVBufferRef **dst, uint8_t *src_data, const AVBufferRef *src_buf, VkBufferUsageFlags usage)
Maps a system RAM buffer into a Vulkan buffer.
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *dst, uint64_t *dst_val, AVFrame *f)
const int16_t ff_prores_raw_rn_cb[RN_CB_MAX+1]
static int vk_prores_raw_end_frame(AVCodecContext *avctx)
int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, AVBufferRef **deps, int nb_deps, int ref)
Execution dependency management.
static int init_decode_shader(ProResRAWContext *prr, FFVulkanContext *s, FFVkExecPool *pool, FFVkSPIRVCompiler *spv, FFVulkanShader *shd, int version)
static int vk_prores_raw_decode_slice(AVCodecContext *avctx, const uint8_t *data, uint32_t size)
static int vk_prores_raw_start_frame(AVCodecContext *avctx, const AVBufferRef *buffer_ref, av_unused const uint8_t *buffer, av_unused uint32_t size)
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
const uint8_t ff_prores_raw_dc_cb[DC_CB_MAX+1]
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.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
int ff_vk_decode_uninit(AVCodecContext *avctx)
Free decoder.
void(* flush)(AVBSFContext *ctx)
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(* init)(AVBSFContext *ctx)
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.
const char * ff_source_prores_raw_comp
void * hwaccel_priv_data
hwaccel-specific private data
#define FF_VK_EXT_PUSH_DESCRIPTOR
int(* compile_shader)(FFVulkanContext *s, struct FFVkSPIRVCompiler *ctx, FFVulkanShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
#define AVERROR_EXTERNAL
Generic error in an external library.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
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.
const char * name
Name of the hardware accelerated codec.
VkDeviceAddress tile_data
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 layout
#define FF_VK_EXT_EXTERNAL_HOST_MEMORY
static void uninit(AVBSFContext *ctx)
VkImageView out[AV_NUM_DATA_POINTERS]
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
#define i(width, name, range_min, range_max)
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags src_stage, VkPipelineStageFlags dst_stage, VkAccessFlagBits new_access, VkImageLayout new_layout, uint32_t new_qf)
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, uint8_t *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
static int ff_vk_unmap_buffer(FFVulkanContext *s, FFVkBuffer *buf, int flush)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * ff_source_common_comp
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd)
Bind a shader.
void ff_vk_decode_flush(AVCodecContext *avctx)
Flush decoder.
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 FFVulkanDecodeDescriptor ff_vk_dec_prores_raw_desc
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
int ff_vk_params_invalidate(AVCodecContext *avctx, int t, const uint8_t *b, uint32_t s)
Removes current session parameters to recreate them.
int ff_vk_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Synchronize the contexts between 2 threads.
A reference to a data buffer.
static int vk_decode_prores_raw_init(AVCodecContext *avctx)
const int16_t ff_prores_raw_ac_cb[AC_CB_MAX+1]
AVBufferPool * tile_data_pool
int width
picture width / height.
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
int ff_vk_decode_init(AVCodecContext *avctx)
Initialize decoder.
const FFHWAccel ff_prores_raw_vulkan_hwaccel
void * hwaccel_picture_private
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVBufferPool **buf_pool, AVBufferRef **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.