From c2d9c6955d8fc1331a6b2b94a308af0da7ce54f1 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 4 Sep 2023 20:14:08 -0300 Subject: [PATCH] Fix layer size for 3D textures with NPOT depth (#5640) --- .../SizeCalculator.cs | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Ryujinx.Graphics.Texture/SizeCalculator.cs b/src/Ryujinx.Graphics.Texture/SizeCalculator.cs index 7fe89e7e..e6122a6c 100644 --- a/src/Ryujinx.Graphics.Texture/SizeCalculator.cs +++ b/src/Ryujinx.Graphics.Texture/SizeCalculator.cs @@ -38,6 +38,7 @@ namespace Ryujinx.Graphics.Texture bool is3D = depth > 1 || gobBlocksInZ > 1; int layerSize = 0; + int layerSizeAligned = 0; int[] allOffsets = new int[is3D ? Calculate3DOffsetCount(levels, depth) : levels * layers * depth]; int[] mipOffsets = new int[levels]; @@ -91,6 +92,8 @@ namespace Ryujinx.Graphics.Texture sliceSizes[level] = totalBlocksOfGobsInY * robSize; levelSizes[level] = totalBlocksOfGobsInZ * sliceSizes[level]; + layerSizeAligned += levelSizes[level]; + if (is3D) { int gobSize = mipGobBlocksInY * GobSize; @@ -130,28 +133,32 @@ namespace Ryujinx.Graphics.Texture depthLevelOffset += d; } + int totalSize; + if (layers > 1) { - layerSize = AlignLayerSize( - layerSize, + layerSizeAligned = AlignLayerSize( + layerSizeAligned, height, depth, blockHeight, gobBlocksInY, gobBlocksInZ, gobBlocksInTileX); - } - int totalSize; - - if (layerSize < gpuLayerSize) - { - totalSize = (layers - 1) * gpuLayerSize + layerSize; - layerSize = gpuLayerSize; + if (layerSizeAligned < gpuLayerSize) + { + totalSize = (layers - 1) * gpuLayerSize + layerSizeAligned; + layerSizeAligned = gpuLayerSize; + } + else + { + totalSize = layerSizeAligned * layers; + } } else { - totalSize = layerSize * layers; + totalSize = layerSize; } if (!is3D) @@ -159,7 +166,7 @@ namespace Ryujinx.Graphics.Texture for (int layer = 0; layer < layers; layer++) { int baseIndex = layer * levels; - int baseOffset = layer * layerSize; + int baseOffset = layer * layerSizeAligned; 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)