From 8a4352c1e532c4e9b11edd7753306ec412525803 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Fri, 29 Jul 2022 20:39:39 -0700 Subject: [PATCH] graphics-hook: Relax Vulkan allocation strategy Stop requiring DEVICE_LOCAL. May be needed for integrated GPUs. --- .../graphics-hook/vulkan-capture.c | 62 ++++++++++++------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/plugins/win-capture/graphics-hook/vulkan-capture.c b/plugins/win-capture/graphics-hook/vulkan-capture.c index 6910d0a50..e413287a4 100644 --- a/plugins/win-capture/graphics-hook/vulkan-capture.c +++ b/plugins/win-capture/graphics-hook/vulkan-capture.c @@ -753,24 +753,6 @@ static inline bool vk_shtex_init_vulkan_tex(struct vk_data *data, VkPhysicalDeviceMemoryProperties pdmp; ifuncs->GetPhysicalDeviceMemoryProperties(data->phy_device, &pdmp); - uint32_t mem_type_idx = 0; - - for (; mem_type_idx < pdmp.memoryTypeCount; mem_type_idx++) { - if ((mr.memoryTypeBits & (1 << mem_type_idx)) && - (pdmp.memoryTypes[mem_type_idx].propertyFlags & - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { - break; - } - } - - if (mem_type_idx == pdmp.memoryTypeCount) { - flog("failed to get memory type index"); - funcs->DestroyImage(device, swap->export_image, data->ac); - swap->export_image = VK_NULL_HANDLE; - return false; - } - /* -------------------------------------------------------- */ /* allocate memory */ @@ -786,7 +768,6 @@ static inline bool vk_shtex_init_vulkan_tex(struct vk_data *data, mai.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; mai.pNext = &imw32hi; mai.allocationSize = mr.size; - mai.memoryTypeIndex = mem_type_idx; VkMemoryDedicatedAllocateInfo mdai; mdai.sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO; @@ -799,9 +780,46 @@ static inline bool vk_shtex_init_vulkan_tex(struct vk_data *data, imw32hi.pNext = &mdai; } - res = funcs->AllocateMemory(device, &mai, NULL, &swap->export_mem); - if (VK_SUCCESS != res) { - flog("failed to AllocateMemory: %s", result_to_str(res)); + bool allocated = false; + for (uint32_t i = 0; i < pdmp.memoryTypeCount; ++i) { + if ((mr.memoryTypeBits & (1 << i)) && + (pdmp.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) == + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { + mai.memoryTypeIndex = i; + res = funcs->AllocateMemory(device, &mai, NULL, + &swap->export_mem); + allocated = res == VK_SUCCESS; + if (allocated) + break; + + flog("failed to AllocateMemory (DEVICE_LOCAL): %s (%d)", + result_to_str(res), (int)res); + } + } + + if (!allocated) { + /* Try again without DEVICE_LOCAL */ + for (uint32_t i = 0; i < pdmp.memoryTypeCount; ++i) { + if ((mr.memoryTypeBits & (1 << i)) && + (pdmp.memoryTypes[i].propertyFlags & + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) { + mai.memoryTypeIndex = i; + res = funcs->AllocateMemory(device, &mai, NULL, + &swap->export_mem); + allocated = res == VK_SUCCESS; + if (allocated) + break; + + flog("failed to AllocateMemory (not DEVICE_LOCAL): %s (%d)", + result_to_str(res), (int)res); + } + } + } + + if (!allocated) { + flog("failed to allocate memory of any type"); funcs->DestroyImage(device, swap->export_image, data->ac); swap->export_image = VK_NULL_HANDLE; return false;