hwcontext_d3d12va.h (3934B)
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; 78 } AVD3D12VADeviceContext; 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; 100 } AVD3D12VASyncContext; 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 */ 119 AVD3D12VASyncContext sync_ctx; 120 } AVD3D12VAFrame; 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; 132 } AVD3D12VAFramesContext; 133 134 #endif /* AVUTIL_HWCONTEXT_D3D12VA_H */