diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/ConstantBufferSyntaxProcessor.Generation.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/ConstantBufferSyntaxProcessor.Generation.cs index 33ef9421..3cd7393e 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/ConstantBufferSyntaxProcessor.Generation.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxProcessors/ConstantBufferSyntaxProcessor.Generation.cs @@ -199,7 +199,7 @@ partial class ConstantBufferSyntaxProcessor writer.WriteLine($"""/// The marshalled instance."""); writer.WriteLine($"""[MethodImpl(MethodImplOptions.AggressiveInlining)]"""); writer.WriteLine($"""[SkipLocalsInit]"""); - writer.WriteLine($"public static {fullyQualifiedTypeName} ToManaged(in ConstantBuffer buffer)"); + writer.WriteLine($"public static {fullyQualifiedTypeName} ToManaged(ref readonly ConstantBuffer buffer)"); using (writer.WriteBlock()) { diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ConstantBuffer.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ConstantBuffer.cs index 1ac0c9b3..2fdaad14 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ConstantBuffer.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.ConstantBuffer.cs @@ -82,7 +82,7 @@ partial class ComputeShaderDescriptorGenerator writer.WriteLine("buffer.__x = x;"); writer.WriteLine("buffer.__y = y;"); writer.WriteLineIf(!info.IsPixelShaderLike, "buffer.__z = z;"); - writer.WriteLineIf(!info.IsPixelShaderLike); + writer.WriteLine(skipIfPresent: true); writer.WriteLine("loader.LoadConstantBuffer(new global::System.ReadOnlySpan(&buffer, sizeof(global::ComputeSharp.Generated.ConstantBuffer)));"); } } diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs index c7b39878..f772dbcc 100644 --- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs +++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator.cs @@ -281,7 +281,7 @@ public class Test_D2DPixelShaderDescriptorGenerator /// The marshalled instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] [SkipLocalsInit] - public static global::MyNamespace.MyShader ToManaged(in ConstantBuffer buffer) + public static global::MyNamespace.MyShader ToManaged(ref readonly ConstantBuffer buffer) { Unsafe.SkipInit(out global::MyNamespace.MyShader shader); @@ -583,7 +583,7 @@ public class Test_D2DPixelShaderDescriptorGenerator /// The marshalled instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] [SkipLocalsInit] - public static global::MyNamespace.MyShader ToManaged(in ConstantBuffer buffer) + public static global::MyNamespace.MyShader ToManaged(ref readonly ConstantBuffer buffer) { Unsafe.SkipInit(out global::MyNamespace.MyShader shader); @@ -933,7 +933,7 @@ public class Test_D2DPixelShaderDescriptorGenerator /// The marshalled instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] [SkipLocalsInit] - public static global::MyNamespace.MyShader ToManaged(in ConstantBuffer buffer) + public static global::MyNamespace.MyShader ToManaged(ref readonly ConstantBuffer buffer) { Unsafe.SkipInit(out global::MyNamespace.MyShader shader); @@ -1231,7 +1231,7 @@ public class Test_D2DPixelShaderDescriptorGenerator /// The marshalled instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] [SkipLocalsInit] - public static global::MyNamespace.MyShader ToManaged(in ConstantBuffer buffer) + public static global::MyNamespace.MyShader ToManaged(ref readonly ConstantBuffer buffer) { Unsafe.SkipInit(out global::MyNamespace.MyShader shader); diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs index 3ef2ed33..3f9c5fe9 100644 --- a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs +++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs @@ -423,6 +423,7 @@ public class Test_ComputeShaderDescriptorGenerator buffer.__x = x; buffer.__y = y; + loader.LoadConstantBuffer(new global::System.ReadOnlySpan(&buffer, sizeof(global::ComputeSharp.Generated.ConstantBuffer))); }