[Ryujinx.Graphics.Gpu] Address dotnet-format issues (#5367)

* 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 IDE0060 warnings

* Silence dotnet format IDE0052 warnings

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA1069 warnings

* Address or silence dotnet format CA2211 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

* Format if-blocks correctly

* Run dotnet format whitespace after rebase

* Run dotnet format style after rebase

* Another rebase, another dotnet format run

* Run dotnet format style after rebase

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Disable 'prefer switch expression' rule

* Add comments to disabled warnings

* Remove a few unused parameters

* Replace MmeShadowScratch with Array256<uint>

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Start working on disabled warnings

* Fix and silence a few dotnet-format warnings again

* Run dotnet format after rebase

* Address IDE0251 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First pass of dotnet format

* Add unsafe dotnet format changes

* Fix typos

* Add trailing commas

* Disable formatting for FormatTable

* Address review feedback
This commit is contained in:
TSRBerry 2023-07-02 02:47:54 +02:00 committed by GitHub
parent 2457cfc911
commit 3b46bb73f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
145 changed files with 1445 additions and 1427 deletions

View file

@ -54,7 +54,7 @@ namespace Ryujinx.Graphics.Gpu.Image
private HashSet<ShortTextureCacheEntry> _shortCacheBuilder;
private HashSet<ShortTextureCacheEntry> _shortCache;
private Dictionary<TextureDescriptor, ShortTextureCacheEntry> _shortCacheLookup;
private readonly Dictionary<TextureDescriptor, ShortTextureCacheEntry> _shortCacheLookup;
/// <summary>
/// Creates a new instance of the automatic deletion cache.
@ -295,4 +295,4 @@ namespace Ryujinx.Graphics.Gpu.Image
return _textures.GetEnumerator();
}
}
}
}

View file

@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <summary>
/// A default, generic RGBA8 texture format.
/// </summary>
public static FormatInfo Default { get; } = new FormatInfo(Format.R8G8B8A8Unorm, 1, 1, 4, 4);
public static FormatInfo Default { get; } = new(Format.R8G8B8A8Unorm, 1, 1, 4, 4);
/// <summary>
/// The format of the texture data.
@ -57,16 +57,16 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="bytesPerPixel">The number of bytes occupied by a single pixel in memory of the texture data</param>
public FormatInfo(
Format format,
int blockWidth,
int blockHeight,
int bytesPerPixel,
int components)
int blockWidth,
int blockHeight,
int bytesPerPixel,
int components)
{
Format = format;
BlockWidth = blockWidth;
BlockHeight = blockHeight;
Format = format;
BlockWidth = blockWidth;
BlockHeight = blockHeight;
BytesPerPixel = bytesPerPixel;
Components = components;
Components = components;
}
}
}
}

View file

@ -1,5 +1,6 @@
using Ryujinx.Graphics.GAL;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.Graphics.Gpu.Image
{
@ -8,6 +9,8 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
static class FormatTable
{
#pragma warning disable IDE0055 // Disable formatting
[SuppressMessage("Design", "CA1069: Enums values should not be duplicated")]
private enum TextureFormat : uint
{
// Formats
@ -244,6 +247,7 @@ namespace Ryujinx.Graphics.Gpu.Image
A5B5G5R1Unorm = A5B5G5R1 | RUnorm | GUnorm | BUnorm | AUnorm, // 0x24913
}
[SuppressMessage("Design", "CA1069: Enums values should not be duplicated")]
private enum VertexAttributeFormat : uint
{
// Width
@ -357,7 +361,7 @@ namespace Ryujinx.Graphics.Gpu.Image
A2B10G10R10Sscaled = (A2B10G10R10 << 21) | (Sscaled << 27), // 0x36000000
}
private static readonly Dictionary<TextureFormat, FormatInfo> _textureFormats = new Dictionary<TextureFormat, FormatInfo>()
private static readonly Dictionary<TextureFormat, FormatInfo> _textureFormats = new()
{
{ TextureFormat.R8Unorm, new FormatInfo(Format.R8Unorm, 1, 1, 1, 1) },
{ TextureFormat.R8Snorm, new FormatInfo(Format.R8Snorm, 1, 1, 1, 1) },
@ -464,10 +468,10 @@ namespace Ryujinx.Graphics.Gpu.Image
{ TextureFormat.Astc2D10x10UnormSrgb, new FormatInfo(Format.Astc10x10Srgb, 10, 10, 16, 4) },
{ TextureFormat.Astc2D12x10UnormSrgb, new FormatInfo(Format.Astc12x10Srgb, 12, 10, 16, 4) },
{ TextureFormat.Astc2D12x12UnormSrgb, new FormatInfo(Format.Astc12x12Srgb, 12, 12, 16, 4) },
{ TextureFormat.A5B5G5R1Unorm, new FormatInfo(Format.A1B5G5R5Unorm, 1, 1, 2, 4) }
{ TextureFormat.A5B5G5R1Unorm, new FormatInfo(Format.A1B5G5R5Unorm, 1, 1, 2, 4) },
};
private static readonly Dictionary<VertexAttributeFormat, Format> _attribFormats = new Dictionary<VertexAttributeFormat, Format>()
private static readonly Dictionary<VertexAttributeFormat, Format> _attribFormats = new()
{
{ VertexAttributeFormat.R8Unorm, Format.R8Unorm },
{ VertexAttributeFormat.R8Snorm, Format.R8Snorm },
@ -547,8 +551,9 @@ namespace Ryujinx.Graphics.Gpu.Image
{ VertexAttributeFormat.A2B10G10R10Snorm, Format.R10G10B10A2Snorm },
{ VertexAttributeFormat.A2B10G10R10Sint, Format.R10G10B10A2Sint },
{ VertexAttributeFormat.A2B10G10R10Uscaled, Format.R10G10B10A2Uscaled },
{ VertexAttributeFormat.A2B10G10R10Sscaled, Format.R10G10B10A2Sscaled }
{ VertexAttributeFormat.A2B10G10R10Sscaled, Format.R10G10B10A2Sscaled },
};
#pragma warning restore IDE0055
/// <summary>
/// Try getting the texture format from an encoded format integer from the Maxwell texture descriptor.
@ -575,4 +580,4 @@ namespace Ryujinx.Graphics.Gpu.Image
return _attribFormats.TryGetValue((VertexAttributeFormat)encoded, out format);
}
}
}
}

View file

@ -67,7 +67,7 @@ namespace Ryujinx.Graphics.Gpu.Image
DescriptorCache = new T2[count];
Address = address;
Size = size;
Size = size;
_memoryTracking = physicalMemory.BeginGranularTracking(address, size, ResourceKind.Pool);
_memoryTracking.RegisterPreciseAction(address, size, PreciseAction);
@ -219,4 +219,4 @@ namespace Ryujinx.Graphics.Gpu.Image
_memoryTracking.Dispose();
}
}
}
}

View file

