vulkan/physicaldevice: add methods for retrieving and checking against an API version

Most version checks should actually be done against the device API version and
not the instance API version.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8554>
This commit is contained in:
Matthew Waters 2025-02-25 14:57:33 +11:00 committed by GStreamer Marge Bot
parent 3e8fbc1203
commit 72860a20bf
4 changed files with 198 additions and 3 deletions

View File

@ -4109,6 +4109,32 @@ surrounding elements of @element.</doc>
</parameter>
</parameters>
</function>
<method name="check_api_version" c:identifier="gst_vulkan_instance_check_api_version" version="1.26">
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">whether the #GstVulkanInstance supports the version specified
by @major, @minor and @patch.</doc>
<type name="gboolean" c:type="gboolean"/>
</return-value>
<parameters>
<instance-parameter name="instance" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">a #GstVulkanInstance</doc>
<type name="VulkanInstance" c:type="GstVulkanInstance*"/>
</instance-parameter>
<parameter name="major" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">the API major version to check</doc>
<type name="guint" c:type="guint"/>
</parameter>
<parameter name="minor" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">the API minor version to check</doc>
<type name="guint" c:type="guint"/>
</parameter>
<parameter name="patch" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">the API patch version to check</doc>
<type name="guint" c:type="guint"/>
</parameter>
</parameters>
</method>
<method name="check_version" c:identifier="gst_vulkan_instance_check_version" version="1.18">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">Check if the configured vulkan instance supports the specified version.
Will not work prior to opening the instance with gst_vulkan_instance_open().
@ -4242,6 +4268,37 @@ is open.</doc>
</instance-parameter>
</parameters>
</method>
<method name="get_api_version" c:identifier="gst_vulkan_instance_get_api_version" version="1.26">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">Returns the vulkan API version configured when constructing the
#GstVulkanInstance. This value can be any valid Vulkan API version and may
not match gst_vulkan_instance_get_version() in any way. This version is the
maximum allowed vulkan API to be used in any capacity.
This will not return valid values until gst_vulkan_instance_open() has been
called.</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.h"/>
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
</return-value>
<parameters>
<instance-parameter name="instance" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">a #GstVulkanInstance</doc>
<type name="VulkanInstance" c:type="GstVulkanInstance*"/>
</instance-parameter>
<parameter name="major" direction="out" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">major version</doc>
<type name="guint" c:type="guint*"/>
</parameter>
<parameter name="minor" direction="out" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">minor version</doc>
<type name="guint" c:type="guint*"/>
</parameter>
<parameter name="patch" direction="out" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">patch version</doc>
<type name="guint" c:type="guint*"/>
</parameter>
</parameters>
</method>
<method name="get_extension_info" c:identifier="gst_vulkan_instance_get_extension_info" version="1.18">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">Retrieves information about an extension.
@ -4319,7 +4376,7 @@ called.</doc>
</parameters>
</method>
<method name="get_version" c:identifier="gst_vulkan_instance_get_version" version="1.18">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">Retrieve the vulkan instance configured version. Only returns the supported
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkinstance.c">Retrieve the vulkan instance supported 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
@ -5092,6 +5149,62 @@ gst_vulkan_operation_add_frame_barrier().</doc>
</parameter>
</parameters>
</function>
<method name="check_api_version" c:identifier="gst_vulkan_physical_device_check_api_version" version="1.26">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">Note: This is the intersection of the exposed supported API version as would
be returned by gst_vulkan_physical_device_get_api_version() and
gst_vulkan_instance_check_version(). The latter will take into account any
requested API version and may result in a different result than directly
comparing against gst_vulkan_instance_get_version().</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.h"/>
<return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">whether the #GstVulkanPhysicalDevice supports the version specified
by @major, @minor and @patch.</doc>
<type name="gboolean" c:type="gboolean"/>
</return-value>
<parameters>
<instance-parameter name="device" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">a #GstVulkanPhysicalDevice</doc>
<type name="VulkanPhysicalDevice" c:type="GstVulkanPhysicalDevice*"/>
</instance-parameter>
<parameter name="major" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">the API major version to check</doc>
<type name="guint" c:type="guint"/>
</parameter>
<parameter name="minor" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">the API minor version to check</doc>
<type name="guint" c:type="guint"/>
</parameter>
<parameter name="patch" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">the API patch version to check</doc>
<type name="guint" c:type="guint"/>
</parameter>
</parameters>
</method>
<method name="get_api_version" c:identifier="gst_vulkan_physical_device_get_api_version" version="1.26">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">Retrieves the advertised Vulkan API version of the #GstVulkanPhysicalDevice.</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.h"/>
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
</return-value>
<parameters>
<instance-parameter name="device" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">a #GstVulkanPhysicalDevice</doc>
<type name="VulkanPhysicalDevice" c:type="GstVulkanPhysicalDevice*"/>
</instance-parameter>
<parameter name="major" direction="out" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">major version</doc>
<type name="guint" c:type="guint*"/>
</parameter>
<parameter name="minor" direction="out" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">minor version</doc>
<type name="guint" c:type="guint*"/>
</parameter>
<parameter name="patch" direction="out" caller-allocates="0" transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">patch version</doc>
<type name="guint" c:type="guint*"/>
</parameter>
</parameters>
</method>
<method name="get_extension_info" c:identifier="gst_vulkan_physical_device_get_extension_info" version="1.18">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkphysicaldevice.c">Retrieves information about a device extension.

