From 35740c5c8ebb16c1dc95cf4c209abc11ed6c5fdd Mon Sep 17 00:00:00 2001 From: Samuliak Date: Wed, 28 Aug 2024 15:26:42 +0200 Subject: [PATCH] always do texture copies on gpu --- .../Latte/Renderer/Metal/LatteTextureMtl.cpp | 2 +- .../HW/Latte/Renderer/Metal/MetalRenderer.cpp | 36 +++++++++---------- .../HW/Latte/Renderer/Metal/MetalRenderer.h | 8 ++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp b/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp index c588a21e..4510571a 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/LatteTextureMtl.cpp @@ -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->GetOptimalTextureStorageMode()); + desc->setStorageMode(MTL::StorageModePrivate); desc->setCpuCacheMode(MTL::CPUCacheModeWriteCombined); sint32 effectiveBaseWidth = width; diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp index 95b72c40..2e541c2b 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.cpp @@ -45,7 +45,7 @@ MetalRenderer::MetalRenderer() m_commandQueue = m_device->newCommandQueue(); // Feature support - m_isAppleGPU = false;//m_device->supportsFamily(MTL::GPUFamilyApple1); + m_isAppleGPU = m_device->supportsFamily(MTL::GPUFamilyApple1); m_hasUnifiedMemory = m_device->hasUnifiedMemory(); m_supportsMetal3 = m_device->supportsFamily(MTL::GPUFamilyMetal3); m_recommendedMaxVRAMUsage = m_device->recommendedMaxWorkingSetSize(); @@ -519,26 +519,26 @@ 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 (m_isAppleGPU) - { - textureMtl->GetTexture()->replaceRegion(MTL::Region(0, 0, offsetZ, width, height, 1), mipIndex, sliceIndex, pixelData, bytesPerRow, 0); - } - else - { - auto blitCommandEncoder = GetBlitCommandEncoder(); + //if (m_isAppleGPU) + //{ + // textureMtl->GetTexture()->replaceRegion(MTL::Region(0, 0, offsetZ, width, height, 1), mipIndex, sliceIndex, pixelData, bytesPerRow, 0); + //} + //else + //{ + auto blitCommandEncoder = GetBlitCommandEncoder(); - // Allocate a temporary buffer - auto& bufferAllocator = m_memoryManager->GetTemporaryBufferAllocator(); - auto allocation = bufferAllocator.GetBufferAllocation(compressedImageSize); - auto buffer = bufferAllocator.GetBuffer(allocation.bufferIndex); + // Allocate a temporary buffer + auto& bufferAllocator = m_memoryManager->GetTemporaryBufferAllocator(); + auto allocation = bufferAllocator.GetBufferAllocation(compressedImageSize); + auto buffer = bufferAllocator.GetBuffer(allocation.bufferIndex); - // Copy the data to the temporary buffer - memcpy(allocation.data, pixelData, compressedImageSize); - //buffer->didModifyRange(NS::Range(allocation.offset, allocation.size)); + // Copy the data to the temporary buffer + memcpy(allocation.data, pixelData, compressedImageSize); + //buffer->didModifyRange(NS::Range(allocation.offset, allocation.size)); - // Copy the data from the temporary buffer to the texture - blitCommandEncoder->copyFromBuffer(buffer, allocation.offset, bytesPerRow, 0, MTL::Size(width, height, 1), textureMtl->GetTexture(), sliceIndex, mipIndex, MTL::Origin(0, 0, offsetZ)); - } + // Copy the data from the temporary buffer to the texture + blitCommandEncoder->copyFromBuffer(buffer, allocation.offset, bytesPerRow, 0, MTL::Size(width, height, 1), textureMtl->GetTexture(), sliceIndex, mipIndex, MTL::Origin(0, 0, offsetZ)); + //} } void MetalRenderer::texture_clearColorSlice(LatteTexture* hostTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a) diff --git a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h index 2ada50c3..586eb79a 100644 --- a/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h +++ b/src/Cafe/HW/Latte/Renderer/Metal/MetalRenderer.h @@ -397,10 +397,10 @@ public: return m_pixelFormatSupport; } - MTL::StorageMode GetOptimalTextureStorageMode() const - { - return (m_isAppleGPU ? MTL::StorageModeShared : MTL::StorageModePrivate); - } + //MTL::StorageMode GetOptimalTextureStorageMode() const + //{ + // return (m_isAppleGPU ? MTL::StorageModeShared : MTL::StorageModePrivate); + //} MTL::ResourceOptions GetOptimalBufferStorageMode() const {