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
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
public static ISwizzle GetSwizzle(GalImage image)
|
2018-09-08 17:51:50 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int blockWidth = ImageUtils.GetBlockWidth (image.Format);
|
|
|
|
int blockHeight = ImageUtils.GetBlockHeight (image.Format);
|
|
|
|
int blockDepth = ImageUtils.GetBlockDepth (image.Format);
|
|
|
|
int bytesPerPixel = ImageUtils.GetBytesPerPixel(image.Format);
|
2018-09-08 17:51:50 +00:00
|
|
|
|
2019-03-04 01:45:25 +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
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (image.Layout == GalMemoryLayout.BlockLinear)
|
2018-09-08 17:51:50 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int alignMask = image.TileWidth * (64 / bytesPerPixel) - 1;
|
2018-09-08 17:51:50 +00:00
|
|
|
|
2019-03-04 01:45:25 +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(
|
2019-03-04 01:45:25 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
image.GobBlockHeight,
|
|
|
|
image.GobBlockDepth,
|
|
|
|
bytesPerPixel);
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 01:45:25 +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(
|
2019-03-04 01:45:25 +00:00
|
|
|
IMemory memory,
|
|
|
|
long position)
|
2018-09-08 17:51:50 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (memory is NvGpuVmm vmm)
|
2018-09-08 17:51:50 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
return (vmm.Memory, vmm.GetPhysicalAddress(position));
|
2018-09-08 17:51:50 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
return ((MemoryManager)memory, position);
|
2018-09-08 17:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|