Skip to content

Commit

Permalink
misc: chore: Use collection expressions everywhere else (except VP9)
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Jan 26, 2025
1 parent 0f85740 commit ac838aa
Show file tree
Hide file tree
Showing 59 changed files with 3,246 additions and 2,452 deletions.
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.GAL/Multithreading/BufferMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BufferMap
private ulong _bufferHandle = 0;

private readonly Dictionary<BufferHandle, BufferHandle> _bufferMap = new();
private readonly HashSet<BufferHandle> _inFlight = new();
private readonly HashSet<BufferHandle> _inFlight = [];
private readonly AutoResetEvent _inFlightChanged = new(false);

internal BufferHandle CreateBufferHandle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public ProgramQueue(IRenderer renderer)
_renderer = renderer;

_toCompile = new Queue<IProgramRequest>();
_inProgress = new List<ThreadedProgram>();
_inProgress = [];
}

public void Add(IProgramRequest request)
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.GAL/Multithreading/SyncMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
{
class SyncMap : IDisposable
{
private readonly HashSet<ulong> _inFlight = new();
private readonly HashSet<ulong> _inFlight = [];
private readonly AutoResetEvent _inFlightChanged = new(false);

internal void CreateSyncHandle(ulong id)
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Host1x/SyncptIncrManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SyncptIncr(uint id, ClassId classId, uint syncptId, bool done = false)
}
}

private readonly List<SyncptIncr> _incrs = new();
private readonly List<SyncptIncr> _incrs = [];

private uint _currentId;

Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx.Graphics.Metal/CacheByRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void AddDependency(int offset, int size, ICacheKey key, Dependency depend
{
if (entry.DependencyList == null)
{
entry.DependencyList = new List<Dependency>();
entry.DependencyList = [];
entries[i] = entry;
}

Expand Down Expand Up @@ -240,7 +240,7 @@ public readonly void ClearRange(int offset, int size)
DestroyEntry(entry);
}

(toRemove ??= new List<ulong>()).Add(range.Key);
(toRemove ??= []).Add(range.Key);
}
}

Expand All @@ -262,7 +262,7 @@ private List<Entry> GetEntries(int offset, int size)