View File

@ -1262,8 +1262,59 @@ gst_vulkan_physical_device_get_features (GstVulkanPhysicalDevice * device)
g_return_val_if_fail (GST_IS_VULKAN_PHYSICAL_DEVICE (device), FALSE);
priv = GET_PRIV (device);
if (gst_vulkan_instance_check_version (device->instance, 1, 2, 0))
if (gst_vulkan_physical_device_check_api_version (device, 1, 2, 0))
return &priv->features10;
#endif
return NULL;
}
/**
* gst_vulkan_physical_device_get_api_version:
* @device: a #GstVulkanPhysicalDevice
* @major: (out): major version
* @minor: (out): minor version
* @patch: (out): patch version
*
* Retrieves the advertised Vulkan API version of the #GstVulkanPhysicalDevice.
*
* Since: 1.26
*/
void
gst_vulkan_physical_device_get_api_version (GstVulkanPhysicalDevice * device,
guint * major, guint * minor, guint * patch)
{
if (major)
*major = VK_VERSION_MAJOR (device->properties.apiVersion);
if (minor)
*minor = VK_VERSION_MINOR (device->properties.apiVersion);
if (patch)
*patch = VK_VERSION_PATCH (device->properties.apiVersion);
}
/**
* gst_vulkan_physical_device_check_api_version:
* @device: a #GstVulkanPhysicalDevice
* @major: the API major version to check
* @minor: the API minor version to check
* @patch: the API patch version to check
*
* Note: This is the intersection of the exposed supported API version as would
* be returned by gst_vulkan_physical_device_get_api_version() and
* gst_vulkan_instance_check_version(). The latter will take into account any
* requested API version and may result in a different result than directly
* comparing against gst_vulkan_instance_get_version().
*
* Returns: whether the #GstVulkanPhysicalDevice supports the version specified
* by @major, @minor and @patch.
*
* Since: 1.26
*/
gboolean
gst_vulkan_physical_device_check_api_version (GstVulkanPhysicalDevice * device,
guint major, guint minor, guint patch)
{
/* Since Vulkan 1.1 it is possible to have different supported API versions
* between an instance and a device */
return VK_MAKE_VERSION (major, minor, patch) <= device->properties.apiVersion
&& (gst_vulkan_instance_check_version (device->instance, 1, 1, 0) || (major == 1 && minor == 0));
}

View File

@ -133,7 +133,16 @@ gboolean gst_vulkan_physical_device_get_layer_info (Gst
gchar ** description,
guint32 * spec_version,
guint32 * implementation_version);
GST_VULKAN_API
void gst_vulkan_physical_device_get_api_version (GstVulkanPhysicalDevice * device,
guint * major,
guint * minor,
guint * patch);
GST_VULKAN_API
gboolean gst_vulkan_physical_device_check_api_version (GstVulkanPhysicalDevice * device,
guint major,
guint minor,
guint patch);
G_END_DECLS

View File

@ -55,6 +55,27 @@ GST_START_TEST (test_device_new)
GST_END_TEST;
GST_START_TEST (test_physical_device_version)
{
GstVulkanPhysicalDevice *phys = gst_vulkan_physical_device_new (instance, 0);
guint major, minor;
gst_vulkan_physical_device_get_api_version (phys, &major, &minor, NULL);
if (major > 1 || minor >= 0)
fail_unless (gst_vulkan_physical_device_check_api_version (phys, major, minor, 0));
if (minor > 0)
fail_unless (gst_vulkan_physical_device_check_api_version (phys, major,
minor - 1, 0));
fail_unless (!gst_vulkan_physical_device_check_api_version (phys, major,
minor + 1, 0));
gst_object_unref (phys);
}
GST_END_TEST;
static Suite *
vkdevice_suite (void)
{
@ -71,6 +92,7 @@ vkdevice_suite (void)
gst_object_unref (instance);
if (have_instance) {
tcase_add_test (tc_basic, test_device_new);
tcase_add_test (tc_basic, test_physical_device_version);
}
return s;