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