From 451673ada576ecd7b8e98fb03e063b5d37152c39 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 26 Dec 2021 12:39:07 -0300 Subject: [PATCH] Fix I2M texture copies when line length is not a multiple of 4 (#2938) * Fix I2M texture copies when line length is not a multiple of 4 * Do not copy padding bytes for 1D copies * Nit --- .../Engine/InlineToMemory/InlineToMemoryClass.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs b/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs index 9649841f27..c093905797 100644 --- a/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs +++ b/Ryujinx.Graphics.Gpu/Engine/InlineToMemory/InlineToMemoryClass.cs @@ -99,9 +99,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory _isLinear = (argument & 1) != 0; _offset = 0; - _size = (int)(state.LineLengthIn * state.LineCount); + _size = (int)(BitUtils.AlignUp(state.LineLengthIn, 4) * state.LineCount); - int count = BitUtils.DivRoundUp(_size, 4); + int count = _size / 4; if (_buffer == null || _buffer.Length < count) { @@ -171,7 +171,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory if (_isLinear && _lineCount == 1) { - memoryManager.WriteTrackedResource(_dstGpuVa, data); + memoryManager.WriteTrackedResource(_dstGpuVa, data.Slice(0, _lineLengthIn)); _context.AdvanceSequence(); } else @@ -224,6 +224,15 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory memoryManager.Write(dstAddress, data[srcOffset]); } + + // All lines must be aligned to 4 bytes, as the data is pushed one word at a time. + // If our copy length is not a multiple of 4, then we need to skip the padding bytes here. + int misalignment = _lineLengthIn & 3; + + if (misalignment != 0) + { + srcOffset += 4 - misalignment; + } } _context.AdvanceSequence();