using System; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.Core.Intrinsics.Attributes; #if !NET6_0_OR_GREATER using RuntimeHelpers = ComputeSharp.NetStandard.RuntimeHelpers; #endif #nullable enable #pragma warning disable CS0660, CS0661 namespace ComputeSharp; /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] public unsafe partial struct Float2 #if NET6_0_OR_GREATER : ISpanFormattable #endif { /// /// A private buffer to which the undefined properties will point to. /// private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float2), sizeof(Float4)); [FieldOffset(0)] private float x; [FieldOffset(4)] private float y; /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public ref float this[int i] => ref *(float*)UndefinedData; /// /// Gets a value with all components set to 0. /// public static Float2 Zero => 0; /// /// Gets a value with all components set to 1. /// public static Float2 One => 1; /// /// Gets a value with the component set to 1, and the others to 0. /// public static Float2 UnitX => new(1, 0); /// /// Gets a value with the component set to 1, and the others to 0. /// public static Float2 UnitY => new(0, 1); /// /// Gets a reference to the value representing the X component. /// [UnscopedRef] public ref float X => ref this.x; /// /// Gets a reference to the value representing the Y component. /// [UnscopedRef] public ref float Y => ref this.y; /// /// Gets a readonly reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float2 XX => ref *(Float2*)UndefinedData; /// /// Gets a reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public ref Float2 XY => ref *(Float2*)UndefinedData; /// /// Gets a reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public ref Float2 YX => ref *(Float2*)UndefinedData; /// /// Gets a readonly reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float2 YY => ref *(Float2*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 XXX => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 XXY => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 XYX => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 XYY => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 YXX => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 YXY => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 YYX => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 YYY => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XXXX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XXXY => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XXYX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XXYY => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XYXX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XYXY => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XYYX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 XYYY => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YXXX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YXXY => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YXYX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YXYY => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YYXX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YYXY => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YYYX => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 YYYY => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the R component. /// [UnscopedRef] public ref float R => ref this.x; /// /// Gets a reference to the value representing the G component. /// [UnscopedRef] public ref float G => ref this.y; /// /// Gets a readonly reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float2 RR => ref *(Float2*)UndefinedData; /// /// Gets a reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public ref Float2 RG => ref *(Float2*)UndefinedData; /// /// Gets a reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public ref Float2 GR => ref *(Float2*)UndefinedData; /// /// Gets a readonly reference to the value with the components , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float2 GG => ref *(Float2*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 RRR => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 RRG => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 RGR => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 RGG => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 GRR => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 GRG => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 GGR => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float3 GGG => ref *(Float3*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RRRR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RRRG => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RRGR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RRGG => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RGRR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RGRG => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RGGR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 RGGG => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GRRR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GRRG => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GRGR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GRGG => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GGRR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GGRG => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GGGR => ref *(Float4*)UndefinedData; /// /// Gets a readonly reference to the value with the components , , , . /// /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. [UnscopedRef] public readonly ref readonly Float4 GGGG => ref *(Float4*)UndefinedData; #if !SOURCE_GENERATOR /// public override readonly string ToString() { string separator = NumberFormatInfo.CurrentInfo.NumberGroupSeparator; #if NET6_0_OR_GREATER return string.Create(null, stackalloc char[64], $"<{this.x}{separator} {this.y}>"); #else return $"<{this.x}{separator} {this.y}>"; #endif } /// public readonly string ToString(string? format, IFormatProvider? formatProvider) { string separator = NumberFormatInfo.GetInstance(formatProvider).NumberGroupSeparator; return FormatInterpolatedStringHandler.Create( format, formatProvider, stackalloc char[64], $"<{this.x}{separator} {this.y}>"); } /// public readonly bool TryFormat(Span destination, out int charsWritten, ReadOnlySpan format, IFormatProvider? provider) { string separator = NumberFormatInfo.GetInstance(provider).NumberGroupSeparator; return TryWriteFormatInterpolatedStringHandler.TryWrite( destination, format, provider, $"<{this.x}{separator} {this.y}>", out charsWritten); } #endif /// /// Negates a value. /// /// The value to negate. /// The negated value of . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator -(Float2 xy) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. /// The result of adding and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator +(Float2 left, Float2 right) => default; /// /// Divides two values. /// /// The first value to divide. /// The second value to divide. /// The result of dividing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator /(Float2 left, Float2 right) => default; /// /// Calculates the remainder of the division between two values. /// /// The first value to divide. /// The second value to divide. /// The remainder of dividing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator %(Float2 left, Float2 right) => default; /// /// Multiplies two values. /// /// The first value to multiply. /// The second value to multiply. /// The result of multiplying and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator *(Float2 left, Float2 right) => default; /// /// Multiplies a pair of and values. /// /// The value to multiply. /// The value to multiply. /// The result of multiplying and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator *(Float2 left, float right) => default; /// /// Multiplies a pair of and values. /// /// The value to multiply. /// The value to multiply. /// The result of multiplying and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator *(float left, Float2 right) => default; /// /// Multiplies two values using matrix math. /// /// The first Float2 input value. /// The second Float2x1 input value. /// The result of times . The result has the dimension -rows by -columns. /// /// This operator is equivalent to using with the same input arguments. /// For more info, see . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. /// [HlslIntrinsicName("mul", RequiresParametersMatching = true)] public static float operator *(Float2 x, Float2x1 y) => default; /// /// Multiplies two values using matrix math. /// /// The first Float2 input value. /// The second Float2x2 input value. /// The result of times . The result has the dimension -rows by -columns. /// /// This operator is equivalent to using with the same input arguments. /// For more info, see . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. /// [HlslIntrinsicName("mul", RequiresParametersMatching = true)] public static Float2 operator *(Float2 x, Float2x2 y) => default; /// /// Multiplies two values using matrix math. /// /// The first Float2 input value. /// The second Float2x3 input value. /// The result of times . The result has the dimension -rows by -columns. /// /// This operator is equivalent to using with the same input arguments. /// For more info, see . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. /// [HlslIntrinsicName("mul", RequiresParametersMatching = true)] public static Float3 operator *(Float2 x, Float2x3 y) => default; /// /// Multiplies two values using matrix math. /// /// The first Float2 input value. /// The second Float2x4 input value. /// The result of times . The result has the dimension -rows by -columns. /// /// This operator is equivalent to using with the same input arguments. /// For more info, see . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. /// [HlslIntrinsicName("mul", RequiresParametersMatching = true)] public static Float4 operator *(Float2 x, Float2x4 y) => default; /// /// Multiplies two values using matrix math. /// /// The first Float2x2 input value. /// The second Float2 input value. /// The result of times . The result has the dimension -rows by -columns. /// /// This operator is equivalent to using with the same input arguments. /// For more info, see . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. /// [HlslIntrinsicName("mul", RequiresParametersMatching = true)] public static Float2 operator *(Float2x2 x, Float2 y) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. /// The result of subtracting and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Float2 operator -(Float2 left, Float2 right) => default; /// /// Compares two values to see if the first is greater than the second. /// /// The first value to compare. /// The second value to compare. /// The result of comparing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Bool2 operator >(Float2 left, Float2 right) => default; /// /// Compares two values to see if the first is greater than or equal to the second. /// /// The first value to compare. /// The second value to compare. /// The result of comparing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Bool2 operator >=(Float2 left, Float2 right) => default; /// /// Compares two values to see if the first is lower than the second. /// /// The first value to compare. /// The second value to compare. /// The result of comparing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Bool2 operator <(Float2 left, Float2 right) => default; /// /// Compares two values to see if the first is lower than or equal to the second. /// /// The first value to compare. /// The second value to compare. /// The result of comparing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Bool2 operator <=(Float2 left, Float2 right) => default; /// /// Compares two values to see if they are equal. /// /// The first value to compare. /// The second value to compare. /// The result of comparing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Bool2 operator ==(Float2 left, Float2 right) => default; /// /// Compares two values to see if they are not equal. /// /// The first value to compare. /// The second value to compare. /// The result of comparing and . /// This method is an intrinsic and can only be used within a shader on the GPU. Using it on the CPU is undefined behavior. public static Bool2 operator !=(Float2 left, Float2 right) => default; }