From 268dfcaad98fb40e5d94b0c7717acd0b59816d55 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Mon, 8 Apr 2019 18:42:12 +1000 Subject: [PATCH] vk*memory: explicitly error out for driver NPOT alignment --- ext/vulkan/vkbuffermemory.c | 7 ++++++- ext/vulkan/vkerror.h | 6 ++++++ ext/vulkan/vkimagememory.c | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ext/vulkan/vkbuffermemory.c b/ext/vulkan/vkbuffermemory.c index fafd73102a..f06af82a0e 100644 --- a/ext/vulkan/vkbuffermemory.c +++ b/ext/vulkan/vkbuffermemory.c @@ -133,7 +133,12 @@ _vk_buffer_mem_new_alloc (GstAllocator * allocator, GstMemory * parent, mem = g_new0 (GstVulkanBufferMemory, 1); vkGetBufferMemoryRequirements (device->device, buffer, &mem->requirements); - /* XXX: assumes alignment is a power of 2 */ + if ((mem->requirements.alignment & (mem->requirements.alignment - 1)) != 0) { + g_set_error_literal (&error, GST_VULKAN_ERROR, GST_VULKAN_FAILED, + "Vulkan implementation requires unsupported non-power-of 2 memory alignment"); + goto error; + } + params.align = mem->requirements.alignment - 1; _vk_buffer_mem_init (mem, allocator, parent, device, usage, ¶ms, mem->requirements.size, user_data, notify); diff --git a/ext/vulkan/vkerror.h b/ext/vulkan/vkerror.h index 788e66da46..de99c718a6 100644 --- a/ext/vulkan/vkerror.h +++ b/ext/vulkan/vkerror.h @@ -29,6 +29,12 @@ G_BEGIN_DECLS #define GST_VULKAN_ERROR (gst_vulkan_error_quark ()) GQuark gst_vulkan_error_quark (void); +/* custom error values */ +typedef enum +{ + GST_VULKAN_FAILED = 0, +} GstVulkanError; + /* only fills error iff error != NULL and result < 0 */ VkResult gst_vulkan_error_to_g_error (VkResult result, GError ** error, const char * format, ...) G_GNUC_PRINTF (3, 4); diff --git a/ext/vulkan/vkimagememory.c b/ext/vulkan/vkimagememory.c index e004c9662f..1bf56b7854 100644 --- a/ext/vulkan/vkimagememory.c +++ b/ext/vulkan/vkimagememory.c @@ -222,7 +222,11 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent, mem->requirements.memoryTypeBits, mem_prop_flags, &type_idx)) goto error; - /* XXX: assumes alignment is a power of 2 */ + if ((mem->requirements.alignment & (mem->requirements.alignment - 1)) != 0) { + g_set_error_literal (&error, GST_VULKAN_ERROR, GST_VULKAN_FAILED, + "Vulkan implementation requires unsupported non-power-of 2 memory alignment"); + goto error; + } params.align = mem->requirements.alignment - 1; mem->vk_mem = (GstVulkanMemory *) gst_vulkan_memory_alloc (device, type_idx, ¶ms, mem->requirements.size, mem_prop_flags);