Go to the documentation of this file.
57 void *spv_opaque =
NULL;
69 spv = ff_vk_spirv_init();
84 VK_SHADER_STAGE_COMPUTE_BIT,
85 (
const char *[]) {
"GL_KHR_shader_subgroup_arithmetic" }, 1,
93 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
95 .mem_quali =
"readonly",
98 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
101 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
103 .mem_quali =
"readonly",
106 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
108 .name =
"sad_buffer",
109 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
110 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
111 .buf_content =
"uint frame_sad[];",
117 GLSLC(0, shared uint wg_sum; );
120 GLSLF(1,
const uint slice = gl_WorkGroupID.x %% %
u; ,
SLICES);
121 GLSLC(1,
const ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
122 GLSLC(1, wg_sum = 0; );
123 GLSLC(1, barrier(); );
124 for (
int i = 0;
i <
s->nb_planes;
i++) {
125 GLSLF(1,
if (IS_WITHIN(
pos, imageSize(cur_img[%d]))) { ,
i);
126 GLSLF(2, uvec4 prev = imageLoad(prev_img[%d],
pos); ,
i);
127 GLSLF(2, uvec4 cur = imageLoad(cur_img[%d],
pos); ,
i);
128 GLSLC(2, uvec4 sad =
abs(ivec4(cur) - ivec4(prev)); );
129 GLSLC(2, uint sum = subgroupAdd(sad.x + sad.y + sad.z); );
130 GLSLC(2,
if (subgroupElect()) );
134 GLSLC(1, barrier(); );
135 GLSLC(1,
if (gl_LocalInvocationIndex == 0) );
170 mafd = (
double) sad * 100.0 / count / (1ULL <<
desc->comp[0].depth);
186 VkImageMemoryBarrier2 img_bar[8];
209 VK_BUFFER_USAGE_TRANSFER_DST_BIT |
210 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
213 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
214 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
215 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
223 VK_PIPELINE_STAGE_2_NONE,
224 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
228 VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
231 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
232 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
233 VK_ACCESS_SHADER_READ_BIT,
234 VK_IMAGE_LAYOUT_GENERAL,
235 VK_QUEUE_FAMILY_IGNORED);
238 VK_PIPELINE_STAGE_2_NONE,
239 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
243 VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
246 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
247 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
248 VK_ACCESS_SHADER_READ_BIT,
249 VK_IMAGE_LAYOUT_GENERAL,
250 VK_QUEUE_FAMILY_IGNORED);
253 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
254 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
255 .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
256 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
257 .srcStageMask = VK_PIPELINE_STAGE_2_NONE,
258 .dstStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
259 .dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
260 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
261 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
262 .buffer = buf_vk->buf,
263 .size = buf_vk->size,
266 .bufferMemoryBarrierCount = 1,
269 vk->CmdFillBuffer(exec->buf, buf_vk->buf, 0, buf_vk->size, 0x0);
271 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
272 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
273 .pImageMemoryBarriers = img_bar,
274 .imageMemoryBarrierCount = nb_img_bar,
275 .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
276 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
277 .srcStageMask = VK_PIPELINE_STAGE_2_TRANSFER_BIT,
278 .dstStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
279 .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT,
280 .dstAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
281 VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
282 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
283 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
284 .buffer = buf_vk->buf,
285 .size = buf_vk->size,
288 .bufferMemoryBarrierCount = 1,
292 buf_vk, 0, buf_vk->size,
293 VK_FORMAT_UNDEFINED));
297 vk->CmdDispatch(exec->buf,
298 FFALIGN(in->width,
s->shd.lg_size[0]) /
s->shd.lg_size[0],
299 FFALIGN(in->height,
s->shd.lg_size[1]) /
s->shd.lg_size[1],
302 vk->CmdPipelineBarrier2(exec->buf, &(VkDependencyInfo) {
303 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
304 .pBufferMemoryBarriers = &(VkBufferMemoryBarrier2) {
305 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER_2,
306 .srcStageMask = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
307 .dstStageMask = VK_PIPELINE_STAGE_2_HOST_BIT,
308 .srcAccessMask = VK_ACCESS_2_SHADER_STORAGE_READ_BIT |
309 VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT,
310 .dstAccessMask = VK_ACCESS_HOST_READ_BIT,
311 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
312 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
313 .buffer = buf_vk->buf,
314 .size = buf_vk->size,
317 .bufferMemoryBarrierCount = 1,
325 snprintf(str,
sizeof(str),
"%0.3f",
s->prev_mafd);
326 av_dict_set(&in->metadata,
"lavfi.scd.mafd", str, 0);
327 snprintf(str,
sizeof(str),
"%0.3f", score);
328 av_dict_set(&in->metadata,
"lavfi.scd.score", str, 0);
330 if (score >=
s->threshold) {
338 if (!
s->sc_pass || score >=
s->threshold)
371 #define OFFSET(x) offsetof(SceneDetectVulkanContext, x)
372 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
401 .
p.
name =
"scdet_vulkan",
403 .p.priv_class = &scdet_vulkan_class,
AVBufferPool * det_buf_pool
static void scdet_vulkan_uninit(AVFilterContext *avctx)
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 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_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *qf, FFVkExecPool *pool, int nb_contexts, int nb_queries, VkQueryType query_type, int query_64bit, const void *query_create_pnext)
Allocates/frees an execution pool.
AVFILTER_DEFINE_CLASS(scdet_vulkan)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
static double evaluate(AVFilterContext *ctx, const SceneDetectBuf *buf)
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
const char * name
Filter name.
A link between two filters.
@ 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)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
void * priv
private data for use by the filter
#define u(width, name, range_min, range_max)
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.
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
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.
A filter pad used for either input or output.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int scdet_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
#define FILTER_OUTPUTS(array)
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 link
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
static __device__ float fabs(float a)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
int ff_vk_filter_config_output(AVFilterLink *outlink)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
uint32_t frame_sad[SLICES]
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int(* init)(AVBSFContext *ctx)
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
#define AV_NUM_DATA_POINTERS
AVRational time_base
Time base for the timestamps in this frame.
AVVulkanDeviceQueueFamily * qf
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
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.
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.
#define AV_LOG_INFO
Standard information.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static void uninit(AVBSFContext *ctx)
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.
const char * name
Pad name.
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd)
Bind 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.
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
const FFFilter ff_vf_scdet_vulkan
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
static const AVFilterPad scdet_vulkan_outputs[]
static const AVOption scdet_vulkan_options[]
int ff_vk_filter_config_input(AVFilterLink *inlink)
AVFilter p
The public AVFilter.
A reference to a data buffer.
static av_cold int init_filter(AVFilterContext *ctx)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
static const AVFilterPad scdet_vulkan_inputs[]
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.