always do texture copies on gpu

This commit is contained in:
Samuliak 2024-08-28 15:26:42 +02:00
parent be76dadb90
commit 35740c5c8e
3 changed files with 23 additions and 23 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) : 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(); MTL::TextureDescriptor* desc = MTL::TextureDescriptor::alloc()->init();
desc->setStorageMode(m_mtlr->GetOptimalTextureStorageMode()); desc->setStorageMode(MTL::StorageModePrivate);
desc->setCpuCacheMode(MTL::CPUCacheModeWriteCombined); desc->setCpuCacheMode(MTL::CPUCacheModeWriteCombined);
sint32 effectiveBaseWidth = width; sint32 effectiveBaseWidth = width;

View File

@ -45,7 +45,7 @@ MetalRenderer::MetalRenderer()
m_commandQueue = m_device->newCommandQueue(); m_commandQueue = m_device->newCommandQueue();
// Feature support // Feature support
m_isAppleGPU = false;//m_device->supportsFamily(MTL::GPUFamilyApple1); m_isAppleGPU = m_device->supportsFamily(MTL::GPUFamilyApple1);
m_hasUnifiedMemory = m_device->hasUnifiedMemory(); m_hasUnifiedMemory = m_device->hasUnifiedMemory();
m_supportsMetal3 = m_device->supportsFamily(MTL::GPUFamilyMetal3); m_supportsMetal3 = m_device->supportsFamily(MTL::GPUFamilyMetal3);
m_recommendedMaxVRAMUsage = m_device->recommendedMaxWorkingSetSize(); 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); size_t bytesPerRow = GetMtlTextureBytesPerRow(textureMtl->GetFormat(), textureMtl->IsDepth(), width);
// No need to set bytesPerImage for 3D textures, since we always load just one slice // 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); //size_t bytesPerImage = GetMtlTextureBytesPerImage(textureMtl->GetFormat(), textureMtl->IsDepth(), height, bytesPerRow);
if (m_isAppleGPU) //if (m_isAppleGPU)
{ //{
textureMtl->GetTexture()->replaceRegion(MTL::Region(0, 0, offsetZ, width, height, 1), mipIndex, sliceIndex, pixelData, bytesPerRow, 0); // textureMtl->GetTexture()->replaceRegion(MTL::Region(0, 0, offsetZ, width, height, 1), mipIndex, sliceIndex, pixelData, bytesPerRow, 0);
} //}
else //else
{ //{
auto blitCommandEncoder = GetBlitCommandEncoder(); auto blitCommandEncoder = GetBlitCommandEncoder();
// Allocate a temporary buffer // Allocate a temporary buffer
auto& bufferAllocator = m_memoryManager->GetTemporaryBufferAllocator(); auto& bufferAllocator = m_memoryManager->GetTemporaryBufferAllocator();
auto allocation = bufferAllocator.GetBufferAllocation(compressedImageSize); auto allocation = bufferAllocator.GetBufferAllocation(compressedImageSize);
auto buffer = bufferAllocator.GetBuffer(allocation.bufferIndex); auto buffer = bufferAllocator.GetBuffer(allocation.bufferIndex);
// Copy the data to the temporary buffer // Copy the data to the temporary buffer
memcpy(allocation.data, pixelData, compressedImageSize); memcpy(allocation.data, pixelData, compressedImageSize);
//buffer->didModifyRange(NS::Range(allocation.offset, allocation.size)); //buffer->didModifyRange(NS::Range(allocation.offset, allocation.size));
// Copy the data from the temporary buffer to the texture // 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)); 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) void MetalRenderer::texture_clearColorSlice(LatteTexture* hostTexture, sint32 sliceIndex, sint32 mipIndex, float r, float g, float b, float a)

View File

@ -397,10 +397,10 @@ public:
return m_pixelFormatSupport; return m_pixelFormatSupport;
} }
MTL::StorageMode GetOptimalTextureStorageMode() const //MTL::StorageMode GetOptimalTextureStorageMode() const
{ //{
return (m_isAppleGPU ? MTL::StorageModeShared : MTL::StorageModePrivate); // return (m_isAppleGPU ? MTL::StorageModeShared : MTL::StorageModePrivate);
} //}
MTL::ResourceOptions GetOptimalBufferStorageMode() const MTL::ResourceOptions GetOptimalBufferStorageMode() const
{ {