@ -126,4 +126,4 @@ namespace Ryujinx.Graphics.Gpu.Image
_pools.Clear();
}
}
}
}

View file

@ -10,6 +10,6 @@ namespace Ryujinx.Graphics.Gpu.Image
{
Average,
Minimum,
Maximum
Maximum,
}
}

View file

@ -40,16 +40,16 @@ namespace Ryujinx.Graphics.Gpu.Image
AddressMode addressP = descriptor.UnpackAddressP();
CompareMode compareMode = descriptor.UnpackCompareMode();
CompareOp compareOp = descriptor.UnpackCompareOp();
CompareOp compareOp = descriptor.UnpackCompareOp();
ColorF color = new ColorF(
ColorF color = new(
descriptor.BorderColorR,
descriptor.BorderColorG,
descriptor.BorderColorB,
descriptor.BorderColorA);
float minLod = descriptor.UnpackMinLod();
float maxLod = descriptor.UnpackMaxLod();
float minLod = descriptor.UnpackMinLod();
float maxLod = descriptor.UnpackMaxLod();
float mipLodBias = descriptor.UnpackMipLodBias();
float maxRequestedAnisotropy = descriptor.UnpackMaxAnisotropy();
@ -112,4 +112,4 @@ namespace Ryujinx.Graphics.Gpu.Image
_anisoSampler?.Dispose();
}
}
}
}

View file

@ -43,17 +43,17 @@ namespace Ryujinx.Graphics.Gpu.Image
0.45833334f,
0.46153846f,
0.4642857f,
0.46666667f
0.46666667f,
};
private static readonly float[] _maxAnisotropyLut = new float[]
{
1, 2, 4, 6, 8, 10, 12, 16
1, 2, 4, 6, 8, 10, 12, 16,
};
private const float Frac8ToF32 = 1.0f / 256.0f;
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public uint Word0;
public uint Word1;
public uint Word2;
@ -68,7 +68,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the texture wrap mode along the X axis.
/// </summary>
/// <returns>The texture wrap mode enum</returns>
public AddressMode UnpackAddressU()
public readonly AddressMode UnpackAddressU()
{
return (AddressMode)(Word0 & 7);
}
@ -77,7 +77,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the texture wrap mode along the Y axis.
/// </summary>
/// <returns>The texture wrap mode enum</returns>
public AddressMode UnpackAddressV()
public readonly AddressMode UnpackAddressV()
{
return (AddressMode)((Word0 >> 3) & 7);
}
@ -86,7 +86,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the texture wrap mode along the Z axis.
/// </summary>
/// <returns>The texture wrap mode enum</returns>
public AddressMode UnpackAddressP()
public readonly AddressMode UnpackAddressP()
{
return (AddressMode)((Word0 >> 6) & 7);
}
@ -97,7 +97,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// This is only relevant for shaders with shadow samplers.
/// </summary>
/// <returns>The depth comparison mode enum</returns>
public CompareMode UnpackCompareMode()
public readonly CompareMode UnpackCompareMode()
{
return (CompareMode)((Word0 >> 9) & 1);
}
@ -108,7 +108,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// This is only relevant for shaders with shadow samplers.
/// </summary>
/// <returns>The depth comparison operation enum</returns>
public CompareOp UnpackCompareOp()
public readonly CompareOp UnpackCompareOp()
{
return (CompareOp)(((Word0 >> 10) & 7) + 1);
}
@ -117,7 +117,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks and converts the maximum anisotropy value used for texture anisotropic filtering.
/// </summary>
/// <returns>The maximum anisotropy</returns>
public float UnpackMaxAnisotropy()
public readonly float UnpackMaxAnisotropy()
{
return _maxAnisotropyLut[(Word0 >> 20) & 7];
}
@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// that is larger than the texture size.
/// </summary>
/// <returns>The magnification filter</returns>
public MagFilter UnpackMagFilter()
public readonly MagFilter UnpackMagFilter()
{
return (MagFilter)(Word1 & 3);
}
@ -139,7 +139,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// that is smaller than the texture size.
/// </summary>
/// <returns>The minification filter</returns>
public MinFilter UnpackMinFilter()
public readonly MinFilter UnpackMinFilter()
{
SamplerMinFilter minFilter = (SamplerMinFilter)((Word1 >> 4) & 3);
SamplerMipFilter mipFilter = (SamplerMipFilter)((Word1 >> 6) & 3);
@ -161,24 +161,30 @@ namespace Ryujinx.Graphics.Gpu.Image
case SamplerMipFilter.None:
switch (minFilter)
{
case SamplerMinFilter.Nearest: return MinFilter.Nearest;
case SamplerMinFilter.Linear: return MinFilter.Linear;
case SamplerMinFilter.Nearest:
return MinFilter.Nearest;
case SamplerMinFilter.Linear:
return MinFilter.Linear;
}
break;
case SamplerMipFilter.Nearest:
switch (minFilter)
{
case SamplerMinFilter.Nearest: return MinFilter.NearestMipmapNearest;
case SamplerMinFilter.Linear: return MinFilter.LinearMipmapNearest;
case SamplerMinFilter.Nearest:
return MinFilter.NearestMipmapNearest;
case SamplerMinFilter.Linear:
return MinFilter.LinearMipmapNearest;
}
break;
case SamplerMipFilter.Linear:
switch (minFilter)
{
case SamplerMinFilter.Nearest: return MinFilter.NearestMipmapLinear;
case SamplerMinFilter.Linear: return MinFilter.LinearMipmapLinear;
case SamplerMinFilter.Nearest:
return MinFilter.NearestMipmapLinear;
case SamplerMinFilter.Linear:
return MinFilter.LinearMipmapLinear;
}
break;
}
@ -190,7 +196,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the seamless cubemap flag.
/// </summary>
/// <returns>The seamless cubemap flag</returns>
public bool UnpackSeamlessCubemap()
public readonly bool UnpackSeamlessCubemap()
{
return (Word1 & (1 << 9)) != 0;
}
@ -200,7 +206,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// This describes how the final value will be computed from neighbouring pixels.
/// </summary>
/// <returns>The reduction filter</returns>
public ReductionFilter UnpackReductionFilter()
public readonly ReductionFilter UnpackReductionFilter()
{
return (ReductionFilter)((Word1 >> 10) & 3);
}
@ -211,7 +217,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// which mipmap level to use from a given texture.
/// </summary>
/// <returns>The level-of-detail bias value</returns>
public float UnpackMipLodBias()
public readonly float UnpackMipLodBias()
{
int fixedValue = (int)(Word1 >> 12) & 0x1fff;
@ -224,7 +230,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the level-of-detail snap value.
/// </summary>
/// <returns>The level-of-detail snap value</returns>
public float UnpackLodSnap()
public readonly float UnpackLodSnap()
{
return _f5ToF32ConversionLut[(Word1 >> 26) & 0x1f];
}
@ -233,7 +239,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the minimum level-of-detail value.
/// </summary>
/// <returns>The minimum level-of-detail value</returns>
public float UnpackMinLod()
public readonly float UnpackMinLod()
{
return (Word2 & 0xfff) * Frac8ToF32;
}
@ -242,7 +248,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the maximum level-of-detail value.
/// </summary>
/// <returns>The maximum level-of-detail value</returns>
public float UnpackMaxLod()
public readonly float UnpackMaxLod()
{
return ((Word2 >> 12) & 0xfff) * Frac8ToF32;
}

View file

@ -6,6 +6,6 @@ namespace Ryujinx.Graphics.Gpu.Image
enum SamplerMinFilter
{
Nearest = 1,
Linear
Linear,
}
}

