Skip to content

Commit a5a3401

Browse files
authored
Merge pull request hrydgard#19710 from Kethen/macos_amd_workaround
Work around metal buffer bug on MacOS + AMD GPU
2 parents d21de81 + 49553bc commit a5a3401

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Common/GPU/Vulkan/VulkanLoader.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,6 @@ static VulkanLibraryHandle VulkanLoadLibrary(std::string *errorString) {
343343
return nullptr;
344344
#elif PPSSPP_PLATFORM(UWP)
345345
return nullptr;
346-
#elif PPSSPP_PLATFORM(MAC) && PPSSPP_ARCH(AMD64)
347-
// Disable Vulkan on Mac/x86. Too many configurations that don't work with MoltenVK
348-
// for whatever reason.
349-
return nullptr;
350346
#elif PPSSPP_PLATFORM(WINDOWS)
351347
return LoadLibrary(L"vulkan-1.dll");
352348
#else

Common/GPU/Vulkan/VulkanMemory.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ static const double PUSH_GARBAGE_COLLECTION_DELAY = 10.0;
3838
VulkanPushPool::VulkanPushPool(VulkanContext *vulkan, const char *name, size_t originalBlockSize, VkBufferUsageFlags usage)
3939
: vulkan_(vulkan), name_(name), originalBlockSize_(originalBlockSize), usage_(usage) {
4040
RegisterGPUMemoryManager(this);
41+
42+
#if PPSSPP_PLATFORM(MAC) && PPSSPP_ARCH(AMD64)
43+
allocation_extra_flags_ = 0;
44+
if (vulkan_->GetPhysicalDeviceProperties().properties.vendorID != VULKAN_VENDOR_INTEL) {
45+
// ref https://github.com/KhronosGroup/MoltenVK/issues/960
46+
INFO_LOG(Log::G3D, "MoltenVK with dedicated gpu, adding VK_MEMORY_PROPERTY_HOST_COHERENT_BIT");
47+
allocation_extra_flags_ = VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
48+
}
49+
#endif
50+
4151
for (int i = 0; i < VulkanContext::MAX_INFLIGHT_FRAMES; i++) {
4252
blocks_.push_back(CreateBlock(originalBlockSize));
4353
blocks_.back().original = true;
@@ -67,7 +77,11 @@ VulkanPushPool::Block VulkanPushPool::CreateBlock(size_t size) {
6777
b.usage = usage_;
6878
b.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6979
VmaAllocationCreateInfo allocCreateInfo{};
80+
7081
allocCreateInfo.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
82+
#if PPSSPP_PLATFORM(MAC) && PPSSPP_ARCH(AMD64)
83+
allocCreateInfo.requiredFlags = allocation_extra_flags_;
84+
#endif
7185
VmaAllocationInfo allocInfo{};
7286

7387
VkResult result = vmaCreateBuffer(vulkan_->Allocator(), &b, &allocCreateInfo, &block.buffer, &block.allocation, &allocInfo);

Common/GPU/Vulkan/VulkanMemory.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@ class VulkanPushPool : public GPUMemoryManager {
9393
VkBufferUsageFlags usage_;
9494
int curBlockIndex_ = -1;
9595
const char *name_;
96+
#if PPSSPP_PLATFORM(MAC) && PPSSPP_ARCH(AMD64)
97+
VkMemoryPropertyFlags allocation_extra_flags_;
98+
#endif
9699
};

0 commit comments

Comments
 (0)