diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index ddedae12..fa5033e9 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -75,6 +75,11 @@ True Float4.tt + + True + True + FloatMxN.tt + True True @@ -144,6 +149,10 @@ TextTemplatingFileGenerator Float4.g.cs + + TextTemplatingFileGenerator + FloatMxN.g.cs + TextTemplatingFileGenerator Int2.g.cs diff --git a/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs new file mode 100644 index 00000000..93298f18 --- /dev/null +++ b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs @@ -0,0 +1,1025 @@ +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; + +namespace ComputeSharp +{ + /// + [StructLayout(LayoutKind.Explicit, Size = 4)] + public partial struct Float1x1 + { + [FieldOffset(0)] + private float m00; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref float this[int row] => throw new InvalidExecutionContextException($"{nameof(Float1x1)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float1x1 operator -(Float1x1 matrix) => throw new InvalidExecutionContextException($"{nameof(Float1x1)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float1x1 operator +(Float1x1 left, Float1x1 right) => throw new InvalidExecutionContextException($"{nameof(Float1x1)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float1x1 operator /(Float1x1 left, Float1x1 right) => throw new InvalidExecutionContextException($"{nameof(Float1x1)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float1x1 operator *(Float1x1 left, Float1x1 right) => throw new InvalidExecutionContextException($"{nameof(Float1x1)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float1x1 operator -(Float1x1 left, Float1x1 right) => throw new InvalidExecutionContextException($"{nameof(Float1x1)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 8)] + public partial struct Float1x2 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float1x2)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float1x2 operator -(Float1x2 matrix) => throw new InvalidExecutionContextException($"{nameof(Float1x2)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float1x2 operator +(Float1x2 left, Float1x2 right) => throw new InvalidExecutionContextException($"{nameof(Float1x2)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float1x2 operator /(Float1x2 left, Float1x2 right) => throw new InvalidExecutionContextException($"{nameof(Float1x2)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float1x2 operator *(Float1x2 left, Float1x2 right) => throw new InvalidExecutionContextException($"{nameof(Float1x2)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float1x2 operator -(Float1x2 left, Float1x2 right) => throw new InvalidExecutionContextException($"{nameof(Float1x2)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 12)] + public partial struct Float1x3 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float1x3)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float1x3 operator -(Float1x3 matrix) => throw new InvalidExecutionContextException($"{nameof(Float1x3)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float1x3 operator +(Float1x3 left, Float1x3 right) => throw new InvalidExecutionContextException($"{nameof(Float1x3)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float1x3 operator /(Float1x3 left, Float1x3 right) => throw new InvalidExecutionContextException($"{nameof(Float1x3)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float1x3 operator *(Float1x3 left, Float1x3 right) => throw new InvalidExecutionContextException($"{nameof(Float1x3)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float1x3 operator -(Float1x3 left, Float1x3 right) => throw new InvalidExecutionContextException($"{nameof(Float1x3)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 16)] + public partial struct Float1x4 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + [FieldOffset(12)] + private float m03; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float1x4)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float1x4 operator -(Float1x4 matrix) => throw new InvalidExecutionContextException($"{nameof(Float1x4)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float1x4 operator +(Float1x4 left, Float1x4 right) => throw new InvalidExecutionContextException($"{nameof(Float1x4)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float1x4 operator /(Float1x4 left, Float1x4 right) => throw new InvalidExecutionContextException($"{nameof(Float1x4)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float1x4 operator *(Float1x4 left, Float1x4 right) => throw new InvalidExecutionContextException($"{nameof(Float1x4)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float1x4 operator -(Float1x4 left, Float1x4 right) => throw new InvalidExecutionContextException($"{nameof(Float1x4)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 8)] + public partial struct Float2x1 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m10; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref float this[int row] => throw new InvalidExecutionContextException($"{nameof(Float2x1)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float2x1 operator -(Float2x1 matrix) => throw new InvalidExecutionContextException($"{nameof(Float2x1)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float2x1 operator +(Float2x1 left, Float2x1 right) => throw new InvalidExecutionContextException($"{nameof(Float2x1)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float2x1 operator /(Float2x1 left, Float2x1 right) => throw new InvalidExecutionContextException($"{nameof(Float2x1)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float2x1 operator *(Float2x1 left, Float2x1 right) => throw new InvalidExecutionContextException($"{nameof(Float2x1)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float2x1 operator -(Float2x1 left, Float2x1 right) => throw new InvalidExecutionContextException($"{nameof(Float2x1)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 16)] + public partial struct Float2x2 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m10; + + [FieldOffset(12)] + private float m11; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float2x2)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float2x2 operator -(Float2x2 matrix) => throw new InvalidExecutionContextException($"{nameof(Float2x2)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float2x2 operator +(Float2x2 left, Float2x2 right) => throw new InvalidExecutionContextException($"{nameof(Float2x2)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float2x2 operator /(Float2x2 left, Float2x2 right) => throw new InvalidExecutionContextException($"{nameof(Float2x2)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float2x2 operator *(Float2x2 left, Float2x2 right) => throw new InvalidExecutionContextException($"{nameof(Float2x2)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float2x2 operator -(Float2x2 left, Float2x2 right) => throw new InvalidExecutionContextException($"{nameof(Float2x2)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 24)] + public partial struct Float2x3 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + [FieldOffset(12)] + private float m10; + + [FieldOffset(16)] + private float m11; + + [FieldOffset(20)] + private float m12; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float2x3)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float2x3 operator -(Float2x3 matrix) => throw new InvalidExecutionContextException($"{nameof(Float2x3)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float2x3 operator +(Float2x3 left, Float2x3 right) => throw new InvalidExecutionContextException($"{nameof(Float2x3)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float2x3 operator /(Float2x3 left, Float2x3 right) => throw new InvalidExecutionContextException($"{nameof(Float2x3)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float2x3 operator *(Float2x3 left, Float2x3 right) => throw new InvalidExecutionContextException($"{nameof(Float2x3)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float2x3 operator -(Float2x3 left, Float2x3 right) => throw new InvalidExecutionContextException($"{nameof(Float2x3)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 32)] + public partial struct Float2x4 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + [FieldOffset(12)] + private float m03; + + [FieldOffset(16)] + private float m10; + + [FieldOffset(20)] + private float m11; + + [FieldOffset(24)] + private float m12; + + [FieldOffset(28)] + private float m13; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float2x4)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float2x4 operator -(Float2x4 matrix) => throw new InvalidExecutionContextException($"{nameof(Float2x4)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float2x4 operator +(Float2x4 left, Float2x4 right) => throw new InvalidExecutionContextException($"{nameof(Float2x4)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float2x4 operator /(Float2x4 left, Float2x4 right) => throw new InvalidExecutionContextException($"{nameof(Float2x4)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float2x4 operator *(Float2x4 left, Float2x4 right) => throw new InvalidExecutionContextException($"{nameof(Float2x4)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float2x4 operator -(Float2x4 left, Float2x4 right) => throw new InvalidExecutionContextException($"{nameof(Float2x4)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 12)] + public partial struct Float3x1 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m10; + + [FieldOffset(8)] + private float m20; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref float this[int row] => throw new InvalidExecutionContextException($"{nameof(Float3x1)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float3x1 operator -(Float3x1 matrix) => throw new InvalidExecutionContextException($"{nameof(Float3x1)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float3x1 operator +(Float3x1 left, Float3x1 right) => throw new InvalidExecutionContextException($"{nameof(Float3x1)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float3x1 operator /(Float3x1 left, Float3x1 right) => throw new InvalidExecutionContextException($"{nameof(Float3x1)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float3x1 operator *(Float3x1 left, Float3x1 right) => throw new InvalidExecutionContextException($"{nameof(Float3x1)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float3x1 operator -(Float3x1 left, Float3x1 right) => throw new InvalidExecutionContextException($"{nameof(Float3x1)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 24)] + public partial struct Float3x2 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m10; + + [FieldOffset(12)] + private float m11; + + [FieldOffset(16)] + private float m20; + + [FieldOffset(20)] + private float m21; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float3x2)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float3x2 operator -(Float3x2 matrix) => throw new InvalidExecutionContextException($"{nameof(Float3x2)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float3x2 operator +(Float3x2 left, Float3x2 right) => throw new InvalidExecutionContextException($"{nameof(Float3x2)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float3x2 operator /(Float3x2 left, Float3x2 right) => throw new InvalidExecutionContextException($"{nameof(Float3x2)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float3x2 operator *(Float3x2 left, Float3x2 right) => throw new InvalidExecutionContextException($"{nameof(Float3x2)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float3x2 operator -(Float3x2 left, Float3x2 right) => throw new InvalidExecutionContextException($"{nameof(Float3x2)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 36)] + public partial struct Float3x3 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + [FieldOffset(12)] + private float m10; + + [FieldOffset(16)] + private float m11; + + [FieldOffset(20)] + private float m12; + + [FieldOffset(24)] + private float m20; + + [FieldOffset(28)] + private float m21; + + [FieldOffset(32)] + private float m22; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float3x3)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float3x3 operator -(Float3x3 matrix) => throw new InvalidExecutionContextException($"{nameof(Float3x3)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float3x3 operator +(Float3x3 left, Float3x3 right) => throw new InvalidExecutionContextException($"{nameof(Float3x3)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float3x3 operator /(Float3x3 left, Float3x3 right) => throw new InvalidExecutionContextException($"{nameof(Float3x3)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float3x3 operator *(Float3x3 left, Float3x3 right) => throw new InvalidExecutionContextException($"{nameof(Float3x3)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float3x3 operator -(Float3x3 left, Float3x3 right) => throw new InvalidExecutionContextException($"{nameof(Float3x3)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 48)] + public partial struct Float3x4 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + [FieldOffset(12)] + private float m03; + + [FieldOffset(16)] + private float m10; + + [FieldOffset(20)] + private float m11; + + [FieldOffset(24)] + private float m12; + + [FieldOffset(28)] + private float m13; + + [FieldOffset(32)] + private float m20; + + [FieldOffset(36)] + private float m21; + + [FieldOffset(40)] + private float m22; + + [FieldOffset(44)] + private float m23; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float3x4)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float3x4 operator -(Float3x4 matrix) => throw new InvalidExecutionContextException($"{nameof(Float3x4)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float3x4 operator +(Float3x4 left, Float3x4 right) => throw new InvalidExecutionContextException($"{nameof(Float3x4)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float3x4 operator /(Float3x4 left, Float3x4 right) => throw new InvalidExecutionContextException($"{nameof(Float3x4)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float3x4 operator *(Float3x4 left, Float3x4 right) => throw new InvalidExecutionContextException($"{nameof(Float3x4)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float3x4 operator -(Float3x4 left, Float3x4 right) => throw new InvalidExecutionContextException($"{nameof(Float3x4)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 16)] + public partial struct Float4x1 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m10; + + [FieldOffset(8)] + private float m20; + + [FieldOffset(12)] + private float m30; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref float this[int row] => throw new InvalidExecutionContextException($"{nameof(Float4x1)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float4x1 operator -(Float4x1 matrix) => throw new InvalidExecutionContextException($"{nameof(Float4x1)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float4x1 operator +(Float4x1 left, Float4x1 right) => throw new InvalidExecutionContextException($"{nameof(Float4x1)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float4x1 operator /(Float4x1 left, Float4x1 right) => throw new InvalidExecutionContextException($"{nameof(Float4x1)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float4x1 operator *(Float4x1 left, Float4x1 right) => throw new InvalidExecutionContextException($"{nameof(Float4x1)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float4x1 operator -(Float4x1 left, Float4x1 right) => throw new InvalidExecutionContextException($"{nameof(Float4x1)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 32)] + public partial struct Float4x2 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m10; + + [FieldOffset(12)] + private float m11; + + [FieldOffset(16)] + private float m20; + + [FieldOffset(20)] + private float m21; + + [FieldOffset(24)] + private float m30; + + [FieldOffset(28)] + private float m31; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float4x2)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float4x2 operator -(Float4x2 matrix) => throw new InvalidExecutionContextException($"{nameof(Float4x2)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float4x2 operator +(Float4x2 left, Float4x2 right) => throw new InvalidExecutionContextException($"{nameof(Float4x2)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float4x2 operator /(Float4x2 left, Float4x2 right) => throw new InvalidExecutionContextException($"{nameof(Float4x2)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float4x2 operator *(Float4x2 left, Float4x2 right) => throw new InvalidExecutionContextException($"{nameof(Float4x2)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float4x2 operator -(Float4x2 left, Float4x2 right) => throw new InvalidExecutionContextException($"{nameof(Float4x2)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 48)] + public partial struct Float4x3 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + [FieldOffset(12)] + private float m10; + + [FieldOffset(16)] + private float m11; + + [FieldOffset(20)] + private float m12; + + [FieldOffset(24)] + private float m20; + + [FieldOffset(28)] + private float m21; + + [FieldOffset(32)] + private float m22; + + [FieldOffset(36)] + private float m30; + + [FieldOffset(40)] + private float m31; + + [FieldOffset(44)] + private float m32; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float4x3)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float4x3 operator -(Float4x3 matrix) => throw new InvalidExecutionContextException($"{nameof(Float4x3)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float4x3 operator +(Float4x3 left, Float4x3 right) => throw new InvalidExecutionContextException($"{nameof(Float4x3)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float4x3 operator /(Float4x3 left, Float4x3 right) => throw new InvalidExecutionContextException($"{nameof(Float4x3)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float4x3 operator *(Float4x3 left, Float4x3 right) => throw new InvalidExecutionContextException($"{nameof(Float4x3)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float4x3 operator -(Float4x3 left, Float4x3 right) => throw new InvalidExecutionContextException($"{nameof(Float4x3)}.-"); + } + + /// + [StructLayout(LayoutKind.Explicit, Size = 64)] + public partial struct Float4x4 + { + [FieldOffset(0)] + private float m00; + + [FieldOffset(4)] + private float m01; + + [FieldOffset(8)] + private float m02; + + [FieldOffset(12)] + private float m03; + + [FieldOffset(16)] + private float m10; + + [FieldOffset(20)] + private float m11; + + [FieldOffset(24)] + private float m12; + + [FieldOffset(28)] + private float m13; + + [FieldOffset(32)] + private float m20; + + [FieldOffset(36)] + private float m21; + + [FieldOffset(40)] + private float m22; + + [FieldOffset(44)] + private float m23; + + [FieldOffset(48)] + private float m30; + + [FieldOffset(52)] + private float m31; + + [FieldOffset(56)] + private float m32; + + [FieldOffset(60)] + private float m33; + + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{nameof(Float4x4)}[int]"); + + /// + /// Negates a value. + /// + /// The value to negate. + public static Float4x4 operator -(Float4x4 matrix) => throw new InvalidExecutionContextException($"{nameof(Float4x4)}.-"); + + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static Float4x4 operator +(Float4x4 left, Float4x4 right) => throw new InvalidExecutionContextException($"{nameof(Float4x4)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static Float4x4 operator /(Float4x4 left, Float4x4 right) => throw new InvalidExecutionContextException($"{nameof(Float4x4)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static Float4x4 operator *(Float4x4 left, Float4x4 right) => throw new InvalidExecutionContextException($"{nameof(Float4x4)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static Float4x4 operator -(Float4x4 left, Float4x4 right) => throw new InvalidExecutionContextException($"{nameof(Float4x4)}.-"); + } +} diff --git a/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.tt b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.tt new file mode 100644 index 00000000..5806eb41 --- /dev/null +++ b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.tt @@ -0,0 +1,4 @@ +<#@include file="..\..\MatrixType.ttinclude" #> +<# +GenerateAllMatrixProperties("Float", sizeof(float)); +#> \ No newline at end of file diff --git a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude new file mode 100644 index 00000000..6b1aca64 --- /dev/null +++ b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude @@ -0,0 +1,115 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ assembly name="System.Core" #> +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Text" #> +<#@ import namespace="System.Text.RegularExpressions" #> +<#@ import namespace="System.Collections.Generic" #> +<#@ output extension=".g.cs"#> +<# +// Generates all matrix members and types for a given HLSL type +void GenerateAllMatrixProperties(string typeName, int elementSize) +{ +#> +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; + +namespace ComputeSharp +{ +<# + for (int rows = 1; rows <= 4; rows++) + for (int columns = 1; columns <= 4; columns++) + { + if (rows > 1 || columns > 1) WriteLine(""); + + GenerateMatrixProperties(typeName, rows, columns, elementSize); + } +#> +} +<# +} + +// Generates all vector access properties for a specified type +void GenerateMatrixProperties(string typeName, int rows, int columns, int elementSize) +{ + string elementTypeName = typeName.ToLower(); + string fullTypeName = $"{typeName}{rows}x{columns}"; + string rowTypeName = columns > 1 ? $"{typeName}{columns}" : elementTypeName; +#> + /// + [StructLayout(LayoutKind.Explicit, Size = <#=(elementSize * rows * columns)#>)] + public partial struct <#=fullTypeName#> + { +<# + PushIndent(" "); + PushIndent(" "); + + // Generate the private fields + for (int i = 0; i < rows; i++) + for (int j = 0; j < columns; j++) + { + WriteLine($"[FieldOffset({(i * columns + j) * elementSize})]"); + WriteLine($"private {elementTypeName} m{i}{j};"); + WriteLine(""); + } + + PopIndent(); + PopIndent(); +#> + /// + /// Gets a reference to a specific row in the current instance. + /// + /// The row to access. + public ref <#=rowTypeName#> this[int row] => throw new InvalidExecutionContextException($"{nameof(<#=fullTypeName#>)}[int]"); +<# + // Generate the negation operator + if (elementTypeName != "Bool" && elementTypeName != "UInt") + { + WriteLine(""); +#> + /// + /// Negates a value. + /// + /// The value to negate. + public static <#=fullTypeName#> operator -(<#=fullTypeName#> matrix) => throw new InvalidExecutionContextException($"{nameof(<#=fullTypeName#>)}.-"); +<# + } + + // Generate the numerical operators + if (elementTypeName != "Bool") + { + WriteLine(""); +#> + /// + /// Sums two values. + /// + /// The first value to sum. + /// The second value to sum. + public static <#=fullTypeName#> operator +(<#=fullTypeName#> left, <#=fullTypeName#> right) => throw new InvalidExecutionContextException($"{nameof(<#=fullTypeName#>)}.+"); + + /// + /// Divides two values (elementwise division). + /// + /// The first value to divide. + /// The second value to divide. + public static <#=fullTypeName#> operator /(<#=fullTypeName#> left, <#=fullTypeName#> right) => throw new InvalidExecutionContextException($"{nameof(<#=fullTypeName#>)}./"); + + /// + /// Multiplies two values (elementwise product). + /// + /// The first value to multiply. + /// The second value to multiply. + public static <#=fullTypeName#> operator *(<#=fullTypeName#> left, <#=fullTypeName#> right) => throw new InvalidExecutionContextException($"{nameof(<#=fullTypeName#>)}.*"); + + /// + /// Subtracts two values. + /// + /// The first value to subtract. + /// The second value to subtract. + public static <#=fullTypeName#> operator -(<#=fullTypeName#> left, <#=fullTypeName#> right) => throw new InvalidExecutionContextException($"{nameof(<#=fullTypeName#>)}.-"); +<# + } +#> + } +<# +} +#> \ No newline at end of file