View file

@ -7,6 +7,6 @@ namespace Ryujinx.Graphics.Gpu.Image
{
None = 1,
Nearest,
Linear
Linear,
}
}

View file

@ -159,4 +159,4 @@ namespace Ryujinx.Graphics.Gpu.Image
item?.Dispose();
}
}
}
}

View file

@ -27,4 +27,4 @@ namespace Ryujinx.Graphics.Gpu.Image
return new SamplerPool(context, channel.MemoryManager.Physical, address, maximumId);
}
}
}
}

View file

@ -119,7 +119,7 @@ namespace Ryujinx.Graphics.Gpu.Image
private bool _modifiedStale = true;
private ITexture _arrayViewTexture;
private Target _arrayViewTarget;
private Target _arrayViewTarget;
private ITexture _flushHostTexture;
private ITexture _setHostTexture;
@ -334,7 +334,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>The child texture</returns>
public Texture CreateView(TextureInfo info, SizeInfo sizeInfo, MultiRange range, int firstLayer, int firstLevel)
{
Texture texture = new Texture(
Texture texture = new(
_context,
_physicalMemory,
info,
@ -523,7 +523,7 @@ namespace Ryujinx.Graphics.Gpu.Image
if (ScaleFactor != scale)
{
Logger.Debug?.Print(LogClass.Gpu, $"Rescaling {Info.Width}x{Info.Height} {Info.FormatInfo.Format.ToString()} to ({ScaleFactor} to {scale}). ");
Logger.Debug?.Print(LogClass.Gpu, $"Rescaling {Info.Width}x{Info.Height} {Info.FormatInfo.Format} to ({ScaleFactor} to {scale}). ");
ScaleFactor = scale;
@ -537,7 +537,7 @@ namespace Ryujinx.Graphics.Gpu.Image
foreach (var view in _views)
{
Logger.Debug?.Print(LogClass.Gpu, $" Recreating view {Info.Width}x{Info.Height} {Info.FormatInfo.Format.ToString()}.");
Logger.Debug?.Print(LogClass.Gpu, $" Recreating view {Info.Width}x{Info.Height} {Info.FormatInfo.Format}.");
view.ScaleFactor = scale;
TextureCreateInfo viewCreateInfo = TextureCache.GetCreateInfo(view.Info, _context.Capabilities, scale);
@ -1254,7 +1254,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
FormatInfo formatInfo = TextureCompatibility.ToHostCompatibleFormat(Info, _context.Capabilities);
TextureCreateInfo createInfo = new TextureCreateInfo(
TextureCreateInfo createInfo = new(
Info.Width,
Info.Height,
target == Target.CubemapArray ? 6 : 1,
@ -1274,7 +1274,7 @@ namespace Ryujinx.Graphics.Gpu.Image
ITexture viewTexture = HostTexture.CreateView(createInfo, 0, 0);
_arrayViewTexture = viewTexture;
_arrayViewTarget = target;
_arrayViewTarget = target;
return viewTexture;
}
@ -1317,29 +1317,21 @@ namespace Ryujinx.Graphics.Gpu.Image
{
case Target.Texture1D:
case Target.Texture1DArray:
return target == Target.Texture1D ||
target == Target.Texture1DArray;
return target == Target.Texture1D || target == Target.Texture1DArray;
case Target.Texture2D:
case Target.Texture2DArray:
return target == Target.Texture2D ||
target == Target.Texture2DArray;
return target == Target.Texture2D || target == Target.Texture2DArray;
case Target.Cubemap:
case Target.CubemapArray:
return target == Target.Cubemap ||
target == Target.CubemapArray;
return target == Target.Cubemap || target == Target.CubemapArray;
case Target.Texture2DMultisample:
case Target.Texture2DMultisampleArray:
return target == Target.Texture2DMultisample ||
target == Target.Texture2DMultisampleArray;
return target == Target.Texture2DMultisample || target == Target.Texture2DMultisampleArray;
case Target.Texture3D:
return target == Target.Texture3D;
default:
return false;
}
return false;
}
/// <summary>
@ -1398,7 +1390,7 @@ namespace Ryujinx.Graphics.Gpu.Image
Height = info.Height;
CanForceAnisotropy = CanTextureForceAnisotropy();
_depth = info.GetDepth();
_depth = info.GetDepth();
_layers = info.GetLayers();
}
@ -1714,4 +1706,4 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
}
}
}

View file

@ -50,12 +50,12 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="flags">The texture's usage flags, indicating how it is used in the shader</param>
public TextureBindingInfo(Target target, Format format, int binding, int cbufSlot, int handle, TextureUsageFlags flags)
{
Target = target;
Format = format;
Binding = binding;
Target = target;
Format = format;
Binding = binding;
CbufSlot = cbufSlot;
Handle = handle;
Flags = flags;
Handle = handle;
Flags = flags;
}
/// <summary>
@ -70,4 +70,4 @@ namespace Ryujinx.Graphics.Gpu.Image
{
}
}
}
}

View file

