2018-09-08 19:51:50 +02:00
|
|
|
using ChocolArm64.Memory;
|
2019-02-28 02:12:24 +01:00
|
|
|
using Ryujinx.Common;
|
2018-09-08 19:51:50 +02:00
|
|
|
using Ryujinx.Graphics.Gal;
|
|
|
|
using Ryujinx.Graphics.Memory;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Texture
|
|
|
|
{
|
|
|
|
static class TextureHelper
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ISwizzle GetSwizzle(GalImage image)
|
2018-09-08 19:51:50 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01: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 19:51:50 +02:00
|
|
|
|
2019-03-04 02:45:25 +01: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 19:51:50 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (image.Layout == GalMemoryLayout.BlockLinear)
|
2018-09-08 19:51:50 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
int alignMask = image.TileWidth * (64 / bytesPerPixel) - 1;
|
2018-09-08 19:51:50 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
width = (width + alignMask) & ~alignMask;
|
2018-09-08 19:51:50 +02:00
|
|
|
|
2019-02-28 02:12:24 +01:00
|
|
|
return new BlockLinearSwizzle(
|
2019-03-04 02:45:25 +01:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
depth,
|
|
|
|
image.GobBlockHeight,
|
|
|
|
image.GobBlockDepth,
|
|
|
|
bytesPerPixel);
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return new LinearSwizzle(image.Pitch, bytesPerPixel, width, height);
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
2018-09-08 19:51:50 +02:00
|
|
|
}
|
|
|
|
|
2018-10-31 02:43:02 +01:00
|
|
|
public static (MemoryManager Memory, long Position) GetMemoryAndPosition(
|
2019-03-04 02:45:25 +01:00
|
|
|
IMemory memory,
|
|
|
|
long position)
|
2018-09-08 19:51:50 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if (memory is NvGpuVmm vmm)
|
2018-09-08 19:51:50 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (vmm.Memory, vmm.GetPhysicalAddress(position));
|
2018-09-08 19:51:50 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
return ((MemoryManager)memory, position);
|
2018-09-08 19:51:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|