Skip to content

Commit

Permalink
Refactor Vulkan stream buffer memory type selection
Browse files Browse the repository at this point in the history
  • Loading branch information
i0x404 authored and Gamer64ytb committed Sep 1, 2024
1 parent a9db475 commit 10466de
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 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,42 @@ 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
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;
Expand Down

0 comments on commit 10466de

Please sign in to comment.