@ -93,10 +93,10 @@ namespace Ryujinx.Graphics.Gpu.Image
int stages = isCompute ? 1 : Constants.ShaderStages;
_textureBindings = new TextureBindingInfo[stages][];
_imageBindings = new TextureBindingInfo[stages][];
_imageBindings = new TextureBindingInfo[stages][];
_textureState = new TextureState[InitialTextureStateSize];
_imageState = new TextureState[InitialImageStateSize];
_imageState = new TextureState[InitialImageStateSize];
for (int stage = 0; stage < stages; stage++)
{
@ -418,6 +418,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
#pragma warning disable IDE0051 // Remove unused private member
/// <summary>
/// Counts the total number of texture bindings used by all shader stages.
/// </summary>
@ -426,16 +427,17 @@ namespace Ryujinx.Graphics.Gpu.Image
{
int count = 0;
for (int i = 0; i < _textureBindings.Length; i++)
foreach (TextureBindingInfo[] textureInfo in _textureBindings)
{
if (_textureBindings[i] != null)
if (textureInfo != null)
{
count += _textureBindings[i].Length;
count += textureInfo.Length;
}
}
return count;
}
#pragma warning restore IDE0051
/// <summary>
/// Ensures that the texture bindings are visible to the host GPU.

View file

@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
private const int OverlapsBufferInitialCapacity = 10;
private const int OverlapsBufferMaxCapacity = 10000;
private const int OverlapsBufferMaxCapacity = 10000;
private readonly GpuContext _context;
private readonly PhysicalMemory _physicalMemory;
@ -224,7 +224,7 @@ namespace Ryujinx.Graphics.Gpu.Image
for (int i = 0; i < overlapCount; i++)
{
var other = _textureOverlaps[i];
if (texture != other &&
(texture.IsViewCompatible(other.Info, other.Range, true, other.LayerSize, _context.Capabilities, out _, out _) != TextureViewCompatibility.Incompatible ||
other.IsViewCompatible(texture.Info, texture.Range, true, texture.LayerSize, _context.Capabilities, out _, out _) != TextureViewCompatibility.Incompatible))
@ -278,7 +278,7 @@ namespace Ryujinx.Graphics.Gpu.Image
width = copyTexture.Width;
}
TextureInfo info = new TextureInfo(
TextureInfo info = new(
copyTexture.Address.Pack() + offset,
GetMinimumWidthInGob(width, sizeHint.Width, formatInfo.BytesPerPixel, copyTexture.LinearLayout),
copyTexture.Height,
@ -371,16 +371,16 @@ namespace Ryujinx.Graphics.Gpu.Image
// so the width we get here is the aligned width.
if (isLinear)
{
width = colorState.WidthOrStride / formatInfo.BytesPerPixel;
width = colorState.WidthOrStride / formatInfo.BytesPerPixel;
stride = colorState.WidthOrStride;
}
else
{
width = colorState.WidthOrStride;
width = colorState.WidthOrStride;
stride = 0;
}
TextureInfo info = new TextureInfo(
TextureInfo info = new(
colorState.Address.Pack(),
GetMinimumWidthInGob(width, sizeHint.Width, formatInfo.BytesPerPixel, isLinear),
colorState.Height,
@ -449,7 +449,7 @@ namespace Ryujinx.Graphics.Gpu.Image
FormatInfo formatInfo = dsState.Format.Convert();
TextureInfo info = new TextureInfo(
TextureInfo info = new(
dsState.Address.Pack(),
GetMinimumWidthInGob(size.Width, sizeHint.Width, formatInfo.BytesPerPixel, false),
size.Height,
@ -1136,14 +1136,14 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
int width = info.Width / info.SamplesInX;
int width = info.Width / info.SamplesInX;
int height = info.Height / info.SamplesInY;
int depth = info.GetDepth() * info.GetLayers();
if (scale != 1f)
{
width = (int)MathF.Ceiling(width * scale);
width = (int)MathF.Ceiling(width * scale);
height = (int)MathF.Ceiling(height * scale);
}

View file

@ -35,7 +35,7 @@ namespace Ryujinx.Graphics.Gpu.Image
Astc10x8,
Astc10x10,
Astc12x10,
Astc12x12
Astc12x12,
}
/// <summary>
@ -629,7 +629,7 @@ namespace Ryujinx.Graphics.Gpu.Image
{
TextureMatchQuality.Perfect => TextureViewCompatibility.Full,
TextureMatchQuality.FormatAlias => TextureViewCompatibility.FormatAlias,
_ => TextureViewCompatibility.Incompatible
_ => TextureViewCompatibility.Incompatible,
};
}
@ -783,80 +783,33 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>Format class</returns>
private static FormatClass GetFormatClass(Format format)
{
switch (format)
return format switch
{
case Format.Bc1RgbaSrgb:
case Format.Bc1RgbaUnorm:
return FormatClass.Bc1Rgba;
case Format.Bc2Srgb:
case Format.Bc2Unorm:
return FormatClass.Bc2;
case Format.Bc3Srgb:
case Format.Bc3Unorm:
return FormatClass.Bc3;
case Format.Bc4Snorm:
case Format.Bc4Unorm:
return FormatClass.Bc4;
case Format.Bc5Snorm:
case Format.Bc5Unorm:
return FormatClass.Bc5;
case Format.Bc6HSfloat:
case Format.Bc6HUfloat:
return FormatClass.Bc6;
case Format.Bc7Srgb:
case Format.Bc7Unorm:
return FormatClass.Bc7;
case Format.Etc2RgbSrgb:
case Format.Etc2RgbUnorm:
return FormatClass.Etc2Rgb;
case Format.Etc2RgbaSrgb:
case Format.Etc2RgbaUnorm:
return FormatClass.Etc2Rgba;
case Format.Astc4x4Srgb:
case Format.Astc4x4Unorm:
return FormatClass.Astc4x4;
case Format.Astc5x4Srgb:
case Format.Astc5x4Unorm:
return FormatClass.Astc5x4;
case Format.Astc5x5Srgb:
case Format.Astc5x5Unorm:
return FormatClass.Astc5x5;
case Format.Astc6x5Srgb:
case Format.Astc6x5Unorm:
return FormatClass.Astc6x5;
case Format.Astc6x6Srgb:
case Format.Astc6x6Unorm:
return FormatClass.Astc6x6;
case Format.Astc8x5Srgb:
case Format.Astc8x5Unorm:
return FormatClass.Astc8x5;
case Format.Astc8x6Srgb:
case Format.Astc8x6Unorm:
return FormatClass.Astc8x6;
case Format.Astc8x8Srgb:
case Format.Astc8x8Unorm:
return FormatClass.Astc8x8;
case Format.Astc10x5Srgb:
case Format.Astc10x5Unorm:
return FormatClass.Astc10x5;
case Format.Astc10x6Srgb:
case Format.Astc10x6Unorm:
return FormatClass.Astc10x6;
case Format.Astc10x8Srgb:
case Format.Astc10x8Unorm:
return FormatClass.Astc10x8;
case Format.Astc10x10Srgb:
case Format.Astc10x10Unorm:
return FormatClass.Astc10x10;
case Format.Astc12x10Srgb:
case Format.Astc12x10Unorm:
return FormatClass.Astc12x10;
case Format.Astc12x12Srgb:
case Format.Astc12x12Unorm:
return FormatClass.Astc12x12;
}
return FormatClass.Unclassified;
Format.Bc1RgbaSrgb or Format.Bc1RgbaUnorm => FormatClass.Bc1Rgba,
Format.Bc2Srgb or Format.Bc2Unorm => FormatClass.Bc2,
Format.Bc3Srgb or Format.Bc3Unorm => FormatClass.Bc3,
Format.Bc4Snorm or Format.Bc4Unorm => FormatClass.Bc4,
Format.Bc5Snorm or Format.Bc5Unorm => FormatClass.Bc5,
Format.Bc6HSfloat or Format.Bc6HUfloat => FormatClass.Bc6,
Format.Bc7Srgb or Format.Bc7Unorm => FormatClass.Bc7,
Format.Etc2RgbSrgb or Format.Etc2RgbUnorm => FormatClass.Etc2Rgb,
Format.Etc2RgbaSrgb or Format.Etc2RgbaUnorm => FormatClass.Etc2Rgba,
Format.Astc4x4Srgb or Format.Astc4x4Unorm => FormatClass.Astc4x4,
Format.Astc5x4Srgb or Format.Astc5x4Unorm => FormatClass.Astc5x4,
Format.Astc5x5Srgb or Format.Astc5x5Unorm => FormatClass.Astc5x5,
Format.Astc6x5Srgb or Format.Astc6x5Unorm => FormatClass.Astc6x5,
Format.Astc6x6Srgb or Format.Astc6x6Unorm => FormatClass.Astc6x6,
Format.Astc8x5Srgb or Format.Astc8x5Unorm => FormatClass.Astc8x5,
Format.Astc8x6Srgb or Format.Astc8x6Unorm => FormatClass.Astc8x6,
Format.Astc8x8Srgb or Format.Astc8x8Unorm => FormatClass.Astc8x8,
Format.Astc10x5Srgb or Format.Astc10x5Unorm => FormatClass.Astc10x5,
Format.Astc10x6Srgb or Format.Astc10x6Unorm => FormatClass.Astc10x6,
Format.Astc10x8Srgb or Format.Astc10x8Unorm => FormatClass.Astc10x8,
Format.Astc10x10Srgb or Format.Astc10x10Unorm => FormatClass.Astc10x10,
Format.Astc12x10Srgb or Format.Astc12x10Unorm => FormatClass.Astc12x10,
Format.Astc12x12Srgb or Format.Astc12x12Unorm => FormatClass.Astc12x12,
_ => FormatClass.Unclassified,
};
}
}
}
}

View file

@ -7,13 +7,13 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
enum TextureComponent
{
Zero = 0,
Red = 2,
Zero = 0,
Red = 2,
Green = 3,
Blue = 4,
Blue = 4,
Alpha = 5,
OneSI = 6,
OneF = 7
OneF = 7,
}
static class TextureComponentConverter
@ -25,19 +25,16 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>Converted enum</returns>
public static SwizzleComponent Convert(this TextureComponent component)
{
switch (component)
return component switch
{
case TextureComponent.Zero: return SwizzleComponent.Zero;
case TextureComponent.Red: return SwizzleComponent.Red;
case TextureComponent.Green: return SwizzleComponent.Green;
case TextureComponent.Blue: return SwizzleComponent.Blue;
case TextureComponent.Alpha: return SwizzleComponent.Alpha;
case TextureComponent.OneSI:
case TextureComponent.OneF:
return SwizzleComponent.One;
}
return SwizzleComponent.Zero;
TextureComponent.Zero => SwizzleComponent.Zero,
TextureComponent.Red => SwizzleComponent.Red,
TextureComponent.Green => SwizzleComponent.Green,
TextureComponent.Blue => SwizzleComponent.Blue,
TextureComponent.Alpha => SwizzleComponent.Alpha,
TextureComponent.OneSI or TextureComponent.OneF => SwizzleComponent.One,
_ => SwizzleComponent.Zero,
};
}
}
}
}

