2019-05-08 04:50:29 +00:00
|
|
|
/*
|
|
|
|
* 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 "gstvkimagebufferpool.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:vkimagebufferpool
|
|
|
|
* @title: GstVulkanImageBufferPool
|
|
|
|
* @short_description: buffer pool for #GstVulkanImageMemory objects
|
|
|
|
* @see_also: #GstBufferPool, #GstVulkanImageMemory
|
|
|
|
*
|
|
|
|
* a #GstVulkanImageBufferPool is an object that allocates buffers with #GstVulkanImageMemory
|
|
|
|
*
|
|
|
|
* A #GstVulkanImageBufferPool is created with gst_vulkan_image_buffer_pool_new()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* bufferpool */
|
|
|
|
struct _GstVulkanImageBufferPoolPrivate
|
|
|
|
{
|
|
|
|
GstCaps *caps;
|
2019-05-16 09:38:35 +00:00
|
|
|
gboolean raw_caps;
|
2019-05-08 04:50:29 +00:00
|
|
|
GstVideoInfo v_info;
|
2021-04-23 10:23:00 +00:00
|
|
|
VkImageUsageFlags usage;
|
|
|
|
VkMemoryPropertyFlags mem_props;
|
2023-04-01 06:12:28 +00:00
|
|
|
VkFormat vk_fmts[GST_VIDEO_MAX_PLANES];
|
|
|
|
int n_imgs;
|
2023-08-10 11:10:04 +00:00
|
|
|
guint32 n_layers;
|
2023-04-03 19:01:34 +00:00
|
|
|
gboolean has_profile;
|
|
|
|
GstVulkanVideoProfile profile;
|
2023-06-29 06:24:18 +00:00
|
|
|
GstVulkanOperation *exec;
|
2019-05-08 04:50:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gst_vulkan_image_buffer_pool_finalize (GObject * object);
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_VULKAN_IMAGE_BUFFER_POOL);
|
|
|
|
#define GST_CAT_DEFAULT GST_CAT_VULKAN_IMAGE_BUFFER_POOL
|
|
|
|
|
2019-11-06 15:41:10 +00:00
|
|
|
#define GET_PRIV(pool) gst_vulkan_image_buffer_pool_get_instance_private (pool)
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
#define gst_vulkan_image_buffer_pool_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVulkanImageBufferPool, gst_vulkan_image_buffer_pool,
|
|
|
|
GST_TYPE_BUFFER_POOL, G_ADD_PRIVATE (GstVulkanImageBufferPool)
|
|
|
|
GST_DEBUG_CATEGORY_INIT (GST_CAT_VULKAN_IMAGE_BUFFER_POOL,
|
|
|
|
"vulkanimagebufferpool", 0, "Vulkan Image Buffer Pool"));
|
|
|
|
|
2021-04-23 10:23:00 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_image_buffer_pool_config_set_allocation_params:
|
|
|
|
* @config: the #GstStructure with the pool's configuration.
|
|
|
|
* @usage: The Vulkan image usage flags.
|
|
|
|
* @mem_properties: Vulkan memory property flags.
|
|
|
|
*
|
|
|
|
* Sets the @usage and @mem_properties of the images to setup.
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vulkan_image_buffer_pool_config_set_allocation_params (GstStructure *
|
|
|
|
config, VkImageUsageFlags usage, VkMemoryPropertyFlags mem_properties)
|
|
|
|
{
|
|
|
|
/* assumption: G_TYPE_UINT is compatible with uint32_t (VkFlags) */
|
|
|
|
gst_structure_set (config, "usage", G_TYPE_UINT, usage, "memory-properties",
|
|
|
|
G_TYPE_UINT, mem_properties, NULL);
|
|
|
|
}
|
|
|
|
|
2023-04-03 19:01:34 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_image_buffer_pool_config_set_decode_caps:
|
|
|
|
* @config: the #GstStructure with the pool's configuration.
|
|
|
|
* @caps: Upstream decode caps.
|
|
|
|
*
|
|
|
|
* Decode @caps are used when the buffers are going to be used either as decoded
|
|
|
|
* dest or DPB images.
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vulkan_image_buffer_pool_config_set_decode_caps (GstStructure * config,
|
|
|
|
GstCaps * caps)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_CAPS (caps));
|
|
|
|
|
|
|
|
gst_structure_set (config, "decode-caps", GST_TYPE_CAPS, caps, NULL);
|
|
|
|
}
|
|
|
|
|
2021-04-23 10:23:00 +00:00
|
|
|
static inline gboolean
|
|
|
|
gst_vulkan_image_buffer_pool_config_get_allocation_params (GstStructure *
|
2023-04-03 19:01:34 +00:00
|
|
|
config, VkImageUsageFlags * usage, VkMemoryPropertyFlags * mem_props,
|
2023-08-10 11:10:04 +00:00
|
|
|
guint32 * n_layers, GstCaps ** decode_caps)
|
2021-04-23 10:23:00 +00:00
|
|
|
{
|
|
|
|
if (!gst_structure_get_uint (config, "usage", usage)) {
|
|
|
|
*usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT
|
|
|
|
| VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gst_structure_get_uint (config, "memory-properties", mem_props))
|
|
|
|
*mem_props = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
|
|
|
|
2023-08-10 11:10:04 +00:00
|
|
|
if (!gst_structure_get_uint (config, "num-layers", n_layers))
|
|
|
|
*n_layers = 1;
|
|
|
|
|
2023-04-03 19:01:34 +00:00
|
|
|
if (decode_caps)
|
|
|
|
gst_structure_get (config, "decode-caps", GST_TYPE_CAPS, decode_caps, NULL);
|
|
|
|
|
2021-04-23 10:23:00 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vulkan_image_buffer_pool_set_config (GstBufferPool * pool,
|
|
|
|
GstStructure * config)
|
|
|
|
{
|
|
|
|
GstVulkanImageBufferPool *vk_pool = GST_VULKAN_IMAGE_BUFFER_POOL_CAST (pool);
|
2019-11-06 15:41:10 +00:00
|
|
|
GstVulkanImageBufferPoolPrivate *priv = GET_PRIV (vk_pool);
|
2023-04-01 06:12:28 +00:00
|
|
|
VkImageTiling tiling;
|
2023-09-08 15:54:25 +00:00
|
|
|
VkImageUsageFlags requested_usage, supported_usage;
|
2023-04-03 18:17:56 +00:00
|
|
|
VkImageCreateInfo image_info;
|
2019-05-08 04:50:29 +00:00
|
|
|
guint min_buffers, max_buffers;
|
2023-04-03 19:01:34 +00:00
|
|
|
GstCaps *caps = NULL, *decode_caps = NULL;
|
2019-05-16 09:38:35 +00:00
|
|
|
GstCapsFeatures *features;
|
2023-09-08 15:54:25 +00:00
|
|
|
gboolean found, no_multiplane, ret = TRUE;
|
2019-05-08 04:50:29 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (!gst_buffer_pool_config_get_params (config, &caps, NULL, &min_buffers,
|
|
|
|
&max_buffers))
|
|
|
|
goto wrong_config;
|
|
|
|
|
|
|
|
if (caps == NULL)
|
|
|
|
goto no_caps;
|
|
|
|
|
|
|
|
/* now parse the caps from the config */
|
|
|
|
if (!gst_video_info_from_caps (&priv->v_info, caps))
|
|
|
|
goto wrong_caps;
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "%dx%d, caps %" GST_PTR_FORMAT, priv->v_info.width,
|
|
|
|
priv->v_info.height, caps);
|
|
|
|
|
|
|
|
gst_caps_replace (&priv->caps, caps);
|
|
|
|
|
2019-05-16 09:38:35 +00:00
|
|
|
features = gst_caps_get_features (caps, 0);
|
|
|
|
priv->raw_caps = features == NULL || gst_caps_features_is_equal (features,
|
|
|
|
GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY);
|
|
|
|
|
2021-04-23 10:23:00 +00:00
|
|
|
gst_vulkan_image_buffer_pool_config_get_allocation_params (config,
|
2023-08-10 11:10:04 +00:00
|
|
|
&priv->usage, &priv->mem_props, &priv->n_layers, &decode_caps);
|
2023-04-03 19:01:34 +00:00
|
|
|
|
|
|
|
priv->has_profile = FALSE;
|
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
if (decode_caps && ((priv->usage
|
|
|
|
& (VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR
|
|
|
|
| VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR)) != 0)) {
|
|
|
|
priv->has_profile =
|
2023-07-10 12:44:05 +00:00
|
|
|
gst_vulkan_video_profile_from_caps (&priv->profile, decode_caps,
|
|
|
|
GST_VULKAN_VIDEO_OPERATION_DECODE);
|
2023-04-03 19:01:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
gst_clear_caps (&decode_caps);
|
|
|
|
|
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
if (((priv->usage & (VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR
|
|
|
|
| VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR)) != 0)
|
|
|
|
&& !priv->has_profile)
|
|
|
|
goto missing_profile;
|
|
|
|
|
2023-09-08 15:54:25 +00:00
|
|
|
if (priv->has_profile) {
|
|
|
|
no_multiplane = FALSE;
|
|
|
|
|
|
|
|
/* HACK(victor): NVIDIA & RADV drivers don't report decoding features for
|
|
|
|
* color format. Setting usage to zero to short circuit validation. */
|
|
|
|
requested_usage = 0;
|
|
|
|
} else
|
2023-04-03 19:01:34 +00:00
|
|
|
#endif
|
2023-09-08 15:54:25 +00:00
|
|
|
{
|
|
|
|
no_multiplane = TRUE;
|
|
|
|
requested_usage = priv->usage;
|
|
|
|
}
|
2021-04-23 10:23:00 +00:00
|
|
|
|
2023-04-01 06:12:28 +00:00
|
|
|
tiling = priv->raw_caps ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
|
|
|
|
found = gst_vulkan_format_from_video_info_2 (vk_pool->device->physical_device,
|
2023-09-08 15:54:25 +00:00
|
|
|
&priv->v_info, tiling, no_multiplane, requested_usage, priv->vk_fmts,
|
2023-09-06 02:46:32 +00:00
|
|
|
&priv->n_imgs, &supported_usage);
|
2023-04-01 06:12:28 +00:00
|
|
|
if (!found)
|
|
|
|
goto no_vk_format;
|
|
|
|
|
|
|
|
if (priv->usage == 0) {
|
|
|
|
priv->usage = supported_usage & (VK_BUFFER_USAGE_TRANSFER_DST_BIT
|
|
|
|
| VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_STORAGE_BIT
|
|
|
|
| VK_IMAGE_USAGE_SAMPLED_BIT);
|
|
|
|
}
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
/* get the size of the buffer to allocate */
|
2023-04-03 18:17:56 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
image_info = (VkImageCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.flags = 0,
|
|
|
|
.imageType = VK_IMAGE_TYPE_2D,
|
|
|
|
/* .format = fill per image, */
|
|
|
|
/* .extent = fill per plane, */
|
|
|
|
.mipLevels = 1,
|
2023-08-10 11:10:04 +00:00
|
|
|
.arrayLayers = priv->n_layers,
|
2023-04-03 18:17:56 +00:00
|
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.tiling = tiling,
|
|
|
|
.usage = priv->usage,
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
.queueFamilyIndexCount = 0,
|
|
|
|
.pQueueFamilyIndices = NULL,
|
|
|
|
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2019-05-08 04:50:29 +00:00
|
|
|
priv->v_info.size = 0;
|
2023-04-01 06:12:28 +00:00
|
|
|
for (i = 0; i < priv->n_imgs; i++) {
|
2019-05-08 04:50:29 +00:00
|
|
|
GstVulkanImageMemory *img_mem;
|
|
|
|
guint width, height;
|
2023-04-03 19:01:34 +00:00
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
VkVideoProfileListInfoKHR profile_list = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR,
|
|
|
|
.profileCount = 1,
|
|
|
|
.pProfiles = &priv->profile.profile,
|
|
|
|
};
|
|
|
|
#endif
|
2019-05-08 04:50:29 +00:00
|
|
|
|
2023-04-01 06:12:28 +00:00
|
|
|
if (GST_VIDEO_INFO_N_PLANES (&priv->v_info) != priv->n_imgs) {
|
|
|
|
width = GST_VIDEO_INFO_WIDTH (&priv->v_info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (&priv->v_info);
|
|
|
|
} else {
|
|
|
|
width = GST_VIDEO_INFO_COMP_WIDTH (&priv->v_info, i);
|
|
|
|
height = GST_VIDEO_INFO_COMP_HEIGHT (&priv->v_info, i);
|
|
|
|
}
|
2019-05-08 04:50:29 +00:00
|
|
|
|
2023-04-03 18:17:56 +00:00
|
|
|
image_info.format = priv->vk_fmts[i];
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
image_info.extent = (VkExtent3D) { width, height, 1 };
|
|
|
|
/* *INDENT-ON* */
|
2023-04-03 19:01:34 +00:00
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
if (priv->has_profile)
|
|
|
|
image_info.pNext = &profile_list;
|
|
|
|
#endif
|
2023-04-03 18:17:56 +00:00
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
img_mem = (GstVulkanImageMemory *)
|
2023-04-03 18:17:56 +00:00
|
|
|
gst_vulkan_image_memory_alloc_with_image_info (vk_pool->device,
|
|
|
|
&image_info, priv->mem_props);
|
|
|
|
if (!img_mem)
|
|
|
|
goto mem_create_failed;
|
2019-05-08 04:50:29 +00:00
|
|
|
|
2023-05-08 15:07:12 +00:00
|
|
|
if (!img_mem)
|
|
|
|
goto image_failed;
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
priv->v_info.offset[i] = priv->v_info.size;
|
|
|
|
priv->v_info.size += img_mem->requirements.size;
|
|
|
|
|
|
|
|
gst_memory_unref (GST_MEMORY_CAST (img_mem));
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_pool_config_set_params (config, caps,
|
|
|
|
priv->v_info.size, min_buffers, max_buffers);
|
|
|
|
|
|
|
|
return GST_BUFFER_POOL_CLASS (parent_class)->set_config (pool, config) && ret;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
wrong_config:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "invalid config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
no_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "no caps in config");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
wrong_caps:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool,
|
|
|
|
"failed getting geometry from caps %" GST_PTR_FORMAT, caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-04-01 06:12:28 +00:00
|
|
|
no_vk_format:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "no Vulkan format available for %s",
|
|
|
|
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&priv->v_info)));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-04-03 18:17:56 +00:00
|
|
|
mem_create_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "Could not create Vulkan Memory");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-04-03 19:01:34 +00:00
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
missing_profile:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "missing or invalid decode-caps");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
2023-05-08 15:07:12 +00:00
|
|
|
image_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "Failed to allocate image");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-05-08 04:50:29 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
#if defined(VK_KHR_synchronization2)
|
2023-05-11 11:18:18 +00:00
|
|
|
static gboolean
|
2023-06-29 06:24:18 +00:00
|
|
|
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * _queue,
|
2023-05-11 11:18:18 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
2023-06-29 06:24:18 +00:00
|
|
|
GstVulkanQueue **queue = user_data;
|
2023-05-11 11:18:18 +00:00
|
|
|
guint flags =
|
2023-06-29 06:24:18 +00:00
|
|
|
device->physical_device->queue_family_props[_queue->family].queueFlags;
|
2023-05-11 11:18:18 +00:00
|
|
|
|
|
|
|
if ((flags & (VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT)) != 0) {
|
2023-06-29 06:24:18 +00:00
|
|
|
*queue = gst_object_ref (_queue);
|
2023-05-11 11:18:18 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
prepare_buffer (GstVulkanImageBufferPool * vk_pool, GstBuffer * buffer)
|
|
|
|
{
|
2023-06-29 06:24:18 +00:00
|
|
|
#if defined(VK_KHR_synchronization2)
|
2023-05-11 11:18:18 +00:00
|
|
|
GstVulkanImageBufferPoolPrivate *priv = GET_PRIV (vk_pool);
|
2023-06-29 06:24:18 +00:00
|
|
|
GArray *barriers = NULL;
|
2023-05-11 11:18:18 +00:00
|
|
|
VkImageLayout new_layout;
|
2023-06-29 06:24:18 +00:00
|
|
|
guint64 new_access;
|
2023-05-11 11:18:18 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
if (!priv->exec) {
|
|
|
|
GstVulkanCommandPool *cmd_pool;
|
|
|
|
GstVulkanQueue *queue = NULL;
|
2023-05-11 11:18:18 +00:00
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
gst_vulkan_device_foreach_queue (vk_pool->device, _choose_queue, &queue);
|
|
|
|
if (!queue)
|
2023-05-11 11:18:18 +00:00
|
|
|
return FALSE;
|
2023-06-29 06:24:18 +00:00
|
|
|
cmd_pool = gst_vulkan_queue_create_command_pool (queue, &error);
|
|
|
|
gst_object_unref (queue);
|
2023-05-11 11:18:18 +00:00
|
|
|
if (error)
|
|
|
|
goto error;
|
2023-06-29 06:24:18 +00:00
|
|
|
priv->exec = gst_vulkan_operation_new (cmd_pool);
|
|
|
|
gst_object_unref (cmd_pool);
|
2023-05-11 11:18:18 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
if (!gst_vulkan_operation_add_dependency_frame (priv->exec, buffer,
|
|
|
|
VK_PIPELINE_STAGE_NONE_KHR, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT))
|
|
|
|
return FALSE;
|
2023-05-11 11:18:18 +00:00
|
|
|
|
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
if ((priv->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR) != 0 &&
|
2023-05-24 18:37:13 +00:00
|
|
|
(priv->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR) == 0) {
|
2023-05-11 11:18:18 +00:00
|
|
|
new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DPB_KHR;
|
|
|
|
new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
|
|
} else if ((priv->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR) != 0) {
|
|
|
|
new_layout = VK_IMAGE_LAYOUT_VIDEO_DECODE_DST_KHR;
|
|
|
|
new_access = VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
|
|
#ifdef VK_ENABLE_BETA_EXTENSIONS
|
|
|
|
} else if ((priv->usage & VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR) != 0) {
|
|
|
|
new_layout = VK_IMAGE_LAYOUT_VIDEO_ENCODE_DPB_KHR;
|
|
|
|
new_access = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
|
|
|
#endif
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
new_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
2023-06-29 06:24:18 +00:00
|
|
|
new_access = VK_ACCESS_MEMORY_WRITE_BIT;
|
2023-05-11 11:18:18 +00:00
|
|
|
}
|
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
if (!gst_vulkan_operation_begin (priv->exec, &error))
|
|
|
|
goto error;
|
2023-05-11 11:18:18 +00:00
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
if (!gst_vulkan_operation_add_frame_barrier (priv->exec, buffer,
|
|
|
|
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, new_access, new_layout, NULL))
|
|
|
|
goto error;
|
2023-05-11 11:18:18 +00:00
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
barriers = gst_vulkan_operation_retrieve_image_barriers (priv->exec);
|
|
|
|
if (barriers->len > 0) {
|
|
|
|
if (gst_vulkan_operation_use_sync2 (priv->exec)) {
|
|
|
|
VkDependencyInfoKHR dependency_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO_KHR,
|
|
|
|
.pImageMemoryBarriers = (gpointer) barriers->data,
|
|
|
|
.imageMemoryBarrierCount = barriers->len,
|
|
|
|
};
|
2023-05-11 11:18:18 +00:00
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
gst_vulkan_operation_pipeline_barrier2 (priv->exec, &dependency_info);
|
|
|
|
} else {
|
|
|
|
gst_vulkan_command_buffer_lock (priv->exec->cmd_buf);
|
|
|
|
vkCmdPipelineBarrier (priv->exec->cmd_buf->cmd,
|
|
|
|
VK_PIPELINE_STAGE_NONE_KHR, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
|
|
|
|
NULL, 0, NULL, barriers->len, (gpointer) barriers->data);
|
|
|
|
gst_vulkan_command_buffer_unlock (priv->exec->cmd_buf);
|
|
|
|
}
|
2023-05-11 11:18:18 +00:00
|
|
|
}
|
2023-06-29 06:24:18 +00:00
|
|
|
g_array_unref (barriers);
|
2023-05-11 11:18:18 +00:00
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
if (!gst_vulkan_operation_end (priv->exec, &error))
|
2023-05-11 11:18:18 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
error:
|
|
|
|
{
|
|
|
|
if (error) {
|
|
|
|
GST_WARNING_OBJECT (vk_pool, "Error: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
/* This function handles GstBuffer creation */
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_vulkan_image_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
|
|
|
GstBufferPoolAcquireParams * params)
|
|
|
|
{
|
|
|
|
GstVulkanImageBufferPool *vk_pool = GST_VULKAN_IMAGE_BUFFER_POOL_CAST (pool);
|
2019-11-06 15:41:10 +00:00
|
|
|
GstVulkanImageBufferPoolPrivate *priv = GET_PRIV (vk_pool);
|
2023-04-01 06:12:28 +00:00
|
|
|
VkImageTiling tiling =
|
|
|
|
priv->raw_caps ? VK_IMAGE_TILING_LINEAR : VK_IMAGE_TILING_OPTIMAL;
|
2023-04-03 18:17:56 +00:00
|
|
|
VkImageCreateInfo image_info;
|
2019-05-08 04:50:29 +00:00
|
|
|
GstBuffer *buf;
|
|
|
|
guint i;
|
|
|
|
|
2023-04-03 18:17:56 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
image_info = (VkImageCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.flags = 0,
|
|
|
|
.imageType = VK_IMAGE_TYPE_2D,
|
|
|
|
/* .format = fill per image, */
|
|
|
|
/* .extent = fill per plane, */
|
|
|
|
.mipLevels = 1,
|
2023-08-10 11:10:04 +00:00
|
|
|
.arrayLayers = priv->n_layers,
|
2023-04-03 18:17:56 +00:00
|
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.tiling = tiling,
|
|
|
|
.usage = priv->usage,
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
.queueFamilyIndexCount = 0,
|
|
|
|
.pQueueFamilyIndices = NULL,
|
|
|
|
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
if (!(buf = gst_buffer_new ())) {
|
|
|
|
goto no_buffer;
|
|
|
|
}
|
|
|
|
|
2023-04-01 06:12:28 +00:00
|
|
|
for (i = 0; i < priv->n_imgs; i++) {
|
2019-05-08 04:50:29 +00:00
|
|
|
GstMemory *mem;
|
2023-04-01 06:12:28 +00:00
|
|
|
guint width, height;
|
2023-05-24 18:37:13 +00:00
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
VkVideoProfileListInfoKHR profile_list = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR,
|
|
|
|
.profileCount = 1,
|
|
|
|
.pProfiles = &priv->profile.profile,
|
|
|
|
};
|
|
|
|
#endif
|
2019-05-08 04:50:29 +00:00
|
|
|
|
2023-04-01 06:12:28 +00:00
|
|
|
if (GST_VIDEO_INFO_N_PLANES (&priv->v_info) != priv->n_imgs) {
|
|
|
|
width = GST_VIDEO_INFO_WIDTH (&priv->v_info);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (&priv->v_info);
|
|
|
|
} else {
|
|
|
|
width = GST_VIDEO_INFO_COMP_WIDTH (&priv->v_info, i);
|
|
|
|
height = GST_VIDEO_INFO_COMP_HEIGHT (&priv->v_info, i);
|
|
|
|
}
|
2019-05-08 04:50:29 +00:00
|
|
|
|
2023-04-03 18:17:56 +00:00
|
|
|
image_info.format = priv->vk_fmts[i];
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
image_info.extent = (VkExtent3D) { width, height, 1 };
|
|
|
|
/* *INDENT-ON* */
|
2023-04-03 19:01:34 +00:00
|
|
|
#if GST_VULKAN_HAVE_VIDEO_EXTENSIONS
|
|
|
|
if (priv->has_profile)
|
2023-05-24 18:37:13 +00:00
|
|
|
image_info.pNext = &profile_list;
|
2023-04-03 19:01:34 +00:00
|
|
|
#endif
|
2023-04-03 18:17:56 +00:00
|
|
|
|
|
|
|
mem = gst_vulkan_image_memory_alloc_with_image_info (vk_pool->device,
|
|
|
|
&image_info, priv->mem_props);
|
2019-05-08 04:50:29 +00:00
|
|
|
if (!mem) {
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
goto mem_create_failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_buffer_append_memory (buf, mem);
|
|
|
|
}
|
|
|
|
|
2023-05-11 11:18:18 +00:00
|
|
|
prepare_buffer (vk_pool, buf);
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
*buffer = buf;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* ERROR */
|
|
|
|
no_buffer:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "can't create image");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
mem_create_failed:
|
|
|
|
{
|
|
|
|
GST_WARNING_OBJECT (pool, "Could not create Vulkan Memory");
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vulkan_image_buffer_pool_stop (GstBufferPool * pool)
|
|
|
|
{
|
|
|
|
#if defined(VK_KHR_synchronization2)
|
|
|
|
GstVulkanImageBufferPool *vk_pool = GST_VULKAN_IMAGE_BUFFER_POOL_CAST (pool);
|
|
|
|
GstVulkanImageBufferPoolPrivate *priv = GET_PRIV (vk_pool);
|
|
|
|
if (priv->exec)
|
|
|
|
gst_vulkan_operation_wait (priv->exec);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return GST_BUFFER_POOL_CLASS (parent_class)->stop (pool);
|
|
|
|
}
|
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
/**
|
|
|
|
* gst_vulkan_image_buffer_pool_new:
|
|
|
|
* @device: the #GstVulkanDevice to use
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #GstBufferPool that allocates buffers with #GstGLMemory
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
GstBufferPool *
|
|
|
|
gst_vulkan_image_buffer_pool_new (GstVulkanDevice * device)
|
|
|
|
{
|
|
|
|
GstVulkanImageBufferPool *pool;
|
|
|
|
|
|
|
|
pool = g_object_new (GST_TYPE_VULKAN_IMAGE_BUFFER_POOL, NULL);
|
|
|
|
g_object_ref_sink (pool);
|
|
|
|
pool->device = gst_object_ref (device);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "new Vulkan buffer pool for device %" GST_PTR_FORMAT,
|
|
|
|
device);
|
|
|
|
|
|
|
|
return GST_BUFFER_POOL_CAST (pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_image_buffer_pool_class_init (GstVulkanImageBufferPoolClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GstBufferPoolClass *gstbufferpool_class = (GstBufferPoolClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->finalize = gst_vulkan_image_buffer_pool_finalize;
|
|
|
|
|
|
|
|
gstbufferpool_class->set_config = gst_vulkan_image_buffer_pool_set_config;
|
|
|
|
gstbufferpool_class->alloc_buffer = gst_vulkan_image_buffer_pool_alloc;
|
2023-06-29 06:24:18 +00:00
|
|
|
gstbufferpool_class->stop = gst_vulkan_image_buffer_pool_stop;
|
2019-05-08 04:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_image_buffer_pool_init (GstVulkanImageBufferPool * pool)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_image_buffer_pool_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstVulkanImageBufferPool *pool = GST_VULKAN_IMAGE_BUFFER_POOL_CAST (object);
|
2019-11-06 15:41:10 +00:00
|
|
|
GstVulkanImageBufferPoolPrivate *priv = GET_PRIV (pool);
|
2019-05-08 04:50:29 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (pool, "finalize Vulkan buffer pool %p", pool);
|
|
|
|
|
|
|
|
if (priv->caps)
|
|
|
|
gst_caps_unref (priv->caps);
|
|
|
|
|
2023-06-29 06:24:18 +00:00
|
|
|
gst_clear_object (&priv->exec);
|
2023-05-11 11:18:18 +00:00
|
|
|
|
2019-05-08 04:50:29 +00:00
|
|
|
G_OBJECT_CLASS (gst_vulkan_image_buffer_pool_parent_class)->finalize (object);
|
|
|
|
|
|
|
|
/* only release the context once all our memory have been deleted */
|
|
|
|
if (pool->device) {
|
|
|
|
gst_object_unref (pool->device);
|
|
|
|
pool->device = NULL;
|
|
|
|
}
|
|
|
|
}
|