From 9bb7479d169aab19b528d87ee696bcf691db3816 Mon Sep 17 00:00:00 2001 From: Samuliak Date: Sun, 18 Aug 2024 17:40:41 +0200 Subject: [PATCH] use more efficient cpu cache mode when possible --- src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp | 1 + src/Cafe/HW/Latte/Renderer/Metal/MetalBufferAllocator.h | 2 +- src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp | 2 +- src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp b/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp index 9bc5b63b..c1e7149e 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp @@ -11,6 +11,7 @@ LatteTextureMtl::LatteTextureMtl(class MetalRenderer* mtlRenderer, Latte::E_DIM { MTL::TextureDescriptor* desc = MTL::TextureDescriptor::alloc()->init(); desc->setStorageMode(m_mtlr->HasUnifiedMemory() ? MTL::StorageModeShared : MTL::StorageModePrivate); + desc->setCpuCacheMode(MTL::CPUCacheModeWriteCombined); sint32 effectiveBaseWidth = width; sint32 effectiveBaseHeight = height; diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalBufferAllocator.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalBufferAllocator.h index a7e54e1e..15f0e7cf 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalBufferAllocator.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalBufferAllocator.h @@ -69,7 +69,7 @@ public: // If no free range was found, allocate a new buffer m_allocationSize = std::max(m_allocationSize, size); - MTL::Buffer* buffer = m_mtlr->GetDevice()->newBuffer(m_allocationSize, m_storageMode); + MTL::Buffer* buffer = m_mtlr->GetDevice()->newBuffer(m_allocationSize, m_storageMode | MTL::ResourceCPUCacheModeWriteCombined); #ifdef CEMU_DEBUG_ASSERT buffer->setLabel(GetLabel("Buffer from buffer allocator", buffer)); #endif diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp index 534b9831..8986805d 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalMemoryManager.cpp @@ -132,7 +132,7 @@ void MetalMemoryManager::InitBufferCache(size_t size) return; } - m_bufferCache = m_mtlr->GetDevice()->newBuffer(size, m_mtlr->GetOptimalResourceStorageMode()); + m_bufferCache = m_mtlr->GetDevice()->newBuffer(size, m_mtlr->GetOptimalResourceStorageMode() | MTL::ResourceCPUCacheModeWriteCombined); #ifdef CEMU_DEBUG_ASSERT m_bufferCache->setLabel(GetLabel("Buffer cache", m_bufferCache)); #endif diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index 21ee47eb..1536c88b 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -73,7 +73,7 @@ MetalRenderer::MetalRenderer() m_samplerCache = new MetalSamplerCache(this); // Texture readback - m_readbackBuffer = m_device->newBuffer(TEXTURE_READBACK_SIZE, MTL::StorageModeShared); + m_readbackBuffer = m_device->newBuffer(TEXTURE_READBACK_SIZE, MTL::ResourceStorageModeShared); #ifdef CEMU_DEBUG_ASSERT m_readbackBuffer->setLabel(GetLabel("Texture readback buffer", m_readbackBuffer)); #endif