Structural and Memory Safety Improvements, Analyzer Cleanup (ryubing/ryujinx!47)

See merge request ryubing/ryujinx!47
This commit is contained in:
MrKev 2025-06-11 17:58:27 -05:00 committed by LotP
parent d03ae9c164
commit ea027d65a7
309 changed files with 1018 additions and 1247 deletions

View file

@ -98,7 +98,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
/// </summary>
unsafe struct ComputeClassState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint SetObject;
public readonly int SetObjectClassId => (int)(SetObject & 0xFFFF);
public readonly int SetObjectEngineId => (int)((SetObject >> 16) & 0x1F);
@ -430,6 +430,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Compute
public readonly int StopShaderPerformanceCounterCounterMask => (int)(StopShaderPerformanceCounter & 0xFF);
public fixed uint Reserved33E8[6];
public Array256<uint> SetMmeShadowScratch;
#pragma warning restore CS0649
}
}

View file

@ -179,7 +179,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
/// </summary>
unsafe struct DmaClassState
{
#pragma warning disable CS0649 // Field is never assigned to
public fixed uint Reserved00[64];
public uint Nop;
public fixed uint Reserved104[15];
@ -266,6 +266,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
public fixed uint Reserved740[629];
public uint PmTriggerEnd;
public fixed uint Reserved1118[2490];
#pragma warning restore CS0649
}
}

View file

@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
/// </summary>
struct DmaTexture
{
#pragma warning disable CS0649 // Field is never assigned to
public MemoryLayout MemoryLayout;
public int Width;
public int Height;
@ -15,6 +15,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Dma
public int RegionZ;
public ushort RegionX;
public ushort RegionY;
#pragma warning restore CS0649
}
}

View file

@ -25,9 +25,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
struct CompressedMethod
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Method;
#pragma warning restore CS0649
public readonly int MethodAddressOld => (int)((Method >> 2) & 0x7FF);
public readonly int MethodAddress => (int)(Method & 0xFFF);
public readonly int SubdeviceMask => (int)((Method >> 4) & 0xFFF);

View file

@ -36,15 +36,15 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
struct GPEntry
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Entry0;
#pragma warning restore CS0649
public readonly Entry0Fetch Entry0Fetch => (Entry0Fetch)(Entry0 & 0x1);
public readonly int Entry0Get => (int)((Entry0 >> 2) & 0x3FFFFFFF);
public readonly int Entry0Operand => (int)(Entry0);
#pragma warning disable CS0649 // Field is never assigned to
public uint Entry1;
#pragma warning restore CS0649
public readonly int Entry1GetHi => (int)(Entry1 & 0xFF);
public readonly Entry1Priv Entry1Priv => (Entry1Priv)((Entry1 >> 8) & 0x1);
public readonly Entry1Level Entry1Level => (Entry1Level)((Entry1 >> 9) & 0x1);

View file

@ -151,7 +151,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
/// </summary>
struct GPFifoClassState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint SetObject;
public readonly int SetObjectNvclass => (int)(SetObject & 0xFFFF);
public readonly int SetObjectEngine => (int)((SetObject >> 16) & 0x1F);
@ -228,6 +228,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.GPFifo
public uint LoadMmeStartAddressRamPointer;
public uint LoadMmeStartAddressRam;
public uint SetMmeShadowRamControl;
#pragma warning restore CS0649
}
}

View file

@ -113,7 +113,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
/// </summary>
unsafe struct InlineToMemoryClassState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint SetObject;
public readonly int SetObjectClassId => (int)(SetObject & 0xFFFF);
public readonly int SetObjectEngineId => (int)((SetObject >> 16) & 0x1F);
@ -178,6 +178,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.InlineToMemory
public uint SetI2mSpareNoop03;
public fixed uint Reserved200[3200];
public Array256<uint> SetMmeShadowScratch;
#pragma warning restore CS0649
}
}

View file

