mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-12-19 05:15:55 +01:00
7c989f88bd
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0052 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA1069 warnings * Address remaining dotnet format analyzer warnings * Address review comments * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Revert formatting changes for while and for-loops * Another rebase, another dotnet format run * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Disable 'prefer switch expression' rule * Add comments to disabled warnings * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Start working on disabled warnings * Address IDE0251 warnings * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Address review feedback * Add trailing commas * Remove SuppressMessage for IDE0066 * Make explicit Equals implementation implicit
180 lines
5.2 KiB
C#
180 lines
5.2 KiB
C#
using Ryujinx.Common;
|
|
using System;
|
|
using System.Numerics;
|
|
|
|
namespace Ryujinx.Graphics.GAL
|
|
{
|
|
public readonly struct TextureCreateInfo : IEquatable<TextureCreateInfo>
|
|
{
|
|
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;
|
|
}
|
|
|
|
public int GetMipSize(int level)
|
|
{
|
|
return GetMipStride(level) * GetLevelHeight(level) * GetLevelDepth(level);
|
|
}
|
|
|
|
public int GetMipSize2D(int level)
|
|
{
|
|
return GetMipStride(level) * GetLevelHeight(level);
|
|
}
|
|
|
|
public int GetMipStride(int level)
|
|
{
|
|
return BitUtils.AlignUp(GetLevelWidth(level) * BytesPerPixel, 4);
|
|
}
|
|
|
|
private int GetLevelWidth(int level)
|
|
{
|
|
return BitUtils.DivRoundUp(GetLevelSize(Width, level), BlockWidth);
|
|
}
|
|
|
|
private int GetLevelHeight(int level)
|
|
{
|
|
return BitUtils.DivRoundUp(GetLevelSize(Height, level), BlockHeight);
|
|
}
|
|
|
|
private int GetLevelDepth(int level)
|
|
{
|
|
return Target == Target.Texture3D ? GetLevelSize(Depth, level) : GetLayers();
|
|
}
|
|
|
|
public int GetDepthOrLayers()
|
|
{
|
|
return Target == Target.Texture3D ? Depth : GetLayers();
|
|
}
|
|
|
|
public int GetLayers()
|
|
{
|
|
if (Target == Target.Texture2DArray ||
|
|
Target == Target.Texture2DMultisampleArray ||
|
|
Target == Target.CubemapArray)
|
|
{
|
|
return Depth;
|
|
}
|
|
else if (Target == Target.Cubemap)
|
|
{
|
|
return 6;
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
public 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);
|
|
}
|
|
|
|
private static int GetLevelSize(int size, int level)
|
|
{
|
|
return Math.Max(1, size >> level);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(Width, Height);
|
|
}
|
|
|
|
public bool 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;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return obj is TextureCreateInfo info && this.Equals(info);
|
|
}
|
|
|
|
public static bool operator ==(TextureCreateInfo left, TextureCreateInfo right)
|
|
{
|
|
return left.Equals(right);
|
|
}
|
|
|
|
public static bool operator !=(TextureCreateInfo left, TextureCreateInfo right)
|
|
{
|
|
return !(left == right);
|
|
}
|
|
}
|
|
}
|