mirror of
https://github.com/PabloMK7/citra
synced 2024-11-14 20:58:23 +00:00
Refactor Vulkan stream buffer memory type selection (#238)
* Refactor Vulkan stream buffer memory type selection This is a fix for GPUs with Vulkan V1.1 and V1.2 * add requested refactoring * clang format * fix typo
This commit is contained in:
parent
9c1f778e79
commit
2f0b2f9839
1 changed files with 27 additions and 5 deletions
|
@ -47,19 +47,41 @@ vk::MemoryPropertyFlags MakePropertyFlags(BufferType type) {
|
|||
/// Get the preferred host visible memory type.
|
||||
u32 GetMemoryType(const vk::PhysicalDeviceMemoryProperties& properties, BufferType type) {
|
||||
vk::MemoryPropertyFlags flags = MakePropertyFlags(type);
|
||||
std::optional preferred_type = FindMemoryType(properties, flags);
|
||||
std::optional<u32> preferred_type;
|
||||
|
||||
// Try to find a memory type with all the requested flags
|
||||
preferred_type = FindMemoryType(properties, flags);
|
||||
if (preferred_type) {
|
||||
return *preferred_type;
|
||||
}
|
||||
|
||||
// If not found, try removing flags one by one
|
||||
constexpr std::array remove_flags = {
|
||||
vk::MemoryPropertyFlagBits::eDeviceLocal,
|
||||
vk::MemoryPropertyFlagBits::eHostCached,
|
||||
vk::MemoryPropertyFlagBits::eHostCoherent,
|
||||
};
|
||||
|
||||
for (u32 i = 0; i < remove_flags.size() && !preferred_type; i++) {
|
||||
flags &= ~remove_flags[i];
|
||||
for (auto remove_flag : remove_flags) {
|
||||
if ((flags & remove_flag) == vk::MemoryPropertyFlags{}) {
|
||||
continue;
|
||||
}
|
||||
flags &= ~remove_flag;
|
||||
preferred_type = FindMemoryType(properties, flags);
|
||||
if (preferred_type) {
|
||||
return *preferred_type;
|
||||
}
|
||||
}
|
||||
ASSERT_MSG(preferred_type, "No suitable memory type found");
|
||||
return preferred_type.value();
|
||||
|
||||
// If still not found, try with only eHostVisible flag
|
||||
preferred_type = FindMemoryType(properties, vk::MemoryPropertyFlagBits::eHostVisible);
|
||||
if (preferred_type) {
|
||||
return *preferred_type;
|
||||
}
|
||||
|
||||
// If we reach here, we couldn't find any suitable memory type
|
||||
UNREACHABLE_MSG("Failed to find a suitable memory type for buffer type {}",
|
||||
BufferTypeName(type));
|
||||
}
|
||||
|
||||
constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000;
|
||||
|
|
Loading…
Reference in a new issue