mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-20 00:31:13 +00:00
Revert "vulkan: remove views from the memory objects."
This reverts commit 1ea817298ee4d5ef9b00f888f8ebe16a888b1150.
This commit is contained in:
parent
3c2710dc0f
commit
1c2aae08c5
4 changed files with 114 additions and 0 deletions
|
@ -56,6 +56,26 @@ _create_info_from_args (VkBufferCreateInfo * info, gsize size,
|
|||
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
|
||||
_vk_buffer_mem_init (GstVulkanBufferMemory * mem, GstAllocator * allocator,
|
||||
GstMemory * parent, GstVulkanDevice * device, VkBufferUsageFlags usage,
|
||||
|
@ -131,6 +151,22 @@ _vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
|||
if (gst_vulkan_error_to_g_error (err, &error, "vkBindBufferMemory") < 0)
|
||||
goto vk_error;
|
||||
|
||||
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;
|
||||
|
||||
vk_error:
|
||||
|
@ -156,6 +192,8 @@ _vk_buffer_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
|||
{
|
||||
GstVulkanBufferMemory *mem = g_new0 (GstVulkanBufferMemory, 1);
|
||||
GstAllocationParams params = { 0, };
|
||||
GError *error = NULL;
|
||||
VkResult err;
|
||||
|
||||
mem->buffer = buffer;
|
||||
|
||||
|
@ -168,7 +206,39 @@ _vk_buffer_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
|||
mem->requirements.size, user_data, notify);
|
||||
mem->wrapped = TRUE;
|
||||
|
||||
/* XXX: we don't actually if the buffer has a vkDeviceMemory bound so
|
||||
* this may fail */
|
||||
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;
|
||||
|
||||
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
|
||||
|
@ -246,6 +316,9 @@ _vk_buffer_mem_free (GstAllocator * allocator, GstMemory * memory)
|
|||
if (mem->buffer && !mem->wrapped)
|
||||
vkDestroyBuffer (mem->device->device, mem->buffer, NULL);
|
||||
|
||||
if (mem->view)
|
||||
vkDestroyBufferView (mem->device->device, mem->view, NULL);
|
||||
|
||||
if (mem->vk_mem)
|
||||
gst_memory_unref ((GstMemory *) mem->vk_mem);
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ struct _GstVulkanBufferMemory
|
|||
GstVulkanDevice * device;
|
||||
|
||||
VkBuffer buffer;
|
||||
VkBufferView view;
|
||||
GstVulkanMemory *vk_mem;
|
||||
|
||||
VkMemoryRequirements requirements;
|
||||
|
|
|
@ -101,6 +101,22 @@ 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
|
||||
_create_info_from_args (VkImageCreateInfo * info, VkFormat format, gsize width,
|
||||
gsize height, VkImageTiling tiling, VkImageUsageFlags usage)
|
||||
|
@ -167,6 +183,7 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
|||
{
|
||||
GstVulkanImageMemory *mem = NULL;
|
||||
GstAllocationParams params = { 0, };
|
||||
VkImageViewCreateInfo view_info;
|
||||
VkImageCreateInfo image_info;
|
||||
VkPhysicalDevice gpu;
|
||||
GError *error = NULL;
|
||||
|
@ -213,6 +230,14 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
|
|||
if (gst_vulkan_error_to_g_error (err, &error, "vkBindImageMemory") < 0)
|
||||
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;
|
||||
|
||||
vk_error:
|
||||
|
@ -239,6 +264,7 @@ _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
|||
{
|
||||
GstVulkanImageMemory *mem = g_new0 (GstVulkanImageMemory, 1);
|
||||
GstAllocationParams params = { 0, };
|
||||
VkImageViewCreateInfo view_info;
|
||||
VkPhysicalDevice gpu;
|
||||
GError *error = NULL;
|
||||
VkResult err;
|
||||
|
@ -267,6 +293,16 @@ _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
|
|||
"vkGetPhysicalDeviceImageFormatProperties") < 0)
|
||||
goto vk_error;
|
||||
|
||||
/* XXX: we don't actually if the image has a vkDeviceMemory bound so
|
||||
* this may fail */
|
||||
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;
|
||||
|
||||
vk_error:
|
||||
|
@ -359,6 +395,9 @@ _vk_image_mem_free (GstAllocator * allocator, GstMemory * memory)
|
|||
if (mem->image && !mem->wrapped)
|
||||
vkDestroyImage (mem->device->device, mem->image, NULL);
|
||||
|
||||
if (mem->view)
|
||||
vkDestroyImageView (mem->device->device, mem->view, NULL);
|
||||
|
||||
if (mem->vk_mem)
|
||||
gst_memory_unref ((GstMemory *) mem->vk_mem);
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ struct _GstVulkanImageMemory
|
|||
|
||||
VkImage image;
|
||||
VkImageLayout image_layout;
|
||||
VkImageView view;
|
||||
GstVulkanMemory *vk_mem;
|
||||
|
||||
VkImageCreateInfo create_info;
|
||||
|
|
Loading…
Reference in a new issue