2019-10-13 02:02:07 -04:00
|
|
|
|
using Ryujinx.Common;
|
2019-12-11 14:43:28 -05:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
using static Ryujinx.Graphics.Texture.BlockLinearConstants;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Texture
|
|
|
|
|
{
|
|
|
|
|
class BlockLinearLayout
|
|
|
|
|
{
|
|
|
|
|
private struct RobAndSliceSizes
|
|
|
|
|
{
|
|
|
|
|
public int RobSize;
|
|
|
|
|
public int SliceSize;
|
|
|
|
|
|
|
|
|
|
public RobAndSliceSizes(int robSize, int sliceSize)
|
|
|
|
|
{
|
|
|
|
|
RobSize = robSize;
|
|
|
|
|
SliceSize = sliceSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int _texBpp;
|
|
|
|
|
|
|
|
|
|
private int _bhMask;
|
|
|
|
|
private int _bdMask;
|
|
|
|
|
|
|
|
|
|
private int _bhShift;
|
|
|
|
|
private int _bdShift;
|
|
|
|
|
private int _bppShift;
|
|
|
|
|
|
|
|
|
|
private int _xShift;
|
|
|
|
|
|
|
|
|
|
private int _robSize;
|
|
|
|
|
private int _sliceSize;
|
|
|
|
|
|
|
|
|
|
public BlockLinearLayout(
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
int depth,
|
|
|
|
|
int gobBlocksInY,
|
|
|
|
|
int gobBlocksInZ,
|
|
|
|
|
int bpp)
|
|
|
|
|
{
|
2019-12-11 14:43:28 -05:00
|
|
|
|
_texBpp = bpp;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
|
|
|
|
_bppShift = BitUtils.CountTrailingZeros32(bpp);
|
|
|
|
|
|
|
|
|
|
_bhMask = gobBlocksInY - 1;
|
|
|
|
|
_bdMask = gobBlocksInZ - 1;
|
|
|
|
|
|
|
|
|
|
_bhShift = BitUtils.CountTrailingZeros32(gobBlocksInY);
|
|
|
|
|
_bdShift = BitUtils.CountTrailingZeros32(gobBlocksInZ);
|
|
|
|
|
|
|
|
|
|
_xShift = BitUtils.CountTrailingZeros32(GobSize * gobBlocksInY * gobBlocksInZ);
|
|
|
|
|
|
|
|
|
|
RobAndSliceSizes rsSizes = GetRobAndSliceSizes(width, height, gobBlocksInY, gobBlocksInZ);
|
|
|
|
|
|
|
|
|
|
_robSize = rsSizes.RobSize;
|
|
|
|
|
_sliceSize = rsSizes.SliceSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private RobAndSliceSizes GetRobAndSliceSizes(int width, int height, int gobBlocksInY, int gobBlocksInZ)
|
|
|
|
|
{
|
|
|
|
|
int widthInGobs = BitUtils.DivRoundUp(width * _texBpp, GobStride);
|
|
|
|
|
|
|
|
|
|
int robSize = GobSize * gobBlocksInY * gobBlocksInZ * widthInGobs;
|
|
|
|
|
|
|
|
|
|
int sliceSize = BitUtils.DivRoundUp(height, gobBlocksInY * GobHeight) * robSize;
|
|
|
|
|
|
|
|
|
|
return new RobAndSliceSizes(robSize, sliceSize);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2019-10-13 02:02:07 -04:00
|
|
|
|
public int GetOffset(int x, int y, int z)
|
|
|
|
|
{
|
2019-12-11 14:43:28 -05:00
|
|
|
|
return GetOffsetWithLineOffset(x << _bppShift, y, z);
|
|
|
|
|
}
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public int GetOffsetWithLineOffset(int x, int y, int z)
|
|
|
|
|
{
|
2019-10-13 02:02:07 -04:00
|
|
|
|
int yh = y / GobHeight;
|
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
int offset = (z >> _bdShift) * _sliceSize + (yh >> _bhShift) * _robSize;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
offset += (x / GobStride) << _xShift;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
offset += (yh & _bhMask) * GobSize;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
offset += ((z & _bdMask) * GobSize) << _bhShift;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
offset += ((x & 0x3f) >> 5) << 8;
|
|
|
|
|
offset += ((y & 0x07) >> 1) << 6;
|
|
|
|
|
offset += ((x & 0x1f) >> 4) << 5;
|
|
|
|
|
offset += ((y & 0x01) >> 0) << 4;
|
|
|
|
|
offset += ((x & 0x0f) >> 0) << 0;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
|
2019-12-11 14:43:28 -05:00
|
|
|
|
return offset;
|
2019-10-13 02:02:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|