FFmpeg
hwcontext_d3d12va.h
Go to the documentation of this file.
1 /*
2  * Direct3D 12 HW acceleration.
3  *
4  * copyright (c) 2022-2023 Wu Jianhua <toqsxw@outlook.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef AVUTIL_HWCONTEXT_D3D12VA_H
24 #define AVUTIL_HWCONTEXT_D3D12VA_H
25 
26 /**
27  * @file
28  * An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
29  *
30  * AVHWFramesContext.pool must contain AVBufferRefs whose
31  * data pointer points to an AVD3D12VAFrame struct.
32  */
33 #include <stdint.h>
34 #include <initguid.h>
35 #include <d3d12.h>
36 #include <d3d12sdklayers.h>
37 #include <d3d12video.h>
38 
39 /**
40  * @brief This struct is allocated as AVHWDeviceContext.hwctx
41  *
42  */
43 typedef struct AVD3D12VADeviceContext {
44  /**
45  * Device used for objects creation and access. This can also be
46  * used to set the libavcodec decoding device.
47  *
48  * Can be set by the user. This is the only mandatory field - the other
49  * device context fields are set from this and are available for convenience.
50  *
51  * Deallocating the AVHWDeviceContext will always release this interface,
52  * and it does not matter whether it was user-allocated.
53  */
54  ID3D12Device *device;
55 
56  /**
57  * If unset, this will be set from the device field on init.
58  *
59  * Deallocating the AVHWDeviceContext will always release this interface,
60  * and it does not matter whether it was user-allocated.
61  */
62  ID3D12VideoDevice *video_device;
63 
64  /**
65  * Callbacks for locking. They protect access to the internal staging
66  * texture (for av_hwframe_transfer_data() calls). They do NOT protect
67  * access to hwcontext or decoder state in general.
68  *
69  * If unset on init, the hwcontext implementation will set them to use an
70  * internal mutex.
71  *
72  * The underlying lock must be recursive. lock_ctx is for free use by the
73  * locking implementation.
74  */
75  void (*lock)(void *lock_ctx);
76  void (*unlock)(void *lock_ctx);
77  void *lock_ctx;
79 
80 /**
81  * @brief This struct is used to sync d3d12 execution
82  *
83  */
84 typedef struct AVD3D12VASyncContext {
85  /**
86  * D3D12 fence object
87  */
88  ID3D12Fence *fence;
89 
90  /**
91  * A handle to the event object that's raised when the fence
92  * reaches a certain value.
93  */
94  HANDLE event;
95 
96  /**
97  * The fence value used for sync
98  */
99  uint64_t fence_value;
101 
102 /**
103  * @brief D3D12VA frame descriptor for pool allocation.
104  *
105  */
106 typedef struct AVD3D12VAFrame {
107  /**
108  * The texture in which the frame is located. The reference count is
109  * managed by the AVBufferRef, and destroying the reference will release
110  * the interface.
111  */
112  ID3D12Resource *texture;
113 
114  /**
115  * The sync context for the texture
116  *
117  * @see: https://learn.microsoft.com/en-us/windows/win32/medfound/direct3d-12-video-overview#directx-12-fences
118  */
121 
122 /**
123  * @brief This struct is allocated as AVHWFramesContext.hwctx
124  *
125  */
126 typedef struct AVD3D12VAFramesContext {
127  /**
128  * DXGI_FORMAT format. MUST be compatible with the pixel format.
129  * If unset, will be automatically set.
130  */
131  DXGI_FORMAT format;
133 
134 #endif /* AVUTIL_HWCONTEXT_D3D12VA_H */
AVD3D12VADeviceContext::device
ID3D12Device * device
Device used for objects creation and access.
Definition: hwcontext_d3d12va.h:54
AVD3D12VADeviceContext::lock_ctx
void * lock_ctx
Definition: hwcontext_d3d12va.h:77
AVD3D12VADeviceContext::unlock
void(* unlock)(void *lock_ctx)
Definition: hwcontext_d3d12va.h:76
AVD3D12VAFrame::sync_ctx
AVD3D12VASyncContext sync_ctx
The sync context for the texture.
Definition: hwcontext_d3d12va.h:119
AVD3D12VASyncContext
This struct is used to sync d3d12 execution.
Definition: hwcontext_d3d12va.h:84
AVD3D12VASyncContext::fence
ID3D12Fence * fence
D3D12 fence object.
Definition: hwcontext_d3d12va.h:88
AVD3D12VAFramesContext
This struct is allocated as AVHWFramesContext.hwctx.
Definition: hwcontext_d3d12va.h:126
AVD3D12VAFrame::texture
ID3D12Resource * texture
The texture in which the frame is located.
Definition: hwcontext_d3d12va.h:112
AVD3D12VADeviceContext::video_device
ID3D12VideoDevice * video_device
If unset, this will be set from the device field on init.
Definition: hwcontext_d3d12va.h:62
AVD3D12VAFrame
D3D12VA frame descriptor for pool allocation.
Definition: hwcontext_d3d12va.h:106
AVD3D12VADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_d3d12va.h:43
AVD3D12VAFramesContext::format
DXGI_FORMAT format
DXGI_FORMAT format.
Definition: hwcontext_d3d12va.h:131
AVD3D12VASyncContext::event
HANDLE event
A handle to the event object that's raised when the fence reaches a certain value.
Definition: hwcontext_d3d12va.h:94
AVD3D12VADeviceContext::lock
void(* lock)(void *lock_ctx)
Callbacks for locking.
Definition: hwcontext_d3d12va.h:75
AVD3D12VASyncContext::fence_value
uint64_t fence_value
The fence value used for sync.
Definition: hwcontext_d3d12va.h:99