@ -469,12 +469,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
for (int i = 0; i < maxDrawCount; i++)
{
FifoWord count = FetchParam();
#pragma warning disable IDE0059 // Remove unnecessary value assignment
FifoWord instanceCount = FetchParam();
_ = FetchParam(); // Instance count
FifoWord firstIndex = FetchParam();
FifoWord firstVertex = FetchParam();
FifoWord firstInstance = FetchParam();
#pragma warning restore IDE0059
_ = FetchParam(); // First vertex
_ = FetchParam(); // First instance
if (i == 0)
{

View file

@ -9,9 +9,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
[StructLayout(LayoutKind.Sequential, Size = 1024)]
struct MmeShadowScratch
{
#pragma warning disable CS0169 // The private field is never used
private uint _e0;
#pragma warning restore CS0169
public ref uint this[int index] => ref AsSpan()[index];
public Span<uint> AsSpan() => MemoryMarshal.CreateSpan(ref _e0, 256);
}

View file

@ -16,9 +16,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
private int _inlineIndexBufferSize;
private int _inlineIndexCount;
private uint[] _buffer;
#pragma warning disable IDE0051 // Remove unused private member
private readonly int _bufferOffset;
#pragma warning restore IDE0051
/// <summary>
/// Indicates if any index buffer data has been pushed.

View file

@ -1,5 +1,3 @@
using System.Diagnostics.CodeAnalysis;
namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
/// <summary>

View file

@ -26,9 +26,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct TessMode
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Packed;
#pragma warning restore CS0649
/// <summary>
/// Unpacks the tessellation abstract patch type.
@ -63,7 +62,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct TfBufferState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 Enable;
public GpuVa Address;
public int Size;
@ -71,7 +70,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public uint Padding0;
public uint Padding1;
public uint Padding2;
#pragma warning restore CS0649
}
/// <summary>
@ -79,12 +78,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct TfState
{
#pragma warning disable CS0649 // Field is never assigned to
public int BufferIndex;
public int VaryingsCount;
public int Stride;
public uint Padding;
#pragma warning restore CS0649
}
/// <summary>
@ -92,7 +91,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct RtColorState
{
#pragma warning disable CS0649 // Field is never assigned to
public GpuVa Address;
public int WidthOrStride;
public int Height;
@ -108,7 +107,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public int Padding3;
public int Padding4;
public int Padding5;
#pragma warning restore CS0649
}
/// <summary>
@ -116,7 +115,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct ViewportTransform
{
#pragma warning disable CS0649 // Field is never assigned to
public float ScaleX;
public float ScaleY;
public float ScaleZ;
@ -125,7 +124,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public float TranslateZ;
public uint Swizzle;
public uint SubpixelPrecisionBias;
#pragma warning restore CS0649
/// <summary>
/// Unpacks viewport swizzle of the position X component.
@ -169,14 +167,14 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct ViewportExtents
{
#pragma warning disable CS0649 // Field is never assigned to
public ushort X;
public ushort Width;
public ushort Y;
public ushort Height;
public float DepthNear;
public float DepthFar;
#pragma warning restore CS0649
}
/// <summary>
@ -184,10 +182,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct VertexBufferDrawState
{
#pragma warning disable CS0649 // Field is never assigned to
public int First;
public int Count;
#pragma warning restore CS0649
}
/// <summary>
@ -195,12 +193,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct ClearColors
{
#pragma warning disable CS0649 // Field is never assigned to
public float Red;
public float Green;
public float Blue;
public float Alpha;
#pragma warning restore CS0649
}
/// <summary>
@ -208,11 +206,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct DepthBiasState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 PointEnable;
public Boolean32 LineEnable;
public Boolean32 FillEnable;
#pragma warning restore CS0649
}
/// <summary>
@ -231,14 +229,14 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct ScissorState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 Enable;
public ushort X1;
public ushort X2;
public ushort Y1;
public ushort Y2;
public uint Padding;
#pragma warning restore CS0649
}
/// <summary>
@ -246,11 +244,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct StencilBackMasks
{
#pragma warning disable CS0649 // Field is never assigned to
public int FuncRef;
public int Mask;
public int FuncMask;
#pragma warning restore CS0649
}
/// <summary>
@ -258,12 +256,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct RtDepthStencilState
{
#pragma warning disable CS0649 // Field is never assigned to
public GpuVa Address;
public ZetaFormat Format;
public MemoryLayout MemoryLayout;
public int LayerSize;
#pragma warning restore CS0649
}
/// <summary>
@ -271,12 +269,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct ScreenScissorState
{
#pragma warning disable CS0649 // Field is never assigned to
public ushort X;
public ushort Width;
public ushort Y;
public ushort Height;
#pragma warning restore CS0649
}
/// <summary>
@ -319,9 +317,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct VertexAttribState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Attribute;
#pragma warning restore CS0649
/// <summary>
/// Unpacks the index of the vertex buffer this attribute belongs to.
@ -383,9 +380,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct RtControl
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Packed;
#pragma warning restore CS0649
/// <summary>
/// Unpacks the number of active draw buffers.
@ -412,7 +408,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct Size3D
{
#pragma warning disable CS0649 // Field is never assigned to
public int Width;
public int Height;
public ushort Depth;
@ -422,7 +418,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
{
return (Flags & 1) == 0;
}
#pragma warning restore CS0649
}
/// <summary>
@ -430,7 +425,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct StencilTestState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 Enable;
public StencilOp FrontSFail;
public StencilOp FrontDpFail;
@ -439,7 +434,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public int FrontFuncRef;
public int FrontFuncMask;
public int FrontMask;
#pragma warning restore CS0649
}
/// <summary>
@ -457,12 +452,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct RgbHalf
{
#pragma warning disable CS0649 // Field is never assigned to
public uint R;
public uint G;
public uint B;
public uint Padding;
#pragma warning restore CS0649
/// <summary>
/// Unpacks the red color component as a 16-bit float value.
@ -512,10 +506,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct PoolState
{
#pragma warning disable CS0649 // Field is never assigned to
public GpuVa Address;
public int MaximumId;
#pragma warning restore CS0649
}
/// <summary>
@ -523,13 +517,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct StencilBackTestState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 TwoSided;
public StencilOp BackSFail;
public StencilOp BackDpFail;
public StencilOp BackDpPass;
public CompareOp BackFunc;
#pragma warning restore CS0649
}
/// <summary>
@ -537,10 +531,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct PrimitiveRestartState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 Enable;
public int Index;
#pragma warning restore CS0649
}
/// <summary>
@ -549,12 +543,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct IndexBufferState
{
#pragma warning disable CS0649 // Field is never assigned to
public GpuVa Address;
public GpuVa EndAddress;
public IndexType Type;
public int First;
#pragma warning restore CS0649
}
/// <summary>
@ -562,11 +556,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct FaceState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 CullEnable;
public FrontFace FrontFace;
public Face CullFace;
#pragma warning restore CS0649
}
/// <summary>
@ -584,10 +578,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct LogicalOpState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 Enable;
public LogicalOp LogicalOp;
#pragma warning restore CS0649
}
/// <summary>
@ -645,11 +639,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct VertexBufferState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Control;
public GpuVa Address;
public int Divisor;
#pragma warning restore CS0649
/// <summary>
/// Vertex buffer stride, defined as the number of bytes occupied by each vertex in memory.
@ -675,7 +668,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct BlendStateCommon
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 SeparateAlpha;
public BlendOp ColorOp;
public BlendFactor ColorSrcFactor;
@ -684,7 +677,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public BlendFactor AlphaSrcFactor;
public uint Unknown0x1354;
public BlendFactor AlphaDstFactor;
#pragma warning restore CS0649
}
/// <summary>
@ -692,7 +685,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct BlendState
{
#pragma warning disable CS0649 // Field is never assigned to
public Boolean32 SeparateAlpha;
public BlendOp ColorOp;
public BlendFactor ColorSrcFactor;
@ -701,7 +694,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public BlendFactor AlphaSrcFactor;
public BlendFactor AlphaDstFactor;
public uint Padding;
#pragma warning restore CS0649
}
/// <summary>
@ -709,7 +702,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct ShaderState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Control;
public uint Offset;
public uint Unknown0x8;
@ -726,7 +719,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public uint Unknown0x34;
public uint Unknown0x38;
public uint Unknown0x3c;
#pragma warning restore CS0649
/// <summary>
/// Unpacks shader enable information.
@ -744,16 +736,16 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
struct UniformBufferState
{
#pragma warning disable CS0649 // Field is never assigned to
public int Size;
public GpuVa Address;
public int Offset;
#pragma warning restore CS0649
}
unsafe struct ThreedClassState : IShadowState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint SetObject;
public readonly int SetObjectClassId => (int)(SetObject & 0xFFFF);
public readonly int SetObjectEngineId => (int)((SetObject >> 16) & 0x1F);
@ -1052,6 +1044,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
public Array4<Array32<uint>> TfVaryingLocations;
public fixed uint Reserved2A00[640];
public Array256<uint> SetMmeShadowScratch;
#pragma warning restore CS0649
}
}

