FFmpeg
Loading...
Searching...
No Matches
d3d12_filter.c File Reference
#include <stdint.h>
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/fifo.h"
#include "libavutil/frame.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_d3d12va.h"
#include "libavutil/pixdesc.h"
#include "d3d12_filter.h"
#include "filters.h"

Go to the source code of this file.

Data Structures

struct  D3D12CommandAllocator
 

Macros

#define COBJMACROS
 

Functions

const D3D12FilterFormat * ff_d3d12_filter_format_from_pix_fmt (enum AVPixelFormat fmt)
 
const D3D12FilterFormat * ff_d3d12_filter_format_from_dxgi (DXGI_FORMAT fmt)
 
const D3D12FilterFormat * ff_d3d12_filter_format_iterate (void **opaque)
 Iterate over all supported formats.
 
static int d3d12_filter_known_matrix (enum AVColorSpace spc)
 
static int d3d12_filter_known_sdr_trc (enum AVColorTransferCharacteristic trc)
 
static int d3d12_filter_reconcile_primaries (AVFilterContext *ctx, int is_output, enum AVColorPrimaries *primaries, enum AVColorPrimaries expected_primaries, const char *space_description)
 
static int d3d12_filter_reject_unrepresentable_nonleft (AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
 
static int d3d12_filter_reject_unrepresentable_left (AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
 
static int d3d12_filter_reject_unrepresentable_siting_2020 (AVFilterContext *ctx, int is_output, enum AVChromaLocation chroma_loc)
 
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.
 
static ID3D12CommandList * d3d12_cmd_get_list (const D3D12CommandContext *cmd)
 
static HRESULT d3d12_cmd_reset_list (D3D12CommandContext *cmd, ID3D12CommandAllocator *allocator)
 
static HRESULT d3d12_cmd_close_list (D3D12CommandContext *cmd)
 
static void d3d12_cmd_free_input_refs (D3D12CommandAllocator *allocator)
 
static int d3d12_cmd_get_valid_command_allocator (D3D12CommandContext *cmd, AVFilterContext *ctx, ID3D12CommandAllocator **ppAllocator)
 
static int d3d12_cmd_discard_command_allocator (D3D12CommandContext *cmd, AVFilterContext *ctx, D3D12CommandAllocator *allocator)
 
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.
 
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.
 
static void d3d12_cmd_force_reconfigure (AVFilterContext *ctx, D3D12CommandContext *cmd, ID3D12CommandAllocator *command_allocator)
 
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_sync (AVFilterContext *ctx, D3D12CommandContext *cmd, DWORD timeout_ms)
 Wait on the CPU until the latest submission has completed.
 
static int d3d12_cmd_wait_frame (AVFilterContext *ctx, D3D12CommandContext *cmd, const AVFrame *frame, const char *fence_name)
 
static int d3d12_cmd_sync_after_failure (AVFilterContext *ctx, D3D12CommandContext *cmd)
 
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.
 

Variables

static const D3D12FilterFormat d3d12_filter_formats []
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 23 of file d3d12_filter.c.

Function Documentation

◆ ff_d3d12_filter_format_from_pix_fmt()

const D3D12FilterFormat * ff_d3d12_filter_format_from_pix_fmt ( enum AVPixelFormat fmt)

◆ ff_d3d12_filter_format_from_dxgi()

const D3D12FilterFormat * ff_d3d12_filter_format_from_dxgi ( DXGI_FORMAT fmt)

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().

◆ d3d12_filter_known_matrix()

static int d3d12_filter_known_matrix ( enum AVColorSpace spc)
static

Definition at line 85 of file d3d12_filter.c.

Referenced by ff_d3d12_filter_get_colorspace().

◆ d3d12_filter_known_sdr_trc()

static int d3d12_filter_known_sdr_trc ( enum AVColorTransferCharacteristic trc)
static

Definition at line 101 of file d3d12_filter.c.

Referenced by ff_d3d12_filter_get_colorspace().

◆ d3d12_filter_reconcile_primaries()

static int d3d12_filter_reconcile_primaries ( AVFilterContext * ctx,
int is_output,
enum AVColorPrimaries * primaries,
enum AVColorPrimaries expected_primaries,
const char * space_description )
static

Definition at line 120 of file d3d12_filter.c.

Referenced by ff_d3d12_filter_get_colorspace().

◆ d3d12_filter_reject_unrepresentable_nonleft()

static int d3d12_filter_reject_unrepresentable_nonleft ( AVFilterContext * ctx,
int is_output,
enum AVChromaLocation chroma_loc )
static

Definition at line 148 of file d3d12_filter.c.

Referenced by ff_d3d12_filter_get_colorspace().

◆ d3d12_filter_reject_unrepresentable_left()

static int d3d12_filter_reject_unrepresentable_left ( AVFilterContext * ctx,
int is_output,
enum AVChromaLocation chroma_loc )
static

Definition at line 169 of file d3d12_filter.c.

Referenced by ff_d3d12_filter_get_colorspace().

◆ d3d12_filter_reject_unrepresentable_siting_2020()

static int d3d12_filter_reject_unrepresentable_siting_2020 ( AVFilterContext * ctx,
int is_output,
enum AVChromaLocation chroma_loc )
static

Definition at line 190 of file d3d12_filter.c.

Referenced by ff_d3d12_filter_get_colorspace().

◆ 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().

◆ d3d12_cmd_get_list()

static ID3D12CommandList * d3d12_cmd_get_list ( const D3D12CommandContext * cmd)
static

Definition at line 619 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_submit(), and ff_d3d12_cmd_uninit().

◆ d3d12_cmd_reset_list()

static HRESULT d3d12_cmd_reset_list ( D3D12CommandContext * cmd,
ID3D12CommandAllocator * allocator )
static

Definition at line 635 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_begin().

◆ d3d12_cmd_close_list()

static HRESULT d3d12_cmd_close_list ( D3D12CommandContext * cmd)
static

Definition at line 651 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_init(), and ff_d3d12_cmd_submit().

◆ d3d12_cmd_free_input_refs()

static void d3d12_cmd_free_input_refs ( D3D12CommandAllocator * allocator)
static

◆ d3d12_cmd_get_valid_command_allocator()

static int d3d12_cmd_get_valid_command_allocator ( D3D12CommandContext * cmd,
AVFilterContext * ctx,
ID3D12CommandAllocator ** ppAllocator )
static

Definition at line 674 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_begin(), and ff_d3d12_cmd_init().

◆ d3d12_cmd_discard_command_allocator()

static int d3d12_cmd_discard_command_allocator ( D3D12CommandContext * cmd,
AVFilterContext * ctx,
D3D12CommandAllocator * allocator )
static

Definition at line 701 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_init(), and ff_d3d12_cmd_submit().

◆ 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().

◆ 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().

◆ d3d12_cmd_force_reconfigure()

static void d3d12_cmd_force_reconfigure ( AVFilterContext * ctx,
D3D12CommandContext * cmd,
ID3D12CommandAllocator * command_allocator )
static

Definition at line 919 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_begin(), and ff_d3d12_cmd_submit().

◆ 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_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.

◆ d3d12_cmd_wait_frame()

static int d3d12_cmd_wait_frame ( AVFilterContext * ctx,
D3D12CommandContext * cmd,
const AVFrame * frame,
const char * fence_name )
static

Definition at line 994 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_submit().

◆ d3d12_cmd_sync_after_failure()

static int d3d12_cmd_sync_after_failure ( AVFilterContext * ctx,
D3D12CommandContext * cmd )
static

Definition at line 1019 of file d3d12_filter.c.

Referenced by ff_d3d12_cmd_submit().

◆ 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().

Variable Documentation

◆ d3d12_filter_formats

const D3D12FilterFormat d3d12_filter_formats[]
static
Initial value:
= {
{ AV_PIX_FMT_NV12, DXGI_FORMAT_NV12, 0 },
{ AV_PIX_FMT_P010, DXGI_FORMAT_P010, 0 },
{ AV_PIX_FMT_P012, DXGI_FORMAT_P016, 0 },
{ AV_PIX_FMT_X2BGR10, DXGI_FORMAT_R10G10B10A2_UNORM, 1 },
}
@ DXGI_FORMAT_B8G8R8A8_UNORM
Definition dds.c:92
@ DXGI_FORMAT_R16G16B16A16_FLOAT
Definition dds.c:63
@ DXGI_FORMAT_R8G8B8A8_UNORM
Definition dds.c:70
#define AV_PIX_FMT_RGBAF16
Definition pixfmt.h:635
#define AV_PIX_FMT_P012
Definition pixfmt.h:614
#define AV_PIX_FMT_P010
Definition pixfmt.h:613
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition pixfmt.h:96
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition pixfmt.h:102
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
#define AV_PIX_FMT_X2BGR10
Definition pixfmt.h:625

Definition at line 45 of file d3d12_filter.c.

Referenced by ff_d3d12_filter_format_from_dxgi(), ff_d3d12_filter_format_from_pix_fmt(), and ff_d3d12_filter_format_iterate().