vulkan: add a simple refcountable fence wrapper

This commit is contained in:
Matthew Waters 2016-09-01 19:51:11 +10:00
parent 23e147f619
commit af8c4589ba
5 changed files with 166 additions and 0 deletions

View file

@ -9,6 +9,7 @@ libgstvulkan_la_SOURCES = \
vkdevice.c \
vkdisplay.c \
vkerror.c \
vkfence.c \
vkbuffermemory.c \
vkimagememory.c \
vkbufferpool.c \
@ -31,6 +32,7 @@ noinst_HEADERS = \
vkdevice.h \
vkdisplay.h \
vkerror.h \
vkfence.h \
vkimagememory.h \
vkinstance.h \
vkmacros.h \

View file

@ -29,6 +29,7 @@
#include "vkinstance.h"
#include "vkdevice.h"
#include "vkqueue.h"
#include "vkfence.h"
#include "vkdisplay.h"
#include "vkwindow.h"
#include "vkswapper.h"

View file

@ -50,6 +50,8 @@ typedef struct _GstVulkanSwapper GstVulkanSwapper;
typedef struct _GstVulkanSwapperClass GstVulkanSwapperClass;
typedef struct _GstVulkanSwapperPrivate GstVulkanSwapperPrivate;
typedef struct _GstVulkanFence GstVulkanFence;
typedef struct _GstVulkanMemory GstVulkanMemory;
typedef struct _GstVulkanMemoryAllocator GstVulkanMemoryAllocator;
typedef struct _GstVulkanMemoryAllocatorClass GstVulkanMemoryAllocatorClass;

98
ext/vulkan/vkfence.c Normal file
View file

@ -0,0 +1,98 @@
/*
* GStreamer
* Copyright (C) 2016 Matthew Waters <matthew@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "vkfence.h"
#include "vkutils_private.h"
GST_DEBUG_CATEGORY (gst_debug_vulkan_fence);
#define GST_CAT_DEFAULT gst_debug_vulkan_fence
static void
_init_debug (void)
{
static volatile gsize init;
if (g_once_init_enter (&init)) {
GST_DEBUG_CATEGORY_INIT (gst_debug_vulkan_fence,
"vulkanfence", 0, "Vulkan Fence");
g_once_init_leave (&init, 1);
}
}
static void
gst_vulkan_fence_free (GstVulkanFence * fence)
{
if (!fence)
return;
GST_TRACE ("Freeing fence %p", fence);
vkDestroyFence (fence->device->device, fence->fence, NULL);
gst_object_unref (fence->device);
g_free (fence);
}
GstVulkanFence *
gst_vulkan_fence_new (GstVulkanDevice * device, VkFenceCreateFlags flags,
GError ** error)
{
VkFenceCreateInfo fence_info = { 0, };
GstVulkanFence *fence;
VkResult err;
_init_debug ();
g_return_val_if_fail (GST_IS_VULKAN_DEVICE (device), FALSE);
fence = g_new0 (GstVulkanFence, 1);
GST_TRACE ("Creating fence %p with device %" GST_PTR_FORMAT, fence, device);
fence->device = gst_object_ref (device);
fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fence_info.pNext = NULL;
fence_info.flags = flags;
err = vkCreateFence (device->device, &fence_info, NULL, &fence->fence);
if (gst_vulkan_error_to_g_error (err, error, "vkCreateFence") < 0) {
g_free (fence);
return NULL;
}
gst_mini_object_init (GST_MINI_OBJECT_CAST (fence), 0, GST_TYPE_VULKAN_FENCE,
NULL, NULL, (GstMiniObjectFreeFunction) gst_vulkan_fence_free);
return fence;
}
gboolean
gst_vulkan_fence_is_signaled (GstVulkanFence * fence)
{
g_return_val_if_fail (fence != NULL, FALSE);
return vkGetFenceStatus (fence->device->device, fence->fence) == VK_SUCCESS;
}
GST_DEFINE_MINI_OBJECT_TYPE (GstVulkanFence, gst_vulkan_fence);

63
ext/vulkan/vkfence.h Normal file
View file

@ -0,0 +1,63 @@
/*
* GStreamer
* Copyright (C) 2016 Matthew Waters <matthew@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _VK_FENCE_H_
#define _VK_FENCE_H_
#include <vk.h>
#define GST_TYPE_VULKAN_FENCE (gst_vulkan_fence_get_type ())
GType gst_vulkan_fence_get_type (void);
#define GST_VULKAN_FENCE_CAST(f) ((GstVulkanFence *) f)
#define GST_VULKAN_FENCE_FENCE(f) (GST_VULKAN_FENCE_CAST(f)->fence)
G_BEGIN_DECLS
struct _GstVulkanFence
{
GstMiniObject parent;
GstVulkanDevice *device;
VkFence fence;
};
GstVulkanFence * gst_vulkan_fence_new (GstVulkanDevice * device,
VkFenceCreateFlags flags,
GError ** error);
GstVulkanFence * gst_vulkan_fence_wait (GstVulkanFence * fence);
gboolean gst_vulkan_fence_is_signaled (GstVulkanFence * fence);
static inline GstVulkanFence *
gst_vulkan_fence_ref (GstVulkanFence * fence)
{
return GST_VULKAN_FENCE_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (fence)));
}
static inline void
gst_vulkan_fence_unref (GstVulkanFence * fence)
{
gst_mini_object_unref (GST_MINI_OBJECT_CAST (fence));
}
G_END_DECLS
#endif /* _VK_FENCE_H_ */