You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
6.4KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_HWCONTEXT_VULKAN_H
  19. #define AVUTIL_HWCONTEXT_VULKAN_H
  20. #include <vulkan/vulkan.h>
  21. /**
  22. * @file
  23. * API-specific header for AV_HWDEVICE_TYPE_VULKAN.
  24. *
  25. * For user-allocated pools, AVHWFramesContext.pool must return AVBufferRefs
  26. * with the data pointer set to an AVVkFrame.
  27. */
  28. /**
  29. * Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
  30. * All of these can be set before init to change what the context uses
  31. */
  32. typedef struct AVVulkanDeviceContext {
  33. /**
  34. * Custom memory allocator, else NULL
  35. */
  36. const VkAllocationCallbacks *alloc;
  37. /**
  38. * Vulkan instance. Must be at least version 1.1.
  39. */
  40. VkInstance inst;
  41. /**
  42. * Physical device
  43. */
  44. VkPhysicalDevice phys_dev;
  45. /**
  46. * Active device
  47. */
  48. VkDevice act_dev;
  49. /**
  50. * Queue family index for graphics
  51. * @note av_hwdevice_create() will set all 3 queue indices if unset
  52. * If there is no dedicated queue for compute or transfer operations,
  53. * they will be set to the graphics queue index which can handle both.
  54. * nb_graphics_queues indicates how many queues were enabled for the
  55. * graphics queue (must be at least 1)
  56. */
  57. int queue_family_index;
  58. int nb_graphics_queues;
  59. /**
  60. * Queue family index to use for transfer operations, and the amount of queues
  61. * enabled. In case there is no dedicated transfer queue, nb_tx_queues
  62. * must be 0 and queue_family_tx_index must be the same as either the graphics
  63. * queue or the compute queue, if available.
  64. */
  65. int queue_family_tx_index;
  66. int nb_tx_queues;
  67. /**
  68. * Queue family index for compute ops, and the amount of queues enabled.
  69. * In case there are no dedicated compute queues, nb_comp_queues must be
  70. * 0 and its queue family index must be set to the graphics queue.
  71. */
  72. int queue_family_comp_index;
  73. int nb_comp_queues;
  74. /**
  75. * Enabled instance extensions. By default, VK_KHR_surface is enabled if found.
  76. * If supplying your own device context, set this to an array of strings, with
  77. * each entry containing the specified Vulkan extension string to enable.
  78. * Duplicates are possible and accepted.
  79. * If no extensions are enabled, set these fields to NULL, and 0 respectively.
  80. */
  81. const char * const *enabled_inst_extensions;
  82. int nb_enabled_inst_extensions;
  83. /**
  84. * Enabled device extensions. By default, VK_KHR_external_memory_fd,
  85. * VK_EXT_external_memory_dma_buf, VK_EXT_image_drm_format_modifier and
  86. * VK_KHR_external_semaphore_fd are enabled if found.
  87. * If supplying your own device context, these fields takes the same format as
  88. * the above fields, with the same conditions that duplicates are possible
  89. * and accepted, and that NULL and 0 respectively means no extensions are enabled.
  90. */
  91. const char * const *enabled_dev_extensions;
  92. int nb_enabled_dev_extensions;
  93. } AVVulkanDeviceContext;
  94. /**
  95. * Allocated as AVHWFramesContext.hwctx, used to set pool-specific options
  96. */
  97. typedef struct AVVulkanFramesContext {
  98. /**
  99. * Controls the tiling of output frames.
  100. */
  101. VkImageTiling tiling;
  102. /**
  103. * Defines extra usage of output frames. This is bitwise OR'd with the
  104. * standard usage flags (SAMPLED, STORAGE, TRANSFER_SRC and TRANSFER_DST).
  105. */
  106. VkImageUsageFlagBits usage;
  107. /**
  108. * Extension data for image creation. By default, if the extension is
  109. * available, this will be chained to a VkImageFormatListCreateInfoKHR.
  110. */
  111. void *create_pnext;
  112. /**
  113. * Extension data for memory allocation. Must have as many entries as
  114. * the number of planes of the sw_format.
  115. * This will be chained to VkExportMemoryAllocateInfo, which is used
  116. * to make all pool images exportable to other APIs.
  117. */
  118. void *alloc_pnext[AV_NUM_DATA_POINTERS];
  119. } AVVulkanFramesContext;
  120. /*
  121. * Frame structure, the VkFormat of the image will always match
  122. * the pool's sw_format.
  123. * All frames, imported or allocated, will be created with the
  124. * VK_IMAGE_CREATE_ALIAS_BIT flag set, so the memory may be aliased if needed.
  125. *
  126. * If all three queue family indices in the device context are the same,
  127. * images will be created with the EXCLUSIVE sharing mode. Otherwise, all images
  128. * will be created using the CONCURRENT sharing mode.
  129. *
  130. * @note the size of this structure is not part of the ABI, to allocate
  131. * you must use @av_vk_frame_alloc().
  132. */
  133. typedef struct AVVkFrame {
  134. /**
  135. * Vulkan images to which the memory is bound to.
  136. */
  137. VkImage img[AV_NUM_DATA_POINTERS];
  138. /**
  139. * Same tiling must be used for all images.
  140. */
  141. VkImageTiling tiling;
  142. /**
  143. * Memory backing the images. Could be less than the amount of images
  144. * if importing from a DRM or VAAPI frame.
  145. */
  146. VkDeviceMemory mem[AV_NUM_DATA_POINTERS];
  147. size_t size[AV_NUM_DATA_POINTERS];
  148. /**
  149. * OR'd flags for all memory allocated
  150. */
  151. VkMemoryPropertyFlagBits flags;
  152. /**
  153. * Updated after every barrier
  154. */
  155. VkAccessFlagBits access[AV_NUM_DATA_POINTERS];
  156. VkImageLayout layout[AV_NUM_DATA_POINTERS];
  157. /**
  158. * Per-image semaphores. Must not be freed manually. Must be waited on
  159. * and signalled at every queue submission.
  160. */
  161. VkSemaphore sem[AV_NUM_DATA_POINTERS];
  162. /**
  163. * Internal data.
  164. */
  165. struct AVVkFrameInternal *internal;
  166. } AVVkFrame;
  167. /**
  168. * Allocates a single AVVkFrame and initializes everything as 0.
  169. * @note Must be freed via av_free()
  170. */
  171. AVVkFrame *av_vk_frame_alloc(void);
  172. /**
  173. * Returns the format of each image up to the number of planes for a given sw_format.
  174. */
  175. const VkFormat *av_vkfmt_from_pixfmt(enum AVPixelFormat p);
  176. #endif /* AVUTIL_HWCONTEXT_VULKAN_H */