Make structs readonly when applicable (#4002)

* Make all structs readonly when applicable. It should reduce amount of needless defensive copies

* Make structs with trivial boilerplate equality code record structs

* Remove unnecessary readonly modifiers from TextureCreateInfo

* Make BitMap structs readonly too
This commit is contained in:
Andrey Sukharev 2022-12-05 16:47:39 +03:00 committed by GitHub
parent ae13f0ab4d
commit 4da44e09cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
133 changed files with 156 additions and 378 deletions

View file

@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <summary>
/// Represents an operation to perform on the <see cref="_fileWriterWorkerQueue"/>.
/// </summary>
private struct CacheFileOperationTask
private readonly struct CacheFileOperationTask
{
/// <summary>
/// The type of operation to perform.
@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <summary>
/// Background shader cache write information.
/// </summary>
private struct AddShaderData
private readonly struct AddShaderData
{
/// <summary>
/// Cached shader program.

View file

@ -3,7 +3,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <summary>
/// Guest shader code and constant buffer data accessed by the shader.
/// </summary>
struct GuestCodeAndCbData
readonly struct GuestCodeAndCbData
{
/// <summary>
/// Maxwell binary shader code.

View file

@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <summary>
/// Program validation entry.
/// </summary>
private struct ProgramEntry
private readonly struct ProgramEntry
{
/// <summary>
/// Cached shader program.
@ -90,7 +90,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <summary>
/// Translated shader compilation entry.
/// </summary>
private struct ProgramCompilation
private readonly struct ProgramCompilation
{
/// <summary>
/// Translated shader stages.
@ -143,7 +143,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <summary>
/// Program translation entry.
/// </summary>
private struct AsyncProgramTranslation
private readonly struct AsyncProgramTranslation
{
/// <summary>
/// Guest code for each active stage.

View file

@ -3,7 +3,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary>
/// State used by the <see cref="GpuAccessor"/>.
/// </summary>
struct GpuChannelComputeState
readonly struct GpuChannelComputeState
{
// New fields should be added to the end of the struct to keep disk shader cache compatibility.

View file

@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary>
/// State used by the <see cref="GpuAccessor"/>.
/// </summary>
struct GpuChannelPoolState : IEquatable<GpuChannelPoolState>
readonly struct GpuChannelPoolState : IEquatable<GpuChannelPoolState>
{
/// <summary>
/// GPU virtual address of the texture pool.

View file

@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.HashTable
/// <summary>
/// Entry for a given data size.
/// </summary>
private struct SizeEntry
private readonly struct SizeEntry
{
/// <summary>
/// Size for the data that will be stored on the hash table on this entry.

View file

@ -26,7 +26,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// </summary>
public const TranslationFlags DefaultFlags = TranslationFlags.DebugMode;
private struct TranslatedShader
private readonly struct TranslatedShader
{
public readonly CachedShaderStage Shader;
public readonly ShaderProgram Program;
@ -38,7 +38,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
}
}
private struct TranslatedShaderVertexPair
private readonly struct TranslatedShaderVertexPair
{
public readonly CachedShaderStage VertexA;
public readonly CachedShaderStage VertexB;
@ -59,7 +59,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
private readonly Dictionary<ulong, CachedShaderProgram> _cpPrograms;
private readonly Dictionary<ShaderAddresses, CachedShaderProgram> _gpPrograms;
private struct ProgramToSave
private readonly struct ProgramToSave
{
public readonly CachedShaderProgram CachedProgram;
public readonly IProgram HostProgram;

View file

@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary>
/// Shader code accessor.
/// </summary>
struct ShaderCodeAccessor : IDataAccessor
readonly struct ShaderCodeAccessor : IDataAccessor
{
private readonly MemoryManager _memoryManager;
private readonly ulong _baseAddress;

View file

@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary>
/// Paths where shader code was dumped on disk.
/// </summary>
struct ShaderDumpPaths
readonly struct ShaderDumpPaths
{
/// <summary>
/// Path where the full shader code with header was dumped, or null if not dumped.

View file

@ -121,7 +121,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary>
/// Texture binding information, used to identify each texture accessed by the shader.
/// </summary>
private struct TextureKey : IEquatable<TextureKey>
private readonly record struct TextureKey
{
// New fields should be added to the end of the struct to keep disk shader cache compatibility.
@ -152,21 +152,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
Handle = handle;
CbufSlot = cbufSlot;
}
public override bool Equals(object obj)
{
return obj is TextureKey textureKey && Equals(textureKey);
}
public bool Equals(TextureKey other)
{
return StageIndex == other.StageIndex && Handle == other.Handle && CbufSlot == other.CbufSlot;
}
public override int GetHashCode()
{
return HashCode.Combine(StageIndex, Handle, CbufSlot);
}
}
private readonly Dictionary<TextureKey, Box<TextureSpecializationState>> _textureSpecialization;