forked from Mirror/Ryujinx
Fix texture level offset/size calculation when sparse tile width is > 1 (#1142)
* Fix texture level offset/size calculation when sparse tile width is > 1 * Sparse tile width affects layer size alignment aswell
This commit is contained in:
parent
bcc5b0d21e
commit
34d19f381c
3 changed files with 81 additions and 37 deletions
|
@ -870,13 +870,6 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||||
{
|
{
|
||||||
int depth = Math.Max(1, info.GetDepth() >> level);
|
int depth = Math.Max(1, info.GetDepth() >> level);
|
||||||
|
|
||||||
(int gobBlocksInY, int gobBlocksInZ) = SizeCalculator.GetMipGobBlockSizes(
|
|
||||||
height,
|
|
||||||
depth,
|
|
||||||
info.FormatInfo.BlockHeight,
|
|
||||||
info.GobBlocksInY,
|
|
||||||
info.GobBlocksInZ);
|
|
||||||
|
|
||||||
return SizeCalculator.GetBlockLinearAlignedSize(
|
return SizeCalculator.GetBlockLinearAlignedSize(
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
@ -884,8 +877,8 @@ namespace Ryujinx.Graphics.Gpu.Image
|
||||||
info.FormatInfo.BlockWidth,
|
info.FormatInfo.BlockWidth,
|
||||||
info.FormatInfo.BlockHeight,
|
info.FormatInfo.BlockHeight,
|
||||||
info.FormatInfo.BytesPerPixel,
|
info.FormatInfo.BytesPerPixel,
|
||||||
gobBlocksInY,
|
info.GobBlocksInY,
|
||||||
gobBlocksInZ,
|
info.GobBlocksInZ,
|
||||||
info.GobBlocksInTileX);
|
info.GobBlocksInTileX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,12 @@ namespace Ryujinx.Graphics.Texture
|
||||||
|
|
||||||
int outOffs = 0;
|
int outOffs = 0;
|
||||||
|
|
||||||
int wAlignment = gobBlocksInTileX * (GobStride / bytesPerPixel);
|
|
||||||
|
|
||||||
int mipGobBlocksInY = gobBlocksInY;
|
int mipGobBlocksInY = gobBlocksInY;
|
||||||
int mipGobBlocksInZ = gobBlocksInZ;
|
int mipGobBlocksInZ = gobBlocksInZ;
|
||||||
|
|
||||||
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
for (int level = 0; level < levels; level++)
|
||||||
{
|
{
|
||||||
int w = Math.Max(1, width >> level);
|
int w = Math.Max(1, width >> level);
|
||||||
|
@ -67,7 +68,15 @@ namespace Ryujinx.Graphics.Texture
|
||||||
int xStart = strideTrunc / bytesPerPixel;
|
int xStart = strideTrunc / bytesPerPixel;
|
||||||
|
|
||||||
int stride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
int stride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
||||||
int wAligned = BitUtils.AlignUp(w, wAlignment);
|
|
||||||
|
int alignment = gobWidth;
|
||||||
|
|
||||||
|
if (d < gobBlocksInZ || w <= gobWidth || h <= gobHeight)
|
||||||
|
{
|
||||||
|
alignment = GobStride / bytesPerPixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wAligned = BitUtils.AlignUp(w, alignment);
|
||||||
|
|
||||||
BlockLinearLayout layoutConverter = new BlockLinearLayout(
|
BlockLinearLayout layoutConverter = new BlockLinearLayout(
|
||||||
wAligned,
|
wAligned,
|
||||||
|
@ -164,11 +173,12 @@ namespace Ryujinx.Graphics.Texture
|
||||||
|
|
||||||
int inOffs = 0;
|
int inOffs = 0;
|
||||||
|
|
||||||
int wAlignment = gobBlocksInTileX * (GobStride / bytesPerPixel);
|
|
||||||
|
|
||||||
int mipGobBlocksInY = gobBlocksInY;
|
int mipGobBlocksInY = gobBlocksInY;
|
||||||
int mipGobBlocksInZ = gobBlocksInZ;
|
int mipGobBlocksInZ = gobBlocksInZ;
|
||||||
|
|
||||||
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
for (int level = 0; level < levels; level++)
|
||||||
{
|
{
|
||||||
int w = Math.Max(1, width >> level);
|
int w = Math.Max(1, width >> level);
|
||||||
|
@ -189,7 +199,15 @@ namespace Ryujinx.Graphics.Texture
|
||||||
}
|
}
|
||||||
|
|
||||||
int stride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
int stride = BitUtils.AlignUp(w * bytesPerPixel, HostStrideAlignment);
|
||||||
int wAligned = BitUtils.AlignUp(w, wAlignment);
|
|
||||||
|
int alignment = gobWidth;
|
||||||
|
|
||||||
|
if (d < gobBlocksInZ || w <= gobWidth || h <= gobHeight)
|
||||||
|
{
|
||||||
|
alignment = GobStride / bytesPerPixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wAligned = BitUtils.AlignUp(w, alignment);
|
||||||
|
|
||||||
BlockLinearLayout layoutConverter = new BlockLinearLayout(
|
BlockLinearLayout layoutConverter = new BlockLinearLayout(
|
||||||
wAligned,
|
wAligned,
|
||||||
|
|
|
@ -32,6 +32,9 @@ namespace Ryujinx.Graphics.Texture
|
||||||
int mipGobBlocksInY = gobBlocksInY;
|
int mipGobBlocksInY = gobBlocksInY;
|
||||||
int mipGobBlocksInZ = gobBlocksInZ;
|
int mipGobBlocksInZ = gobBlocksInZ;
|
||||||
|
|
||||||
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
for (int level = 0; level < levels; level++)
|
for (int level = 0; level < levels; level++)
|
||||||
{
|
{
|
||||||
int w = Math.Max(1, width >> level);
|
int w = Math.Max(1, width >> level);
|
||||||
|
@ -51,7 +54,16 @@ namespace Ryujinx.Graphics.Texture
|
||||||
mipGobBlocksInZ >>= 1;
|
mipGobBlocksInZ >>= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int widthInGobs = BitUtils.AlignUp(BitUtils.DivRoundUp(w * bytesPerPixel, GobStride), gobBlocksInTileX);
|
int widthInGobs = BitUtils.DivRoundUp(w * bytesPerPixel, GobStride);
|
||||||
|
|
||||||
|
int alignment = gobBlocksInTileX;
|
||||||
|
|
||||||
|
if (d < gobBlocksInZ || w <= gobWidth || h <= gobHeight)
|
||||||
|
{
|
||||||
|
alignment = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
widthInGobs = BitUtils.AlignUp(widthInGobs, alignment);
|
||||||
|
|
||||||
int totalBlocksOfGobsInZ = BitUtils.DivRoundUp(d, mipGobBlocksInZ);
|
int totalBlocksOfGobsInZ = BitUtils.DivRoundUp(d, mipGobBlocksInZ);
|
||||||
int totalBlocksOfGobsInY = BitUtils.DivRoundUp(BitUtils.DivRoundUp(h, GobHeight), mipGobBlocksInY);
|
int totalBlocksOfGobsInY = BitUtils.DivRoundUp(BitUtils.DivRoundUp(h, GobHeight), mipGobBlocksInY);
|
||||||
|
@ -88,7 +100,8 @@ namespace Ryujinx.Graphics.Texture
|
||||||
depth,
|
depth,
|
||||||
blockHeight,
|
blockHeight,
|
||||||
gobBlocksInY,
|
gobBlocksInY,
|
||||||
gobBlocksInZ);
|
gobBlocksInZ,
|
||||||
|
gobBlocksInTileX);
|
||||||
|
|
||||||
if (!is3D)
|
if (!is3D)
|
||||||
{
|
{
|
||||||
|
@ -124,7 +137,10 @@ namespace Ryujinx.Graphics.Texture
|
||||||
int depth,
|
int depth,
|
||||||
int blockHeight,
|
int blockHeight,
|
||||||
int gobBlocksInY,
|
int gobBlocksInY,
|
||||||
int gobBlocksInZ)
|
int gobBlocksInZ,
|
||||||
|
int gobBlocksInTileX)
|
||||||
|
{
|
||||||
|
if (gobBlocksInTileX < 2)
|
||||||
{
|
{
|
||||||
height = BitUtils.DivRoundUp(height, blockHeight);
|
height = BitUtils.DivRoundUp(height, blockHeight);
|
||||||
|
|
||||||
|
@ -146,6 +162,13 @@ namespace Ryujinx.Graphics.Texture
|
||||||
{
|
{
|
||||||
size = (sizeInBlockOfGobs + 1) * blockOfGobsSize;
|
size = (sizeInBlockOfGobs + 1) * blockOfGobsSize;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int alignment = (gobBlocksInTileX * GobSize) * gobBlocksInY * gobBlocksInZ;
|
||||||
|
|
||||||
|
size = BitUtils.AlignUp(size, alignment);
|
||||||
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
@ -164,12 +187,22 @@ namespace Ryujinx.Graphics.Texture
|
||||||
width = BitUtils.DivRoundUp(width, blockWidth);
|
width = BitUtils.DivRoundUp(width, blockWidth);
|
||||||
height = BitUtils.DivRoundUp(height, blockHeight);
|
height = BitUtils.DivRoundUp(height, blockHeight);
|
||||||
|
|
||||||
int gobWidth = gobBlocksInTileX * (GobStride / bytesPerPixel);
|
int gobWidth = (GobStride / bytesPerPixel) * gobBlocksInTileX;
|
||||||
|
int gobHeight = gobBlocksInY * GobHeight;
|
||||||
|
|
||||||
|
int alignment = gobWidth;
|
||||||
|
|
||||||
|
if (depth < gobBlocksInZ || width <= gobWidth || height <= gobHeight)
|
||||||
|
{
|
||||||
|
alignment = GobStride / bytesPerPixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
(gobBlocksInY, gobBlocksInZ) = GetMipGobBlockSizes(height, depth, blockHeight, gobBlocksInY, gobBlocksInZ);
|
||||||
|
|
||||||
int blockOfGobsHeight = gobBlocksInY * GobHeight;
|
int blockOfGobsHeight = gobBlocksInY * GobHeight;
|
||||||
int blockOfGobsDepth = gobBlocksInZ;
|
int blockOfGobsDepth = gobBlocksInZ;
|
||||||
|
|
||||||
width = BitUtils.AlignUp(width, gobWidth);
|
width = BitUtils.AlignUp(width, alignment);
|
||||||
height = BitUtils.AlignUp(height, blockOfGobsHeight);
|
height = BitUtils.AlignUp(height, blockOfGobsHeight);
|
||||||
depth = BitUtils.AlignUp(depth, blockOfGobsDepth);
|
depth = BitUtils.AlignUp(depth, blockOfGobsDepth);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue