From 4da44e09cb2a32f69b4a6b47221117b78e4618dc Mon Sep 17 00:00:00 2001 From: Andrey Sukharev Date: Mon, 5 Dec 2022 16:47:39 +0300 Subject: 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 --- .../Shader/DiskCache/BackgroundDiskCacheWriter.cs | 4 ++-- .../Shader/DiskCache/GuestCodeAndCbData.cs | 2 +- .../Shader/DiskCache/ParallelDiskCacheLoader.cs | 6 +++--- Ryujinx.Graphics.Gpu/Shader/GpuChannelComputeState.cs | 2 +- Ryujinx.Graphics.Gpu/Shader/GpuChannelPoolState.cs | 2 +- .../Shader/HashTable/PartitionedHashTable.cs | 2 +- Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 6 +++--- Ryujinx.Graphics.Gpu/Shader/ShaderCodeAccessor.cs | 2 +- Ryujinx.Graphics.Gpu/Shader/ShaderDumpPaths.cs | 2 +- .../Shader/ShaderSpecializationState.cs | 17 +---------------- 10 files changed, 15 insertions(+), 30 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Shader') diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/BackgroundDiskCacheWriter.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/BackgroundDiskCacheWriter.cs index 98655ed6..568fe968 100644 --- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/BackgroundDiskCacheWriter.cs +++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/BackgroundDiskCacheWriter.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache /// /// Represents an operation to perform on the . /// - private struct CacheFileOperationTask + private readonly struct CacheFileOperationTask { /// /// The type of operation to perform. @@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache /// /// Background shader cache write information. /// - private struct AddShaderData + private readonly struct AddShaderData { /// /// Cached shader program. diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/GuestCodeAndCbData.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/GuestCodeAndCbData.cs index 0096533d..959d6e18 100644 --- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/GuestCodeAndCbData.cs +++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/GuestCodeAndCbData.cs @@ -3,7 +3,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache /// /// Guest shader code and constant buffer data accessed by the shader. /// - struct GuestCodeAndCbData + readonly struct GuestCodeAndCbData { /// /// Maxwell binary shader code. diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/ParallelDiskCacheLoader.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/ParallelDiskCacheLoader.cs index 9261cb0d..722e66b3 100644 --- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/ParallelDiskCacheLoader.cs +++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/ParallelDiskCacheLoader.cs @@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache /// /// Program validation entry. /// - private struct ProgramEntry + private readonly struct ProgramEntry { /// /// Cached shader program. @@ -90,7 +90,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache /// /// Translated shader compilation entry. /// - private struct ProgramCompilation + private readonly struct ProgramCompilation { /// /// Translated shader stages. @@ -143,7 +143,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache /// /// Program translation entry. /// - private struct AsyncProgramTranslation + private readonly struct AsyncProgramTranslation { /// /// Guest code for each active stage. diff --git a/Ryujinx.Graphics.Gpu/Shader/GpuChannelComputeState.cs b/Ryujinx.Graphics.Gpu/Shader/GpuChannelComputeState.cs index 356d3f3e..b65dd75e 100644 --- a/Ryujinx.Graphics.Gpu/Shader/GpuChannelComputeState.cs +++ b/Ryujinx.Graphics.Gpu/Shader/GpuChannelComputeState.cs @@ -3,7 +3,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// State used by the . /// - struct GpuChannelComputeState + readonly struct GpuChannelComputeState { // New fields should be added to the end of the struct to keep disk shader cache compatibility. diff --git a/Ryujinx.Graphics.Gpu/Shader/GpuChannelPoolState.cs b/Ryujinx.Graphics.Gpu/Shader/GpuChannelPoolState.cs index b894c57e..1e34c5de 100644 --- a/Ryujinx.Graphics.Gpu/Shader/GpuChannelPoolState.cs +++ b/Ryujinx.Graphics.Gpu/Shader/GpuChannelPoolState.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// State used by the . /// - struct GpuChannelPoolState : IEquatable + readonly struct GpuChannelPoolState : IEquatable { /// /// GPU virtual address of the texture pool. diff --git a/Ryujinx.Graphics.Gpu/Shader/HashTable/PartitionedHashTable.cs b/Ryujinx.Graphics.Gpu/Shader/HashTable/PartitionedHashTable.cs index f26fbdbb..e9a4f654 100644 --- a/Ryujinx.Graphics.Gpu/Shader/HashTable/PartitionedHashTable.cs +++ b/Ryujinx.Graphics.Gpu/Shader/HashTable/PartitionedHashTable.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.HashTable /// /// Entry for a given data size. /// - private struct SizeEntry + private readonly struct SizeEntry { /// /// Size for the data that will be stored on the hash table on this entry. diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 23b213b4..5c045d9b 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -26,7 +26,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// 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 _cpPrograms; private readonly Dictionary _gpPrograms; - private struct ProgramToSave + private readonly struct ProgramToSave { public readonly CachedShaderProgram CachedProgram; public readonly IProgram HostProgram; diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCodeAccessor.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCodeAccessor.cs index dbb33d22..e896493c 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCodeAccessor.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCodeAccessor.cs @@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// Shader code accessor. /// - struct ShaderCodeAccessor : IDataAccessor + readonly struct ShaderCodeAccessor : IDataAccessor { private readonly MemoryManager _memoryManager; private readonly ulong _baseAddress; diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderDumpPaths.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderDumpPaths.cs index f96a8ce1..6ca7daef 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderDumpPaths.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderDumpPaths.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// Paths where shader code was dumped on disk. /// - struct ShaderDumpPaths + readonly struct ShaderDumpPaths { /// /// Path where the full shader code with header was dumped, or null if not dumped. diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs index 14f64bbf..872aaf67 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderSpecializationState.cs @@ -121,7 +121,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// Texture binding information, used to identify each texture accessed by the shader. /// - private struct TextureKey : IEquatable + 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> _textureSpecialization; -- cgit v1.2.3