View file

@ -486,10 +486,10 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
/// </summary>
struct RenderSolidPrimPoint
{
#pragma warning disable CS0649 // Field is never assigned to
public uint SetX;
public uint Y;
#pragma warning restore CS0649
}
/// <summary>
@ -497,7 +497,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
/// </summary>
unsafe struct TwodClassState : IShadowState
{
#pragma warning disable CS0649 // Field is never assigned to
public uint SetObject;
public readonly int SetObjectClassId => (int)(SetObject & 0xFFFF);
public readonly int SetObjectEngineId => (int)((SetObject >> 16) & 0x1F);
@ -811,6 +811,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
public readonly bool MmeDmaWriteMethodBarrierV => (MmeDmaWriteMethodBarrier & 0x1) != 0;
public fixed uint ReservedDF0[2436];
public Array256<uint> SetMmeShadowScratch;
#pragma warning restore CS0649
}
}

View file

@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
/// </summary>
struct TwodTexture
{
#pragma warning disable CS0649 // Field is never assigned to
public ColorFormat Format;
public Boolean32 LinearLayout;
public MemoryLayout MemoryLayout;
@ -17,6 +17,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.Twod
public int Width;
public int Height;
public GpuVa Address;
#pragma warning restore CS0649
}
}

View file

@ -5,10 +5,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.Types
/// </summary>
struct GpuVa
{
#pragma warning disable CS0649 // Field is never assigned to
public uint High;
public uint Low;
#pragma warning restore CS0649
/// <summary>
/// Packs the split address into a 64-bits address value.

View file

@ -5,9 +5,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Types
/// </summary>
struct MemoryLayout
{
#pragma warning disable CS0649 // Field is never assigned to
public uint Packed;
#pragma warning restore CS0649
public readonly int UnpackGobBlocksInX()
{

View file

@ -5,12 +5,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Types
/// </summary>
struct SbDescriptor
{
#pragma warning disable CS0649 // Field is never assigned to
public uint AddressLow;
public uint AddressHigh;
public int Size;
public int Padding;
#pragma warning restore CS0649
public readonly ulong PackAddress()
{