aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2022-11-23 13:05:59 +0100
committerLynne <dev@lynne.ee>2023-05-29 00:41:44 +0200
commitfa67ccee3735c400bb0f93d56140a93e249b5ddd (patch)
tree3c41ea2bca974f8cff69fb0f8117b4afb4b4ae43 /libavutil
parente8fce74abfd1aa4ad13f4daf103e7f71954459ba (diff)
downloadffmpeg-fa67ccee3735c400bb0f93d56140a93e249b5ddd.tar.gz
vulkan: add ff_vk_image_create()
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/vulkan.c89
-rw-r--r--libavutil/vulkan.h11
2 files changed, 100 insertions, 0 deletions
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index eceef295a8..212f134466 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -401,6 +401,95 @@ void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
vk->FreeMemory(s->hwctx->act_dev, buf->mem, s->hwctx->alloc);
}
+int ff_vk_image_create(FFVulkanContext *s, AVVkFrame *f, int idx,
+ int width, int height, VkFormat fmt, VkImageTiling tiling,
+ VkImageUsageFlagBits usage, VkImageCreateFlags flags,
+ void *create_pnext, VkDeviceMemory *mem, void *alloc_pnext)
+{
+ int err;
+ VkResult ret;
+ FFVulkanFunctions *vk = &s->vkfn;
+ AVVulkanDeviceContext *hwctx = s->hwctx;
+
+ VkExportSemaphoreCreateInfo ext_sem_info = {
+ .sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO,
+#ifdef _WIN32
+ .handleTypes = IsWindows8OrGreater()
+ ? VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT
+ : VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT,
+#else
+ .handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT,
+#endif
+ };
+
+ VkSemaphoreTypeCreateInfo sem_type_info = {
+ .sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO,
+#ifdef _WIN32
+ .pNext = s->extensions & FF_VK_EXT_EXTERNAL_WIN32_SEM ? &ext_sem_info : NULL,
+#else
+ .pNext = s->extensions & FF_VK_EXT_EXTERNAL_FD_SEM ? &ext_sem_info : NULL,
+#endif
+ .semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE,
+ .initialValue = 0,
+ };
+
+ VkSemaphoreCreateInfo sem_spawn = {
+ .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
+ .pNext = &sem_type_info,
+ };
+
+ /* Create the image */
+ VkImageCreateInfo create_info = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ .pNext = create_pnext,
+ .imageType = VK_IMAGE_TYPE_2D,
+ .format = fmt,
+ .extent.depth = 1,
+ .mipLevels = 1,
+ .arrayLayers = 1,
+ .flags = flags,
+ .tiling = tiling,
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ .usage = usage,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .pQueueFamilyIndices = s->qfs,
+ .queueFamilyIndexCount = s->nb_qfs,
+ .sharingMode = s->nb_qfs > 1 ? VK_SHARING_MODE_CONCURRENT :
+ VK_SHARING_MODE_EXCLUSIVE,
+ };
+
+ ret = vk->CreateImage(hwctx->act_dev, &create_info,
+ hwctx->alloc, &f->img[0]);
+ if (ret != VK_SUCCESS) {
+ av_log(s, AV_LOG_ERROR, "Image creation failure: %s\n",
+ ff_vk_ret2str(ret));
+ err = AVERROR(EINVAL);
+ goto fail;
+ }
+
+ /* Create semaphore */
+ ret = vk->CreateSemaphore(hwctx->act_dev, &sem_spawn,
+ hwctx->alloc, &f->sem[0]);
+ if (ret != VK_SUCCESS) {
+ av_log(s, AV_LOG_ERROR, "Failed to create semaphore: %s\n",
+ ff_vk_ret2str(ret));
+ return AVERROR_EXTERNAL;
+ }
+
+ f->queue_family[0] = s->nb_qfs > 1 ? VK_QUEUE_FAMILY_IGNORED : s->qfs[0];
+ f->layout[0] = create_info.initialLayout;
+ f->access[0] = 0x0;
+ f->sem_value[0] = 0;
+
+ f->flags = 0x0;
+ f->tiling = tiling;
+
+ return 0;
+
+fail:
+ return err;
+}
+
int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size,
VkShaderStageFlagBits stage)
{
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 4540c3eda1..a0baba7fc8 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -428,6 +428,17 @@ int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer *buf, int nb_buffers,
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf);
/**
+ * Creates an image, allocates and binds memory in the given
+ * idx value of the dst frame. If mem is non-NULL, then no memory will be
+ * allocated, but instead the given memory will be bound to the image.
+ */
+int ff_vk_image_create(FFVulkanContext *s, AVVkFrame *dst, int idx,
+ int width, int height, VkFormat fmt, VkImageTiling tiling,
+ VkImageUsageFlagBits usage, VkImageCreateFlags flags,
+ void *create_pnext,
+ VkDeviceMemory *mem, void *alloc_pnext);
+
+/**
* Frees the main Vulkan context.
*/
void ff_vk_uninit(FFVulkanContext *s);