2018-09-08 17:51:50 +00:00
|
|
|
using ChocolArm64.Memory;
|
2019-02-28 01:12:24 +00:00
|
|
|
using Ryujinx.Common;
|
2018-09-08 17:51:50 +00:00
|
|
|
using Ryujinx.Graphics.Gal;
|
|
|
|
using Ryujinx.Graphics.Memory;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Texture
|
|
|
|
{
|
|
|
|
static class TextureHelper
|
|
|
|
{
|
2018-09-18 04:30:35 +00:00
|
|
|
public static ISwizzle GetSwizzle(GalImage Image)
|
2018-09-08 17:51:50 +00:00
|
|
|
{
|
2018-09-18 04:30:35 +00:00
|
|
|
int BlockWidth = ImageUtils.GetBlockWidth (Image.Format);
|
2019-02-28 01:12:24 +00:00
|
|
|
int BlockHeight = ImageUtils.GetBlockHeight (Image.Format);
|
|
|
|
int BlockDepth = ImageUtils.GetBlockDepth (Image.Format);
|
2018-09-18 04:30:35 +00:00
|
|
|
int BytesPerPixel = ImageUtils.GetBytesPerPixel(Image.Format);
|
2018-09-08 17:51:50 +00:00
|
|
|
|
2019-02-28 01:12:24 +00:00
|
|
|
int Width = BitUtils.DivRoundUp(Image.Width, BlockWidth);
|
|
|
|
int Height = BitUtils.DivRoundUp(Image.Height, BlockHeight);
|
|
|
|
int Depth = BitUtils.DivRoundUp(Image.Depth, BlockDepth);
|
2018-09-08 17:51:50 +00:00
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
if (Image.Layout == GalMemoryLayout.BlockLinear)
|
2018-09-08 17:51:50 +00:00
|
|
|
{
|
2018-09-18 04:30:35 +00:00
|
|
|
int AlignMask = Image.TileWidth * (64 / BytesPerPixel) - 1;
|
2018-09-08 17:51:50 +00:00
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
Width = (Width + AlignMask) & ~AlignMask;
|
2018-09-08 17:51:50 +00:00
|
|
|
|
2019-02-28 01:12:24 +00:00
|
|
|
return new BlockLinearSwizzle(
|
|
|
|
Width,
|
|
|
|
Height,
|
|
|
|
Depth,
|
|
|
|
Image.GobBlockHeight,
|
|
|
|
Image.GobBlockDepth,
|
|
|
|
BytesPerPixel);
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-28 01:12:24 +00:00
|
|
|
return new LinearSwizzle(Image.Pitch, BytesPerPixel, Width, Height);
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
2018-09-08 17:51:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 01:43:02 +00:00
|
|
|
public static (MemoryManager Memory, long Position) GetMemoryAndPosition(
|
|
|
|
IMemory Memory,
|
|
|
|
long Position)
|
2018-09-08 17:51:50 +00:00
|
|
|
{
|
|
|
|
if (Memory is NvGpuVmm Vmm)
|
|
|
|
{
|
|
|
|
return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
|
|
|
|
}
|
|
|
|
|
2018-10-31 01:43:02 +00:00
|
|
|
return ((MemoryManager)Memory, Position);
|
2018-09-08 17:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|