View file

@ -9,7 +9,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
struct TextureDescriptor : ITextureDescriptor, IEquatable<TextureDescriptor>
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public uint Word0;
public uint Word1;
public uint Word2;
@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks Maxwell texture format integer.
/// </summary>
/// <returns>The texture format integer</returns>
public uint UnpackFormat()
public readonly uint UnpackFormat()
{
return Word0 & 0x8007ffff;
}
@ -33,43 +33,43 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the swizzle component for the texture red color channel.
/// </summary>
/// <returns>The swizzle component</returns>
public TextureComponent UnpackSwizzleR()
public readonly TextureComponent UnpackSwizzleR()
{
return(TextureComponent)((Word0 >> 19) & 7);
return (TextureComponent)((Word0 >> 19) & 7);
}
/// <summary>
/// Unpacks the swizzle component for the texture green color channel.
/// </summary>
/// <returns>The swizzle component</returns>
public TextureComponent UnpackSwizzleG()
public readonly TextureComponent UnpackSwizzleG()
{
return(TextureComponent)((Word0 >> 22) & 7);
return (TextureComponent)((Word0 >> 22) & 7);
}
/// <summary>
/// Unpacks the swizzle component for the texture blue color channel.
/// </summary>
/// <returns>The swizzle component</returns>
public TextureComponent UnpackSwizzleB()
public readonly TextureComponent UnpackSwizzleB()
{
return(TextureComponent)((Word0 >> 25) & 7);
return (TextureComponent)((Word0 >> 25) & 7);
}
/// <summary>
/// Unpacks the swizzle component for the texture alpha color channel.
/// </summary>
/// <returns>The swizzle component</returns>
public TextureComponent UnpackSwizzleA()
public readonly TextureComponent UnpackSwizzleA()
{
return(TextureComponent)((Word0 >> 28) & 7);
return (TextureComponent)((Word0 >> 28) & 7);
}
/// <summary>
/// Unpacks the 40-bits texture GPU virtual address.
/// </summary>
/// <returns>The GPU virtual address</returns>
public ulong UnpackAddress()
public readonly ulong UnpackAddress()
{
return Word1 | ((ulong)(Word2 & 0xffff) << 32);
}
@ -79,7 +79,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// This defines the texture layout, among other things.
/// </summary>
/// <returns>The texture descriptor type</returns>
public TextureDescriptorType UnpackTextureDescriptorType()
public readonly TextureDescriptorType UnpackTextureDescriptorType()
{
return (TextureDescriptorType)((Word2 >> 21) & 7);
}
@ -89,7 +89,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Always 32-bytes aligned.
/// </summary>
/// <returns>The linear texture stride</returns>
public int UnpackStride()
public readonly int UnpackStride()
{
return (int)(Word3 & 0xffff) << 5;
}
@ -99,7 +99,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Must be always 1, ignored by the GPU.
/// </summary>
/// <returns>THe GOB block X size</returns>
public int UnpackGobBlocksInX()
public readonly int UnpackGobBlocksInX()
{
return 1 << (int)(Word3 & 7);
}
@ -109,7 +109,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Must be always a power of 2, with a maximum value of 32.
/// </summary>
/// <returns>THe GOB block Y size</returns>
public int UnpackGobBlocksInY()
public readonly int UnpackGobBlocksInY()
{
return 1 << (int)((Word3 >> 3) & 7);
}
@ -120,7 +120,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Must be 1 for any texture target other than 3D textures.
/// </summary>
/// <returns>The GOB block Z size</returns>
public int UnpackGobBlocksInZ()
public readonly int UnpackGobBlocksInZ()
{
return 1 << (int)((Word3 >> 6) & 7);
}
@ -130,7 +130,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// This is only used for sparse textures, should be 1 otherwise.
/// </summary>
/// <returns>The number of GOB blocks per tile</returns>
public int UnpackGobBlocksInTileX()
public readonly int UnpackGobBlocksInTileX()
{
return 1 << (int)((Word3 >> 10) & 7);
}
@ -139,7 +139,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the number of mipmap levels of the texture.
/// </summary>
/// <returns>The number of mipmap levels</returns>
public int UnpackLevels()
public readonly int UnpackLevels()
{
return (int)(Word3 >> 28) + 1;
}
@ -148,7 +148,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpack the base level texture width size.
/// </summary>
/// <returns>The texture width</returns>
public int UnpackWidth()
public readonly int UnpackWidth()
{
return (int)(Word4 & 0xffff) + 1;
}
@ -157,7 +157,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpack the width of a buffer texture.
/// </summary>
/// <returns>The texture width</returns>
public int UnpackBufferTextureWidth()
public readonly int UnpackBufferTextureWidth()
{
return (int)((Word4 & 0xffff) | (Word3 << 16)) + 1;
}
@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the texture sRGB format flag.
/// </summary>
/// <returns>True if the texture is sRGB, false otherwise</returns>
public bool UnpackSrgb()
public readonly bool UnpackSrgb()
{
return (Word4 & (1 << 22)) != 0;
}
@ -175,7 +175,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the texture target.
/// </summary>
/// <returns>The texture target</returns>
public TextureTarget UnpackTextureTarget()
public readonly TextureTarget UnpackTextureTarget()
{
return (TextureTarget)((Word4 >> 23) & 0xf);
}
@ -185,7 +185,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Should be ignored for 1D or buffer textures.
/// </summary>
/// <returns>The texture height or layers count</returns>
public int UnpackHeight()
public readonly int UnpackHeight()
{
return (int)(Word5 & 0xffff) + 1;
}
@ -195,7 +195,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// The meaning of this value depends on the texture target.
/// </summary>
/// <returns>The texture depth, layer or faces count</returns>
public int UnpackDepth()
public readonly int UnpackDepth()
{
return (int)((Word5 >> 16) & 0x3fff) + 1;
}
@ -207,7 +207,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// It must be set to false (by the guest driver) for rectangle textures.
/// </summary>
/// <returns>The texture coordinates normalized flag</returns>
public bool UnpackTextureCoordNormalized()
public readonly bool UnpackTextureCoordNormalized()
{
return (Word5 & (1 << 31)) != 0;
}
@ -216,7 +216,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Unpacks the base mipmap level of the texture.
/// </summary>
/// <returns>The base mipmap level of the texture</returns>
public int UnpackBaseLevel()
public readonly int UnpackBaseLevel()
{
return (int)(Word7 & 0xf);
}
@ -226,7 +226,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Usually equal to Levels minus 1.
/// </summary>
/// <returns>The maximum mipmap level (inclusive) of the texture</returns>
public int UnpackMaxLevelInclusive()
public readonly int UnpackMaxLevelInclusive()
{
return (int)((Word7 >> 4) & 0xf);
}
@ -236,7 +236,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// Must be ignored for non-multisample textures.
/// </summary>
/// <returns>The multisample counts enum</returns>
public TextureMsaaMode UnpackTextureMsaaMode()
public readonly TextureMsaaMode UnpackTextureMsaaMode()
{
return (TextureMsaaMode)((Word7 >> 8) & 0xf);
}
@ -269,5 +269,10 @@ namespace Ryujinx.Graphics.Gpu.Image
{
return Unsafe.As<TextureDescriptor, Vector256<byte>>(ref this).GetHashCode();
}
public override bool Equals(object obj)
{
return obj is TextureDescriptor descriptor && Equals(descriptor);
}
}
}

