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.

159 lines
4.5KB

  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. * Instance
  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. */
  55. int queue_family_index;
  56. /**
  57. * Queue family index for transfer ops only
  58. */
  59. int queue_family_tx_index;
  60. /**
  61. * Queue family index for compute ops
  62. */
  63. int queue_family_comp_index;
  64. } AVVulkanDeviceContext;
  65. /**
  66. * Allocated as AVHWFramesContext.hwctx, used to set pool-specific options
  67. */
  68. typedef struct AVVulkanFramesContext {
  69. /**
  70. * Controls the tiling of output frames.
  71. */
  72. VkImageTiling tiling;
  73. /**
  74. * Defines extra usage of output frames. This is bitwise OR'd with the
  75. * standard usage flags (SAMPLED, STORAGE, TRANSFER_SRC and TRANSFER_DST).
  76. */
  77. VkImageUsageFlagBits usage;
  78. /**
  79. * Extension data for image creation. By default, if the extension is
  80. * available, this will be chained to a VkImageFormatListCreateInfoKHR.
  81. */
  82. void *create_pnext;
  83. /**
  84. * Extension data for memory allocation. Must have as many entries as
  85. * the number of planes of the sw_format.
  86. * This will be chained to VkExportMemoryAllocateInfo, which is used
  87. * to make all pool images exportable to other APIs.
  88. */
  89. void *alloc_pnext[AV_NUM_DATA_POINTERS];
  90. } AVVulkanFramesContext;
  91. /*
  92. * Frame structure, the VkFormat of the image will always match
  93. * the pool's sw_format.
  94. * All frames, imported or allocated, will be created with the
  95. * VK_IMAGE_CREATE_ALIAS_BIT flag set, so the memory may be aliased if needed.
  96. *
  97. * @note the size of this structure is not part of the ABI, to allocate
  98. * you must use @av_vk_frame_alloc().
  99. */
  100. typedef struct AVVkFrame {
  101. /**
  102. * Vulkan images to which the memory is bound to.
  103. */
  104. VkImage img[AV_NUM_DATA_POINTERS];
  105. /**
  106. * Same tiling must be used for all images.
  107. */
  108. VkImageTiling tiling;
  109. /**
  110. * Memory backing the images. Could be less than the amount of images
  111. * if importing from a DRM or VAAPI frame.
  112. */
  113. VkDeviceMemory mem[AV_NUM_DATA_POINTERS];
  114. size_t size[AV_NUM_DATA_POINTERS];
  115. /**
  116. * OR'd flags for all memory allocated
  117. */
  118. VkMemoryPropertyFlagBits flags;
  119. /**
  120. * Updated after every barrier
  121. */
  122. VkAccessFlagBits access[AV_NUM_DATA_POINTERS];
  123. VkImageLayout layout[AV_NUM_DATA_POINTERS];
  124. /**
  125. * Per-image semaphores. Must not be freed manually. Must be waited on
  126. * and signalled at every queue submission.
  127. */
  128. VkSemaphore sem[AV_NUM_DATA_POINTERS];
  129. /**
  130. * Internal data.
  131. */
  132. struct AVVkFrameInternal *internal;
  133. } AVVkFrame;
  134. /**
  135. * Allocates a single AVVkFrame and initializes everything as 0.
  136. * @note Must be freed via av_free()
  137. */
  138. AVVkFrame *av_vk_frame_alloc(void);
  139. /**
  140. * Returns the format of each image up to the number of planes for a given sw_format.
  141. */
  142. const VkFormat *av_vkfmt_from_pixfmt(enum AVPixelFormat p);
  143. #endif /* AVUTIL_HWCONTEXT_VULKAN_H */