From bb4cb531f20c3e09abad68e8e4b707436374f645 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 30 May 2024 13:20:37 +0100 Subject: [PATCH] Fix 3D -> 3D Texture Copies --- src/Ryujinx.Graphics.Metal/Texture.cs | 68 ++++++++++++++++++++------- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/Texture.cs b/src/Ryujinx.Graphics.Metal/Texture.cs index eb13145bb..4ec5773bf 100644 --- a/src/Ryujinx.Graphics.Metal/Texture.cs +++ b/src/Ryujinx.Graphics.Metal/Texture.cs @@ -98,15 +98,31 @@ namespace Ryujinx.Graphics.Metal if (destination is Texture destinationTexture) { - blitCommandEncoder.CopyFromTexture( - _mtlTexture, - (ulong)firstLayer, - (ulong)firstLevel, - destinationTexture._mtlTexture, - (ulong)firstLayer, - (ulong)firstLevel, - _mtlTexture.ArrayLength, - _mtlTexture.MipmapLevelCount); + if (destinationTexture.Info.Target == Target.Texture3D) + { + blitCommandEncoder.CopyFromTexture( + _mtlTexture, + 0, + (ulong)firstLevel, + new MTLOrigin { x = 0, y = 0, z = (ulong)firstLayer }, + new MTLSize { width = (ulong)Math.Min(Info.Width, destinationTexture.Info.Width), height = (ulong)Math.Min(Info.Height, destinationTexture.Info.Height), depth = 1}, + destinationTexture._mtlTexture, + 0, + (ulong)firstLevel, + new MTLOrigin { x = 0, y = 0, z = (ulong)firstLayer }); + } + else + { + blitCommandEncoder.CopyFromTexture( + _mtlTexture, + (ulong)firstLayer, + (ulong)firstLevel, + destinationTexture._mtlTexture, + (ulong)firstLayer, + (ulong)firstLevel, + _mtlTexture.ArrayLength, + _mtlTexture.MipmapLevelCount); + } } } @@ -116,15 +132,31 @@ namespace Ryujinx.Graphics.Metal if (destination is Texture destinationTexture) { - blitCommandEncoder.CopyFromTexture( - _mtlTexture, - (ulong)srcLayer, - (ulong)srcLevel, - destinationTexture._mtlTexture, - (ulong)dstLayer, - (ulong)dstLevel, - _mtlTexture.ArrayLength, - _mtlTexture.MipmapLevelCount); + if (destinationTexture.Info.Target == Target.Texture3D) + { + blitCommandEncoder.CopyFromTexture( + _mtlTexture, + 0, + (ulong)srcLevel, + new MTLOrigin { x = 0, y = 0, z = (ulong)srcLayer }, + new MTLSize { width = (ulong)Math.Min(Info.Width, destinationTexture.Info.Width), height = (ulong)Math.Min(Info.Height, destinationTexture.Info.Height), depth = 1}, + destinationTexture._mtlTexture, + 0, + (ulong)dstLevel, + new MTLOrigin { x = 0, y = 0, z = (ulong)dstLayer }); + } + else + { + blitCommandEncoder.CopyFromTexture( + _mtlTexture, + (ulong)srcLayer, + (ulong)srcLevel, + destinationTexture._mtlTexture, + (ulong)dstLayer, + (ulong)dstLevel, + _mtlTexture.ArrayLength, + _mtlTexture.MipmapLevelCount); + } } }