mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 20:21:24 +00:00
vulkan: remove views from the memory objects.
They are not used and it's not possible to create the view before binding the VkDeviceMemory object to them.
This commit is contained in:
parent
0309c9fbc7
commit
4c0a169af9
4 changed files with 18 additions and 122 deletions
|
@ -56,26 +56,6 @@ _create_info_from_args (VkBufferCreateInfo * info, gsize size,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GST_VK_BUFFER_VIEW_CREATE_INFO_INIT GST_VK_STRUCT_7
|
|
||||||
#define GST_VK_BUFFER_VIEW_CREATE_INFO(info, pNext, flags, buffer, format, offset, range) \
|
|
||||||
G_STMT_START { \
|
|
||||||
VkBufferViewCreateInfo tmp = GST_VK_BUFFER_VIEW_CREATE_INFO_INIT (VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO, pNext, flags, buffer, format, offset, range); \
|
|
||||||
(info) = tmp; \
|
|
||||||
} G_STMT_END
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
_create_view_from_args (VkBufferViewCreateInfo * info, VkBuffer buffer,
|
|
||||||
VkFormat format, gsize offset, gsize range)
|
|
||||||
{
|
|
||||||
/* FIXME: validate these */
|
|
||||||
g_assert (format != VK_FORMAT_UNDEFINED);
|
|
||||||
|
|
||||||
GST_VK_BUFFER_VIEW_CREATE_INFO (*info, NULL, 0, buffer, format, offset,
|
|
||||||
range);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_vk_buffer_mem_init (GstVulkanBufferMemory * mem, GstAllocator * allocator,
|
_vk_buffer_mem_init (GstVulkanBufferMemory * mem, GstAllocator * allocator,
|
||||||
GstMemory * parent, GstVulkanDevice * device, VkBufferUsageFlags usage,
|
GstMemory * parent, GstVulkanDevice * device, VkBufferUsageFlags usage,
|
||||||
|
@ -136,22 +116,6 @@ _vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
||||||
mem->requirements.size, user_data, notify);
|
mem->requirements.size, user_data, notify);
|
||||||
mem->buffer = buffer;
|
mem->buffer = buffer;
|
||||||
|
|
||||||
if (usage & (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT)) {
|
|
||||||
VkBufferViewCreateInfo view_info;
|
|
||||||
|
|
||||||
_create_view_from_args (&view_info, mem->buffer, format, 0,
|
|
||||||
mem->requirements.size);
|
|
||||||
err = vkCreateBufferView (device->device, &view_info, NULL, &mem->view);
|
|
||||||
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateBufferView") < 0)
|
|
||||||
goto vk_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
|
|
||||||
vk_error:
|
vk_error:
|
||||||
|
@ -177,8 +141,6 @@ _vk_buffer_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
||||||
{
|
{
|
||||||
GstVulkanBufferMemory *mem = g_new0 (GstVulkanBufferMemory, 1);
|
GstVulkanBufferMemory *mem = g_new0 (GstVulkanBufferMemory, 1);
|
||||||
GstAllocationParams params = { 0, };
|
GstAllocationParams params = { 0, };
|
||||||
GError *error = NULL;
|
|
||||||
VkResult err;
|
|
||||||
|
|
||||||
mem->buffer = buffer;
|
mem->buffer = buffer;
|
||||||
|
|
||||||
|
@ -191,37 +153,7 @@ _vk_buffer_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
||||||
mem->requirements.size, user_data, notify);
|
mem->requirements.size, user_data, notify);
|
||||||
mem->wrapped = TRUE;
|
mem->wrapped = TRUE;
|
||||||
|
|
||||||
if (usage & (VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_INDEX_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT |
|
|
||||||
VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT)) {
|
|
||||||
VkBufferViewCreateInfo view_info;
|
|
||||||
|
|
||||||
_create_view_from_args (&view_info, mem->buffer, format, 0,
|
|
||||||
mem->requirements.size);
|
|
||||||
err = vkCreateBufferView (device->device, &view_info, NULL, &mem->view);
|
|
||||||
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateBufferView") < 0)
|
|
||||||
goto vk_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
|
|
||||||
vk_error:
|
|
||||||
{
|
|
||||||
GST_CAT_ERROR (GST_CAT_VULKAN_BUFFER_MEMORY,
|
|
||||||
"Failed to allocate buffer memory %s", error->message);
|
|
||||||
g_clear_error (&error);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
error:
|
|
||||||
{
|
|
||||||
gst_memory_unref ((GstMemory *) mem);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gpointer
|
static gpointer
|
||||||
|
@ -299,9 +231,6 @@ _vk_buffer_mem_free (GstAllocator * allocator, GstMemory * memory)
|
||||||
if (mem->buffer && !mem->wrapped)
|
if (mem->buffer && !mem->wrapped)
|
||||||
vkDestroyBuffer (mem->device->device, mem->buffer, NULL);
|
vkDestroyBuffer (mem->device->device, mem->buffer, NULL);
|
||||||
|
|
||||||
if (mem->view)
|
|
||||||
vkDestroyBufferView (mem->device->device, mem->view, NULL);
|
|
||||||
|
|
||||||
if (mem->vk_mem)
|
if (mem->vk_mem)
|
||||||
gst_memory_unref ((GstMemory *) mem->vk_mem);
|
gst_memory_unref ((GstMemory *) mem->vk_mem);
|
||||||
|
|
||||||
|
@ -405,13 +334,16 @@ gst_vulkan_buffer_memory_bind (GstVulkanBufferMemory * buf_mem,
|
||||||
|
|
||||||
g_mutex_lock (&buf_mem->lock);
|
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) {
|
if (buf_mem->vk_mem) {
|
||||||
guint vk_mem_map_count = buf_mem->vk_mem->map_count;
|
g_mutex_unlock (&buf_mem->lock);
|
||||||
if (vk_mem_map_count > 0) {
|
return FALSE;
|
||||||
g_mutex_unlock (&buf_mem->lock);
|
|
||||||
g_return_val_if_fail (vk_mem_map_count > 0, FALSE);
|
|
||||||
}
|
|
||||||
gst_memory_unref (GST_MEMORY_CAST (buf_mem->vk_mem));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vkBindBufferMemory (buf_mem->device->device, buf_mem->buffer, memory->mem_ptr,
|
vkBindBufferMemory (buf_mem->device->device, buf_mem->buffer, memory->mem_ptr,
|
||||||
|
|
|
@ -49,7 +49,6 @@ struct _GstVulkanBufferMemory
|
||||||
GstVulkanDevice * device;
|
GstVulkanDevice * device;
|
||||||
|
|
||||||
VkBuffer buffer;
|
VkBuffer buffer;
|
||||||
VkBufferView view;
|
|
||||||
GstVulkanMemory *vk_mem;
|
GstVulkanMemory *vk_mem;
|
||||||
|
|
||||||
VkMemoryRequirements requirements;
|
VkMemoryRequirements requirements;
|
||||||
|
|
|
@ -101,22 +101,6 @@ gst_vulkan_format_from_video_format (GstVideoFormat v_format, guint plane)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
_view_create_info (VkImage image, VkFormat format, VkImageViewCreateInfo * info)
|
|
||||||
{
|
|
||||||
info->sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
|
||||||
info->pNext = NULL;
|
|
||||||
info->image = image;
|
|
||||||
info->format = format;
|
|
||||||
info->viewType = VK_IMAGE_VIEW_TYPE_2D;
|
|
||||||
info->flags = 0;
|
|
||||||
|
|
||||||
GST_VK_COMPONENT_MAPPING (info->components, VK_COMPONENT_SWIZZLE_R,
|
|
||||||
VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A);
|
|
||||||
GST_VK_IMAGE_SUBRESOURCE_RANGE (info->subresourceRange,
|
|
||||||
VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_create_info_from_args (VkImageCreateInfo * info, VkFormat format, gsize width,
|
_create_info_from_args (VkImageCreateInfo * info, VkFormat format, gsize width,
|
||||||
gsize height, VkImageTiling tiling, VkImageUsageFlags usage)
|
gsize height, VkImageTiling tiling, VkImageUsageFlags usage)
|
||||||
|
@ -183,7 +167,6 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
||||||
{
|
{
|
||||||
GstVulkanImageMemory *mem = NULL;
|
GstVulkanImageMemory *mem = NULL;
|
||||||
GstAllocationParams params = { 0, };
|
GstAllocationParams params = { 0, };
|
||||||
VkImageViewCreateInfo view_info;
|
|
||||||
VkImageCreateInfo image_info;
|
VkImageCreateInfo image_info;
|
||||||
VkPhysicalDevice gpu;
|
VkPhysicalDevice gpu;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
@ -213,14 +196,6 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
||||||
vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D,
|
vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D,
|
||||||
tiling, usage, 0, &mem->format_properties);
|
tiling, usage, 0, &mem->format_properties);
|
||||||
|
|
||||||
if (usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
|
|
||||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) {
|
|
||||||
_view_create_info (mem->image, format, &view_info);
|
|
||||||
err = vkCreateImageView (device->device, &view_info, NULL, &mem->view);
|
|
||||||
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateImageView") < 0)
|
|
||||||
goto vk_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
|
|
||||||
vk_error:
|
vk_error:
|
||||||
|
@ -247,7 +222,6 @@ _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
||||||
{
|
{
|
||||||
GstVulkanImageMemory *mem = g_new0 (GstVulkanImageMemory, 1);
|
GstVulkanImageMemory *mem = g_new0 (GstVulkanImageMemory, 1);
|
||||||
GstAllocationParams params = { 0, };
|
GstAllocationParams params = { 0, };
|
||||||
VkImageViewCreateInfo view_info;
|
|
||||||
VkPhysicalDevice gpu;
|
VkPhysicalDevice gpu;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
VkResult err;
|
VkResult err;
|
||||||
|
@ -274,14 +248,6 @@ _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
||||||
"vkGetPhysicalDeviceImageFormatProperties") < 0)
|
"vkGetPhysicalDeviceImageFormatProperties") < 0)
|
||||||
goto vk_error;
|
goto vk_error;
|
||||||
|
|
||||||
if (usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
|
|
||||||
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) {
|
|
||||||
_view_create_info (mem->image, format, &view_info);
|
|
||||||
err = vkCreateImageView (device->device, &view_info, NULL, &mem->view);
|
|
||||||
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateImageView") < 0)
|
|
||||||
goto vk_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
|
|
||||||
vk_error:
|
vk_error:
|
||||||
|
@ -374,9 +340,6 @@ _vk_image_mem_free (GstAllocator * allocator, GstMemory * memory)
|
||||||
if (mem->image && !mem->wrapped)
|
if (mem->image && !mem->wrapped)
|
||||||
vkDestroyImage (mem->device->device, mem->image, NULL);
|
vkDestroyImage (mem->device->device, mem->image, NULL);
|
||||||
|
|
||||||
if (mem->view)
|
|
||||||
vkDestroyImageView (mem->device->device, mem->view, NULL);
|
|
||||||
|
|
||||||
if (mem->vk_mem)
|
if (mem->vk_mem)
|
||||||
gst_memory_unref ((GstMemory *) mem->vk_mem);
|
gst_memory_unref ((GstMemory *) mem->vk_mem);
|
||||||
|
|
||||||
|
@ -538,13 +501,16 @@ gst_vulkan_image_memory_bind (GstVulkanImageMemory * img_mem,
|
||||||
|
|
||||||
g_mutex_lock (&img_mem->lock);
|
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) {
|
if (img_mem->vk_mem) {
|
||||||
guint vk_mem_map_count = img_mem->vk_mem->map_count;
|
g_mutex_unlock (&img_mem->lock);
|
||||||
if (vk_mem_map_count > 0) {
|
return FALSE;
|
||||||
g_mutex_unlock (&img_mem->lock);
|
|
||||||
g_return_val_if_fail (vk_mem_map_count > 0, FALSE);
|
|
||||||
}
|
|
||||||
gst_memory_unref (GST_MEMORY_CAST (img_mem->vk_mem));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vkBindImageMemory (img_mem->device->device, img_mem->image, memory->mem_ptr,
|
vkBindImageMemory (img_mem->device->device, img_mem->image, memory->mem_ptr,
|
||||||
|
|
|
@ -52,7 +52,6 @@ struct _GstVulkanImageMemory
|
||||||
|
|
||||||
VkImage image;
|
VkImage image;
|
||||||
VkImageLayout image_layout;
|
VkImageLayout image_layout;
|
||||||
VkImageView view;
|
|
||||||
GstVulkanMemory *vk_mem;
|
GstVulkanMemory *vk_mem;
|
||||||
|
|
||||||
VkImageCreateInfo create_info;
|
VkImageCreateInfo create_info;
|
||||||
|
|
Loading…
Reference in a new issue