Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Refactor Vulkan stream buffer memory type selection #238

Merged
merged 4 commits into from
Aug 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/video_core/renderer_vulkan/vk_stream_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down