mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-30 05:24:13 +01:00
Refactor Vulkan stream buffer memory type selection (#384)
This fixes an issue where devices using Vulkan <=1.2 would crash instantly
This commit is contained in:
parent
a319b81665
commit
9298e1d237
@ -1,7 +1,10 @@
|
|||||||
// Copyright 2019 yuzu Emulator Project
|
// Copyright Citra Emulator Project / Lime3DS Emulator Project
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
// Copyright 2019 Yuzu Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
@ -47,19 +50,42 @@ vk::MemoryPropertyFlags MakePropertyFlags(BufferType type) {
|
|||||||
/// Get the preferred host visible memory type.
|
/// Get the preferred host visible memory type.
|
||||||
u32 GetMemoryType(const vk::PhysicalDeviceMemoryProperties& properties, BufferType type) {
|
u32 GetMemoryType(const vk::PhysicalDeviceMemoryProperties& properties, BufferType type) {
|
||||||
vk::MemoryPropertyFlags flags = MakePropertyFlags(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 = {
|
constexpr std::array remove_flags = {
|
||||||
|
vk::MemoryPropertyFlagBits::eDeviceLocal,
|
||||||
vk::MemoryPropertyFlagBits::eHostCached,
|
vk::MemoryPropertyFlagBits::eHostCached,
|
||||||
vk::MemoryPropertyFlagBits::eHostCoherent,
|
vk::MemoryPropertyFlagBits::eHostCoherent,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (u32 i = 0; i < remove_flags.size() && !preferred_type; i++) {
|
for (auto remove_flag : remove_flags) {
|
||||||
flags &= ~remove_flags[i];
|
if ((flags & remove_flag) == vk::MemoryPropertyFlags{}) {
|
||||||
preferred_type = FindMemoryType(properties, flags);
|
continue;
|
||||||
}
|
}
|
||||||
ASSERT_MSG(preferred_type, "No suitable memory type found");
|
flags &= ~remove_flag;
|
||||||
return preferred_type.value();
|
preferred_type = FindMemoryType(properties, flags);
|
||||||
|
if (preferred_type) {
|
||||||
|
return *preferred_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
LOG_CRITICAL(Render_Vulkan, "Failed to find a suitable memory type for buffer type {}",
|
||||||
|
BufferTypeName(type));
|
||||||
|
return 0; // Return 0 as a fallback, though this will likely cause issues
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000;
|
constexpr u64 WATCHES_INITIAL_RESERVE = 0x4000;
|
||||||
|
Loading…
Reference in New Issue
Block a user