FFmpeg
Loading...
Searching...
No Matches
d3d12_filter.h File Reference
#include "config.h"
#include "libavutil/buffer.h"
#include "libavutil/fifo.h"
#include "libavutil/frame.h"
#include "libavutil/hwcontext_d3d12va.h"
#include "libavutil/pixfmt.h"
#include "avfilter.h"

Go to the source code of this file.

Data Structures

struct  D3D12FilterFormat
 
struct  D3D12CommandContext
 One command queue with its command list, a pool of command allocators and a private fence. More...
 

Macros

#define D3D12_FILTER_MAX_INPUTS   8
 Maximum number of input frames (including reference frames) that one submission can read.
 

Functions

const D3D12FilterFormat * ff_d3d12_filter_format_from_pix_fmt (enum AVPixelFormat pix_fmt)
 
const D3D12FilterFormat * ff_d3d12_filter_format_from_dxgi (DXGI_FORMAT dxgi_format)
 
const D3D12FilterFormat * ff_d3d12_filter_format_iterate (void **opaque)
 Iterate over all supported formats.
 
int ff_d3d12_filter_get_colorspace (AVFilterContext *ctx, int is_rgb, int is_output, enum AVColorSpace *spc, enum AVColorRange *range, enum AVColorPrimaries *primaries, enum AVColorTransferCharacteristic *trc, enum AVChromaLocation chroma_loc, enum AVColorPrimaries input_601_hint, DXGI_COLOR_SPACE_TYPE *out_space)
 Map AVFrame color properties to a DXGI color space.
 
enum AVChromaLocation ff_d3d12_filter_chroma_location (DXGI_COLOR_SPACE_TYPE space)
 
AVRational ff_d3d12_filter_get_input_framerate (AVFilterContext *ctx, AVFilterLink *inlink, const AVFrame *in)
 
int ff_d3d12_filter_wait_fence (ID3D12Fence *fence, UINT64 target, HANDLE fence_event, DWORD timeout_ms)
 Wait until fence reaches target, or until timeout_ms expires.
 
void ff_d3d12_filter_add_frame_barriers (D3D12_RESOURCE_BARRIER *barriers, int *nb_barriers, const AVD3D12VAFrame *frame, int nb_planes, D3D12_RESOURCE_STATES state_before, D3D12_RESOURCE_STATES state_after)
 Append one transition barrier per plane of a D3D12 frame.
 
int ff_d3d12_filter_init_output_frames (AVFilterContext *ctx, AVBufferRef *device_ref, enum AVPixelFormat sw_format, int width, int height, int initial_pool_size, AVBufferRef **frames_ref)
 Allocate and initialize a pool of D3D12 frames that can be used as render targets.
 
int ff_d3d12_cmd_init (AVFilterContext *ctx, D3D12CommandContext *cmd, ID3D12Device *device, D3D12_COMMAND_LIST_TYPE type)
 Create the command queue, the fence and a closed command list of the given type, after releasing any previous configuration.
 
int ff_d3d12_cmd_begin (AVFilterContext *ctx, D3D12CommandContext *cmd)
 Get a command allocator the GPU is done with, and reset it together with the command list for recording.
 
int ff_d3d12_cmd_wait_context (AVFilterContext *ctx, D3D12CommandContext *cmd, const D3D12CommandContext *other)
 Make the queue of cmd wait, on the GPU, until the latest submission of other has completed.
 
int ff_d3d12_cmd_submit (AVFilterContext *ctx, D3D12CommandContext *cmd, AVFrame *const *inputs, int nb_inputs, AVFrame *output, int *frames_in_use)
 Close and execute the command list.
 
int ff_d3d12_cmd_sync (AVFilterContext *ctx, D3D12CommandContext *cmd, DWORD timeout_ms)
 Wait on the CPU until the latest submission has completed.
 
