mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-10 21:26:39 +00:00
Correct BPP of buffer to texture copies (#1670)
This commit is contained in:
parent
a89b81a812
commit
24dbfc0fe6
1 changed files with 13 additions and 29 deletions
|
@ -2,7 +2,6 @@ using Ryujinx.Common;
|
||||||
using Ryujinx.Graphics.Gpu.State;
|
using Ryujinx.Graphics.Gpu.State;
|
||||||
using Ryujinx.Graphics.Texture;
|
using Ryujinx.Graphics.Texture;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.Intrinsics;
|
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Gpu.Engine
|
namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
{
|
{
|
||||||
|
@ -17,24 +16,21 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
/// <param name="cbp">Copy command parameters</param>
|
/// <param name="cbp">Copy command parameters</param>
|
||||||
/// <param name="tex">Texture to compare</param>
|
/// <param name="tex">Texture to compare</param>
|
||||||
/// <param name="linear">True if the texture is linear, false if block linear</param>
|
/// <param name="linear">True if the texture is linear, false if block linear</param>
|
||||||
/// <param name="bpp">Texture bytes per pixel</param>
|
|
||||||
/// <param name="stride">Texture stride</param>
|
/// <param name="stride">Texture stride</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private bool IsTextureCopyComplete(CopyBufferParams cbp, CopyBufferTexture tex, bool linear, int bpp, int stride)
|
private bool IsTextureCopyComplete(CopyBufferParams cbp, CopyBufferTexture tex, bool linear, int stride)
|
||||||
{
|
{
|
||||||
if (linear)
|
if (linear)
|
||||||
{
|
{
|
||||||
int alignWidth = StrideAlignment / bpp;
|
|
||||||
return tex.RegionX == 0 &&
|
return tex.RegionX == 0 &&
|
||||||
tex.RegionY == 0 &&
|
tex.RegionY == 0 &&
|
||||||
stride / bpp == BitUtils.AlignUp(cbp.XCount, alignWidth);
|
stride == BitUtils.AlignUp(cbp.XCount, StrideAlignment);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int alignWidth = GobAlignment / bpp;
|
|
||||||
return tex.RegionX == 0 &&
|
return tex.RegionX == 0 &&
|
||||||
tex.RegionY == 0 &&
|
tex.RegionY == 0 &&
|
||||||
tex.Width == BitUtils.AlignUp(cbp.XCount, alignWidth) &&
|
tex.Width == BitUtils.AlignUp(cbp.XCount, GobAlignment) &&
|
||||||
tex.Height == cbp.YCount;
|
tex.Height == cbp.YCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,9 +60,6 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
if (copy2D)
|
if (copy2D)
|
||||||
{
|
{
|
||||||
// Buffer to texture copy.
|
// Buffer to texture copy.
|
||||||
int srcBpp = swizzle.UnpackSrcComponentsCount() * swizzle.UnpackComponentSize();
|
|
||||||
int dstBpp = swizzle.UnpackDstComponentsCount() * swizzle.UnpackComponentSize();
|
|
||||||
|
|
||||||
var dst = state.Get<CopyBufferTexture>(MethodOffset.CopyBufferDstTexture);
|
var dst = state.Get<CopyBufferTexture>(MethodOffset.CopyBufferDstTexture);
|
||||||
var src = state.Get<CopyBufferTexture>(MethodOffset.CopyBufferSrcTexture);
|
var src = state.Get<CopyBufferTexture>(MethodOffset.CopyBufferSrcTexture);
|
||||||
|
|
||||||
|
@ -77,7 +70,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
srcLinear,
|
srcLinear,
|
||||||
src.MemoryLayout.UnpackGobBlocksInY(),
|
src.MemoryLayout.UnpackGobBlocksInY(),
|
||||||
src.MemoryLayout.UnpackGobBlocksInZ(),
|
src.MemoryLayout.UnpackGobBlocksInZ(),
|
||||||
srcBpp);
|
1);
|
||||||
|
|
||||||
var dstCalculator = new OffsetCalculator(
|
var dstCalculator = new OffsetCalculator(
|
||||||
dst.Width,
|
dst.Width,
|
||||||
|
@ -86,7 +79,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
dstLinear,
|
dstLinear,
|
||||||
dst.MemoryLayout.UnpackGobBlocksInY(),
|
dst.MemoryLayout.UnpackGobBlocksInY(),
|
||||||
dst.MemoryLayout.UnpackGobBlocksInZ(),
|
dst.MemoryLayout.UnpackGobBlocksInZ(),
|
||||||
dstBpp);
|
1);
|
||||||
|
|
||||||
ulong srcBaseAddress = _context.MemoryManager.Translate(cbp.SrcAddress.Pack());
|
ulong srcBaseAddress = _context.MemoryManager.Translate(cbp.SrcAddress.Pack());
|
||||||
ulong dstBaseAddress = _context.MemoryManager.Translate(cbp.DstAddress.Pack());
|
ulong dstBaseAddress = _context.MemoryManager.Translate(cbp.DstAddress.Pack());
|
||||||
|
@ -97,8 +90,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
ReadOnlySpan<byte> srcSpan = _context.PhysicalMemory.GetSpan(srcBaseAddress + (ulong)srcBaseOffset, srcSize, true);
|
ReadOnlySpan<byte> srcSpan = _context.PhysicalMemory.GetSpan(srcBaseAddress + (ulong)srcBaseOffset, srcSize, true);
|
||||||
Span<byte> dstSpan = _context.PhysicalMemory.GetSpan(dstBaseAddress + (ulong)dstBaseOffset, dstSize).ToArray();
|
Span<byte> dstSpan = _context.PhysicalMemory.GetSpan(dstBaseAddress + (ulong)dstBaseOffset, dstSize).ToArray();
|
||||||
|
|
||||||
bool completeSource = IsTextureCopyComplete(cbp, src, srcLinear, srcBpp, cbp.SrcStride);
|
bool completeSource = IsTextureCopyComplete(cbp, src, srcLinear, cbp.SrcStride);
|
||||||
bool completeDest = IsTextureCopyComplete(cbp, dst, dstLinear, dstBpp, cbp.DstStride);
|
bool completeDest = IsTextureCopyComplete(cbp, dst, dstLinear, cbp.DstStride);
|
||||||
|
|
||||||
if (completeSource && completeDest)
|
if (completeSource && completeDest)
|
||||||
{
|
{
|
||||||
|
@ -127,10 +120,10 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
1,
|
1,
|
||||||
srcBpp,
|
1,
|
||||||
src.MemoryLayout.UnpackGobBlocksInY(),
|
src.MemoryLayout.UnpackGobBlocksInY(),
|
||||||
src.MemoryLayout.UnpackGobBlocksInZ(),
|
src.MemoryLayout.UnpackGobBlocksInZ(),
|
||||||
src.MemoryLayout.UnpackGobBlocksInX(),
|
1,
|
||||||
new SizeInfo((int)target.Size),
|
new SizeInfo((int)target.Size),
|
||||||
srcSpan);
|
srcSpan);
|
||||||
}
|
}
|
||||||
|
@ -174,16 +167,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _ = srcBpp switch
|
Convert<byte>(dstSpan, srcSpan);
|
||||||
{
|
|
||||||
1 => Convert<byte>(dstSpan, srcSpan),
|
|
||||||
2 => Convert<ushort>(dstSpan, srcSpan),
|
|
||||||
4 => Convert<uint>(dstSpan, srcSpan),
|
|
||||||
8 => Convert<ulong>(dstSpan, srcSpan),
|
|
||||||
12 => Convert<Bpp12Pixel>(dstSpan, srcSpan),
|
|
||||||
16 => Convert<Vector128<byte>>(dstSpan, srcSpan),
|
|
||||||
_ => throw new NotSupportedException($"Unable to copy ${srcBpp} bpp pixel format.")
|
|
||||||
};
|
|
||||||
|
|
||||||
_context.PhysicalMemory.Write(dstBaseAddress + (ulong)dstBaseOffset, dstSpan);
|
_context.PhysicalMemory.Write(dstBaseAddress + (ulong)dstBaseOffset, dstSpan);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue