2019-10-13 08:02:07 +02:00
|
|
|
using Ryujinx.Common;
|
|
|
|
using System;
|
2021-11-04 00:58:24 +01:00
|
|
|
using System.Numerics;
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2019-12-29 18:41:50 +01:00
|
|
|
namespace Ryujinx.Graphics.GAL
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2020-09-10 21:44:04 +02:00
|
|
|
public struct TextureCreateInfo : IEquatable<TextureCreateInfo>
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
public int Width { get; }
|
|
|
|
public int Height { get; }
|
|
|
|
public int Depth { get; }
|
|
|
|
public int Levels { get; }
|
|
|
|
public int Samples { get; }
|
|
|
|
public int BlockWidth { get; }
|
|
|
|
public int BlockHeight { get; }
|
|
|
|
public int BytesPerPixel { get; }
|
|
|
|
|
|
|
|
public bool IsCompressed => (BlockWidth | BlockHeight) != 1;
|
|
|
|
|
|
|
|
public Format Format { get; }
|
|
|
|
|
|
|
|
public DepthStencilMode DepthStencilMode { get; }
|
|
|
|
|
|
|
|
public Target Target { get; }
|
|
|
|
|
|
|
|
public SwizzleComponent SwizzleR { get; }
|
|
|
|
public SwizzleComponent SwizzleG { get; }
|
|
|
|
public SwizzleComponent SwizzleB { get; }
|
|
|
|
public SwizzleComponent SwizzleA { get; }
|
|
|
|
|
|
|
|
public TextureCreateInfo(
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int depth,
|
|
|
|
int levels,
|
|
|
|
int samples,
|
|
|
|
int blockWidth,
|
|
|
|
int blockHeight,
|
|
|
|
int bytesPerPixel,
|
|
|
|
Format format,
|
|
|
|
DepthStencilMode depthStencilMode,
|
|
|
|
Target target,
|
|
|
|
SwizzleComponent swizzleR,
|
|
|
|
SwizzleComponent swizzleG,
|
|
|
|
SwizzleComponent swizzleB,
|
|
|
|
SwizzleComponent swizzleA)
|
|
|
|
{
|
|
|
|
Width = width;
|
|
|
|
Height = height;
|
|
|
|
Depth = depth;
|
|
|
|
Levels = levels;
|
|
|
|
Samples = samples;
|
|
|
|
BlockWidth = blockWidth;
|
|
|
|
BlockHeight = blockHeight;
|
|
|
|
BytesPerPixel = bytesPerPixel;
|
|
|
|
Format = format;
|
|
|
|
DepthStencilMode = depthStencilMode;
|
|
|
|
Target = target;
|
|
|
|
SwizzleR = swizzleR;
|
|
|
|
SwizzleG = swizzleG;
|
|
|
|
SwizzleB = swizzleB;
|
|
|
|
SwizzleA = swizzleA;
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
public readonly int GetMipSize(int level)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
return GetMipStride(level) * GetLevelHeight(level) * GetLevelDepth(level);
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
public readonly int GetMipSize2D(int level)
|
2019-12-05 21:34:47 +01:00
|
|
|
{
|
|
|
|
return GetMipStride(level) * GetLevelHeight(level);
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
public readonly int GetMipStride(int level)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
return BitUtils.AlignUp(GetLevelWidth(level) * BytesPerPixel, 4);
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
private readonly int GetLevelWidth(int level)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
return BitUtils.DivRoundUp(GetLevelSize(Width, level), BlockWidth);
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
private readonly int GetLevelHeight(int level)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
return BitUtils.DivRoundUp(GetLevelSize(Height, level), BlockHeight);
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
private readonly int GetLevelDepth(int level)
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
return Target == Target.Texture3D ? GetLevelSize(Depth, level) : GetLayers();
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
public readonly int GetDepthOrLayers()
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
return Target == Target.Texture3D ? Depth : GetLayers();
|
|
|
|
}
|
|
|
|
|
2020-01-06 23:27:50 +01:00
|
|
|
public readonly int GetLayers()
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
if (Target == Target.Texture2DArray ||
|
|
|
|
Target == Target.Texture2DMultisampleArray ||
|
|
|
|
Target == Target.CubemapArray)
|
|
|
|
{
|
|
|
|
return Depth;
|
|
|
|
}
|
|
|
|
else if (Target == Target.Cubemap)
|
|
|
|
{
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-11-04 00:58:24 +01:00
|
|
|
public readonly int GetLevelsClamped()
|
|
|
|
{
|
|
|
|
int maxSize = Width;
|
|
|
|
|
|
|
|
if (Target != Target.Texture1D &&
|
|
|
|
Target != Target.Texture1DArray)
|
|
|
|
{
|
|
|
|
maxSize = Math.Max(maxSize, Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Target == Target.Texture3D)
|
|
|
|
{
|
|
|
|
maxSize = Math.Max(maxSize, Depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
int maxLevels = BitOperations.Log2((uint)maxSize) + 1;
|
|
|
|
return Math.Min(Levels, maxLevels);
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
private static int GetLevelSize(int size, int level)
|
|
|
|
{
|
|
|
|
return Math.Max(1, size >> level);
|
|
|
|
}
|
2020-09-10 21:44:04 +02:00
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return HashCode.Combine(Width, Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IEquatable<TextureCreateInfo>.Equals(TextureCreateInfo other)
|
|
|
|
{
|
|
|
|
return Width == other.Width &&
|
|
|
|
Height == other.Height &&
|
|
|
|
Depth == other.Depth &&
|
|
|
|
Levels == other.Levels &&
|
|
|
|
Samples == other.Samples &&
|
|
|
|
BlockWidth == other.BlockWidth &&
|
|
|
|
BlockHeight == other.BlockHeight &&
|
|
|
|
BytesPerPixel == other.BytesPerPixel &&
|
|
|
|
Format == other.Format &&
|
|
|
|
DepthStencilMode == other.DepthStencilMode &&
|
|
|
|
Target == other.Target &&
|
|
|
|
SwizzleR == other.SwizzleR &&
|
|
|
|
SwizzleG == other.SwizzleG &&
|
|
|
|
SwizzleB == other.SwizzleB &&
|
|
|
|
SwizzleA == other.SwizzleA;
|
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
}
|