2015-10-24 06:29:05 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2015 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
|
|
|
|
|
2019-04-08 11:35:22 +00:00
|
|
|
#include "gstvkinstance.h"
|
2015-10-24 06:29:05 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* SECTION:vkinstance
|
|
|
|
* @title: GstVulkanInstance
|
2020-06-13 07:31:07 +00:00
|
|
|
* @short_description: GStreamer Vulkan instance
|
2020-08-12 05:59:01 +00:00
|
|
|
* @see_also: #GstVulkanPhysicalDevice, #GstVulkanDevice, #GstVulkanDisplay
|
2019-04-11 06:52:54 +00:00
|
|
|
*
|
2020-06-13 07:31:07 +00:00
|
|
|
* #GstVulkanInstance encapsulates the necessary information for the toplevel
|
|
|
|
* Vulkan instance object.
|
|
|
|
*
|
|
|
|
* If GStreamer is built with debugging support, the default Vulkan API chosen
|
|
|
|
* can be selected with the environment variable
|
|
|
|
* `GST_VULKAN_INSTANCE_API_VERSION=1.0`. Any subsequent setting of the
|
|
|
|
* requested Vulkan API version through the available properties will override
|
|
|
|
* the environment variable.
|
2019-04-11 06:52:54 +00:00
|
|
|
*/
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
#define APP_SHORT_NAME "GStreamer"
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_vulkan_instance_debug
|
|
|
|
GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
|
|
|
|
GST_DEBUG_CATEGORY (GST_VULKAN_DEBUG_CAT);
|
2016-02-10 14:31:14 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2016-02-08 03:25:49 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
SIGNAL_CREATE_DEVICE,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_REQUESTED_API_MAJOR_VERSION,
|
|
|
|
PROP_REQUESTED_API_MINOR_VERSION,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_REQUESTED_API_VERSION_MAJOR 0
|
|
|
|
#define DEFAULT_REQUESTED_API_VERSION_MINOR 0
|
|
|
|
|
2016-02-08 03:25:49 +00:00
|
|
|
static guint gst_vulkan_instance_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
static void gst_vulkan_instance_finalize (GObject * object);
|
|
|
|
|
2015-12-07 06:00:37 +00:00
|
|
|
struct _GstVulkanInstancePrivate
|
|
|
|
{
|
2020-06-14 11:00:06 +00:00
|
|
|
gboolean info_collected;
|
2015-12-07 06:00:37 +00:00
|
|
|
gboolean opened;
|
2020-06-13 07:31:07 +00:00
|
|
|
guint requested_api_major;
|
|
|
|
guint requested_api_minor;
|
|
|
|
uint32_t supported_instance_api;
|
2020-06-14 11:00:06 +00:00
|
|
|
|
|
|
|
guint n_available_layers;
|
|
|
|
VkLayerProperties *available_layers;
|
|
|
|
guint n_available_extensions;
|
|
|
|
VkExtensionProperties *available_extensions;
|
|
|
|
GPtrArray *enabled_layers;
|
|
|
|
GPtrArray *enabled_extensions;
|
2020-06-14 11:04:37 +00:00
|
|
|
|
|
|
|
#if !defined (GST_DISABLE_DEBUG)
|
|
|
|
VkDebugReportCallbackEXT msg_callback;
|
|
|
|
PFN_vkCreateDebugReportCallbackEXT dbgCreateDebugReportCallback;
|
|
|
|
PFN_vkDestroyDebugReportCallbackEXT dbgDestroyDebugReportCallback;
|
|
|
|
PFN_vkDebugReportMessageEXT dbgReportMessage;
|
|
|
|
#endif
|
2015-12-07 06:00:37 +00:00
|
|
|
};
|
|
|
|
|
2019-06-11 08:37:59 +00:00
|
|
|
static void
|
|
|
|
_init_debug (void)
|
|
|
|
{
|
2021-03-22 03:34:36 +00:00
|
|
|
static gsize _init = 0;
|
2019-06-11 08:37:59 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "vulkaninstance", 0,
|
|
|
|
"Vulkan Instance");
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_VULKAN_DEBUG_CAT, "vulkandebug", 0,
|
|
|
|
"Vulkan Debug");
|
|
|
|
GST_DEBUG_CATEGORY_GET (GST_CAT_CONTEXT, "GST_CONTEXT");
|
|
|
|
g_once_init_leave (&_init, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 15:41:10 +00:00
|
|
|
#define GET_PRIV(instance) gst_vulkan_instance_get_instance_private (instance)
|
|
|
|
|
2018-06-23 22:17:26 +00:00
|
|
|
#define gst_vulkan_instance_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVulkanInstance, gst_vulkan_instance,
|
|
|
|
GST_TYPE_OBJECT, G_ADD_PRIVATE (GstVulkanInstance)
|
2019-06-11 08:37:59 +00:00
|
|
|
_init_debug ());
|
2018-06-23 22:17:26 +00:00
|
|
|
|
2020-08-12 05:59:01 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_new:
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new uninitialized #GstVulkanInstance
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2015-10-24 06:29:05 +00:00
|
|
|
GstVulkanInstance *
|
|
|
|
gst_vulkan_instance_new (void)
|
|
|
|
{
|
2017-05-15 17:31:31 +00:00
|
|
|
GstVulkanInstance *instance;
|
|
|
|
|
|
|
|
instance = g_object_new (GST_TYPE_VULKAN_INSTANCE, NULL);
|
|
|
|
gst_object_ref_sink (instance);
|
|
|
|
|
|
|
|
return instance;
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
static void
|
|
|
|
gst_vulkan_instance_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVulkanInstance *instance = GST_VULKAN_INSTANCE (object);
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_REQUESTED_API_MAJOR_VERSION:
|
|
|
|
if (priv->opened)
|
|
|
|
g_warning ("Attempt to set the requested API version after the "
|
|
|
|
"instance has been opened");
|
|
|
|
priv->requested_api_major = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
case PROP_REQUESTED_API_MINOR_VERSION:
|
|
|
|
if (priv->opened)
|
|
|
|
g_warning ("Attempt to set the requested API version after the "
|
|
|
|
"instance has been opened");
|
|
|
|
priv->requested_api_minor = g_value_get_uint (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_instance_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstVulkanInstance *instance = GST_VULKAN_INSTANCE (object);
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_REQUESTED_API_MAJOR_VERSION:
|
|
|
|
g_value_set_uint (value, priv->requested_api_major);
|
|
|
|
break;
|
|
|
|
case PROP_REQUESTED_API_MINOR_VERSION:
|
|
|
|
g_value_set_uint (value, priv->requested_api_minor);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
}
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
static void
|
|
|
|
gst_vulkan_instance_init (GstVulkanInstance * instance)
|
|
|
|
{
|
2020-06-13 07:31:07 +00:00
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
priv->requested_api_major = DEFAULT_REQUESTED_API_VERSION_MAJOR;
|
|
|
|
priv->requested_api_minor = DEFAULT_REQUESTED_API_VERSION_MINOR;
|
|
|
|
|
2020-06-14 11:00:06 +00:00
|
|
|
priv->enabled_layers = g_ptr_array_new_with_free_func (g_free);
|
|
|
|
priv->enabled_extensions = g_ptr_array_new_with_free_func (g_free);
|
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
#if !defined (GST_DISABLE_DEBUG)
|
|
|
|
{
|
|
|
|
const gchar *api_override = g_getenv ("GST_VULKAN_INSTANCE_API_VERSION");
|
|
|
|
if (api_override) {
|
|
|
|
gchar *end;
|
|
|
|
gint64 major, minor;
|
|
|
|
|
|
|
|
major = g_ascii_strtoll (api_override, &end, 10);
|
|
|
|
if (end && end[0] == '.') {
|
|
|
|
minor = g_ascii_strtoll (&end[1], NULL, 10);
|
|
|
|
if (major > 0 && major < G_MAXINT64 && minor >= 0 && minor < G_MAXINT64) {
|
|
|
|
priv->requested_api_major = major;
|
|
|
|
priv->requested_api_minor = minor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-02-08 03:25:49 +00:00
|
|
|
gst_vulkan_instance_class_init (GstVulkanInstanceClass * klass)
|
2015-10-24 06:29:05 +00:00
|
|
|
{
|
2020-06-13 07:31:07 +00:00
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
gst_vulkan_memory_init_once ();
|
|
|
|
gst_vulkan_image_memory_init_once ();
|
2016-02-05 08:18:40 +00:00
|
|
|
gst_vulkan_buffer_memory_init_once ();
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
gobject_class->get_property = gst_vulkan_instance_get_property;
|
|
|
|
gobject_class->set_property = gst_vulkan_instance_set_property;
|
|
|
|
gobject_class->finalize = gst_vulkan_instance_finalize;
|
|
|
|
|
2020-08-12 05:59:01 +00:00
|
|
|
/**
|
|
|
|
* GstVulkanInstance:requested-api-major:
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2020-06-13 07:31:07 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_REQUESTED_API_MAJOR_VERSION,
|
|
|
|
g_param_spec_uint ("requested-api-major", "Requested API Major",
|
|
|
|
"Major version of the requested Vulkan API (0 = maximum supported)",
|
|
|
|
0, G_MAXUINT, DEFAULT_REQUESTED_API_VERSION_MAJOR,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2020-08-12 05:59:01 +00:00
|
|
|
/**
|
|
|
|
* GstVulkanInstance:requested-api-minor:
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2020-06-13 07:31:07 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_REQUESTED_API_MINOR_VERSION,
|
|
|
|
g_param_spec_uint ("requested-api-minor", "Requested API Minor",
|
|
|
|
"Minor version of the requested Vulkan API",
|
|
|
|
0, G_MAXUINT, DEFAULT_REQUESTED_API_VERSION_MINOR,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2016-02-08 03:25:49 +00:00
|
|
|
/**
|
|
|
|
* GstVulkanInstance::create-device:
|
|
|
|
* @object: the #GstVulkanDisplay
|
|
|
|
*
|
|
|
|
* Overrides the #GstVulkanDevice creation mechanism.
|
|
|
|
* It can be called from any thread.
|
|
|
|
*
|
2019-04-11 06:52:54 +00:00
|
|
|
* Returns: (transfer full): the newly created #GstVulkanDevice.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
2016-02-08 03:25:49 +00:00
|
|
|
*/
|
|
|
|
gst_vulkan_instance_signals[SIGNAL_CREATE_DEVICE] =
|
|
|
|
g_signal_new ("create-device", G_TYPE_FROM_CLASS (klass),
|
2019-08-27 05:59:27 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, GST_TYPE_VULKAN_DEVICE, 0);
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_instance_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstVulkanInstance *instance = GST_VULKAN_INSTANCE (object);
|
2019-11-06 15:41:10 +00:00
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2019-11-06 15:41:10 +00:00
|
|
|
if (priv->opened) {
|
2020-06-14 11:04:37 +00:00
|
|
|
if (priv->dbgDestroyDebugReportCallback)
|
|
|
|
priv->dbgDestroyDebugReportCallback (instance->instance,
|
|
|
|
priv->msg_callback, NULL);
|
2015-12-07 06:00:37 +00:00
|
|
|
|
|
|
|
g_free (instance->physical_devices);
|
|
|
|
}
|
2019-11-06 15:41:10 +00:00
|
|
|
priv->opened = FALSE;
|
2015-12-07 06:00:37 +00:00
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
if (instance->instance)
|
2015-12-29 05:05:17 +00:00
|
|
|
vkDestroyInstance (instance->instance, NULL);
|
2015-10-24 06:29:05 +00:00
|
|
|
instance->instance = NULL;
|
2016-02-10 08:34:55 +00:00
|
|
|
|
2020-06-14 11:00:06 +00:00
|
|
|
g_free (priv->available_layers);
|
|
|
|
priv->available_layers = NULL;
|
|
|
|
|
|
|
|
g_free (priv->available_extensions);
|
|
|
|
priv->available_extensions = NULL;
|
|
|
|
|
|
|
|
g_ptr_array_unref (priv->enabled_layers);
|
|
|
|
priv->enabled_layers = NULL;
|
|
|
|
|
|
|
|
g_ptr_array_unref (priv->enabled_extensions);
|
|
|
|
priv->enabled_extensions = NULL;
|
|
|
|
|
2016-02-10 08:34:55 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 06:27:16 +00:00
|
|
|
VKAPI_ATTR static VkBool32
|
2016-01-27 04:20:49 +00:00
|
|
|
_gst_vk_debug_callback (VkDebugReportFlagsEXT msgFlags,
|
|
|
|
VkDebugReportObjectTypeEXT objType, uint64_t srcObject, size_t location,
|
|
|
|
int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
|
|
|
|
void *pUserData)
|
2015-10-24 06:29:05 +00:00
|
|
|
{
|
2016-01-27 04:20:49 +00:00
|
|
|
if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
|
2015-10-24 06:29:05 +00:00
|
|
|
GST_CAT_ERROR (GST_VULKAN_DEBUG_CAT, "[%s] Code %d : %s", pLayerPrefix,
|
|
|
|
msgCode, pMsg);
|
2019-10-30 08:33:25 +00:00
|
|
|
g_critical ("[%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
|
2016-02-16 04:53:56 +00:00
|
|
|
} else if (msgFlags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
|
2015-10-24 06:29:05 +00:00
|
|
|
GST_CAT_WARNING (GST_VULKAN_DEBUG_CAT, "[%s] Code %d : %s", pLayerPrefix,
|
|
|
|
msgCode, pMsg);
|
2019-10-30 08:33:25 +00:00
|
|
|
g_warning ("[%s] Code %d : %s", pLayerPrefix, msgCode, pMsg);
|
2016-02-16 04:53:56 +00:00
|
|
|
} else if (msgFlags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
|
2015-10-24 06:29:05 +00:00
|
|
|
GST_CAT_LOG (GST_VULKAN_DEBUG_CAT, "[%s] Code %d : %s", pLayerPrefix,
|
|
|
|
msgCode, pMsg);
|
2016-02-16 04:53:56 +00:00
|
|
|
} else if (msgFlags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
|
2015-10-24 06:29:05 +00:00
|
|
|
GST_CAT_FIXME (GST_VULKAN_DEBUG_CAT, "[%s] Code %d : %s", pLayerPrefix,
|
|
|
|
msgCode, pMsg);
|
2016-01-27 04:20:49 +00:00
|
|
|
} else if (msgFlags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
|
2015-10-24 06:29:05 +00:00
|
|
|
GST_CAT_TRACE (GST_VULKAN_DEBUG_CAT, "[%s] Code %d : %s", pLayerPrefix,
|
|
|
|
msgCode, pMsg);
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* false indicates that layer should not bail-out of an
|
|
|
|
* API call that had validation failures. This may mean that the
|
|
|
|
* app dies inside the driver due to invalid parameter(s).
|
|
|
|
* That's what would happen without validation layers, so we'll
|
|
|
|
* keep that behavior here.
|
|
|
|
*/
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-14 11:00:06 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vulkan_instance_get_layer_info_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name, gchar ** description, guint32 * spec_version,
|
|
|
|
guint32 * implementation_version)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
for (i = 0; i < priv->n_available_layers; i++) {
|
|
|
|
if (g_strcmp0 (name, priv->available_layers[i].layerName) == 0) {
|
|
|
|
if (description)
|
|
|
|
*description = g_strdup (priv->available_layers[i].description);
|
|
|
|
if (spec_version)
|
|
|
|
*spec_version = priv->available_layers[i].specVersion;
|
|
|
|
if (implementation_version)
|
|
|
|
*spec_version = priv->available_layers[i].implementationVersion;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_get_layer_info:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @name: the layer name to look for
|
|
|
|
* @description: (out) (nullable): return value for the layer description or %NULL
|
|
|
|
* @spec_version: (out) (nullable): return value for the layer specification version
|
|
|
|
* @implementation_version: (out) (nullable): return value for the layer implementation version
|
|
|
|
*
|
|
|
|
* Retrieves information about a layer.
|
|
|
|
*
|
|
|
|
* Will not find any layers before gst_vulkan_instance_fill_info() has been
|
|
|
|
* called.
|
|
|
|
*
|
|
|
|
* Returns: whether layer @name is available
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_get_layer_info (GstVulkanInstance * instance,
|
|
|
|
const gchar * name, gchar ** description, guint32 * spec_version,
|
|
|
|
guint32 * implementation_version)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret =
|
|
|
|
gst_vulkan_instance_get_layer_info_unlocked (instance, name, description,
|
|
|
|
spec_version, implementation_version);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_GNUC_INTERNAL gboolean
|
|
|
|
gst_vulkan_instance_get_extension_info_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name, guint32 * spec_version);
|
|
|
|
|
|
|
|
G_GNUC_INTERNAL gboolean
|
|
|
|
gst_vulkan_instance_get_extension_info_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name, guint32 * spec_version)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
for (i = 0; i < priv->n_available_extensions; i++) {
|
|
|
|
if (g_strcmp0 (name, priv->available_extensions[i].extensionName) == 0) {
|
|
|
|
if (spec_version)
|
|
|
|
*spec_version = priv->available_extensions[i].specVersion;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_get_extension_info:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @name: the layer name to look for
|
|
|
|
* @spec_version: (out) (nullable): return value for the layer specification version
|
|
|
|
*
|
|
|
|
* Retrieves information about an extension.
|
|
|
|
*
|
|
|
|
* Will not find any extensions before gst_vulkan_instance_fill_info() has been
|
|
|
|
* called.
|
|
|
|
*
|
|
|
|
* Returns: whether extension @name is available
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_get_extension_info (GstVulkanInstance * instance,
|
|
|
|
const gchar * name, guint32 * spec_version)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret =
|
|
|
|
gst_vulkan_instance_get_extension_info_unlocked (instance, name,
|
|
|
|
spec_version);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reimplement a specfic case of g_ptr_array_find_with_equal_func as that
|
|
|
|
* requires Glib 2.54 */
|
|
|
|
static gboolean
|
|
|
|
ptr_array_find_string (GPtrArray * array, const gchar * str, guint * index)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < array->len; i++) {
|
|
|
|
gchar *val = (gchar *) g_ptr_array_index (array, i);
|
|
|
|
if (g_strcmp0 (val, str) == 0) {
|
|
|
|
if (index)
|
|
|
|
*index = i;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_instance_is_extension_enabled_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name, guint * index)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
return ptr_array_find_string (priv->enabled_extensions, name, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_is_extension_enabled:
|
|
|
|
* @instance: a # GstVulkanInstance
|
|
|
|
* @name: extension name
|
|
|
|
*
|
|
|
|
* Returns: whether extension @name is enabled
|
2020-08-12 05:59:01 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2020-06-14 11:00:06 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_is_extension_enabled (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret =
|
|
|
|
gst_vulkan_instance_is_extension_enabled_unlocked (instance, name, NULL);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_instance_enable_extension_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
gboolean extension_is_available = FALSE;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (gst_vulkan_instance_is_extension_enabled_unlocked (instance, name, NULL))
|
|
|
|
/* extension is already enabled */
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->n_available_extensions; i++) {
|
|
|
|
if (g_strcmp0 (name, priv->available_extensions[i].extensionName) == 0) {
|
|
|
|
extension_is_available = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extension_is_available)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_ptr_array_add (priv->enabled_extensions, g_strdup (name));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_enable_extension:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @name: extension name to enable
|
|
|
|
*
|
|
|
|
* Enable an Vulkan extension by @name. Extensions cannot be enabled until
|
|
|
|
* gst_vulkan_instance_fill_info() has been called. Enabling an extension will
|
|
|
|
* only have an effect before the call to gst_vulkan_instance_open().
|
|
|
|
*
|
|
|
|
* Returns: whether the Vulkan extension could be enabled.
|
2020-08-12 05:59:01 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2020-06-14 11:00:06 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_enable_extension (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret = gst_vulkan_instance_enable_extension_unlocked (instance, name);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_instance_disable_extension_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
gboolean extension_is_available = FALSE;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->n_available_extensions; i++) {
|
|
|
|
if (g_strcmp0 (name, priv->available_extensions[i].extensionName) == 0) {
|
|
|
|
extension_is_available = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!extension_is_available)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!gst_vulkan_instance_is_extension_enabled_unlocked (instance, name, &i))
|
|
|
|
/* extension is already enabled */
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
g_ptr_array_remove_index_fast (priv->enabled_extensions, i);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_disable_extension:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @name: extension name to enable
|
|
|
|
*
|
|
|
|
* Disable an Vulkan extension by @name. Disabling an extension will only have
|
|
|
|
* an effect before the call to gst_vulkan_instance_open().
|
|
|
|
*
|
|
|
|
* Returns: whether the Vulkan extension could be disabled.
|
2020-08-12 05:59:01 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2020-06-14 11:00:06 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_disable_extension (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret = gst_vulkan_instance_disable_extension_unlocked (instance, name);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_instance_is_layer_enabled_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
return ptr_array_find_string (priv->enabled_layers, name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_is_layer_enabled:
|
|
|
|
* @instance: a # GstVulkanInstance
|
|
|
|
* @name: layer name
|
|
|
|
*
|
|
|
|
* Returns: whether layer @name is enabled
|
2020-08-12 05:59:01 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2020-06-14 11:00:06 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_is_layer_enabled (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret = gst_vulkan_instance_is_layer_enabled_unlocked (instance, name);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_instance_enable_layer_unlocked (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
gboolean layer_is_available = FALSE;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (gst_vulkan_instance_is_layer_enabled_unlocked (instance, name))
|
|
|
|
/* layer is already enabled */
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
for (i = 0; i < priv->n_available_layers; i++) {
|
|
|
|
if (g_strcmp0 (name, priv->available_layers[i].layerName) == 0) {
|
|
|
|
layer_is_available = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!layer_is_available)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_ptr_array_add (priv->enabled_layers, g_strdup (name));
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_enable_layer:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @name: layer name to enable
|
|
|
|
*
|
|
|
|
* Enable an Vulkan layer by @name. Layer cannot be enabled until
|
|
|
|
* gst_vulkan_instance_fill_info() has been called. Enabling a layer will
|
|
|
|
* only have an effect before the call to gst_vulkan_instance_open().
|
|
|
|
*
|
|
|
|
* Returns: whether the Vulkan layer could be enabled.
|
2020-08-12 05:59:01 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
2020-06-14 11:00:06 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_enable_layer (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
g_return_val_if_fail (name != NULL, FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret = gst_vulkan_instance_enable_layer_unlocked (instance, name);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
static void
|
|
|
|
gst_vulkan_get_supported_api_version_unlocked (GstVulkanInstance * instance)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv = GET_PRIV (instance);
|
|
|
|
PFN_vkEnumerateInstanceVersion gst_vkEnumerateInstanceVersion;
|
|
|
|
|
|
|
|
if (priv->supported_instance_api)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gst_vkEnumerateInstanceVersion =
|
|
|
|
(PFN_vkEnumerateInstanceVersion) vkGetInstanceProcAddr (NULL,
|
|
|
|
"vkEnumerateInstanceVersion");
|
|
|
|
|
|
|
|
if (!gst_vkEnumerateInstanceVersion
|
|
|
|
|| VK_SUCCESS !=
|
|
|
|
gst_vkEnumerateInstanceVersion (&priv->supported_instance_api)) {
|
|
|
|
priv->supported_instance_api = VK_MAKE_VERSION (1, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 11:00:06 +00:00
|
|
|
G_GNUC_INTERNAL GstVulkanDisplayType
|
|
|
|
gst_vulkan_display_choose_type_unlocked (GstVulkanInstance * instance);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_instance_fill_info_unlocked (GstVulkanInstance * instance,
|
|
|
|
GError ** error)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv;
|
|
|
|
VkResult err;
|
2020-06-14 15:38:03 +00:00
|
|
|
guint i;
|
2020-06-14 11:00:06 +00:00
|
|
|
|
|
|
|
priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
if (priv->info_collected)
|
|
|
|
return TRUE;
|
|
|
|
priv->info_collected = TRUE;
|
|
|
|
|
|
|
|
gst_vulkan_get_supported_api_version_unlocked (instance);
|
|
|
|
|
|
|
|
/* Look for validation layers */
|
|
|
|
err = vkEnumerateInstanceLayerProperties (&priv->n_available_layers, NULL);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, error,
|
|
|
|
"vKEnumerateInstanceLayerProperties") < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->available_layers = g_new0 (VkLayerProperties, priv->n_available_layers);
|
|
|
|
err =
|
|
|
|
vkEnumerateInstanceLayerProperties (&priv->n_available_layers,
|
|
|
|
priv->available_layers);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, error,
|
|
|
|
"vKEnumerateInstanceLayerProperties") < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
err =
|
|
|
|
vkEnumerateInstanceExtensionProperties (NULL,
|
|
|
|
&priv->n_available_extensions, NULL);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, error,
|
|
|
|
"vkEnumerateInstanceExtensionProperties") < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->available_extensions =
|
|
|
|
g_new0 (VkExtensionProperties, priv->n_available_extensions);
|
|
|
|
err =
|
|
|
|
vkEnumerateInstanceExtensionProperties (NULL,
|
|
|
|
&priv->n_available_extensions, priv->available_extensions);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, error,
|
|
|
|
"vkEnumerateInstanceExtensionProperties") < 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-06-14 15:38:03 +00:00
|
|
|
GST_INFO_OBJECT (instance, "found %u layers and %u extensions",
|
|
|
|
priv->n_available_layers, priv->n_available_extensions);
|
|
|
|
|
|
|
|
for (i = 0; i < priv->n_available_layers; i++)
|
|
|
|
GST_DEBUG_OBJECT (instance, "available layer %u: %s", i,
|
|
|
|
priv->available_layers[i].layerName);
|
|
|
|
for (i = 0; i < priv->n_available_extensions; i++)
|
|
|
|
GST_DEBUG_OBJECT (instance, "available extension %u: %s", i,
|
|
|
|
priv->available_extensions[i].extensionName);
|
|
|
|
|
2020-06-14 11:00:06 +00:00
|
|
|
/* configure default extensions */
|
|
|
|
{
|
|
|
|
GstVulkanDisplayType display_type;
|
|
|
|
const gchar *winsys_ext_name;
|
|
|
|
GstDebugLevel vulkan_debug_level;
|
|
|
|
|
|
|
|
display_type = gst_vulkan_display_choose_type_unlocked (instance);
|
|
|
|
|
|
|
|
winsys_ext_name =
|
|
|
|
gst_vulkan_display_type_to_extension_string (display_type);
|
|
|
|
if (!winsys_ext_name) {
|
|
|
|
GST_WARNING_OBJECT (instance, "No window system extension enabled");
|
|
|
|
} else if (gst_vulkan_instance_get_extension_info_unlocked (instance,
|
|
|
|
VK_KHR_SURFACE_EXTENSION_NAME, NULL)
|
|
|
|
&& gst_vulkan_instance_get_extension_info_unlocked (instance,
|
|
|
|
winsys_ext_name, NULL)) {
|
|
|
|
gst_vulkan_instance_enable_extension_unlocked (instance,
|
|
|
|
VK_KHR_SURFACE_EXTENSION_NAME);
|
|
|
|
gst_vulkan_instance_enable_extension_unlocked (instance, winsys_ext_name);
|
|
|
|
}
|
|
|
|
#if !defined (GST_DISABLE_DEBUG)
|
|
|
|
vulkan_debug_level =
|
|
|
|
gst_debug_category_get_threshold (GST_VULKAN_DEBUG_CAT);
|
|
|
|
|
|
|
|
if (vulkan_debug_level >= GST_LEVEL_ERROR) {
|
|
|
|
if (gst_vulkan_instance_get_extension_info_unlocked (instance,
|
|
|
|
VK_EXT_DEBUG_REPORT_EXTENSION_NAME, NULL)) {
|
|
|
|
gst_vulkan_instance_enable_extension_unlocked (instance,
|
|
|
|
VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_fill_info:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @error: #GError
|
|
|
|
*
|
|
|
|
* Retrieve as much information about the available Vulkan instance without
|
|
|
|
* actually creating an Vulkan instance. Will not do anything while @instance
|
|
|
|
* is open.
|
|
|
|
*
|
|
|
|
* Returns: whether the instance information could be retrieved
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_fill_info (GstVulkanInstance * instance, GError ** error)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
ret = gst_vulkan_instance_fill_info_unlocked (instance, error);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_open:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @error: #GError
|
|
|
|
*
|
2019-09-02 19:08:44 +00:00
|
|
|
* Returns: whether the instance could be created
|
2019-04-11 06:52:54 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2015-10-24 06:29:05 +00:00
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_open (GstVulkanInstance * instance, GError ** error)
|
|
|
|
{
|
2019-11-06 15:41:10 +00:00
|
|
|
GstVulkanInstancePrivate *priv;
|
2020-06-13 07:31:07 +00:00
|
|
|
uint32_t requested_instance_api;
|
2020-06-14 11:00:06 +00:00
|
|
|
GstDebugLevel vulkan_debug_level;
|
2015-10-24 06:29:05 +00:00
|
|
|
VkResult err;
|
|
|
|
|
2018-02-08 06:02:17 +00:00
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
|
2019-11-06 15:41:10 +00:00
|
|
|
priv = GET_PRIV (instance);
|
|
|
|
|
2015-12-07 06:00:37 +00:00
|
|
|
GST_OBJECT_LOCK (instance);
|
2019-11-06 15:41:10 +00:00
|
|
|
if (priv->opened) {
|
2015-12-07 06:00:37 +00:00
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-06-14 11:00:06 +00:00
|
|
|
if (!gst_vulkan_instance_fill_info_unlocked (instance, error))
|
|
|
|
goto error;
|
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
if (priv->requested_api_major) {
|
|
|
|
requested_instance_api =
|
|
|
|
VK_MAKE_VERSION (priv->requested_api_major, priv->requested_api_minor,
|
|
|
|
0);
|
|
|
|
} else {
|
|
|
|
requested_instance_api = priv->supported_instance_api;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (requested_instance_api > priv->supported_instance_api) {
|
|
|
|
g_set_error (error, GST_VULKAN_ERROR, VK_ERROR_INITIALIZATION_FAILED,
|
|
|
|
"Requested API version (%u.%u) is larger than the maximum supported "
|
|
|
|
"version (%u.%u)", VK_VERSION_MAJOR (requested_instance_api),
|
|
|
|
VK_VERSION_MINOR (requested_instance_api),
|
|
|
|
VK_VERSION_MAJOR (priv->supported_instance_api),
|
|
|
|
VK_VERSION_MINOR (priv->supported_instance_api));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2020-06-14 15:38:03 +00:00
|
|
|
/* list of known vulkan loader environment variables taken from:
|
|
|
|
* https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md#table-of-debug-environment-variables */
|
|
|
|
GST_DEBUG_OBJECT (instance, "VK_ICD_FILENAMES: %s",
|
|
|
|
g_getenv ("VK_ICD_FILENAMES"));
|
|
|
|
GST_DEBUG_OBJECT (instance, "VK_INSTANCE_LAYERS: %s",
|
|
|
|
g_getenv ("VK_INSTANCE_LAYERS"));
|
|
|
|
GST_DEBUG_OBJECT (instance, "VK_LAYER_PATH: %s", g_getenv ("VK_LAYER_PATH"));
|
|
|
|
GST_DEBUG_OBJECT (instance, "VK_LOADER_DISABLE_INST_EXT_FILTER: %s",
|
|
|
|
g_getenv ("VK_LOADER_DISABLE_INST_EXT_FILTER"));
|
|
|
|
GST_DEBUG_OBJECT (instance, "VK_LOADER_DEBUG: %s",
|
|
|
|
g_getenv ("VK_LOADER_DEBUG"));
|
|
|
|
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
GST_INFO_OBJECT (instance, "attempting to create instance for Vulkan API "
|
|
|
|
"%u.%u, max supported %u.%u with %u layers and %u extensions",
|
|
|
|
VK_VERSION_MAJOR (requested_instance_api),
|
|
|
|
VK_VERSION_MINOR (requested_instance_api),
|
|
|
|
VK_VERSION_MAJOR (priv->supported_instance_api),
|
|
|
|
VK_VERSION_MINOR (priv->supported_instance_api),
|
|
|
|
priv->enabled_layers->len, priv->enabled_extensions->len);
|
|
|
|
|
|
|
|
for (i = 0; i < priv->enabled_layers->len; i++)
|
|
|
|
GST_DEBUG_OBJECT (instance, "layer %u: %s", i,
|
|
|
|
(gchar *) g_ptr_array_index (priv->enabled_layers, i));
|
|
|
|
for (i = 0; i < priv->enabled_extensions->len; i++)
|
|
|
|
GST_DEBUG_OBJECT (instance, "extension %u: %s", i,
|
|
|
|
(gchar *) g_ptr_array_index (priv->enabled_extensions, i));
|
|
|
|
}
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
{
|
2015-12-02 06:10:39 +00:00
|
|
|
VkApplicationInfo app = { 0, };
|
|
|
|
VkInstanceCreateInfo inst_info = { 0, };
|
|
|
|
|
2019-05-09 11:50:47 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
app = (VkApplicationInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.pApplicationName = APP_SHORT_NAME,
|
|
|
|
.applicationVersion = 0,
|
|
|
|
.pEngineName = APP_SHORT_NAME,
|
|
|
|
.engineVersion = 0,
|
2020-06-13 07:31:07 +00:00
|
|
|
.apiVersion = requested_instance_api,
|
2019-05-09 11:50:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inst_info = (VkInstanceCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.pApplicationInfo = &app,
|
2020-06-14 11:00:06 +00:00
|
|
|
.enabledLayerCount = priv->enabled_layers->len,
|
|
|
|
.ppEnabledLayerNames = (const char *const *) priv->enabled_layers->pdata,
|
|
|
|
.enabledExtensionCount = priv->enabled_extensions->len,
|
|
|
|
.ppEnabledExtensionNames = (const char *const *) priv->enabled_extensions->pdata,
|
2019-05-09 11:50:47 +00:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2015-12-29 05:05:17 +00:00
|
|
|
err = vkCreateInstance (&inst_info, NULL, &instance->instance);
|
2015-10-24 06:29:05 +00:00
|
|
|
if (gst_vulkan_error_to_g_error (err, error, "vkCreateInstance") < 0) {
|
2015-12-07 06:00:37 +00:00
|
|
|
goto error;
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err =
|
|
|
|
vkEnumeratePhysicalDevices (instance->instance,
|
|
|
|
&instance->n_physical_devices, NULL);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, error,
|
|
|
|
"vkEnumeratePhysicalDevices") < 0)
|
2015-12-07 06:00:37 +00:00
|
|
|
goto error;
|
2021-06-03 16:44:47 +00:00
|
|
|
|
|
|
|
if (instance->n_physical_devices == 0) {
|
|
|
|
GST_WARNING_OBJECT (instance, "No available physical device");
|
|
|
|
g_set_error_literal (error,
|
|
|
|
GST_RESOURCE_ERROR, GST_RESOURCE_ERROR_NOT_FOUND,
|
|
|
|
"No available physical device");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
instance->physical_devices =
|
|
|
|
g_new0 (VkPhysicalDevice, instance->n_physical_devices);
|
|
|
|
err =
|
|
|
|
vkEnumeratePhysicalDevices (instance->instance,
|
|
|
|
&instance->n_physical_devices, instance->physical_devices);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, error,
|
|
|
|
"vkEnumeratePhysicalDevices") < 0)
|
2015-12-07 06:00:37 +00:00
|
|
|
goto error;
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2020-06-14 11:00:06 +00:00
|
|
|
#if !defined (GST_DISABLE_DEBUG)
|
|
|
|
vulkan_debug_level = gst_debug_category_get_threshold (GST_VULKAN_DEBUG_CAT);
|
|
|
|
|
|
|
|
if (vulkan_debug_level >= GST_LEVEL_ERROR
|
|
|
|
&& gst_vulkan_instance_is_extension_enabled_unlocked (instance,
|
|
|
|
VK_EXT_DEBUG_REPORT_EXTENSION_NAME, NULL)) {
|
2016-01-27 04:20:49 +00:00
|
|
|
VkDebugReportCallbackCreateInfoEXT info = { 0, };
|
|
|
|
|
2020-06-14 11:04:37 +00:00
|
|
|
priv->dbgCreateDebugReportCallback = (PFN_vkCreateDebugReportCallbackEXT)
|
2019-03-29 05:24:15 +00:00
|
|
|
gst_vulkan_instance_get_proc_address (instance,
|
|
|
|
"vkCreateDebugReportCallbackEXT");
|
2020-06-14 11:04:37 +00:00
|
|
|
if (!priv->dbgCreateDebugReportCallback) {
|
2019-03-29 05:24:15 +00:00
|
|
|
g_set_error (error, GST_VULKAN_ERROR, VK_ERROR_INITIALIZATION_FAILED,
|
2019-09-02 19:08:44 +00:00
|
|
|
"Failed to retrieve vkCreateDebugReportCallback");
|
2019-03-29 05:24:15 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2020-06-14 11:04:37 +00:00
|
|
|
priv->dbgDestroyDebugReportCallback = (PFN_vkDestroyDebugReportCallbackEXT)
|
2019-03-29 05:24:15 +00:00
|
|
|
gst_vulkan_instance_get_proc_address (instance,
|
|
|
|
"vkDestroyDebugReportCallbackEXT");
|
2020-06-14 11:04:37 +00:00
|
|
|
if (!priv->dbgDestroyDebugReportCallback) {
|
2019-03-29 05:24:15 +00:00
|
|
|
g_set_error (error, GST_VULKAN_ERROR, VK_ERROR_INITIALIZATION_FAILED,
|
2019-09-02 19:08:44 +00:00
|
|
|
"Failed to retrieve vkDestroyDebugReportCallback");
|
2019-03-29 05:24:15 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2020-06-14 11:04:37 +00:00
|
|
|
priv->dbgReportMessage = (PFN_vkDebugReportMessageEXT)
|
2019-03-29 05:24:15 +00:00
|
|
|
gst_vulkan_instance_get_proc_address (instance,
|
|
|
|
"vkDebugReportMessageEXT");
|
2020-06-14 11:04:37 +00:00
|
|
|
if (!priv->dbgReportMessage) {
|
2019-03-29 05:24:15 +00:00
|
|
|
g_set_error (error, GST_VULKAN_ERROR, VK_ERROR_INITIALIZATION_FAILED,
|
2019-09-02 19:08:44 +00:00
|
|
|
"Failed to retrieve vkDebugReportMessage");
|
2019-03-29 05:24:15 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-01-27 04:20:49 +00:00
|
|
|
info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
|
|
|
|
info.pNext = NULL;
|
2020-06-14 11:04:37 +00:00
|
|
|
info.flags = 0;
|
2016-01-27 04:20:49 +00:00
|
|
|
info.pfnCallback = (PFN_vkDebugReportCallbackEXT) _gst_vk_debug_callback;
|
|
|
|
info.pUserData = NULL;
|
2020-06-14 11:04:37 +00:00
|
|
|
/* matches the conditions in _gst_vk_debug_callback() */
|
|
|
|
if (vulkan_debug_level >= GST_LEVEL_ERROR)
|
|
|
|
info.flags |= VK_DEBUG_REPORT_ERROR_BIT_EXT;
|
|
|
|
if (vulkan_debug_level >= GST_LEVEL_WARNING)
|
|
|
|
info.flags |= VK_DEBUG_REPORT_WARNING_BIT_EXT;
|
|
|
|
if (vulkan_debug_level >= GST_LEVEL_FIXME)
|
|
|
|
info.flags |= VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT;
|
|
|
|
if (vulkan_debug_level >= GST_LEVEL_LOG)
|
|
|
|
info.flags |= VK_DEBUG_REPORT_INFORMATION_BIT_EXT;
|
|
|
|
if (vulkan_debug_level >= GST_LEVEL_TRACE)
|
|
|
|
info.flags |= VK_DEBUG_REPORT_DEBUG_BIT_EXT;
|
2016-01-27 04:20:49 +00:00
|
|
|
|
|
|
|
err =
|
2020-06-14 11:04:37 +00:00
|
|
|
priv->dbgCreateDebugReportCallback (instance->instance, &info, NULL,
|
|
|
|
&priv->msg_callback);
|
2016-01-27 04:20:49 +00:00
|
|
|
if (gst_vulkan_error_to_g_error (err, error,
|
|
|
|
"vkCreateDebugReportCallback") < 0)
|
|
|
|
goto error;
|
|
|
|
}
|
2020-06-14 11:00:06 +00:00
|
|
|
#endif
|
2015-12-07 06:00:37 +00:00
|
|
|
|
2019-11-06 15:41:10 +00:00
|
|
|
priv->opened = TRUE;
|
2015-12-07 06:00:37 +00:00
|
|
|
GST_OBJECT_UNLOCK (instance);
|
2015-10-24 06:29:05 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2015-12-07 06:00:37 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_get_proc_address:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @name: name of the function to retrieve
|
|
|
|
*
|
2020-08-12 05:59:01 +00:00
|
|
|
* Performs `vkGetInstanceProcAddr()` with @instance and @name
|
2019-04-11 06:52:54 +00:00
|
|
|
*
|
2022-10-17 08:29:02 +00:00
|
|
|
* Returns: (nullable): the function pointer for @name or %NULL
|
2019-04-11 06:52:54 +00:00
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2015-10-24 06:29:05 +00:00
|
|
|
gpointer
|
|
|
|
gst_vulkan_instance_get_proc_address (GstVulkanInstance * instance,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
2020-06-13 07:31:07 +00:00
|
|
|
gpointer ret;
|
|
|
|
|
2015-10-24 06:29:05 +00:00
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), NULL);
|
|
|
|
g_return_val_if_fail (instance->instance != NULL, NULL);
|
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
ret = vkGetInstanceProcAddr (instance->instance, name);
|
2015-10-24 06:29:05 +00:00
|
|
|
|
2020-06-13 07:31:07 +00:00
|
|
|
GST_TRACE_OBJECT (instance, "%s = %p", name, ret);
|
|
|
|
|
|
|
|
return ret;
|
2015-10-24 06:29:05 +00:00
|
|
|
}
|
2015-12-07 06:33:43 +00:00
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_create_device:
|
2020-08-12 05:59:01 +00:00
|
|
|
* @instance: a #GstVulkanInstance
|
2023-03-21 13:59:52 +00:00
|
|
|
* @error: (out) (optional): a #GError
|
2019-04-11 06:52:54 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstVulkanDevice
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2016-02-08 03:25:49 +00:00
|
|
|
GstVulkanDevice *
|
|
|
|
gst_vulkan_instance_create_device (GstVulkanInstance * instance,
|
|
|
|
GError ** error)
|
|
|
|
{
|
|
|
|
GstVulkanDevice *device;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), NULL);
|
|
|
|
|
|
|
|
g_signal_emit (instance, gst_vulkan_instance_signals[SIGNAL_CREATE_DEVICE], 0,
|
|
|
|
&device);
|
|
|
|
|
2019-09-16 02:59:08 +00:00
|
|
|
if (!device) {
|
|
|
|
device = gst_vulkan_device_new_with_index (instance, 0);
|
|
|
|
}
|
2016-02-08 03:25:49 +00:00
|
|
|
|
|
|
|
if (!gst_vulkan_device_open (device, error)) {
|
|
|
|
gst_object_unref (device);
|
|
|
|
device = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2015-12-07 06:33:43 +00:00
|
|
|
/**
|
|
|
|
* gst_context_set_vulkan_instance:
|
|
|
|
* @context: a #GstContext
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
*
|
|
|
|
* Sets @instance on @context
|
|
|
|
*
|
2019-04-11 06:52:54 +00:00
|
|
|
* Since: 1.18
|
2015-12-07 06:33:43 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_context_set_vulkan_instance (GstContext * context,
|
|
|
|
GstVulkanInstance * instance)
|
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
|
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
g_return_if_fail (gst_context_is_writable (context));
|
|
|
|
|
|
|
|
if (instance)
|
|
|
|
GST_CAT_LOG (GST_CAT_CONTEXT,
|
|
|
|
"setting GstVulkanInstance(%" GST_PTR_FORMAT ") on context(%"
|
|
|
|
GST_PTR_FORMAT ")", instance, context);
|
|
|
|
|
|
|
|
s = gst_context_writable_structure (context);
|
|
|
|
gst_structure_set (s, GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR,
|
|
|
|
GST_TYPE_VULKAN_INSTANCE, instance, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_context_get_vulkan_instance:
|
|
|
|
* @context: a #GstContext
|
|
|
|
* @instance: resulting #GstVulkanInstance
|
|
|
|
*
|
|
|
|
* Returns: Whether @instance was in @context
|
|
|
|
*
|
2019-04-11 06:52:54 +00:00
|
|
|
* Since: 1.18
|
2015-12-07 06:33:43 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_context_get_vulkan_instance (GstContext * context,
|
|
|
|
GstVulkanInstance ** instance)
|
|
|
|
{
|
|
|
|
const GstStructure *s;
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (instance != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (context != NULL, FALSE);
|
|
|
|
|
|
|
|
s = gst_context_get_structure (context);
|
|
|
|
ret = gst_structure_get (s, GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR,
|
|
|
|
GST_TYPE_VULKAN_INSTANCE, instance, NULL);
|
|
|
|
|
|
|
|
GST_CAT_LOG (GST_CAT_CONTEXT, "got GstVulkanInstance(%" GST_PTR_FORMAT
|
|
|
|
") from context(%" GST_PTR_FORMAT ")", *instance, context);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2016-02-10 14:31:14 +00:00
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_handle_context_query:
|
|
|
|
* @element: a #GstElement
|
|
|
|
* @query: a #GstQuery of type #GST_QUERY_CONTEXT
|
2019-09-16 01:21:55 +00:00
|
|
|
* @instance: (nullable): the #GstVulkanInstance
|
2019-04-11 06:52:54 +00:00
|
|
|
*
|
|
|
|
* If a #GstVulkanInstance is requested in @query, sets @instance as the reply.
|
|
|
|
*
|
|
|
|
* Intended for use with element query handlers to respond to #GST_QUERY_CONTEXT
|
|
|
|
* for a #GstVulkanInstance.
|
|
|
|
*
|
|
|
|
* Returns: whether @query was responded to with @instance
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2016-02-10 14:31:14 +00:00
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_handle_context_query (GstElement * element,
|
2019-09-16 01:21:55 +00:00
|
|
|
GstQuery * query, GstVulkanInstance * instance)
|
2016-02-10 14:31:14 +00:00
|
|
|
{
|
|
|
|
gboolean res = FALSE;
|
|
|
|
const gchar *context_type;
|
|
|
|
GstContext *context, *old_context;
|
|
|
|
|
|
|
|
g_return_val_if_fail (element != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (query != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GST_QUERY_TYPE (query) == GST_QUERY_CONTEXT, FALSE);
|
2019-09-16 01:21:55 +00:00
|
|
|
|
|
|
|
if (!instance)
|
|
|
|
return FALSE;
|
2016-02-10 14:31:14 +00:00
|
|
|
|
|
|
|
gst_query_parse_context_type (query, &context_type);
|
|
|
|
|
|
|
|
if (g_strcmp0 (context_type, GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR) == 0) {
|
|
|
|
gst_query_parse_context (query, &old_context);
|
|
|
|
|
|
|
|
if (old_context)
|
|
|
|
context = gst_context_copy (old_context);
|
|
|
|
else
|
|
|
|
context = gst_context_new (GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR, TRUE);
|
|
|
|
|
2019-09-16 01:21:55 +00:00
|
|
|
gst_context_set_vulkan_instance (context, instance);
|
2016-02-10 14:31:14 +00:00
|
|
|
gst_query_set_context (query, context);
|
|
|
|
gst_context_unref (context);
|
|
|
|
|
2019-09-16 01:21:55 +00:00
|
|
|
res = instance != NULL;
|
2016-02-10 14:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-04-11 06:52:54 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_run_context_query:
|
|
|
|
* @element: a #GstElement
|
|
|
|
* @instance: (inout): a #GstVulkanInstance
|
|
|
|
*
|
|
|
|
* Attempt to retrieve a #GstVulkanInstance using #GST_QUERY_CONTEXT from the
|
|
|
|
* surrounding elements of @element.
|
|
|
|
*
|
|
|
|
* Returns: whether @instance contains a valid #GstVulkanInstance
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
2016-02-10 14:31:14 +00:00
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_run_context_query (GstElement * element,
|
|
|
|
GstVulkanInstance ** instance)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_ELEMENT (element), FALSE);
|
|
|
|
g_return_val_if_fail (instance != NULL, FALSE);
|
|
|
|
|
2019-06-11 08:37:59 +00:00
|
|
|
_init_debug ();
|
|
|
|
|
2016-02-10 14:31:14 +00:00
|
|
|
if (*instance && GST_IS_VULKAN_INSTANCE (*instance))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
gst_vulkan_global_context_query (element,
|
|
|
|
GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (element, "found instance %p", *instance);
|
|
|
|
|
|
|
|
if (*instance)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-06-13 07:31:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_check_version:
|
|
|
|
* @instance: a #GstVulkanInstance
|
|
|
|
* @major: major version
|
|
|
|
* @minor: minor version
|
|
|
|
* @patch: patch version
|
|
|
|
*
|
|
|
|
* Check if the configured vulkan instance supports the specified version.
|
|
|
|
* Will not work prior to opening the instance with gst_vulkan_instance_open().
|
|
|
|
* If a specific version is requested, the @patch level is ignored.
|
|
|
|
*
|
|
|
|
* Returns: whether @instance is at least the requested version.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_vulkan_instance_check_version (GstVulkanInstance * instance,
|
|
|
|
guint major, guint minor, guint patch)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_VULKAN_INSTANCE (instance), FALSE);
|
|
|
|
|
|
|
|
priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
return (priv->requested_api_major == 0
|
|
|
|
&& VK_MAKE_VERSION (major, minor, patch) <= priv->supported_instance_api)
|
|
|
|
|| (priv->requested_api_major >= 0 && (major < priv->requested_api_major
|
|
|
|
|| (major == priv->requested_api_major
|
|
|
|
&& minor <= priv->requested_api_minor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vulkan_instance_get_version:
|
|
|
|
* @instance: a #GstVulkanInstance
|
2021-01-03 23:40:24 +00:00
|
|
|
* @major: (out): major version
|
|
|
|
* @minor: (out): minor version
|
|
|
|
* @patch: (out): patch version
|
2020-06-13 07:31:07 +00:00
|
|
|
*
|
|
|
|
* Retrieve the vulkan instance configured version. Only returns the supported
|
|
|
|
* API version by the instance without taking into account the requested API
|
|
|
|
* version. This means gst_vulkan_instance_check_version() will return
|
|
|
|
* different values if a specific version has been requested (which is the
|
|
|
|
* default) than a version check that is performed manually by retrieving the
|
|
|
|
* version with this function.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vulkan_instance_get_version (GstVulkanInstance * instance,
|
|
|
|
guint * major, guint * minor, guint * patch)
|
|
|
|
{
|
|
|
|
GstVulkanInstancePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_VULKAN_INSTANCE (instance));
|
|
|
|
|
|
|
|
priv = GET_PRIV (instance);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (instance);
|
|
|
|
if (!priv->supported_instance_api)
|
|
|
|
gst_vulkan_get_supported_api_version_unlocked (instance);
|
|
|
|
|
|
|
|
if (major)
|
|
|
|
*major = VK_VERSION_MAJOR (priv->supported_instance_api);
|
|
|
|
if (minor)
|
|
|
|
*minor = VK_VERSION_MINOR (priv->supported_instance_api);
|
|
|
|
if (patch)
|
|
|
|
*patch = VK_VERSION_PATCH (priv->supported_instance_api);
|
|
|
|
GST_OBJECT_UNLOCK (instance);
|
|
|
|
}
|