mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-26 10:10:32 +00:00
vkbufferpool: allow to set allocation params
Add the possibility to change the vulkan usage and mem properties from external source. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5645>
This commit is contained in:
parent
d23a90cb16
commit
c6a5437e0d
3 changed files with 66 additions and 6 deletions
|
@ -1102,6 +1102,26 @@ multiple times. This must be called before any other #GstVulkanBufferMemory ope
|
|||
</parameter>
|
||||
</parameters>
|
||||
</constructor>
|
||||
<function name="config_set_allocation_params" c:identifier="gst_vulkan_buffer_pool_config_set_allocation_params" version="1.24">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkbufferpool.c">Sets the @usage of the buffers to setup.</doc>
|
||||
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkbufferpool.h"/>
|
||||
<return-value transfer-ownership="none">
|
||||
<type name="none" c:type="void"/>
|
||||
</return-value>
|
||||
<parameters>
|
||||
<parameter name="config" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkbufferpool.c">the #GstStructure with the pool's configuration.</doc>
|
||||
<type name="Gst.Structure" c:type="GstStructure*"/>
|
||||
</parameter>
|
||||
<parameter name="usage" transfer-ownership="none">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkbufferpool.c">The Vulkan buffer usage flags.</doc>
|
||||
<type name="Vulkan.ImageUsageFlags" c:type="VkImageUsageFlags"/>
|
||||
</parameter>
|
||||
<parameter name="mem_properties" transfer-ownership="none">
|
||||
<type name="Vulkan.MemoryPropertyFlags" c:type="VkMemoryPropertyFlags"/>
|
||||
</parameter>
|
||||
</parameters>
|
||||
</function>
|
||||
<field name="bufferpool">
|
||||
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/vulkan/gstvkbufferpool.h">the parent #GstBufferPool</doc>
|
||||
<type name="Gst.BufferPool" c:type="GstBufferPool"/>
|
||||
|
|
|
@ -44,6 +44,8 @@ struct _GstVulkanBufferPoolPrivate
|
|||
GstCaps *caps;
|
||||
GstVideoInfo v_info;
|
||||
gboolean add_videometa;
|
||||
VkImageUsageFlags usage;
|
||||
VkMemoryPropertyFlags mem_props;
|
||||
gsize alloc_sizes[GST_VIDEO_MAX_PLANES];
|
||||
};
|
||||
|
||||
|
@ -70,6 +72,39 @@ gst_vulkan_buffer_pool_get_options (GstBufferPool * pool)
|
|||
return options;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
gst_vulkan_buffer_pool_config_get_allocation_params (GstStructure *
|
||||
config, VkImageUsageFlags * usage, VkMemoryPropertyFlags * mem_props)
|
||||
{
|
||||
if (!gst_structure_get_uint (config, "usage", usage)) {
|
||||
*usage =
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
}
|
||||
|
||||
if (!gst_structure_get_uint (config, "memory-properties", mem_props))
|
||||
*mem_props = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vulkan_buffer_pool_config_set_allocation_params:
|
||||
* @config: the #GstStructure with the pool's configuration.
|
||||
* @usage: The Vulkan buffer usage flags.
|
||||
*
|
||||
* Sets the @usage of the buffers to setup.
|
||||
*
|
||||
* Since: 1.24
|
||||
*/
|
||||
void
|
||||
gst_vulkan_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);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_vulkan_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||
{
|
||||
|
@ -96,6 +131,9 @@ gst_vulkan_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
|||
|
||||
gst_caps_replace (&priv->caps, caps);
|
||||
|
||||
gst_vulkan_buffer_pool_config_get_allocation_params (config,
|
||||
&priv->usage, &priv->mem_props);
|
||||
|
||||
/* get the size of the buffer to allocate */
|
||||
priv->v_info.size = 0;
|
||||
for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&priv->v_info); i++) {
|
||||
|
@ -110,7 +148,6 @@ gst_vulkan_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
|||
|
||||
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 */
|
||||
|
@ -150,10 +187,7 @@ gst_vulkan_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
|||
GstMemory *mem;
|
||||
|
||||
mem = gst_vulkan_buffer_memory_alloc (vk_pool->device, priv->alloc_sizes[i],
|
||||
/* FIXME: choose from outside */
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
||||
/* FIXME: choose from outside */
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
|
||||
priv->usage, priv->mem_props);
|
||||
if (!mem) {
|
||||
gst_buffer_unref (buf);
|
||||
goto mem_create_failed;
|
||||
|
|
|
@ -79,7 +79,13 @@ struct _GstVulkanBufferPoolClass
|
|||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstVulkanBufferPool, gst_object_unref);
|
||||
|
||||
GST_VULKAN_API
|
||||
GstBufferPool *gst_vulkan_buffer_pool_new (GstVulkanDevice * device);
|
||||
GstBufferPool *gst_vulkan_buffer_pool_new (GstVulkanDevice * device);
|
||||
|
||||
GST_VULKAN_API
|
||||
void gst_vulkan_buffer_pool_config_set_allocation_params
|
||||
(GstStructure * config,
|
||||
VkImageUsageFlags usage,
|
||||
VkMemoryPropertyFlags mem_properties);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in a new issue