do GPU texture loading on non-apple GPUs

This commit is contained in:
Samuliak 2024-08-19 16:14:06 +02:00
parent b59dbfc9c3
commit 69a36246fb
6 changed files with 16 additions and 8 deletions

View File

@ -10,7 +10,7 @@ LatteTextureMtl::LatteTextureMtl(class MetalRenderer* mtlRenderer, Latte::E_DIM
: LatteTexture(dim, physAddress, physMipAddress, format, width, height, depth, pitch, mipLevels, swizzle, tileMode, isDepth), m_mtlr(mtlRenderer), m_format(format), m_isDepth(isDepth)
{
MTL::TextureDescriptor* desc = MTL::TextureDescriptor::alloc()->init();
desc->setStorageMode(m_mtlr->HasUnifiedMemory() ? MTL::StorageModeShared : MTL::StorageModePrivate);
desc->setStorageMode(m_mtlr->GetOptimalTextureStorageMode());
desc->setCpuCacheMode(MTL::CPUCacheModeWriteCombined);
sint32 effectiveBaseWidth = width;

View File

@ -149,7 +149,7 @@ struct MetalSyncedBuffer
class MetalTemporaryBufferAllocator : public MetalBufferAllocator<MetalSyncedBuffer>
{
public:
MetalTemporaryBufferAllocator(class MetalRenderer* metalRenderer) : MetalBufferAllocator<MetalSyncedBuffer>(metalRenderer, metalRenderer->GetOptimalResourceStorageMode()) {}
MetalTemporaryBufferAllocator(class MetalRenderer* metalRenderer) : MetalBufferAllocator<MetalSyncedBuffer>(metalRenderer, metalRenderer->GetOptimalBufferStorageMode()) {}
void SetActiveCommandBuffer(MTL::CommandBuffer* commandBuffer)
{

View File

@ -132,7 +132,7 @@ void MetalMemoryManager::InitBufferCache(size_t size)
return;
}
m_bufferCache = m_mtlr->GetDevice()->newBuffer(size, m_mtlr->GetOptimalResourceStorageMode() | MTL::ResourceCPUCacheModeWriteCombined);
m_bufferCache = m_mtlr->GetDevice()->newBuffer(size, m_mtlr->GetOptimalBufferStorageMode() | MTL::ResourceCPUCacheModeWriteCombined);
#ifdef CEMU_DEBUG_ASSERT
m_bufferCache->setLabel(GetLabel("Buffer cache", m_bufferCache));
#endif

View File

@ -58,7 +58,7 @@ private:
class MetalMemoryManager
{
public:
MetalMemoryManager(class MetalRenderer* metalRenderer) : m_mtlr{metalRenderer}, m_bufferAllocator(metalRenderer, m_mtlr->GetOptimalResourceStorageMode()), m_framePersistentBufferAllocator(metalRenderer, MTL::ResourceStorageModePrivate), m_tempBufferAllocator(metalRenderer), m_vertexBufferCache(metalRenderer, m_framePersistentBufferAllocator) {}
MetalMemoryManager(class MetalRenderer* metalRenderer) : m_mtlr{metalRenderer}, m_bufferAllocator(metalRenderer, m_mtlr->GetOptimalBufferStorageMode()), m_framePersistentBufferAllocator(metalRenderer, MTL::ResourceStorageModePrivate), m_tempBufferAllocator(metalRenderer), m_vertexBufferCache(metalRenderer, m_framePersistentBufferAllocator) {}
~MetalMemoryManager();
// Pipelines

View File

@ -19,6 +19,7 @@
#include "Cemu/Logging/CemuDebugLogging.h"
#include "Common/precompiled.h"
#include "HW/Latte/Renderer/Metal/MetalCommon.h"
#include "Metal/MTLDevice.hpp"
#include "gui/guiWrapper.h"
#define COMMIT_TRESHOLD 256
@ -34,6 +35,7 @@ MetalRenderer::MetalRenderer()
// Feature support
m_hasUnifiedMemory = m_device->hasUnifiedMemory();
m_isAppleGPU = m_device->supportsFamily(MTL::GPUFamilyApple1);
// Resources
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
@ -391,7 +393,7 @@ void MetalRenderer::texture_loadSlice(LatteTexture* hostTexture, sint32 width, s
size_t bytesPerRow = GetMtlTextureBytesPerRow(textureMtl->GetFormat(), textureMtl->IsDepth(), width);
// No need to set bytesPerImage for 3D textures, since we always load just one slice
//size_t bytesPerImage = GetMtlTextureBytesPerImage(textureMtl->GetFormat(), textureMtl->IsDepth(), height, bytesPerRow);
if (HasUnifiedMemory())
if (IsAppleGPU())
{
textureMtl->GetTexture()->replaceRegion(MTL::Region(0, 0, offsetZ, width, height, 1), mipIndex, sliceIndex, pixelData, bytesPerRow, 0);
}

View File

@ -366,12 +366,17 @@ public:
return m_hasUnifiedMemory;
}
MTL::StorageMode GetOptimalStorageMode() const
bool IsAppleGPU() const
{
return (m_hasUnifiedMemory ? MTL::StorageModeShared : MTL::StorageModeManaged);
return m_isAppleGPU;
}
MTL::ResourceOptions GetOptimalResourceStorageMode() const
MTL::StorageMode GetOptimalTextureStorageMode() const
{
return (m_isAppleGPU ? MTL::StorageModeShared : MTL::StorageModePrivate);
}
MTL::ResourceOptions GetOptimalBufferStorageMode() const
{
return (m_hasUnifiedMemory ? MTL::ResourceStorageModeShared : MTL::ResourceStorageModeManaged);
}
@ -391,6 +396,7 @@ private:
// Feature support
bool m_hasUnifiedMemory;
bool m_isAppleGPU;
// Managers and caches
class MetalMemoryManager* m_memoryManager;