View file

@ -11,6 +11,6 @@ namespace Ryujinx.Graphics.Gpu.Image
LinearColorKey,
Linear,
BlockLinear,
BlockLinearColorKey
BlockLinearColorKey,
}
}
}

View file

@ -78,11 +78,11 @@ namespace Ryujinx.Graphics.Gpu.Image
private int[] _allOffsets;
private int[] _sliceSizes;
private bool _is3D;
private readonly bool _is3D;
private bool _hasMipViews;
private bool _hasLayerViews;
private int _layers;
private int _levels;
private readonly int _layers;
private readonly int _levels;
private MultiRange TextureRange => Storage.Range;
@ -96,9 +96,9 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <summary>
/// Other texture groups that have incompatible overlaps with this one.
/// </summary>
private List<TextureIncompatibleOverlap> _incompatibleOverlaps;
private readonly List<TextureIncompatibleOverlap> _incompatibleOverlaps;
private bool _incompatibleOverlapsDirty = true;
private bool _flushIncompatibleOverlaps;
private readonly bool _flushIncompatibleOverlaps;
private BufferHandle _flushBuffer;
private bool _flushBufferImported;
@ -423,7 +423,7 @@ namespace Ryujinx.Graphics.Gpu.Image
int offsetIndex = GetOffsetIndex(info.BaseLayer + layer, info.BaseLevel + level);
int offset = _allOffsets[offsetIndex];
ReadOnlySpan<byte> data = dataSpan.Slice(offset - spanBase);
ReadOnlySpan<byte> data = dataSpan[(offset - spanBase)..];
SpanOrArray<byte> result = Storage.ConvertToHostCompatibleFormat(data, info.BaseLevel + level, true);
@ -1500,13 +1500,13 @@ namespace Ryujinx.Graphics.Gpu.Image
{
for (int i = 0; i < _allOffsets.Length; i++)
{
(int layer, int level) = GetLayerLevelForView(i);
(_, int level) = GetLayerLevelForView(i);
MultiRange handleRange = Storage.Range.Slice((ulong)_allOffsets[i], 1);
ulong handleBase = handleRange.GetSubRange(0).Address;
for (int j = 0; j < other._handles.Length; j++)
{
(int otherLayer, int otherLevel) = other.GetLayerLevelForView(j);
(_, int otherLevel) = other.GetLayerLevelForView(j);
MultiRange otherHandleRange = other.Storage.Range.Slice((ulong)other._allOffsets[j], 1);
ulong otherHandleBase = otherHandleRange.GetSubRange(0).Address;

View file

@ -22,10 +22,10 @@ namespace Ryujinx.Graphics.Gpu.Image
private const int FlushBalanceMax = 60;
private const int FlushBalanceMin = -10;
private TextureGroup _group;
private readonly TextureGroup _group;
private int _bindCount;
private int _firstLevel;
private int _firstLayer;
private readonly int _firstLevel;
private readonly int _firstLayer;
// Sync state for texture flush.
@ -463,8 +463,8 @@ namespace Ryujinx.Graphics.Gpu.Image
_group.HasCopyDependencies = true;
other._group.HasCopyDependencies = true;
TextureDependency dependency = new TextureDependency(this);
TextureDependency otherDependency = new TextureDependency(other);
TextureDependency dependency = new(this);
TextureDependency otherDependency = new(other);
dependency.Other = otherDependency;
otherDependency.Other = dependency;

View file

@ -134,45 +134,45 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="swizzleB">Swizzle for the blue color channel</param>
/// <param name="swizzleA">Swizzle for the alpha color channel</param>
public TextureInfo(
ulong gpuAddress,
int width,
int height,
int depthOrLayers,
int levels,
int samplesInX,
int samplesInY,
int stride,
bool isLinear,
int gobBlocksInY,
int gobBlocksInZ,
int gobBlocksInTileX,
Target target,
FormatInfo formatInfo,
ulong gpuAddress,
int width,
int height,
int depthOrLayers,
int levels,
int samplesInX,
int samplesInY,
int stride,
bool isLinear,
int gobBlocksInY,
int gobBlocksInZ,
int gobBlocksInTileX,
Target target,
FormatInfo formatInfo,
DepthStencilMode depthStencilMode = DepthStencilMode.Depth,
SwizzleComponent swizzleR = SwizzleComponent.Red,
SwizzleComponent swizzleG = SwizzleComponent.Green,
SwizzleComponent swizzleB = SwizzleComponent.Blue,
SwizzleComponent swizzleA = SwizzleComponent.Alpha)
SwizzleComponent swizzleR = SwizzleComponent.Red,
SwizzleComponent swizzleG = SwizzleComponent.Green,
SwizzleComponent swizzleB = SwizzleComponent.Blue,
SwizzleComponent swizzleA = SwizzleComponent.Alpha)
{
GpuAddress = gpuAddress;
Width = width;
Height = height;
DepthOrLayers = depthOrLayers;
Levels = levels;
SamplesInX = samplesInX;
SamplesInY = samplesInY;
Stride = stride;
IsLinear = isLinear;
GobBlocksInY = gobBlocksInY;
GobBlocksInZ = gobBlocksInZ;
GpuAddress = gpuAddress;
Width = width;
Height = height;
DepthOrLayers = depthOrLayers;
Levels = levels;
SamplesInX = samplesInX;
SamplesInY = samplesInY;
Stride = stride;
IsLinear = isLinear;
GobBlocksInY = gobBlocksInY;
GobBlocksInZ = gobBlocksInZ;
GobBlocksInTileX = gobBlocksInTileX;
Target = target;
FormatInfo = formatInfo;
Target = target;
FormatInfo = formatInfo;
DepthStencilMode = depthStencilMode;
SwizzleR = swizzleR;
SwizzleG = swizzleG;
SwizzleB = swizzleB;
SwizzleA = swizzleA;
SwizzleR = swizzleR;
SwizzleG = swizzleG;
SwizzleB = swizzleB;
SwizzleA = swizzleA;
}
/// <summary>
@ -318,17 +318,17 @@ namespace Ryujinx.Graphics.Gpu.Image
// - If the parent format is not compressed, and the view is, the view
// size is calculated as described on the first point, but the width and height
// of the view must be also multiplied by the block width and height.
int width = Math.Max(1, parent.Info.Width >> firstLevel);
int width = Math.Max(1, parent.Info.Width >> firstLevel);
int height = Math.Max(1, parent.Info.Height >> firstLevel);
if (parent.Info.FormatInfo.IsCompressed && !FormatInfo.IsCompressed)
{
width = BitUtils.DivRoundUp(width, parent.Info.FormatInfo.BlockWidth);
width = BitUtils.DivRoundUp(width, parent.Info.FormatInfo.BlockWidth);
height = BitUtils.DivRoundUp(height, parent.Info.FormatInfo.BlockHeight);
}
else if (!parent.Info.FormatInfo.IsCompressed && FormatInfo.IsCompressed)
{
width *= FormatInfo.BlockWidth;
width *= FormatInfo.BlockWidth;
height *= FormatInfo.BlockHeight;
}
@ -408,4 +408,4 @@ namespace Ryujinx.Graphics.Gpu.Image
SwizzleA);
}
}
}
}

View file

@ -41,8 +41,8 @@ namespace Ryujinx.Graphics.Gpu.Image
_context = context;
_channel = channel;
TexturePoolCache texturePoolCache = new TexturePoolCache(context);
SamplerPoolCache samplerPoolCache = new SamplerPoolCache(context);
TexturePoolCache texturePoolCache = new(context);
SamplerPoolCache samplerPoolCache = new(context);
float[] scales = new float[64];
new Span<float>(scales).Fill(1f);
@ -139,7 +139,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
/// <param name="texture">The texture to check</param>
/// <returns>True if the scale needs updating, false if the scale is up to date</returns>
private bool ScaleNeedsUpdated(Texture texture)
private static bool ScaleNeedsUpdated(Texture texture)
{
return texture != null && !(texture.ScaleMode == TextureScaleMode.Blacklisted || texture.ScaleMode == TextureScaleMode.Undesired) && texture.ScaleFactor != GraphicsConfig.ResScale;
}
@ -234,7 +234,11 @@ namespace Ryujinx.Graphics.Gpu.Image
void ConsiderTarget(Texture target)
{
if (target == null) return;
if (target == null)
{
return;
}
float scale = target.ScaleFactor;
switch (target.ScaleMode)
@ -445,7 +449,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </remarks>
public void UpdateRenderTargetDepthStencil()
{
new Span<ITexture>(_rtHostColors).Fill(null);
new Span<ITexture>(_rtHostColors).Clear();
_rtHostDs = _rtDepthStencil?.HostTexture;
_context.Renderer.Pipeline.SetRenderTargets(_rtHostColors, _rtHostDs);

View file

@ -4,6 +4,6 @@
{
NoMatch,
FormatAlias,
Perfect
Perfect,
}
}

View file

@ -9,7 +9,7 @@ namespace Ryujinx.Graphics.Gpu.Image
Ms2x2 = 2,
Ms4x2 = 4,
Ms2x1 = 5,
Ms4x4 = 6
Ms4x4 = 6,
}
static class TextureMsaaModeConverter
@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Gpu.Image
TextureMsaaMode.Ms2x2 => 4,
TextureMsaaMode.Ms4x2 => 8,
TextureMsaaMode.Ms4x4 => 16,
_ => 1
_ => 1,
};
}
@ -44,7 +44,7 @@ namespace Ryujinx.Graphics.Gpu.Image
TextureMsaaMode.Ms2x2 => 2,
TextureMsaaMode.Ms4x2 => 4,
TextureMsaaMode.Ms4x4 => 4,
_ => 1
_ => 1,
};
}
@ -61,8 +61,8 @@ namespace Ryujinx.Graphics.Gpu.Image
TextureMsaaMode.Ms2x2 => 2,
TextureMsaaMode.Ms4x2 => 2,
TextureMsaaMode.Ms4x4 => 4,
_ => 1
_ => 1,
};
}
}
}
}

