mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
vulkanmemory: remove bind variants
This commit is contained in:
parent
4c0a169af9
commit
3c2710dc0f
5 changed files with 43 additions and 187 deletions
|
@ -96,6 +96,7 @@ _vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
|||
GstAllocationParams params = { 0, };
|
||||
VkBufferCreateInfo buffer_info;
|
||||
GError *error = NULL;
|
||||
guint32 type_idx;
|
||||
VkBuffer buffer;
|
||||
VkResult err;
|
||||
|
||||
|
@ -111,11 +112,25 @@ _vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
|||
mem = g_new0 (GstVulkanBufferMemory, 1);
|
||||
vkGetBufferMemoryRequirements (device->device, buffer, &mem->requirements);
|
||||
|
||||
params.align = mem->requirements.alignment;
|
||||
/* XXX: assumes alignment is a power of 2 */
|
||||
params.align = mem->requirements.alignment - 1;
|
||||
_vk_buffer_mem_init (mem, allocator, parent, device, usage, ¶ms,
|
||||
mem->requirements.size, user_data, notify);
|
||||
mem->buffer = buffer;
|
||||
|
||||
if (!gst_vulkan_memory_find_memory_type_index_with_type_properties (device,
|
||||
mem->requirements.memoryTypeBits, mem_prop_flags, &type_idx))
|
||||
goto error;
|
||||
|
||||
mem->vk_mem = (GstVulkanMemory *) gst_vulkan_memory_alloc (device, type_idx,
|
||||
¶ms, mem->requirements.size, mem_prop_flags);
|
||||
if (!mem->vk_mem)
|
||||
goto error;
|
||||
|
||||
err = vkBindBufferMemory (device->device, buffer, mem->vk_mem->mem_ptr, 0);
|
||||
if (gst_vulkan_error_to_g_error (err, &error, "vkBindBufferMemory") < 0)
|
||||
goto vk_error;
|
||||
|
||||
return mem;
|
||||
|
||||
vk_error:
|
||||
|
@ -147,8 +162,8 @@ _vk_buffer_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
|||
vkGetBufferMemoryRequirements (device->device, mem->buffer,
|
||||
&mem->requirements);
|
||||
|
||||
/* no device memory so no mapping */
|
||||
params.flags = GST_MEMORY_FLAG_NOT_MAPPABLE | GST_MEMORY_FLAG_READONLY;
|
||||
params.align = mem->requirements.alignment - 1;
|
||||
params.flags = GST_MEMORY_FLAG_NOT_MAPPABLE;
|
||||
_vk_buffer_mem_init (mem, allocator, parent, device, usage, ¶ms,
|
||||
mem->requirements.size, user_data, notify);
|
||||
mem->wrapped = TRUE;
|
||||
|
@ -263,46 +278,6 @@ gst_vulkan_buffer_memory_alloc (GstVulkanDevice * device, VkFormat format,
|
|||
return (GstMemory *) mem;
|
||||
}
|
||||
|
||||
GstMemory *
|
||||
gst_vulkan_buffer_memory_alloc_bind (GstVulkanDevice * device, VkFormat format,
|
||||
gsize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags mem_prop_flags)
|
||||
{
|
||||
GstAllocationParams params = { 0, };
|
||||
GstVulkanBufferMemory *mem;
|
||||
GstVulkanMemory *dev_mem;
|
||||
guint32 type_idx;
|
||||
|
||||
mem =
|
||||
(GstVulkanBufferMemory *) gst_vulkan_buffer_memory_alloc (device, format,
|
||||
size, usage, mem_prop_flags);
|
||||
if (!mem)
|
||||
return NULL;
|
||||
|
||||
if (!gst_vulkan_memory_find_memory_type_index_with_type_properties (device,
|
||||
mem->requirements.memoryTypeBits, mem_prop_flags, &type_idx)) {
|
||||
gst_memory_unref (GST_MEMORY_CAST (mem));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* XXX: assumes alignment is a power of 2 */
|
||||
params.align = mem->requirements.alignment - 1;
|
||||
dev_mem = (GstVulkanMemory *) gst_vulkan_memory_alloc (device, type_idx,
|
||||
¶ms, mem->requirements.size, mem_prop_flags);
|
||||
if (!dev_mem) {
|
||||
gst_memory_unref (GST_MEMORY_CAST (mem));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_buffer_memory_bind (mem, dev_mem)) {
|
||||
gst_memory_unref (GST_MEMORY_CAST (dev_mem));
|
||||
gst_memory_unref (GST_MEMORY_CAST (mem));
|
||||
return NULL;
|
||||
}
|
||||
gst_memory_unref (GST_MEMORY_CAST (dev_mem));
|
||||
|
||||
return (GstMemory *) mem;
|
||||
}
|
||||
|
||||
GstMemory *
|
||||
gst_vulkan_buffer_memory_wrapped (GstVulkanDevice * device, VkBuffer buffer,
|
||||
VkFormat format, VkBufferUsageFlags usage, gpointer user_data,
|
||||
|
@ -317,45 +292,6 @@ gst_vulkan_buffer_memory_wrapped (GstVulkanDevice * device, VkBuffer buffer,
|
|||
return (GstMemory *) mem;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_vulkan_buffer_memory_bind (GstVulkanBufferMemory * buf_mem,
|
||||
GstVulkanMemory * memory)
|
||||
{
|
||||
gsize maxsize;
|
||||
|
||||
g_return_val_if_fail (gst_is_vulkan_buffer_memory (GST_MEMORY_CAST (buf_mem)),
|
||||
FALSE);
|
||||
g_return_val_if_fail (gst_is_vulkan_memory (GST_MEMORY_CAST (memory)), FALSE);
|
||||
|
||||
/* will we overrun the allocated data */
|
||||
gst_memory_get_sizes (GST_MEMORY_CAST (memory), NULL, &maxsize);
|
||||
g_return_val_if_fail (memory->vk_offset + buf_mem->requirements.size <=
|
||||
maxsize, FALSE);
|
||||
|
||||
g_mutex_lock (&buf_mem->lock);
|
||||
|
||||
/* "Once a buffer or image is bound to a region of a memory object, it must
|
||||
* not be rebound or unbound." */
|
||||
if (buf_mem->vk_mem == memory) {
|
||||
g_mutex_unlock (&buf_mem->lock);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (buf_mem->vk_mem) {
|
||||
g_mutex_unlock (&buf_mem->lock);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vkBindBufferMemory (buf_mem->device->device, buf_mem->buffer, memory->mem_ptr,
|
||||
memory->vk_offset);
|
||||
|
||||
buf_mem->vk_mem =
|
||||
(GstVulkanMemory *) gst_memory_ref (GST_MEMORY_CAST (memory));
|
||||
g_mutex_unlock (&buf_mem->lock);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
G_DEFINE_TYPE (GstVulkanBufferMemoryAllocator,
|
||||
gst_vulkan_buffer_memory_allocator, GST_TYPE_ALLOCATOR);
|
||||
|
||||
|
|
|
@ -89,12 +89,6 @@ GstMemory * gst_vulkan_buffer_memory_alloc (GstVulkanDevice * devi
|
|||
VkBufferUsageFlags usage,
|
||||
VkMemoryPropertyFlags mem_prop_flags);
|
||||
|
||||
GstMemory * gst_vulkan_buffer_memory_alloc_bind (GstVulkanDevice * device,
|
||||
VkFormat format,
|
||||
gsize size,
|
||||
VkBufferUsageFlags usage,
|
||||
VkMemoryPropertyFlags mem_prop_flags);
|
||||
|
||||
GstMemory * gst_vulkan_buffer_memory_wrapped (GstVulkanDevice * device,
|
||||
VkBuffer buffer,
|
||||
VkFormat format,
|
||||
|
@ -102,9 +96,6 @@ GstMemory * gst_vulkan_buffer_memory_wrapped (GstVulkanDevice * devi
|
|||
gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
|
||||
gboolean gst_vulkan_buffer_memory_bind (GstVulkanBufferMemory * buf_mem,
|
||||
GstVulkanMemory * memory);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _VK_BUFFER_MEMORY_H_ */
|
||||
|
|
|
@ -165,7 +165,7 @@ gst_vulkan_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
|
|||
|
||||
vk_format = gst_vulkan_format_from_video_format (v_format, i);
|
||||
|
||||
mem = gst_vulkan_buffer_memory_alloc_bind (vk_pool->device,
|
||||
mem = gst_vulkan_buffer_memory_alloc (vk_pool->device,
|
||||
vk_format, priv->alloc_sizes[i],
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
|
||||
|
|
|
@ -170,6 +170,7 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
|||
VkImageCreateInfo image_info;
|
||||
VkPhysicalDevice gpu;
|
||||
GError *error = NULL;
|
||||
guint32 type_idx;
|
||||
VkImage image;
|
||||
VkResult err;
|
||||
|
||||
|
@ -185,16 +186,32 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
|||
goto vk_error;
|
||||
|
||||
mem = g_new0 (GstVulkanImageMemory, 1);
|
||||
vkGetImageMemoryRequirements (device->device, image, &mem->requirements);
|
||||
|
||||
params.align = mem->requirements.alignment;
|
||||
_vk_image_mem_init (mem, allocator, parent, device, usage, ¶ms,
|
||||
mem->requirements.size, user_data, notify);
|
||||
mem->create_info = image_info;
|
||||
mem->image = image;
|
||||
|
||||
vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D,
|
||||
vkGetImageMemoryRequirements (device->device, image, &mem->requirements);
|
||||
err = vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D,
|
||||
tiling, usage, 0, &mem->format_properties);
|
||||
if (gst_vulkan_error_to_g_error (err, &error,
|
||||
"vkGetPhysicalDeviceImageFormatProperties") < 0)
|
||||
goto vk_error;
|
||||
|
||||
if (!gst_vulkan_memory_find_memory_type_index_with_type_properties (device,
|
||||
mem->requirements.memoryTypeBits, mem_prop_flags, &type_idx))
|
||||
goto error;
|
||||
|
||||
/* XXX: assumes alignment is a power of 2 */
|
||||
params.align = mem->requirements.alignment - 1;
|
||||
mem->vk_mem = (GstVulkanMemory *) gst_vulkan_memory_alloc (device, type_idx,
|
||||
¶ms, mem->requirements.size, mem_prop_flags);
|
||||
if (!mem->vk_mem)
|
||||
goto error;
|
||||
|
||||
err = vkBindImageMemory (device->device, image, mem->vk_mem->mem_ptr, 0);
|
||||
if (gst_vulkan_error_to_g_error (err, &error, "vkBindImageMemory") < 0)
|
||||
goto vk_error;
|
||||
|
||||
return mem;
|
||||
|
||||
|
@ -231,7 +248,9 @@ _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
|||
|
||||
vkGetImageMemoryRequirements (device->device, mem->image, &mem->requirements);
|
||||
|
||||
params.flags = GST_MEMORY_FLAG_NOT_MAPPABLE | GST_MEMORY_FLAG_READONLY;
|
||||
/* XXX: assumes alignment is a power of 2 */
|
||||
params.align = mem->requirements.alignment - 1;
|
||||
params.flags = GST_MEMORY_FLAG_NOT_MAPPABLE;
|
||||
_vk_image_mem_init (mem, allocator, parent, device, usage, ¶ms,
|
||||
mem->requirements.size, user_data, notify);
|
||||
mem->wrapped = TRUE;
|
||||
|
@ -412,47 +431,6 @@ gst_vulkan_image_memory_alloc (GstVulkanDevice * device, VkFormat format,
|
|||
return (GstMemory *) mem;
|
||||
}
|
||||
|
||||
GstMemory *
|
||||
gst_vulkan_image_memory_alloc_bind (GstVulkanDevice * device, VkFormat format,
|
||||
gsize width, gsize height, VkImageTiling tiling, VkImageUsageFlags usage,
|
||||
VkMemoryPropertyFlags mem_prop_flags)
|
||||
{
|
||||
GstAllocationParams params = { 0, };
|
||||
GstVulkanImageMemory *mem;
|
||||
GstVulkanMemory *dev_mem;
|
||||
guint32 type_idx;
|
||||
|
||||
mem =
|
||||
(GstVulkanImageMemory *) gst_vulkan_image_memory_alloc (device, format,
|
||||
width, height, tiling, usage, mem_prop_flags);
|
||||
if (!mem)
|
||||
return NULL;
|
||||
|
||||
if (!gst_vulkan_memory_find_memory_type_index_with_type_properties (device,
|
||||
mem->requirements.memoryTypeBits, mem_prop_flags, &type_idx)) {
|
||||
gst_memory_unref (GST_MEMORY_CAST (mem));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* XXX: assumes alignment is a power of 2 */
|
||||
params.align = mem->requirements.alignment - 1;
|
||||
dev_mem = (GstVulkanMemory *) gst_vulkan_memory_alloc (device, type_idx,
|
||||
¶ms, mem->requirements.size, mem_prop_flags);
|
||||
if (!dev_mem) {
|
||||
gst_memory_unref (GST_MEMORY_CAST (mem));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!gst_vulkan_image_memory_bind (mem, dev_mem)) {
|
||||
gst_memory_unref (GST_MEMORY_CAST (dev_mem));
|
||||
gst_memory_unref (GST_MEMORY_CAST (mem));
|
||||
return NULL;
|
||||
}
|
||||
gst_memory_unref (GST_MEMORY_CAST (dev_mem));
|
||||
|
||||
return (GstMemory *) mem;
|
||||
}
|
||||
|
||||
GstMemory *
|
||||
gst_vulkan_image_memory_wrapped (GstVulkanDevice * device, VkImage image,
|
||||
VkFormat format, gsize width, gsize height, VkImageTiling tiling,
|
||||
|
@ -484,44 +462,6 @@ gst_vulkan_image_memory_get_height (GstVulkanImageMemory * image)
|
|||
return image->create_info.extent.height;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_vulkan_image_memory_bind (GstVulkanImageMemory * img_mem,
|
||||
GstVulkanMemory * memory)
|
||||
{
|
||||
gsize maxsize;
|
||||
|
||||
g_return_val_if_fail (gst_is_vulkan_image_memory (GST_MEMORY_CAST (img_mem)),
|
||||
FALSE);
|
||||
g_return_val_if_fail (gst_is_vulkan_memory (GST_MEMORY_CAST (memory)), FALSE);
|
||||
|
||||
/* will we overrun the allocated data? */
|
||||
gst_memory_get_sizes (GST_MEMORY_CAST (memory), NULL, &maxsize);
|
||||
g_return_val_if_fail (memory->vk_offset + img_mem->requirements.size <=
|
||||
maxsize, FALSE);
|
||||
|
||||
g_mutex_lock (&img_mem->lock);
|
||||
|
||||
/* "Once a buffer or image is bound to a region of a memory object, it must
|
||||
* not be rebound or unbound." */
|
||||
if (img_mem->vk_mem == memory) {
|
||||
g_mutex_unlock (&img_mem->lock);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (img_mem->vk_mem) {
|
||||
g_mutex_unlock (&img_mem->lock);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
vkBindImageMemory (img_mem->device->device, img_mem->image, memory->mem_ptr,
|
||||
memory->vk_offset);
|
||||
img_mem->vk_mem =
|
||||
(GstVulkanMemory *) gst_memory_ref (GST_MEMORY_CAST (memory));
|
||||
g_mutex_unlock (&img_mem->lock);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
G_DEFINE_TYPE (GstVulkanImageMemoryAllocator, gst_vulkan_image_memory_allocator,
|
||||
GST_TYPE_ALLOCATOR);
|
||||
|
||||
|
|
|
@ -96,14 +96,6 @@ GstMemory * gst_vulkan_image_memory_alloc (GstVulkanDevice * devic
|
|||
VkImageUsageFlags usage,
|
||||
VkMemoryPropertyFlags mem_prop_flags);
|
||||
|
||||
GstMemory * gst_vulkan_image_memory_alloc_bind (GstVulkanDevice * device,
|
||||
VkFormat format,
|
||||
gsize width,
|
||||
gsize height,
|
||||
VkImageTiling tiling,
|
||||
VkImageUsageFlags usage,
|
||||
VkMemoryPropertyFlags mem_prop_flags);
|
||||
|
||||
GstMemory * gst_vulkan_image_memory_wrapped (GstVulkanDevice * device,
|
||||
VkImage image,
|
||||
VkFormat format,
|
||||
|
@ -114,9 +106,6 @@ GstMemory * gst_vulkan_image_memory_wrapped (GstVulkanDevice * devic
|
|||
gpointer user_data,
|
||||
GDestroyNotify notify);
|
||||
|
||||
gboolean gst_vulkan_image_memory_bind (GstVulkanImageMemory * img_mem,
|
||||
GstVulkanMemory * memory);
|
||||
|
||||
gboolean gst_vulkan_image_memory_set_layout (GstVulkanImageMemory * vk_mem,
|
||||
VkImageLayout,
|
||||
VkImageMemoryBarrier * barrier);
|
||||
|
|
Loading…
Reference in a new issue