diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index d777fdc5..f4f964df 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -70,6 +70,18 @@ partial class ID2D1ShaderGenerator { switch (fieldInfo) { + case FieldInfo.Primitive { TypeName: "System.Boolean" } primitive: + + // Read a boolean value and cast it to Bool first, which will apply the correct size expansion. This will generate the following: + // + // global::System.Runtime.CompilerServices.Unsafe.As( + // ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint))) = (global::ComputeSharp.Bool) + statements.Add(ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){primitive.Offset}))"), + ParseExpression($"(global::ComputeSharp.Bool){string.Join(".", primitive.FieldPath)}")))); + break; case FieldInfo.Primitive primitive: // Read a primitive value and serialize it into the target buffer. This will generate: diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index 006f1058..1d3a8c4d 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -121,6 +121,18 @@ partial class IShaderGenerator ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.Add(ref r1, {resource.Offset})"), ParseExpression($"global::ComputeSharp.__Internals.GraphicsResourceHelper.ValidateAndGetGpuDescriptorHandle({resource.FieldName}, device)")))); break; + case FieldInfo.Primitive { TypeName: "System.Boolean" } primitive: + + // Read a boolean value and cast it to Bool first, which will apply the correct size expansion. This will generate the following: + // + // global::System.Runtime.CompilerServices.Unsafe.As( + // ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint))) = (global::ComputeSharp.Bool) + statements.Add(ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){primitive.Offset}))"), + ParseExpression($"(global::ComputeSharp.Bool){string.Join(".", primitive.FieldPath)}")))); + break; case FieldInfo.Primitive primitive: // Read a primitive value and serialize it into the target buffer. This will generate: