From e4aff539b0508a4621d91ebd1bc5095ba4faf039 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 22 Sep 2021 21:47:53 +0300 Subject: [PATCH] vk: Fix scanning for upload heap types. - HOST_CACHED support must be prioritized, but is not a mandate. - Scan for that flag explicitly and fall back to uncached if it is not supported. - Uncached memory is too slow for our requirements to contend with cached memory. --- rpcs3/Emu/RSX/VK/vkutils/device.cpp | 45 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/vkutils/device.cpp b/rpcs3/Emu/RSX/VK/vkutils/device.cpp index 990a09c095..f716ea467b 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/device.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/device.cpp @@ -738,9 +738,23 @@ namespace vk return results; }; - auto device_local_types = find_memory_type_with_property(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, (VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD)); - auto host_coherent_types = find_memory_type_with_property((VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), 0); - auto bar_memory_types = find_memory_type_with_property((VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), 0); + auto device_local_types = find_memory_type_with_property( + VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, + (VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD | VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD)); + auto host_coherent_types = find_memory_type_with_property( + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT), + 0); + auto bar_memory_types = find_memory_type_with_property( + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), + 0); + + if (host_coherent_types.empty()) + { + rsx_log.warning("[Performance Warning] Could not identify a cached upload heap. Will fall back to uncached transport."); + host_coherent_types = find_memory_type_with_property( + (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), + 0); + } ensure(!device_local_types.empty()); ensure(!host_coherent_types.empty()); @@ -774,22 +788,19 @@ namespace vk result.device_local_total_bytes += type.size; } - // Some prioritization is needed for host-visible memory. We only need to pick only one block unlike the others. - // Use host-cached memory if available, but this is not really required. - bool is_host_cached = false; + // Sort upload heap entries based on size. + if (host_coherent_types.size() > 1) + { + std::sort(host_coherent_types.begin(), host_coherent_types.end(), [](const auto& a, const auto& b) + { + return a.size > b.size; + }); + } + for (auto& type : host_coherent_types) { - if (!is_host_cached && type.flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) - { - is_host_cached = true; - result.host_visible_coherent = { type.type_index, type.size }; - result.host_visible_total_bytes = type.size; - } - else if (result.host_visible_total_bytes < type.size) - { - result.host_visible_coherent = { type.type_index, type.size }; - result.host_visible_total_bytes = type.size; - } + result.host_visible_coherent.push(type.type_index, type.size); + result.host_visible_total_bytes += type.size; } rsx_log.notice("Detected %llu MB of device local memory", result.device_local_total_bytes / (0x100000));