aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2021-01-15 15:14:00 -0300
committerGitHub <noreply@github.com>2021-01-15 19:14:00 +0100
commit3bad321d2b0994cd19129bc18ed98bb3ab81c3b0 (patch)
tree0c1c3610b7b0b42a2be3f797baf46ce42986a98b /Ryujinx.Graphics.Gpu/Image/TextureInfo.cs
parent1e5b37c94f870dc3faa94fb2d095cfa39fecb2a3 (diff)
Fix mipmap base level being ignored for sampled textures and images (#1911)
* Fix mipmap base level being ignored for sampled textures and images * Fix layer size and max level for textures * Missing XML doc + reorder comments
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Image/TextureInfo.cs')
-rw-r--r--Ryujinx.Graphics.Gpu/Image/TextureInfo.cs76
1 files changed, 70 insertions, 6 deletions
diff --git a/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs b/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs
index 2bcafd72..d27194b8 100644
--- a/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs
+++ b/Ryujinx.Graphics.Gpu/Image/TextureInfo.cs
@@ -1,4 +1,5 @@
using Ryujinx.Graphics.GAL;
+using Ryujinx.Graphics.Texture;
namespace Ryujinx.Graphics.Gpu.Image
{
@@ -92,14 +93,17 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Texture swizzle for the red color channel.
/// </summary>
public SwizzleComponent SwizzleR { get; }
+
/// <summary>
/// Texture swizzle for the green color channel.
/// </summary>
public SwizzleComponent SwizzleG { get; }
+
/// <summary>
/// Texture swizzle for the blue color channel.
/// </summary>
public SwizzleComponent SwizzleB { get; }
+
/// <summary>
/// Texture swizzle for the alpha color channel.
/// </summary>
@@ -176,7 +180,19 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>Texture depth</returns>
public int GetDepth()
{
- return Target == Target.Texture3D ? DepthOrLayers : 1;
+ return GetDepth(Target, DepthOrLayers);
+ }
+
+ /// <summary>
+ /// Gets the real texture depth.
+ /// Returns 1 for any target other than 3D textures.
+ /// </summary>
+ /// <param name="target">Texture target</param>
+ /// <param name="depthOrLayers">Texture depth if the texture is 3D, otherwise ignored</param>
+ /// <returns>Texture depth</returns>
+ public static int GetDepth(Target target, int depthOrLayers)
+ {
+ return target == Target.Texture3D ? depthOrLayers : 1;
}
/// <summary>
@@ -186,15 +202,27 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>The number of texture layers</returns>
public int GetLayers()
{
- if (Target == Target.Texture2DArray || Target == Target.Texture2DMultisampleArray)
+ return GetLayers(Target, DepthOrLayers);
+ }
+
+ /// <summary>
+ /// Gets the number of layers of the texture.
+ /// Returns 1 for non-array textures, 6 for cubemap textures, and layer faces for cubemap array textures.
+ /// </summary>
+ /// <param name="target">Texture target</param>
+ /// <param name="depthOrLayers">Texture layers if the is a array texture, ignored otherwise</param>
+ /// <returns>The number of texture layers</returns>
+ public static int GetLayers(Target target, int depthOrLayers)
+ {
+ if (target == Target.Texture2DArray || target == Target.Texture2DMultisampleArray)
{
- return DepthOrLayers;
+ return depthOrLayers;
}
- else if (Target == Target.CubemapArray)
+ else if (target == Target.CubemapArray)
{
- return DepthOrLayers * 6;
+ return depthOrLayers * 6;
}
- else if (Target == Target.Cubemap)
+ else if (target == Target.Cubemap)
{
return 6;
}
@@ -203,5 +231,41 @@ namespace Ryujinx.Graphics.Gpu.Image
return 1;
}
}
+
+ /// <summary>
+ /// Calculates the size information from the texture information.
+ /// </summary>
+ /// <param name="layerSize">Optional size of each texture layer in bytes</param>
+ /// <returns>Texture size information</returns>
+ public SizeInfo CalculateSizeInfo(int layerSize = 0)
+ {
+ if (Target == Target.TextureBuffer)
+ {
+ return new SizeInfo(Width * FormatInfo.BytesPerPixel);
+ }
+ else if (IsLinear)
+ {
+ return SizeCalculator.GetLinearTextureSize(
+ Stride,
+ Height,
+ FormatInfo.BlockHeight);
+ }
+ else
+ {
+ return SizeCalculator.GetBlockLinearTextureSize(
+ Width,
+ Height,
+ GetDepth(),
+ Levels,
+ GetLayers(),
+ FormatInfo.BlockWidth,
+ FormatInfo.BlockHeight,
+ FormatInfo.BytesPerPixel,
+ GobBlocksInY,
+ GobBlocksInZ,
+ GobBlocksInTileX,
+ layerSize);
+ }
+ }
}
} \ No newline at end of file