Fix layer size for 3D textures with NPOT depth (#5640)

This commit is contained in:
gdkchan 2023-09-04 20:14:08 -03:00 committed by GitHub
parent fbe0c211c1
commit c2d9c6955d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,7 @@ namespace Ryujinx.Graphics.Texture
bool is3D = depth > 1 || gobBlocksInZ > 1; bool is3D = depth > 1 || gobBlocksInZ > 1;
int layerSize = 0; int layerSize = 0;
int layerSizeAligned = 0;
int[] allOffsets = new int[is3D ? Calculate3DOffsetCount(levels, depth) : levels * layers * depth]; int[] allOffsets = new int[is3D ? Calculate3DOffsetCount(levels, depth) : levels * layers * depth];
int[] mipOffsets = new int[levels]; int[] mipOffsets = new int[levels];
@ -91,6 +92,8 @@ namespace Ryujinx.Graphics.Texture
sliceSizes[level] = totalBlocksOfGobsInY * robSize; sliceSizes[level] = totalBlocksOfGobsInY * robSize;
levelSizes[level] = totalBlocksOfGobsInZ * sliceSizes[level]; levelSizes[level] = totalBlocksOfGobsInZ * sliceSizes[level];
layerSizeAligned += levelSizes[level];
if (is3D) if (is3D)
{ {
int gobSize = mipGobBlocksInY * GobSize; int gobSize = mipGobBlocksInY * GobSize;
@ -130,28 +133,32 @@ namespace Ryujinx.Graphics.Texture
depthLevelOffset += d; depthLevelOffset += d;
} }
int totalSize;
if (layers > 1) if (layers > 1)
{ {
layerSize = AlignLayerSize( layerSizeAligned = AlignLayerSize(
layerSize, layerSizeAligned,
height, height,
depth, depth,
blockHeight, blockHeight,
gobBlocksInY, gobBlocksInY,
gobBlocksInZ, gobBlocksInZ,
gobBlocksInTileX); gobBlocksInTileX);
}
int totalSize; if (layerSizeAligned < gpuLayerSize)
{
if (layerSize < gpuLayerSize) totalSize = (layers - 1) * gpuLayerSize + layerSizeAligned;
{ layerSizeAligned = gpuLayerSize;
totalSize = (layers - 1) * gpuLayerSize + layerSize; }
layerSize = gpuLayerSize; else
{
totalSize = layerSizeAligned * layers;
}
} }
else else
{ {
totalSize = layerSize * layers; totalSize = layerSize;
} }
if (!is3D) if (!is3D)
@ -159,7 +166,7 @@ namespace Ryujinx.Graphics.Texture
for (int layer = 0; layer < layers; layer++) for (int layer = 0; layer < layers; layer++)
{ {
int baseIndex = layer * levels; int baseIndex = layer * levels;
int baseOffset = layer * layerSize; int baseOffset = layer * layerSizeAligned;
for (int level = 0; level < levels; level++) for (int level = 0; level < levels; level++)
{ {
@ -168,7 +175,7 @@ namespace Ryujinx.Graphics.Texture
} }
} }
return new SizeInfo(mipOffsets, allOffsets, sliceSizes, levelSizes, depth, levels, layerSize, totalSize, is3D); return new SizeInfo(mipOffsets, allOffsets, sliceSizes, levelSizes, depth, levels, layerSizeAligned, totalSize, is3D);
} }
public static SizeInfo GetLinearTextureSize(int stride, int height, int blockHeight) public static SizeInfo GetLinearTextureSize(int stride, int height, int blockHeight)