int ff_d3d12_cmd_uninit (AVFilterContext *ctx, D3D12CommandContext *cmd)
 Wait for the GPU to finish all submitted work, then release all D3D12 objects and clear cmd->ready.
 

Macro Definition Documentation

◆ D3D12_FILTER_MAX_INPUTS

#define D3D12_FILTER_MAX_INPUTS   8

Maximum number of input frames (including reference frames) that one submission can read.

Definition at line 40 of file d3d12_filter.h.

Referenced by ff_d3d12_cmd_submit().

Function Documentation

◆ ff_d3d12_filter_format_from_pix_fmt()

const D3D12FilterFormat * ff_d3d12_filter_format_from_pix_fmt ( enum AVPixelFormat pix_fmt)

◆ ff_d3d12_filter_format_from_dxgi()

const D3D12FilterFormat * ff_d3d12_filter_format_from_dxgi ( DXGI_FORMAT dxgi_format)

Definition at line 64 of file d3d12_filter.c.

Referenced by scale_d3d12_configure_processor(), and scale_d3d12_filter_frame().

◆ ff_d3d12_filter_format_iterate()

const D3D12FilterFormat * ff_d3d12_filter_format_iterate ( void ** opaque)

Iterate over all supported formats.

Parameters
opaquea pointer where state is stored, must point to NULL on the first call
Returns
the next format, or NULL when the iteration is finished

Definition at line 73 of file d3d12_filter.c.

Referenced by ff_d3d12_vpp_report_output_support().

◆ ff_d3d12_filter_get_colorspace()

int ff_d3d12_filter_get_colorspace ( AVFilterContext * ctx,
int is_rgb,
int is_output,
enum AVColorSpace * spc,
enum AVColorRange * range,
enum AVColorPrimaries * primaries,
enum AVColorTransferCharacteristic * trc,
enum AVChromaLocation chroma_loc,
enum AVColorPrimaries input_601_hint,
DXGI_COLOR_SPACE_TYPE * out_space )

Map AVFrame color properties to a DXGI color space.

For an input (is_output = 0), properties that no DXGI color space can represent are rejected. For an output request (is_output = 1), they are retagged to the nearest representable value where possible. spc and primaries may be adjusted; range and trc are only inspected. The caller must derive the final AVFrame color metadata, including any transfer characteristic reconciliation required by a conversion.

Parameters
input_601_hintprimaries of a BT.601 input, used to keep the output's PAL/NTSC primaries consistent with it

< Default to Rec.709

Definition at line 213 of file d3d12_filter.c.

Referenced by ff_d3d12_vpp_report_output_support(), and scale_d3d12_filter_frame().

◆ ff_d3d12_filter_chroma_location()

enum AVChromaLocation ff_d3d12_filter_chroma_location ( DXGI_COLOR_SPACE_TYPE space)

Definition at line 479 of file d3d12_filter.c.

Referenced by scale_d3d12_filter_frame().

◆ ff_d3d12_filter_get_input_framerate()

AVRational ff_d3d12_filter_get_input_framerate ( AVFilterContext * ctx,
AVFilterLink * inlink,
const AVFrame * in )

Definition at line 494 of file d3d12_filter.c.

Referenced by scale_d3d12_filter_frame().

◆ ff_d3d12_filter_wait_fence()

int ff_d3d12_filter_wait_fence ( ID3D12Fence * fence,
UINT64 target,
HANDLE fence_event,
DWORD timeout_ms )

Wait until fence reaches target, or until timeout_ms expires.

Returns
1 if the fence reached target, 0 otherwise

Definition at line 515 of file d3d12_filter.c.

Referenced by d3d12_cmd_discard_command_allocator(), d3d12_cmd_sync_after_failure(), ff_d3d12_cmd_sync(), and ff_d3d12_cmd_uninit().

◆ ff_d3d12_filter_add_frame_barriers()

void ff_d3d12_filter_add_frame_barriers ( D3D12_RESOURCE_BARRIER * barriers,
int * nb_barriers,
const AVD3D12VAFrame * frame,
int nb_planes,
D3D12_RESOURCE_STATES state_before,
D3D12_RESOURCE_STATES state_after )

Append one transition barrier per plane of a D3D12 frame.

Definition at line 549 of file d3d12_filter.c.

Referenced by scale_d3d12_filter_frame().

◆ ff_d3d12_filter_init_output_frames()

int ff_d3d12_filter_init_output_frames ( AVFilterContext * ctx,
AVBufferRef * device_ref,
enum AVPixelFormat sw_format,
int width,
int height,
int initial_pool_size,
AVBufferRef ** frames_ref )

Allocate and initialize a pool of D3D12 frames that can be used as render targets.

ctx->extra_hw_frames is added to initial_pool_size.

Definition at line 574 of file d3d12_filter.c.

Referenced by scale_d3d12_config_props().

◆ ff_d3d12_cmd_init()

int ff_d3d12_cmd_init ( AVFilterContext * ctx,
D3D12CommandContext * cmd,
ID3D12Device * device,
D3D12_COMMAND_LIST_TYPE type )

Create the command queue, the fence and a closed command list of the given type, after releasing any previous configuration.

type must be DIRECT, VIDEO_PROCESS or, when available in the headers, VIDEO_ENCODE. Releases everything on failure.

Definition at line 802 of file d3d12_filter.c.

Referenced by ff_d3d12_vpp_init().

◆ ff_d3d12_cmd_begin()

int ff_d3d12_cmd_begin ( AVFilterContext * ctx,
D3D12CommandContext * cmd )

Get a command allocator the GPU is done with, and reset it together with the command list for recording.

If the command list cannot be reset, the context is torn down and cmd->ready is cleared.

Definition at line 926 of file d3d12_filter.c.

Referenced by ff_d3d12_vpp_begin().

◆ ff_d3d12_cmd_wait_context()

int ff_d3d12_cmd_wait_context ( AVFilterContext * ctx,
D3D12CommandContext * cmd,
const D3D12CommandContext * other )

Make the queue of cmd wait, on the GPU, until the latest submission of other has completed.

Must be called before the submission of cmd that depends on it. Does nothing if other has no pending work.

Definition at line 955 of file d3d12_filter.c.

◆ ff_d3d12_cmd_submit()

int ff_d3d12_cmd_submit ( AVFilterContext * ctx,
D3D12CommandContext * cmd,
AVFrame *const * inputs,
int nb_inputs,
AVFrame * output,
int * frames_in_use )

Close and execute the command list.

The queue first waits for the fences of all inputs and of the output, then signals the output frame's fence. output may be NULL. References to the inputs are kept until the GPU has finished with them. If the command list cannot be closed, the context is torn down and cmd->ready is cleared.

Parameters
[out]frames_in_useset to 1 on failure if the GPU may still access the frames, in which case the caller must not free them

Definition at line 1062 of file d3d12_filter.c.

Referenced by ff_d3d12_vpp_submit().

◆ ff_d3d12_cmd_sync()

int ff_d3d12_cmd_sync ( AVFilterContext * ctx,
D3D12CommandContext * cmd,
DWORD timeout_ms )

Wait on the CPU until the latest submission has completed.

Returns
0 on success, AVERROR_EXTERNAL on timeout or failure

Definition at line 978 of file d3d12_filter.c.

◆ ff_d3d12_cmd_uninit()

int ff_d3d12_cmd_uninit ( AVFilterContext * ctx,
D3D12CommandContext * cmd )

Wait for the GPU to finish all submitted work, then release all D3D12 objects and clear cmd->ready.

Returns
0 on success, AVERROR_EXTERNAL if the GPU could not be confirmed idle, in which case nothing is released

Definition at line 722 of file d3d12_filter.c.

Referenced by d3d12_cmd_force_reconfigure(), ff_d3d12_cmd_init(), and ff_d3d12_vpp_uninit().