diff options
Diffstat (limited to 'src/Ryujinx.Graphics.Texture/SizeCalculator.cs')
-rw-r--r-- | src/Ryujinx.Graphics.Texture/SizeCalculator.cs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/Ryujinx.Graphics.Texture/SizeCalculator.cs b/src/Ryujinx.Graphics.Texture/SizeCalculator.cs index 5568784f..4ddd8d4d 100644 --- a/src/Ryujinx.Graphics.Texture/SizeCalculator.cs +++ b/src/Ryujinx.Graphics.Texture/SizeCalculator.cs @@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.Texture int gobBlocksInTileX, int gpuLayerSize = 0) { - bool is3D = depth > 1; + bool is3D = depth > 1 || gobBlocksInZ > 1; int layerSize = 0; @@ -67,7 +67,7 @@ namespace Ryujinx.Graphics.Texture mipGobBlocksInY >>= 1; } - while (d <= (mipGobBlocksInZ >> 1) && mipGobBlocksInZ != 1) + if (level > 0 && d <= (mipGobBlocksInZ >> 1) && mipGobBlocksInZ != 1) { mipGobBlocksInZ >>= 1; } @@ -88,6 +88,9 @@ namespace Ryujinx.Graphics.Texture int robSize = widthInGobs * mipGobBlocksInY * mipGobBlocksInZ * GobSize; + mipOffsets[level] = layerSize; + sliceSizes[level] = totalBlocksOfGobsInY * robSize; + if (is3D) { int gobSize = mipGobBlocksInY * GobSize; @@ -105,10 +108,18 @@ namespace Ryujinx.Graphics.Texture allOffsets[z + depthLevelOffset] = baseOffset + zLow * gobSize + zHigh * sliceSize; } + + int gobRemainderZ = d % mipGobBlocksInZ; + + if (gobRemainderZ != 0 && level == levels - 1) + { + // The slice only covers up to the end of this slice's depth, rather than the full aligned size. + // Avoids size being too large on partial views of 3d textures. + + sliceSizes[level] -= gobSize * (mipGobBlocksInZ - gobRemainderZ); + } } - mipOffsets[level] = layerSize; - sliceSizes[level] = totalBlocksOfGobsInY * robSize; levelSizes[level] = totalBlocksOfGobsInZ * sliceSizes[level]; layerSize += levelSizes[level]; @@ -267,7 +278,8 @@ namespace Ryujinx.Graphics.Texture int depth, int blockHeight, int gobBlocksInY, - int gobBlocksInZ) + int gobBlocksInZ, + int level = int.MaxValue) { height = BitUtils.DivRoundUp(height, blockHeight); @@ -276,7 +288,7 @@ namespace Ryujinx.Graphics.Texture gobBlocksInY >>= 1; } - while (depth <= (gobBlocksInZ >> 1) && gobBlocksInZ != 1) + while (level-- > 0 && depth <= (gobBlocksInZ >> 1) && gobBlocksInZ != 1) { gobBlocksInZ >>= 1; } |