Commit 0cb416db authored by Matthew Waters's avatar Matthew Waters 🐨

vkbuffermemory: report requested size of the memory

Rather than using Vulkan's much larger aligned sizes. Fixes multi-planer
video with the GstVideoFrame API.
parent 2180fbb4
......@@ -730,6 +730,15 @@ _raw_to_image_set_caps (gpointer impl, GstCaps * in_caps, GstCaps * out_caps)
if (!gst_video_info_from_caps (&raw->out_info, out_caps))
return FALSE;
if (raw->in_pool) {
if (raw->in_pool_active) {
gst_buffer_pool_set_active (raw->in_pool, FALSE);
}
raw->in_pool_active = FALSE;
gst_object_unref (raw->in_pool);
raw->in_pool = NULL;
}
return TRUE;
}
......@@ -906,7 +915,7 @@ _raw_to_image_perform (gpointer impl, GstBuffer * inbuf, GstBuffer ** outbuf)
.dstQueueFamilyIndex = 0,
.buffer = buf_mem->buffer,
.offset = region.bufferOffset,
.size = region.bufferRowLength * region.bufferImageHeight
.size = region.bufferRowLength * region.bufferImageHeight,
};
image_memory_barrier = (VkImageMemoryBarrier) {
......@@ -920,7 +929,7 @@ _raw_to_image_perform (gpointer impl, GstBuffer * inbuf, GstBuffer ** outbuf)
.srcQueueFamilyIndex = 0,
.dstQueueFamilyIndex = 0,
.image = img_mem->image,
.subresourceRange = img_mem->barrier.subresource_range
.subresourceRange = img_mem->barrier.subresource_range,
};
/* *INDENT-ON* */
......
......@@ -150,8 +150,8 @@ _vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
}
params.align = mem->requirements.alignment - 1;
_vk_buffer_mem_init (mem, allocator, parent, device, usage, &params,
mem->requirements.size, user_data, notify);
_vk_buffer_mem_init (mem, allocator, parent, device, usage, &params, size,
user_data, notify);
mem->buffer = buffer;
if (!gst_vulkan_memory_find_memory_type_index_with_type_properties (device,
......
......@@ -97,28 +97,10 @@ gst_vulkan_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
/* 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++) {
GstVideoFormat v_format = GST_VIDEO_INFO_FORMAT (&priv->v_info);
GstVulkanImageMemory *img_mem;
guint width, height;
VkFormat vk_format;
vk_format = gst_vulkan_format_from_video_format (v_format, i);
width = GST_VIDEO_INFO_PLANE_STRIDE (&priv->v_info, i);
height = GST_VIDEO_INFO_COMP_HEIGHT (&priv->v_info, i);
img_mem = (GstVulkanImageMemory *)
gst_vulkan_image_memory_alloc (vk_pool->device, vk_format, width,
height, VK_IMAGE_TILING_OPTIMAL,
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,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
priv->alloc_sizes[i] = img_mem->requirements.size;
priv->alloc_sizes[i] = GST_VIDEO_INFO_COMP_HEIGHT (&priv->v_info, i) *
GST_VIDEO_INFO_PLANE_STRIDE (&priv->v_info, i);
priv->v_info.offset[i] = priv->v_info.size;
priv->v_info.size += priv->alloc_sizes[i];
gst_memory_unref (GST_MEMORY_CAST (img_mem));
}
priv->add_videometa = gst_buffer_pool_config_has_option (config,
......@@ -173,7 +155,7 @@ gst_vulkan_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
vk_format, priv->alloc_sizes[i],
/* FIXME: choose from outside */
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
/* FIXME: choosefrom outside */
/* FIXME: choose from outside */
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
if (!mem) {
gst_buffer_unref (buf);
......@@ -183,6 +165,13 @@ gst_vulkan_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
gst_buffer_append_memory (buf, mem);
}
gst_buffer_add_video_meta_full (buf, 0,
GST_VIDEO_INFO_FORMAT (&priv->v_info),
GST_VIDEO_INFO_WIDTH (&priv->v_info),
GST_VIDEO_INFO_HEIGHT (&priv->v_info),
GST_VIDEO_INFO_N_PLANES (&priv->v_info), priv->v_info.offset,
priv->v_info.stride);
*buffer = buf;
return GST_FLOW_OK;
......
......@@ -113,8 +113,7 @@ GST_START_TEST (test_vulkan_color_convert_rgba_reorder)
outbuf = gst_harness_push_and_pull (h, inbuf);
fail_unless (gst_buffer_map (outbuf, &map_info, GST_MAP_READ));
/* FIXME: wrong size! */
fail_unless (map_info.size >= out_info.size);
fail_unless (map_info.size == out_info.size);
for (k = 0; k < out_info.size; k++) {
if (test_rgba_reorder[j].data[0][k] != IGNORE_MAGIC
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment