using System; using System.Runtime.InteropServices; namespace ComputeSharp; /// /// A that can be used in place of the type in HLSL shaders. /// [StructLayout(LayoutKind.Explicit, Size = sizeof(int), Pack = 4)] public readonly struct Bool { /// /// The wrapped value for the current instance. /// [FieldOffset(0)] private readonly bool Value; /// /// Creates a new instance for a given value. /// /// . private Bool(bool value) { Value = value; } /// public override bool Equals(object? obj) { return obj is Bool x && Value == x.Value; } /// public override int GetHashCode() { return Value.GetHashCode(); } /// public override string ToString() { return Value.ToString(); } /// public string ToString(IFormatProvider? formatProvider) { return Value.ToString(); } #if NET6_0_OR_GREATER /// public bool TryFormat(Span destination, out int charsWritten) { return Value.TryFormat(destination, out charsWritten); } #endif /// /// Checks whether or not two instances represent the same value. /// /// The left instance. /// The right instance. public static bool operator ==(Bool left, Bool right) => left.Value == right.Value; /// /// Checks whether or not two instances represent a different value. /// /// The left instance. /// The right instance. public static bool operator !=(Bool left, Bool right) => left.Value != right.Value; /// /// Inverts the value represented by a given instance. /// /// The input instance. public static Bool operator !(Bool x) => new(!x.Value); /// /// Converts a given instance to its corresponding value. /// /// The input instance. public static implicit operator bool(Bool x) => x.Value; /// /// Converts a value to a corresponding instance. /// /// The input value. public static implicit operator Bool(bool x) => new(x); }