View file

@ -18,7 +18,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <summary>
/// A request to dereference a texture from a pool.
/// </summary>
private struct DereferenceRequest
private readonly struct DereferenceRequest
{
/// <summary>
/// Whether the dereference is due to a mapping change or not.
@ -71,7 +71,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
private readonly GpuChannel _channel;
private readonly ConcurrentQueue<DereferenceRequest> _dereferenceQueue = new ConcurrentQueue<DereferenceRequest>();
private readonly ConcurrentQueue<DereferenceRequest> _dereferenceQueue = new();
private TextureDescriptor _defaultDescriptor;
/// <summary>
@ -379,10 +379,10 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="descriptor">The texture descriptor</param>
/// <param name="layerSize">Layer size for textures using a sub-range of mipmap levels, otherwise 0</param>
/// <returns>The texture information</returns>
private TextureInfo GetInfo(in TextureDescriptor descriptor, out int layerSize)
private static TextureInfo GetInfo(in TextureDescriptor descriptor, out int layerSize)
{
int depthOrLayers = descriptor.UnpackDepth();
int levels = descriptor.UnpackLevels();
int levels = descriptor.UnpackLevels();
TextureMsaaMode msaaMode = descriptor.UnpackTextureMsaaMode();
@ -424,7 +424,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
uint format = descriptor.UnpackFormat();
bool srgb = descriptor.UnpackSrgb();
bool srgb = descriptor.UnpackSrgb();
ulong gpuVa = descriptor.UnpackAddress();
@ -451,7 +451,7 @@ namespace Ryujinx.Graphics.Gpu.Image
// Linear textures don't support mipmaps, so we don't handle this case here.
if ((minLod != 0 || maxLod + 1 != levels) && target != Target.TextureBuffer && !isLinear)
{
int depth = TextureInfo.GetDepth(target, depthOrLayers);
int depth = TextureInfo.GetDepth(target, depthOrLayers);
int layers = TextureInfo.GetLayers(target, depthOrLayers);
SizeInfo sizeInfo = SizeCalculator.GetBlockLinearTextureSize(
@ -476,7 +476,7 @@ namespace Ryujinx.Graphics.Gpu.Image
// address if there is a overlapping texture on the cache that can contain the new texture.
gpuVa += (ulong)sizeInfo.GetMipOffset(minLod);
width = Math.Max(1, width >> minLod);
width = Math.Max(1, width >> minLod);
height = Math.Max(1, height >> minLod);
if (target == Target.Texture3D)
@ -608,4 +608,4 @@ namespace Ryujinx.Graphics.Gpu.Image
base.Dispose();
}
}
}
}

View file

@ -27,4 +27,4 @@ namespace Ryujinx.Graphics.Gpu.Image
return new TexturePool(context, channel, address, maximumId);
}
}
}
}

View file

@ -11,6 +11,6 @@
Eligible = 0,
Scaled = 1,
Blacklisted = 2,
Undesired = 3
Undesired = 3,
}
}

View file

@ -8,11 +8,11 @@ namespace Ryujinx.Graphics.Gpu.Image
[Flags]
enum TextureSearchFlags
{
None = 0,
ForSampler = 1 << 1,
ForCopy = 1 << 2,
DepthAlias = 1 << 3,
None = 0,
ForSampler = 1 << 1,
ForCopy = 1 << 2,
DepthAlias = 1 << 3,
WithUpscale = 1 << 4,
NoCreate = 1 << 5
NoCreate = 1 << 5,
}
}
}

View file

@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.Gpu.Image
Texture2DArray,
TextureBuffer,
Texture2DRect,
CubemapArray
CubemapArray,
}
static class TextureTargetConverter
@ -33,23 +33,34 @@ namespace Ryujinx.Graphics.Gpu.Image
{
switch (target)
{
case TextureTarget.Texture2D: return Target.Texture2DMultisample;
case TextureTarget.Texture2DArray: return Target.Texture2DMultisampleArray;
case TextureTarget.Texture2D:
return Target.Texture2DMultisample;
case TextureTarget.Texture2DArray:
return Target.Texture2DMultisampleArray;
}
}
else
{
switch (target)
{
case TextureTarget.Texture1D: return Target.Texture1D;
case TextureTarget.Texture2D: return Target.Texture2D;
case TextureTarget.Texture2DRect: return Target.Texture2D;
case TextureTarget.Texture3D: return Target.Texture3D;
case TextureTarget.Texture1DArray: return Target.Texture1DArray;
case TextureTarget.Texture2DArray: return Target.Texture2DArray;
case TextureTarget.Cubemap: return Target.Cubemap;
case TextureTarget.CubemapArray: return Target.CubemapArray;
case TextureTarget.TextureBuffer: return Target.TextureBuffer;
case TextureTarget.Texture1D:
return Target.Texture1D;
case TextureTarget.Texture2D:
return Target.Texture2D;
case TextureTarget.Texture2DRect:
return Target.Texture2D;
case TextureTarget.Texture3D:
return Target.Texture3D;
case TextureTarget.Texture1DArray:
return Target.Texture1DArray;
case TextureTarget.Texture2DArray:
return Target.Texture2DArray;
case TextureTarget.Cubemap:
return Target.Cubemap;
case TextureTarget.CubemapArray:
return Target.CubemapArray;
case TextureTarget.TextureBuffer:
return Target.TextureBuffer;
}
}
@ -65,17 +76,17 @@ namespace Ryujinx.Graphics.Gpu.Image
{
return target switch
{
TextureTarget.Texture1D => SamplerType.Texture1D,
TextureTarget.Texture2D => SamplerType.Texture2D,
TextureTarget.Texture3D => SamplerType.Texture3D,
TextureTarget.Cubemap => SamplerType.TextureCube,
TextureTarget.Texture1D => SamplerType.Texture1D,
TextureTarget.Texture2D => SamplerType.Texture2D,
TextureTarget.Texture3D => SamplerType.Texture3D,
TextureTarget.Cubemap => SamplerType.TextureCube,
TextureTarget.Texture1DArray => SamplerType.Texture1D | SamplerType.Array,
TextureTarget.Texture2DArray => SamplerType.Texture2D | SamplerType.Array,
TextureTarget.TextureBuffer => SamplerType.TextureBuffer,
TextureTarget.Texture2DRect => SamplerType.Texture2D,
TextureTarget.CubemapArray => SamplerType.TextureCube | SamplerType.Array,
_ => SamplerType.Texture2D
TextureTarget.TextureBuffer => SamplerType.TextureBuffer,
TextureTarget.Texture2DRect => SamplerType.Texture2D,
TextureTarget.CubemapArray => SamplerType.TextureCube | SamplerType.Array,
_ => SamplerType.Texture2D,
};
}
}
}
}

View file

@ -10,6 +10,6 @@
LayoutIncompatible,
CopyOnly,
FormatAlias,
Full
Full,
}
}