if (!_ranges.TryGetValue(key, out List<Entry> value))
{
value = new List<Entry>();
value = [];
_ranges.Add(key, value);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Metal/CommandBufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void Use(MTLCommandQueue queue, IEncoderFactory stateManager)

public void Initialize()
{
Dependants = new List<IAuto>();
Waitables = new List<MultiFenceHolder>();
Dependants = [];
Waitables = [];
Encoders = new CommandBufferEncoder();
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Ryujinx.Graphics.Metal/EncoderResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Ryujinx.Graphics.Metal
{
public struct RenderEncoderBindings
{
public List<Resource> Resources = new();
public List<BufferResource> VertexBuffers = new();
public List<BufferResource> FragmentBuffers = new();
public List<Resource> Resources = [];
public List<BufferResource> VertexBuffers = [];
public List<BufferResource> FragmentBuffers = [];

public RenderEncoderBindings() { }

Expand All @@ -21,8 +21,8 @@ public readonly void Clear()

public struct ComputeEncoderBindings
{
public List<Resource> Resources = new();
public List<BufferResource> Buffers = new();
public List<Resource> Resources = [];
public List<BufferResource> Buffers = [];

public ComputeEncoderBindings() { }

Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Metal/HashTableSlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ public void Add(ref TKey key, TValue value)
}
else
{
bucket.Entries = new[]
{
entry,
};
bucket.Entries =
[
entry
];
}

bucket.Length++;
Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx.Graphics.Metal/HelperShader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class HelperShader : IDisposable
private readonly IProgram _programColorBlitMsF;
private readonly IProgram _programColorBlitMsI;
private readonly IProgram _programColorBlitMsU;
private readonly List<IProgram> _programsColorClearF = new();
private readonly List<IProgram> _programsColorClearI = new();
private readonly List<IProgram> _programsColorClearU = new();
private readonly List<IProgram> _programsColorClearF = [];
private readonly List<IProgram> _programsColorClearI = [];
private readonly List<IProgram> _programsColorClearU = [];
private readonly IProgram _programDepthStencilClear;
private readonly IProgram _programStrideChange;
private readonly IProgram _programConvertD32S8ToD24S8;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Metal/IdList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IdList<T> where T : class

public IdList()
{
_list = new List<T>();
_list = [];
_freeMin = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Metal/MetalRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public sealed class MetalRenderer : IRenderer
public MetalRenderer(Func<CAMetalLayer> metalLayer)
{
_device = MTLDevice.CreateSystemDefaultDevice();
Programs = new HashSet<Program>();
Samplers = new HashSet<SamplerHolder>();
Programs = [];
Samplers = [];

if (_device.ArgumentBuffersSupport != MTLArgumentBuffersTier.Tier2)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Metal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static (ResourceBindingSegment[][], int[], int[]) BuildBindingSegments(R

for (int setIndex = 0; setIndex < setUsages.Count; setIndex++)
{
List<ResourceBindingSegment> currentSegments = new();
List<ResourceBindingSegment> currentSegments = [];

ResourceUsage currentUsage = default;
int currentCount = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Metal/ResourceLayoutBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public ResourceLayoutBuilder()

for (int index = 0; index < TotalSets; index++)
{
_resourceDescriptors[index] = new();
_resourceUsages[index] = new();
_resourceDescriptors[index] = [];
_resourceUsages[index] = [];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Metal/SyncManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public bool NeedsFlush(ulong currentFlushId)
public SyncManager(MetalRenderer renderer)
{
_renderer = renderer;
_handles = new List<SyncHandle>();
_handles = [];
}

public void RegisterFlush()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@ public static Span<byte> Reconstruct(ref H264PictureInfo pictureInfo, byte[] wor
}

// ZigZag LUTs from libavcodec.
private static ReadOnlySpan<byte> ZigZagDirect => new byte[]
{
private static ReadOnlySpan<byte> ZigZagDirect =>
[
0, 1, 8, 16, 9, 2, 3, 10,
17, 24, 32, 25, 18, 11, 4, 5,
12, 19, 26, 33, 40, 48, 41, 34,
27, 20, 13, 6, 7, 14, 21, 28,
35, 42, 49, 56, 57, 50, 43, 36,
29, 22, 15, 23, 30, 37, 44, 51,
58, 59, 52, 45, 38, 31, 39, 46,
53, 60, 61, 54, 47, 55, 62, 63,
};
53, 60, 61, 54, 47, 55, 62, 63
];

private static ReadOnlySpan<byte> ZigZagScan => new byte[]
{
private static ReadOnlySpan<byte> ZigZagScan =>
[
0 + 0 * 4, 1 + 0 * 4, 0 + 1 * 4, 0 + 2 * 4,
1 + 1 * 4, 2 + 0 * 4, 3 + 0 * 4, 2 + 1 * 4,
1 + 2 * 4, 0 + 3 * 4, 1 + 3 * 4, 2 + 2 * 4,
3 + 1 * 4, 3 + 2 * 4, 2 + 3 * 4, 3 + 3 * 4,
};
3 + 1 * 4, 3 + 2 * 4, 2 + 3 * 4, 3 + 3 * 4
];

private static void WriteScalingList(ref H264BitStreamWriter writer, IArray<byte> list)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Graphics.Texture/Astc/AstcDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,12 +1693,12 @@ static void DecodeBlockInfo(ref BitStream128 bitStream, out TexelWeightParams te

if (h)
{
ReadOnlySpan<byte> maxWeights = new byte[] { 9, 11, 15, 19, 23, 31 };
ReadOnlySpan<byte> maxWeights = [9, 11, 15, 19, 23, 31];
texelParams.MaxWeight = maxWeights[r - 2];
}
else
{
ReadOnlySpan<byte> maxWeights = new byte[] { 1, 2, 3, 4, 5, 7 };
ReadOnlySpan<byte> maxWeights = [1, 2, 3, 4, 5, 7];
texelParams.MaxWeight = maxWeights[r - 2];
}

Expand Down
18 changes: 9 additions & 9 deletions src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static void DecodeQuintBlock(
ref IntegerSequence listIntegerEncoded,
int numberBitsPerValue)
{
ReadOnlySpan<byte> interleavedBits = new byte[] { 3, 2, 2 };
ReadOnlySpan<byte> interleavedBits = [3, 2, 2];

// Implement the algorithm in section C.2.12
Span<int> m = stackalloc int[3];
Expand Down Expand Up @@ -213,8 +213,8 @@ private static ReadOnlySpan<byte> GetQuintEncoding(int index)
return QuintEncodings.Slice(index * 3, 3);
}

private static ReadOnlySpan<byte> TritEncodings => new byte[]
{
private static ReadOnlySpan<byte> TritEncodings =>
[
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0,
2, 1, 0, 0, 0, 1, 0, 2, 0, 0, 0, 2, 0, 0, 0,
Expand Down Expand Up @@ -300,11 +300,11 @@ private static ReadOnlySpan<byte> GetQuintEncoding(int index)
2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 0, 2, 1, 1, 2,
1, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2,
0, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 1, 2, 2, 2,
};
2, 1, 2, 2, 2
];

private static ReadOnlySpan<byte> QuintEncodings => new byte[]
{
private static ReadOnlySpan<byte> QuintEncodings =>
[
0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 0, 4, 0, 0,
0, 4, 0, 4, 4, 0, 4, 4, 4, 0, 1, 0, 1, 1, 0,
2, 1, 0, 3, 1, 0, 4, 1, 0, 1, 4, 0, 4, 4, 1,
Expand All @@ -330,7 +330,7 @@ private static ReadOnlySpan<byte> GetQuintEncoding(int index)
0, 1, 4, 1, 1, 4, 0, 2, 3, 1, 2, 3, 2, 2, 3,
3, 2, 3, 4, 2, 3, 2, 4, 3, 0, 2, 4, 1, 2, 4,
0, 3, 3, 1, 3, 3, 2, 3, 3, 3, 3, 3, 4, 3, 3,
3, 4, 3, 0, 3, 4, 1, 3, 4,
};
3, 4, 3, 0, 3, 4, 1, 3, 4
];
}
}
62 changes: 31 additions & 31 deletions src/Ryujinx.Graphics.Texture/ETC2Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ public static class ETC2Decoder
private const int BlockHeight = 4;

private static readonly int[][] _etc1Lut =
{
new int[] { 2, 8, -2, -8 },
new int[] { 5, 17, -5, -17 },
new int[] { 9, 29, -9, -29 },
new int[] { 13, 42, -13, -42 },
new int[] { 18, 60, -18, -60 },
new int[] { 24, 80, -24, -80 },
new int[] { 33, 106, -33, -106 },
new int[] { 47, 183, -47, -183 },
};
[
[2, 8, -2, -8],
[5, 17, -5, -17],
[9, 29, -9, -29],
[13, 42, -13, -42],
[18, 60, -18, -60],
[24, 80, -24, -80],
[33, 106, -33, -106],
[47, 183, -47, -183]
];

private static readonly int[] _etc2Lut =
{
3, 6, 11, 16, 23, 32, 41, 64,
};
[
3, 6, 11, 16, 23, 32, 41, 64
];

private static readonly int[][] _etc2AlphaLut =
{
new int[] { -3, -6, -9, -15, 2, 5, 8, 14 },
new int[] { -3, -7, -10, -13, 2, 6, 9, 12 },
new int[] { -2, -5, -8, -13, 1, 4, 7, 12 },
new int[] { -2, -4, -6, -13, 1, 3, 5, 12 },
new int[] { -3, -6, -8, -12, 2, 5, 7, 11 },
new int[] { -3, -7, -9, -11, 2, 6, 8, 10 },
new int[] { -4, -7, -8, -11, 3, 6, 7, 10 },
new int[] { -3, -5, -8, -11, 2, 4, 7, 10 },
new int[] { -2, -6, -8, -10, 1, 5, 7, 9 },
new int[] { -2, -5, -8, -10, 1, 4, 7, 9 },
new int[] { -2, -4, -8, -10, 1, 3, 7, 9 },
new int[] { -2, -5, -7, -10, 1, 4, 6, 9 },
new int[] { -3, -4, -7, -10, 2, 3, 6, 9 },
new int[] { -1, -2, -3, -10, 0, 1, 2, 9 },
new int[] { -4, -6, -8, -9, 3, 5, 7, 8 },
new int[] { -3, -5, -7, -9, 2, 4, 6, 8 },
};
[
[-3, -6, -9, -15, 2, 5, 8, 14],
[-3, -7, -10, -13, 2, 6, 9, 12],
[-2, -5, -8, -13, 1, 4, 7, 12],
[-2, -4, -6, -13, 1, 3, 5, 12],
[-3, -6, -8, -12, 2, 5, 7, 11],
[-3, -7, -9, -11, 2, 6, 8, 10],
[-4, -7, -8, -11, 3, 6, 7, 10],
[-3, -5, -8, -11, 2, 4, 7, 10],
[-2, -6, -8, -10, 1, 5, 7, 9],
[-2, -5, -8, -10, 1, 4, 7, 9],
[-2, -4, -8, -10, 1, 3, 7, 9],
[-2, -5, -7, -10, 1, 4, 6, 9],
[-3, -4, -7, -10, 2, 3, 6, 9],
[-1, -2, -3, -10, 0, 1, 2, 9],
[-4, -6, -8, -9, 3, 5, 7, 8],
[-3, -5, -7, -9, 2, 4, 6, 8]
];

public static MemoryOwner<byte> DecodeRgb(ReadOnlySpan<byte> data, int width, int height, int depth, int levels, int layers)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Texture/Encoders/BC7Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public static void Encode(Memory<byte> outputStorage, ReadOnlyMemory<byte> data,
}
}

private static readonly int[] _mostFrequentPartitions = new int[]
{
0, 13, 2, 1, 15, 14, 10, 23,
};
private static readonly int[] _mostFrequentPartitions =
[
0, 13, 2, 1, 15, 14, 10, 23
];

private static Block CompressBlock(ReadOnlySpan<byte> data, int x, int y, int width, int height, bool fastMode)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Graphics.Texture/SizeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public readonly struct SizeInfo

public SizeInfo(int size)
{
_mipOffsets = new int[] { 0 };
AllOffsets = new int[] { 0 };
SliceSizes = new int[] { size };
LevelSizes = new int[] { size };
_mipOffsets = [0];
AllOffsets = [0];
SliceSizes = [size];
LevelSizes = [size];
_depth = 1;
_levels = 1;
LayerSize = size;
Expand Down
Loading

0 comments on commit ac838aa

Please sign in to comment.