hwcontext_d3d12va.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #ifndef AVUTIL_HWCONTEXT_D3D12VA_H
  23. #define AVUTIL_HWCONTEXT_D3D12VA_H
  24. /**
  25. * @file
  26. * An API-specific header for AV_HWDEVICE_TYPE_D3D12VA.
  27. *
  28. * AVHWFramesContext.pool must contain AVBufferRefs whose
  29. * data pointer points to an AVD3D12VAFrame struct.
  30. */
  31. #include <stdint.h>
  32. #include <initguid.h>
  33. #include <d3d12.h>
  34. #include <d3d12sdklayers.h>
  35. #include <d3d12video.h>
  36. /**
  37. * @brief This struct is allocated as AVHWDeviceContext.hwctx
  38. *
  39. */
  40. typedef struct AVD3D12VADeviceContext {
  41. /**
  42. * Device used for objects creation and access. This can also be
  43. * used to set the libavcodec decoding device.
  44. *
  45. * Can be set by the user. This is the only mandatory field - the other
  46. * device context fields are set from this and are available for convenience.
  47. *
  48. * Deallocating the AVHWDeviceContext will always release this interface,
  49. * and it does not matter whether it was user-allocated.
  50. */
  51. ID3D12Device *device;
  52. /**
  53. * If unset, this will be set from the device field on init.
  54. *
  55. * Deallocating the AVHWDeviceContext will always release this interface,
  56. * and it does not matter whether it was user-allocated.
  57. */
  58. ID3D12VideoDevice *video_device;
  59. /**
  60. * Callbacks for locking. They protect access to the internal staging
  61. * texture (for av_hwframe_transfer_data() calls). They do NOT protect
  62. * access to hwcontext or decoder state in general.
  63. *
  64. * If unset on init, the hwcontext implementation will set them to use an
  65. * internal mutex.
  66. *
  67. * The underlying lock must be recursive. lock_ctx is for free use by the
  68. * locking implementation.
  69. */
  70. void (*lock)(void *lock_ctx);
  71. void (*unlock)(void *lock_ctx);
  72. void *lock_ctx;
  73. } AVD3D12VADeviceContext;
  74. /**
  75. * @brief This struct is used to sync d3d12 execution
  76. *
  77. */
  78. typedef struct AVD3D12VASyncContext {
  79. /**
  80. * D3D12 fence object
  81. */
  82. ID3D12Fence *fence;
  83. /**
  84. * A handle to the event object that's raised when the fence
  85. * reaches a certain value.
  86. */
  87. HANDLE event;
  88. /**
  89. * The fence value used for sync
  90. */
  91. uint64_t fence_value;
  92. } AVD3D12VASyncContext;
  93. /**
  94. * @brief D3D12VA frame descriptor for pool allocation.
  95. *
  96. */
  97. typedef struct AVD3D12VAFrame {
  98. /**
  99. * The texture in which the frame is located. The reference count is
  100. * managed by the AVBufferRef, and destroying the reference will release
  101. * the interface.
  102. */
  103. ID3D12Resource *texture;
  104. /**
  105. * The sync context for the texture
  106. *
  107. * @see: https://learn.microsoft.com/en-us/windows/win32/medfound/direct3d-12-video-overview#directx-12-fences
  108. */
  109. AVD3D12VASyncContext sync_ctx;
  110. } AVD3D12VAFrame;
  111. /**
  112. * @brief This struct is allocated as AVHWFramesContext.hwctx
  113. *
  114. */
  115. typedef struct AVD3D12VAFramesContext {
  116. /**
  117. * DXGI_FORMAT format. MUST be compatible with the pixel format.
  118. * If unset, will be automatically set.
  119. */
  120. DXGI_FORMAT format;
  121. } AVD3D12VAFramesContext;
  122. #endif /* AVUTIL_HWCONTEXT_D3D12VA_H */