From f7e97a30af4bb771b5b0e21a45e17a2065d5d686 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 29 May 2024 23:52:29 +0100 Subject: [PATCH] Handle Array Format SetData --- src/Ryujinx.Graphics.Metal/Texture.cs | 32 ++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/Texture.cs b/src/Ryujinx.Graphics.Metal/Texture.cs index 6692d6133..eb13145bb 100644 --- a/src/Ryujinx.Graphics.Metal/Texture.cs +++ b/src/Ryujinx.Graphics.Metal/Texture.cs @@ -201,7 +201,6 @@ namespace Ryujinx.Graphics.Metal } } - // TODO: Handle array formats public unsafe void SetData(IMemoryOwner data) { var blitCommandEncoder = _pipeline.GetOrCreateBlitEncoder(); @@ -215,14 +214,14 @@ namespace Ryujinx.Graphics.Metal int height = Info.Height; int depth = Info.Depth; int levels = Info.GetLevelsClamped(); + int layers = Info.GetLayers(); bool is3D = Info.Target == Target.Texture3D; int offset = 0; for (int level = 0; level < levels; level++) { - int mipSize = Info.GetMipSize(level); - + int mipSize = Info.GetMipSize2D(level); int endOffset = offset + mipSize; if ((uint)endOffset > (uint)dataSpan.Length) @@ -230,19 +229,22 @@ namespace Ryujinx.Graphics.Metal return; } - blitCommandEncoder.CopyFromBuffer( - mtlBuffer, - (ulong)offset, - (ulong)Info.GetMipStride(level), - (ulong)mipSize, - new MTLSize { width = (ulong)width, height = (ulong)height, depth = is3D ? (ulong)depth : 1 }, - _mtlTexture, - 0, - (ulong)level, - new MTLOrigin() - ); + for (int layer = 0; layer < layers; layer++) + { + blitCommandEncoder.CopyFromBuffer( + mtlBuffer, + (ulong)offset, + (ulong)Info.GetMipStride(level), + (ulong)mipSize, + new MTLSize { width = (ulong)width, height = (ulong)height, depth = is3D ? (ulong)depth : 1 }, + _mtlTexture, + (ulong)layer, + (ulong)level, + new MTLOrigin() + ); - offset += mipSize; + offset += mipSize; + } width = Math.Max(1, width >> 1); height = Math.Max(1, height >> 1);