From 0ff4d41a0ad72748a6a435dda65ae82d49723649 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 22 Oct 2022 19:11:38 +0200 Subject: [PATCH] Fix more analyzer warnings (mostly missing readonly) --- .../Shaders/Interop/D2D1PixelShaderEffect.cs | 7 +++---- .../Windows/other/helper-types/BOOL.cs | 2 +- .../Windows/other/helper-types/HANDLE.cs | 2 +- .../Windows/other/helper-types/HRESULT.cs | 2 +- .../Windows/other/helper-types/HWND.cs | 2 +- .../Windows/other/helper-types/LPARAM.cs | 2 +- .../Windows/other/helper-types/LRESULT.cs | 2 +- .../Windows/other/helper-types/WPARAM.cs | 2 +- tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs | 4 ++-- tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs | 4 ++-- tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs | 2 +- 11 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs index 52f4044e..4e88db45 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs @@ -340,8 +340,6 @@ public static unsafe class D2D1PixelShaderEffect public static ReadOnlyMemory GetRegistrationBlob(ID2D1TransformMapperFactory? mapperFactory, out Guid effectId) where T : unmanaged, ID2D1PixelShader { - effectId = default; - PixelShaderEffect.For.Initialize(mapperFactory); ArrayPoolBufferWriter writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize); @@ -514,12 +512,13 @@ public static unsafe class D2D1PixelShaderEffect // Effect factory writer.WriteRaw((nint)PixelShaderEffect.For.Factory); - effectId = PixelShaderEffect.For.Id; - byte[] registrationBlob = writer.WrittenSpan.ToArray(); writer.Dispose(); + // Extract the effect id (the same that was encoded in the registration blob) + effectId = PixelShaderEffect.For.Id; + return registrationBlob; } diff --git a/src/TerraFX.Interop.Windows/Windows/other/helper-types/BOOL.cs b/src/TerraFX.Interop.Windows/Windows/other/helper-types/BOOL.cs index 6698a75a..7d9fc597 100644 --- a/src/TerraFX.Interop.Windows/Windows/other/helper-types/BOOL.cs +++ b/src/TerraFX.Interop.Windows/Windows/other/helper-types/BOOL.cs @@ -4,7 +4,7 @@ using System; namespace TerraFX.Interop.Windows { - internal partial struct BOOL : IComparable, IComparable, IEquatable, IFormattable + internal readonly partial struct BOOL : IComparable, IComparable, IEquatable, IFormattable { public readonly int Value; diff --git a/src/TerraFX.Interop.Windows/Windows/other/helper-types/HANDLE.cs b/src/TerraFX.Interop.Windows/Windows/other/helper-types/HANDLE.cs index cca80e73..5d6dfa1c 100644 --- a/src/TerraFX.Interop.Windows/Windows/other/helper-types/HANDLE.cs +++ b/src/TerraFX.Interop.Windows/Windows/other/helper-types/HANDLE.cs @@ -4,7 +4,7 @@ using System; namespace TerraFX.Interop.Windows { - internal unsafe partial struct HANDLE : IComparable, IComparable, IEquatable, IFormattable + internal readonly unsafe partial struct HANDLE : IComparable, IComparable, IEquatable, IFormattable { public readonly void* Value; diff --git a/src/TerraFX.Interop.Windows/Windows/other/helper-types/HRESULT.cs b/src/TerraFX.Interop.Windows/Windows/other/helper-types/HRESULT.cs index efd5b460..99155dba 100644 --- a/src/TerraFX.Interop.Windows/Windows/other/helper-types/HRESULT.cs +++ b/src/TerraFX.Interop.Windows/Windows/other/helper-types/HRESULT.cs @@ -4,7 +4,7 @@ using System; namespace TerraFX.Interop.Windows { - internal unsafe partial struct HRESULT : IComparable, IComparable, IEquatable, IFormattable + internal readonly unsafe partial struct HRESULT : IComparable, IComparable, IEquatable, IFormattable { public readonly int Value; diff --git a/src/TerraFX.Interop.Windows/Windows/other/helper-types/HWND.cs b/src/TerraFX.Interop.Windows/Windows/other/helper-types/HWND.cs index 5b66968d..55366762 100644 --- a/src/TerraFX.Interop.Windows/Windows/other/helper-types/HWND.cs +++ b/src/TerraFX.Interop.Windows/Windows/other/helper-types/HWND.cs @@ -4,7 +4,7 @@ using System; namespace TerraFX.Interop.Windows { - internal unsafe partial struct HWND : IComparable, IComparable, IEquatable, IFormattable + internal readonly unsafe partial struct HWND : IComparable, IComparable, IEquatable, IFormattable { public readonly void* Value; diff --git a/src/TerraFX.Interop.Windows/Windows/other/helper-types/LPARAM.cs b/src/TerraFX.Interop.Windows/Windows/other/helper-types/LPARAM.cs index 5225af47..cdcd7bfd 100644 --- a/src/TerraFX.Interop.Windows/Windows/other/helper-types/LPARAM.cs +++ b/src/TerraFX.Interop.Windows/Windows/other/helper-types/LPARAM.cs @@ -4,7 +4,7 @@ using System; namespace TerraFX.Interop.Windows { - internal unsafe partial struct LPARAM : IComparable, IComparable, IEquatable, IFormattable + internal readonly unsafe partial struct LPARAM : IComparable, IComparable, IEquatable, IFormattable { public readonly nint Value; diff --git a/src/TerraFX.Interop.Windows/Windows/other/helper-types/LRESULT.cs b/src/TerraFX.Interop.Windows/Windows/other/helper-types/LRESULT.cs index 30bbbb1c..051e7533 100644 --- a/src/TerraFX.Interop.Windows/Windows/other/helper-types/LRESULT.cs +++ b/src/TerraFX.Interop.Windows/Windows/other/helper-types/LRESULT.cs @@ -4,7 +4,7 @@ using System; namespace TerraFX.Interop.Windows { - internal partial struct LRESULT : IComparable, IComparable, IEquatable, IFormattable + internal readonly partial struct LRESULT : IComparable, IComparable, IEquatable, IFormattable { public readonly nint Value; diff --git a/src/TerraFX.Interop.Windows/Windows/other/helper-types/WPARAM.cs b/src/TerraFX.Interop.Windows/Windows/other/helper-types/WPARAM.cs index b4e1dca2..6eab09b3 100644 --- a/src/TerraFX.Interop.Windows/Windows/other/helper-types/WPARAM.cs +++ b/src/TerraFX.Interop.Windows/Windows/other/helper-types/WPARAM.cs @@ -4,7 +4,7 @@ using System; namespace TerraFX.Interop.Windows { - internal unsafe partial struct WPARAM : IComparable, IComparable, IEquatable, IFormattable + internal readonly unsafe partial struct WPARAM : IComparable, IComparable, IEquatable, IFormattable { public readonly nuint Value; diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs index 39e3c3f7..c68de934 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs @@ -508,7 +508,7 @@ public sealed partial class BokehBlurEffect [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] [D2DRequiresScenePosition] [AutoConstructor] - public partial struct Shader : ID2D1PixelShader + public readonly partial struct Shader : ID2D1PixelShader { public readonly int kernelLength; @@ -557,7 +557,7 @@ public sealed partial class BokehBlurEffect [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] [D2DRequiresScenePosition] [AutoConstructor] - public partial struct Shader : ID2D1PixelShader + public readonly partial struct Shader : ID2D1PixelShader { public readonly int kernelLength; private readonly float z; diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs index 161077a3..59ed43c7 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/PixelateEffect.cs @@ -5,10 +5,10 @@ namespace ComputeSharp.D2D1.Tests.Effects; [D2DRequiresScenePosition] [D2DShaderProfile(D2D1ShaderProfile.PixelShader40)] [AutoConstructor] -public partial struct PixelateEffect : ID2D1PixelShader +public readonly partial struct PixelateEffect : ID2D1PixelShader { [AutoConstructor] - public partial struct Constants + public readonly partial struct Constants { public readonly int inputWidth; public readonly int inputHeight; diff --git a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs index e261d54a..f2d367f0 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs +++ b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs @@ -133,7 +133,7 @@ public partial class DeviceDisposalTests [EmbeddedBytecode(DispatchAxis.X)] [AutoConstructor] - private partial struct InitializeShader : IComputeShader + private readonly partial struct InitializeShader : IComputeShader { private readonly ReadWriteBuffer buffer;