diff --git a/Directory.Build.props b/Directory.Build.props
index d1ad3df7..c26c1b9c 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -40,8 +40,8 @@
-
-
+
+
diff --git a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj
index 45c89c59..83e2dc56 100644
--- a/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj
+++ b/src/ComputeSharp.Core.SourceGenerators/ComputeSharp.Core.SourceGenerators.csproj
@@ -63,7 +63,7 @@
-
+
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
index d6125b6b..58f4f8f8 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
@@ -95,7 +95,7 @@
-
+
diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriterExtensions.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriterExtensions.cs
index 71ba9ed1..0ca1d077 100644
--- a/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriterExtensions.cs
+++ b/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriterExtensions.cs
@@ -23,7 +23,7 @@ internal static class ArrayPoolBinaryWriterExtensions
/// The target instance to write data to.
/// The value to write.
/// This method will just blit the data of into the target buffer.
- public static unsafe void WriteRaw(this in ArrayPoolBufferWriter writer, in T value)
+ public static unsafe void WriteRaw(this ref ArrayPoolBufferWriter writer, scoped in T value)
where T : unmanaged
{
Span span = writer.GetSpan(sizeof(T));
@@ -39,7 +39,7 @@ internal static class ArrayPoolBinaryWriterExtensions
/// The type of value to write.
/// The target instance to write data to.
/// The value to write.
- public static unsafe void WriteRaw(this in ArrayPoolBufferWriter writer, in T value)
+ public static unsafe void WriteRaw(this ref ArrayPoolBufferWriter writer, scoped in T value)
where T : unmanaged
{
Span span = writer.GetSpan(1);
@@ -55,7 +55,7 @@ internal static class ArrayPoolBinaryWriterExtensions
/// The type of values in the target writer.
/// The target instance to write data to.
/// The data to write.
- public static void WriteRaw(this in ArrayPoolBufferWriter writer, ReadOnlySpan data)
+ public static void WriteRaw(this ref ArrayPoolBufferWriter writer, scoped ReadOnlySpan data)
where T : unmanaged
{
Span span = writer.GetSpan(data.Length);
@@ -71,7 +71,7 @@ internal static class ArrayPoolBinaryWriterExtensions
///
/// The target instance to write data to.
/// The data to write.
- public static void WriteRaw(this in ArrayPoolBufferWriter writer, string data)
+ public static void WriteRaw(this ref ArrayPoolBufferWriter writer, string data)
{
Span span = writer.GetSpan(data.Length);
@@ -86,7 +86,7 @@ internal static class ArrayPoolBinaryWriterExtensions
///
/// The target instance to write data to.
/// The value to write.
- public static void WriteAsUtf8(this in ArrayPoolBufferWriter writer, int value)
+ public static void WriteAsUtf8(this ref ArrayPoolBufferWriter writer, int value)
{
#if NET6_0_OR_GREATER
// Get a span of at least 10 elements (10 is the length of int.MaxValue as text)
@@ -106,7 +106,7 @@ internal static class ArrayPoolBinaryWriterExtensions
///
/// The target instance to write data to.
/// The text to write.
- public static void WriteAsUtf8(this in ArrayPoolBufferWriter writer, string text)
+ public static void WriteAsUtf8(this ref ArrayPoolBufferWriter writer, string text)
{
int maximumByteSize = Encoding.UTF8.GetMaxByteCount(text.Length);
@@ -122,7 +122,7 @@ internal static class ArrayPoolBinaryWriterExtensions
///
/// The target instance to write data to.
/// The value to write.
- public static void WriteAsUnicode(this in ArrayPoolBufferWriter writer, int value)
+ public static void WriteAsUnicode(this ref ArrayPoolBufferWriter writer, int value)
{
#if NET6_0_OR_GREATER
// Get a span of at least 10 elements (10 is the length of int.MaxValue as text)
diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter{T}.cs
index 3d56598d..c5378083 100644
--- a/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter{T}.cs
+++ b/src/ComputeSharp.D2D1/Shaders/Interop/Buffers/ArrayPoolBinaryWriter{T}.cs
@@ -35,7 +35,7 @@ internal ref struct ArrayPoolBufferWriter
///
/// The starting offset within .
///
- private readonly int index;
+ private int index;
///
/// Initializes a new instance of the class.
@@ -59,7 +59,7 @@ internal ref struct ArrayPoolBufferWriter
if (array is null)
{
- ThrowObjectDisposedException();
+ ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
}
return array.AsSpan(0, this.index);
@@ -74,26 +74,26 @@ internal ref struct ArrayPoolBufferWriter
/// Must be called after .
/// This and the methods below are to enable mutating extensions.
///
- internal readonly void Advance(int count)
+ internal void Advance(int count)
{
T[]? array = this.array;
if (array is null)
{
- ThrowObjectDisposedException();
+ ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
}
if (count < 0)
{
- ThrowArgumentOutOfRangeExceptionForNegativeCount();
+ ArrayPoolBufferWriterHelpers.ThrowArgumentOutOfRangeExceptionForNegativeCount();
}
if (this.index > array.Length - count)
{
- ThrowArgumentExceptionForAdvancedTooFar();
+ ArrayPoolBufferWriterHelpers.ThrowArgumentExceptionForAdvancedTooFar();
}
- Unsafe.AsRef(in this.index) += count;
+ this.index += count;
}
///
@@ -102,7 +102,7 @@ internal ref struct ArrayPoolBufferWriter
/// The capacity to request.
/// A to write data to.
[UnscopedRef]
- internal readonly Span GetSpan(int sizeHint = 0)
+ internal Span GetSpan(int sizeHint = 0)
{
CheckBufferAndEnsureCapacity(sizeHint);
@@ -114,18 +114,18 @@ internal ref struct ArrayPoolBufferWriter
///
/// The minimum number of items to ensure space for in .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private readonly void CheckBufferAndEnsureCapacity(int sizeHint)
+ private void CheckBufferAndEnsureCapacity(int sizeHint)
{
T[]? array = this.array;
if (array is null)
{
- ThrowObjectDisposedException();
+ ArrayPoolBufferWriterHelpers.ThrowObjectDisposedException();
}
if (sizeHint < 0)
{
- ThrowArgumentOutOfRangeExceptionForNegativeSizeHint();
+ ArrayPoolBufferWriterHelpers.ThrowArgumentOutOfRangeExceptionForNegativeSizeHint();
}
if (sizeHint == 0)
@@ -144,7 +144,7 @@ internal ref struct ArrayPoolBufferWriter
///
/// The minimum number of items to ensure space for in .
[MethodImpl(MethodImplOptions.NoInlining)]
- private readonly unsafe void ResizeBuffer(int sizeHint)
+ private unsafe void ResizeBuffer(int sizeHint)
{
uint minimumSize = (uint)this.index + (uint)sizeHint;
@@ -164,7 +164,7 @@ internal ref struct ArrayPoolBufferWriter
ArrayPool.Shared.Return(this.array!);
- Unsafe.AsRef(in this.array) = newArray;
+ this.array = newArray;
}
///
@@ -181,12 +181,18 @@ internal ref struct ArrayPoolBufferWriter
ArrayPool.Shared.Return(array);
}
+}
+///
+/// Private helpers for .
+///
+file static class ArrayPoolBufferWriterHelpers
+{
///
/// Throws an when the requested count is negative.
///
[DoesNotReturn]
- private static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
+ public static void ThrowArgumentOutOfRangeExceptionForNegativeCount()
{
throw new ArgumentOutOfRangeException("count", "The count can't be a negative value.");
}
@@ -195,7 +201,7 @@ internal ref struct ArrayPoolBufferWriter
/// Throws an when the size hint is negative.
///
[DoesNotReturn]
- private static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
+ public static void ThrowArgumentOutOfRangeExceptionForNegativeSizeHint()
{
throw new ArgumentOutOfRangeException("sizeHint", "The size hint can't be a negative value.");
}
@@ -204,16 +210,16 @@ internal ref struct ArrayPoolBufferWriter
/// Throws an when the requested count is negative.
///
[DoesNotReturn]
- private static void ThrowArgumentExceptionForAdvancedTooFar()
+ public static void ThrowArgumentExceptionForAdvancedTooFar()
{
throw new ArgumentException("The buffer writer has advanced too far.");
}
///
- /// Throws an when is .
+ /// Throws an when the array is .
///
[DoesNotReturn]
- private static void ThrowObjectDisposedException()
+ public static void ThrowObjectDisposedException()
{
throw new ObjectDisposedException("The current buffer has already been disposed.");
}
diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs
index 8e2704c8..4e88db45 100644
--- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs
+++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs
@@ -82,7 +82,7 @@ public static unsafe class D2D1PixelShaderEffect
PixelShaderEffect.For.Initialize(mapperFactory);
- using ArrayPoolBufferWriter writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
+ ArrayPoolBufferWriter writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
// Build the XML text
writer.WriteRaw("""
@@ -263,6 +263,8 @@ public static unsafe class D2D1PixelShaderEffect
effectId = PixelShaderEffect.For.Id;
}
+
+ writer.Dispose();
}
///
@@ -338,11 +340,9 @@ public static unsafe class D2D1PixelShaderEffect
public static ReadOnlyMemory GetRegistrationBlob(ID2D1TransformMapperFactory? mapperFactory, out Guid effectId)
where T : unmanaged, ID2D1PixelShader
{
- effectId = default;
-
PixelShaderEffect.For.Initialize(mapperFactory);
- using ArrayPoolBufferWriter writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
+ ArrayPoolBufferWriter writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize);
// Blob id
writer.WriteRaw(D2D1EffectRegistrationData.V1.BlobId);
@@ -512,9 +512,14 @@ public static unsafe class D2D1PixelShaderEffect
// Effect factory
writer.WriteRaw((nint)PixelShaderEffect.For.Factory);
+ 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 writer.WrittenSpan.ToArray();
+ return registrationBlob;
}
///
diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
index fde18d60..91d5d798 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
+++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj
@@ -85,7 +85,7 @@
-
+
diff --git a/src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs b/src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs
index 2e9ef06e..7f2bc9f2 100644
--- a/src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs
+++ b/src/ComputeSharp/Shaders/Dispatching/__Internals/ArrayPoolStringBuilder.cs
@@ -44,7 +44,7 @@ public ref struct ArrayPoolStringBuilder
/// Gets the data written to the underlying buffer so far, as a .
///
[UnscopedRef]
- public ReadOnlySpan WrittenSpan
+ public readonly ReadOnlySpan WrittenSpan
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new(this.array, 0, this.index);
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;
diff --git a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj
index dece4391..b2877c18 100644
--- a/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj
+++ b/tests/ComputeSharp.Tests.SourceGenerators/ComputeSharp.Tests.SourceGenerators.csproj
@@ -9,7 +9,7 @@
-
+