diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs new file mode 100644 index 00000000..2675b97d --- /dev/null +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs @@ -0,0 +1,157 @@ +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; + +namespace ComputeSharp +{ + /// + /// A that maps the bool2 HLSL type + /// + [StructLayout(LayoutKind.Explicit, Size = sizeof(int) * 2)] + public struct Bool2 + { + /// + /// Gets an value with all components set to + /// + public static Bool2 False { get; } = new Bool2(false, false); + + /// + /// Gets an value with all components set to + /// + public static Bool2 True { get; } = new Bool2(true, true); + + /// + /// Gets an value with the component set to , and the others to + /// + public static Bool2 TrueX { get; } = new Bool2(true, false); + + /// + /// Gets an value with the component set to , and the others to + /// + public static Bool2 TrueY { get; } = new Bool2(false, true); + + /// + /// Creates a new instance with the specified parameters + /// + /// The value to assign to the first vector component + /// The value to assign to the second vector component + public Bool2(bool x, bool y) + { + _X = x; + _Y = y; + } + + [FieldOffset(0)] + private bool _X; + + /// + /// Gets or sets the value of the first vector component + /// + public bool X + { + get => _X; + set => _X = value; + } + + [FieldOffset(4)] + private bool _Y; + + /// + /// Gets or sets the value of the second vector component + /// + public bool Y + { + get => _Y; + set => _Y = value; + } + + /// + /// Gets or sets the value of the first color component + /// + public uint R + { + get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(R)}"); + set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(R)}"); + } + + /// + /// Gets or sets the value of the second color component + /// + public uint G + { + get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(G)}"); + set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(G)}"); + } + + /// + /// Gets or sets a specific component in the current instance + /// + /// The index of the component to access + public float this[int i] + { + get => throw new InvalidExecutionContextException($"{nameof(Bool2)}[int]"); + set => throw new InvalidExecutionContextException($"{nameof(Bool2)}[int]"); + } + + /// + /// Gets an value with the value for all components + /// + public Bool2 XX => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(XX)}"); + + /// + /// Gets or sets an value with the and values + /// + public Bool2 XY + { + get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(XY)}"); + set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(XY)}"); + } + + /// + /// Gets an value with the and values + /// + public Bool2 YX + { + get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(YX)}"); + set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(YX)}"); + } + + /// + /// Gets an value with the value for all components + /// + public Bool2 YY => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(YY)}"); + + /// + /// Gets an value with the value for all components + /// + public Bool2 RR => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(RR)}"); + + /// + /// Gets or sets an value with the and values + /// + public Bool2 RG + { + get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(RG)}"); + set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(RG)}"); + } + + /// + /// Gets an value with the and values + /// + public Bool2 GR + { + get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(GR)}"); + set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(GR)}"); + } + + /// + /// Gets an value with the value for all components + /// + public Bool2 GG => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(GG)}"); + + /// + /// Creates a new value with the same value for all its components + /// + /// The value to use for the components of the new instance + public static implicit operator Bool2(bool x) => new Bool2(x, x); + } +} diff --git a/src/ComputeSharp.Graphics/Buffers/Extensions/GraphicsResourceExtensions.cs b/src/ComputeSharp.Graphics/Buffers/Extensions/GraphicsResourceExtensions.cs index 75d6bf79..f1aa321c 100644 --- a/src/ComputeSharp.Graphics/Buffers/Extensions/GraphicsResourceExtensions.cs +++ b/src/ComputeSharp.Graphics/Buffers/Extensions/GraphicsResourceExtensions.cs @@ -44,6 +44,7 @@ namespace ComputeSharp.Graphics.Buffers.Extensions Unsafe.As(ref ub) = b; WriteValue(ub, ref r0); break; + case Bool2 b2: WriteValue(b2, ref r0); break; case int i: WriteValue(i, ref r0); break; case Int2 i2: WriteValue(i2, ref r0); break; case Int3 i3: WriteValue(i3, ref r0); break;