aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/vulkan.c
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2024-09-01 02:45:28 +0000
committerLynne <dev@lynne.ee>2024-09-09 07:05:45 +0200
commit620822c0c5c03bceaa33a0e8c0aa8bd5e9a3e76d (patch)
tree34aee831ea9773c4bad952eb1b9afab01ab0ae08 /libavutil/vulkan.c
parent0ffa967170352c4a5ba73c21f2ef096efef0ee59 (diff)
downloadffmpeg-620822c0c5c03bceaa33a0e8c0aa8bd5e9a3e76d.tar.gz
vulkan: add a ff_vk_init function
This function sets the class correctly, and calls functions that all users have to call anyway.
Diffstat (limited to 'libavutil/vulkan.c')
-rw-r--r--libavutil/vulkan.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index c2a3b5cfa3..4316886ca4 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -22,6 +22,7 @@
#include "mem.h"
#include "vulkan.h"
+#include "libavutil/vulkan_loader.h"
const VkComponentMapping ff_comp_identity_map = {
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
@@ -816,7 +817,7 @@ int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req,
}
if (index < 0) {
- av_log(s->device, AV_LOG_ERROR, "No memory type found for flags 0x%x\n",
+ av_log(s, AV_LOG_ERROR, "No memory type found for flags 0x%x\n",
req_flags);
return AVERROR(EINVAL);
}
@@ -1868,5 +1869,59 @@ void ff_vk_uninit(FFVulkanContext *s)
av_freep(&s->video_props);
av_freep(&s->coop_mat_props);
+ av_buffer_unref(&s->device_ref);
av_buffer_unref(&s->frames_ref);
}
+
+int ff_vk_init(FFVulkanContext *s, void *log_parent,
+ AVBufferRef *device_ref, AVBufferRef *frames_ref)
+{
+ int err;
+
+ static const AVClass vulkan_context_class = {
+ .class_name = "vk",
+ .version = LIBAVUTIL_VERSION_INT,
+ .parent_log_context_offset = offsetof(FFVulkanContext, log_parent),
+ };
+
+ memset(s, 0, sizeof(*s));
+ s->log_parent = log_parent;
+ s->class = &vulkan_context_class;
+
+ if (frames_ref) {
+ s->frames_ref = av_buffer_ref(frames_ref);
+ if (!s->frames_ref)
+ return AVERROR(ENOMEM);
+
+ s->frames = (AVHWFramesContext *)s->frames_ref->data;
+ s->hwfc = s->frames->hwctx;
+
+ device_ref = s->frames->device_ref;
+ }
+
+ s->device_ref = av_buffer_ref(device_ref);
+ if (!s->device_ref) {
+ ff_vk_uninit(s);
+ return AVERROR(ENOMEM);
+ }
+
+ s->device = (AVHWDeviceContext *)s->device_ref->data;
+ s->hwctx = s->device->hwctx;
+
+ s->extensions = ff_vk_extensions_to_mask(s->hwctx->enabled_dev_extensions,
+ s->hwctx->nb_enabled_dev_extensions);
+
+ err = ff_vk_load_functions(s->device, &s->vkfn, s->extensions, 1, 1);
+ if (err < 0) {
+ ff_vk_uninit(s);
+ return err;
+ }
+
+ err = ff_vk_load_props(s);
+ if (err < 0) {
+ ff_vk_uninit(s);
+ return err;
+ }
+
+ return 0;
+}