mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 14:08:56 +00:00
vulkan: find memory type index with requirements
The specification says: VUID-vkAllocateMemory-pAllocateInfo-01713 must pAllocateInfo->allocationSize be less than or equal to VkPhysicalDeviceMemoryProperties::memoryHeaps[memindex].size where memindex = VkPhysicalDeviceMemoryProperties::memoryTypes[pAllocateInfo->memoryTypeIndex].heapIndex as returned by vkGetPhysicalDeviceMemoryProperties for the VkPhysicalDevice that device was created from. Though this can be catch by the validation layer, the requested frame size depends on the use case so it's better to check this restriction by our code. This patch also makes use of this new function to find memory type index, and removes the unused function to find memory type index, which, as GstVulkan is considered unstable, we can do it. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4351>
This commit is contained in:
parent
4dd0fd6797
commit
83e73a2f59
4 changed files with 28 additions and 22 deletions
|
@ -126,8 +126,8 @@ _vk_buffer_mem_new_alloc_with_buffer_info (GstAllocator * allocator,
|
|||
¶ms, buffer_info->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))
|
||||
if (!gst_vulkan_memory_find_memory_type_index_with_requirements (device,
|
||||
&mem->requirements, mem_prop_flags, &type_idx))
|
||||
goto error;
|
||||
|
||||
mem->vk_mem = (GstVulkanMemory *) gst_vulkan_memory_alloc (device, type_idx,
|
||||
|
|
|
@ -169,8 +169,8 @@ _vk_image_mem_new_alloc_with_image_info (GstAllocator * allocator,
|
|||
"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))
|
||||
if (!gst_vulkan_memory_find_memory_type_index_with_requirements (device,
|
||||
&mem->requirements, mem_prop_flags, &type_idx))
|
||||
goto error;
|
||||
|
||||
if ((mem->requirements.alignment & (mem->requirements.alignment - 1)) != 0) {
|
||||
|
|
|
@ -236,34 +236,39 @@ _vk_mem_free (GstAllocator * allocator, GstMemory * memory)
|
|||
}
|
||||
|
||||
/**
|
||||
* gst_vulkan_memory_find_memory_type_index_with_type_properties:
|
||||
* gst_vulkan_memory_find_memory_type_index_with_requirements:
|
||||
* @device: a #GstVulkanDevice
|
||||
* @type_bits: memory type bits to search for
|
||||
* @req: memory requirements to look for
|
||||
* @properties: memory properties to search for
|
||||
* @type_index: resulting index of the memory type
|
||||
* @type_index: (out): resulting index of the memory type
|
||||
*
|
||||
* Returns: whether a valid memory type could be found
|
||||
*
|
||||
* Since: 1.18
|
||||
* Since: 1.24
|
||||
*/
|
||||
gboolean
|
||||
gst_vulkan_memory_find_memory_type_index_with_type_properties (GstVulkanDevice *
|
||||
device, guint32 type_bits, VkMemoryPropertyFlags properties,
|
||||
gst_vulkan_memory_find_memory_type_index_with_requirements (GstVulkanDevice *
|
||||
device, VkMemoryRequirements * req, VkMemoryPropertyFlags properties,
|
||||
guint32 * type_index)
|
||||
{
|
||||
guint32 i;
|
||||
VkPhysicalDeviceMemoryProperties *props;
|
||||
|
||||
g_return_val_if_fail (GST_IS_VULKAN_DEVICE (device), FALSE);
|
||||
|
||||
props = &device->physical_device->memory_properties;
|
||||
|
||||
/* Search memtypes to find first index with those properties */
|
||||
for (i = 0; i < 32; i++) {
|
||||
if ((type_bits & 1) == 1) {
|
||||
/* Type is available, does it match user properties? */
|
||||
if ((device->physical_device->memory_properties.memoryTypes[i].
|
||||
propertyFlags & properties) == properties) {
|
||||
*type_index = i;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
type_bits >>= 1;
|
||||
for (i = 0; i < props->memoryTypeCount; i++) {
|
||||
if (!(req->memoryTypeBits & (1 << i)))
|
||||
continue;
|
||||
if ((props->memoryTypes[i].propertyFlags & properties) != properties)
|
||||
continue;
|
||||
if (req->size > props->memoryHeaps[props->memoryTypes[i].heapIndex].size)
|
||||
continue;
|
||||
|
||||
*type_index = i;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
|
|
@ -138,11 +138,12 @@ GstMemory * gst_vulkan_memory_alloc (GstVulkanDevice * device,
|
|||
VkMemoryPropertyFlags mem_prop_flags);
|
||||
|
||||
GST_VULKAN_API
|
||||
gboolean gst_vulkan_memory_find_memory_type_index_with_type_properties (GstVulkanDevice * device,
|
||||
guint32 type_bits,
|
||||
gboolean gst_vulkan_memory_find_memory_type_index_with_requirements (GstVulkanDevice * device,
|
||||
VkMemoryRequirements * req,
|
||||
VkMemoryPropertyFlags properties,
|
||||
guint32 * type_index);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* _GST_VULKAN_BASE_BUFFER_H_ */
|
||||
|
|
Loading…
Reference in a new issue