diff --git a/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs b/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs index 1b3586df..8492d73a 100644 --- a/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs +++ b/src/ComputeSharp/Core/Primitives/Bool/BoolMxN.g.cs @@ -1,12 +1,17 @@ -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ComputeSharp { /// [StructLayout(LayoutKind.Explicit, Size = 4, Pack = 4)] - public partial struct Bool1x1 + public unsafe partial struct Bool1x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool1x1), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -23,14 +28,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref bool this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}[{typeof(int)}]"); + /// 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 ref bool this[int row] => ref *(bool*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -38,7 +45,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -47,12 +55,13 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Creates a new value with the same value for all its components. @@ -71,41 +80,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool1x1 operator -(Bool1x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}.-"); + /// 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 Bool1x1 operator -(Bool1x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool1x1 operator +(Bool1x1 left, Bool1x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}.+"); + /// 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 Bool1x1 operator +(Bool1x1 left, Bool1x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool1x1 operator /(Bool1x1 left, Bool1x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}./"); + /// 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 Bool1x1 operator /(Bool1x1 left, Bool1x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool1x1 operator *(Bool1x1 left, Bool1x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}.*"); + /// 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 Bool1x1 operator *(Bool1x1 left, Bool1x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool1x1 operator -(Bool1x1 left, Bool1x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x1)}.-"); + /// 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 Bool1x1 operator -(Bool1x1 left, Bool1x1 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct Bool1x2 + public unsafe partial struct Bool1x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool1x2), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -127,14 +146,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}[{typeof(int)}]"); + /// 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 ref Bool2 this[int row] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -142,7 +163,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -151,17 +173,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Creates a new value with the same value for all its components. @@ -181,47 +204,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool1x2 operator -(Bool1x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}.-"); + /// 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 Bool1x2 operator -(Bool1x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool1x2 operator +(Bool1x2 left, Bool1x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}.+"); + /// 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 Bool1x2 operator +(Bool1x2 left, Bool1x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool1x2 operator /(Bool1x2 left, Bool1x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}./"); + /// 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 Bool1x2 operator /(Bool1x2 left, Bool1x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool1x2 operator *(Bool1x2 left, Bool1x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}.*"); + /// 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 Bool1x2 operator *(Bool1x2 left, Bool1x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool1x2 operator -(Bool1x2 left, Bool1x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}.-"); + /// 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 Bool1x2 operator -(Bool1x2 left, Bool1x2 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Bool1x2(Bool2 vector) => throw new InvalidExecutionContextException($"{typeof(Bool1x2)}.{typeof(Bool1x2)}({typeof(Bool2)})"); + public static implicit operator Bool1x2(Bool2 vector) => *(Bool1x2*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct Bool1x3 + public unsafe partial struct Bool1x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool1x3), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -248,14 +281,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}[{typeof(int)}]"); + /// 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 ref Bool3 this[int row] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -263,7 +298,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -272,22 +308,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Creates a new value with the same value for all its components. @@ -308,47 +345,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool1x3 operator -(Bool1x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.-"); + /// 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 Bool1x3 operator -(Bool1x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool1x3 operator +(Bool1x3 left, Bool1x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.+"); + /// 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 Bool1x3 operator +(Bool1x3 left, Bool1x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool1x3 operator /(Bool1x3 left, Bool1x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}./"); + /// 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 Bool1x3 operator /(Bool1x3 left, Bool1x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool1x3 operator *(Bool1x3 left, Bool1x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.*"); + /// 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 Bool1x3 operator *(Bool1x3 left, Bool1x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool1x3 operator -(Bool1x3 left, Bool1x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.-"); + /// 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 Bool1x3 operator -(Bool1x3 left, Bool1x3 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Bool1x3(Bool3 vector) => throw new InvalidExecutionContextException($"{typeof(Bool1x3)}.{typeof(Bool1x3)}({typeof(Bool3)})"); + public static implicit operator Bool1x3(Bool3 vector) => *(Bool1x3*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Bool1x4 + public unsafe partial struct Bool1x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool1x4), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -380,14 +427,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}[{typeof(int)}]"); + /// 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 ref Bool4 this[int row] => ref *(Bool4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -395,7 +444,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -404,27 +454,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref bool M14 => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.M14"); + public ref bool M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Creates a new value with the same value for all its components. @@ -446,47 +497,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool1x4 operator -(Bool1x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.-"); + /// 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 Bool1x4 operator -(Bool1x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool1x4 operator +(Bool1x4 left, Bool1x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.+"); + /// 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 Bool1x4 operator +(Bool1x4 left, Bool1x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool1x4 operator /(Bool1x4 left, Bool1x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}./"); + /// 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 Bool1x4 operator /(Bool1x4 left, Bool1x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool1x4 operator *(Bool1x4 left, Bool1x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.*"); + /// 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 Bool1x4 operator *(Bool1x4 left, Bool1x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool1x4 operator -(Bool1x4 left, Bool1x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.-"); + /// 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 Bool1x4 operator -(Bool1x4 left, Bool1x4 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Bool1x4(Bool4 vector) => throw new InvalidExecutionContextException($"{typeof(Bool1x4)}.{typeof(Bool1x4)}({typeof(Bool4)})"); + public static implicit operator Bool1x4(Bool4 vector) => *(Bool1x4*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct Bool2x1 + public unsafe partial struct Bool2x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool2x1), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -508,14 +569,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref bool this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}[{typeof(int)}]"); + /// 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 ref bool this[int row] => ref *(bool*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -523,7 +586,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -532,17 +596,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Creates a new value with the same value for all its components. @@ -562,47 +627,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool2x1 operator -(Bool2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}.-"); + /// 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 Bool2x1 operator -(Bool2x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool2x1 operator +(Bool2x1 left, Bool2x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}.+"); + /// 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 Bool2x1 operator +(Bool2x1 left, Bool2x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool2x1 operator /(Bool2x1 left, Bool2x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}./"); + /// 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 Bool2x1 operator /(Bool2x1 left, Bool2x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool2x1 operator *(Bool2x1 left, Bool2x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}.*"); + /// 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 Bool2x1 operator *(Bool2x1 left, Bool2x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool2x1 operator -(Bool2x1 left, Bool2x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}.-"); + /// 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 Bool2x1 operator -(Bool2x1 left, Bool2x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Bool2(Bool2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool2x1)}.{typeof(Bool2)}({typeof(Bool2x1)})"); + public static implicit operator Bool2(Bool2x1 matrix) => *(Bool2*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Bool2x2 + public unsafe partial struct Bool2x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool2x2), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -647,14 +722,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}[{typeof(int)}]"); + /// 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 ref Bool2 this[int row] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -662,7 +739,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -671,27 +749,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Creates a new value with the same value for all its components. @@ -713,41 +792,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool2x2 operator -(Bool2x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.-"); + /// 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 Bool2x2 operator -(Bool2x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool2x2 operator +(Bool2x2 left, Bool2x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.+"); + /// 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 Bool2x2 operator +(Bool2x2 left, Bool2x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool2x2 operator /(Bool2x2 left, Bool2x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}./"); + /// 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 Bool2x2 operator /(Bool2x2 left, Bool2x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool2x2 operator *(Bool2x2 left, Bool2x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.*"); + /// 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 Bool2x2 operator *(Bool2x2 left, Bool2x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool2x2 operator -(Bool2x2 left, Bool2x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x2)}.-"); + /// 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 Bool2x2 operator -(Bool2x2 left, Bool2x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct Bool2x3 + public unsafe partial struct Bool2x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool2x3), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -804,14 +893,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}[{typeof(int)}]"); + /// 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 ref Bool3 this[int row] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -819,7 +910,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -828,37 +920,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref bool M23 => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.M23"); + public ref bool M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Creates a new value with the same value for all its components. @@ -882,41 +975,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool2x3 operator -(Bool2x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.-"); + /// 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 Bool2x3 operator -(Bool2x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool2x3 operator +(Bool2x3 left, Bool2x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.+"); + /// 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 Bool2x3 operator +(Bool2x3 left, Bool2x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool2x3 operator /(Bool2x3 left, Bool2x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}./"); + /// 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 Bool2x3 operator /(Bool2x3 left, Bool2x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool2x3 operator *(Bool2x3 left, Bool2x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.*"); + /// 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 Bool2x3 operator *(Bool2x3 left, Bool2x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool2x3 operator -(Bool2x3 left, Bool2x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x3)}.-"); + /// 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 Bool2x3 operator -(Bool2x3 left, Bool2x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct Bool2x4 + public unsafe partial struct Bool2x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool2x4), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -985,14 +1088,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}[{typeof(int)}]"); + /// 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 ref Bool4 this[int row] => ref *(Bool4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1000,7 +1105,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1009,47 +1115,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref bool M14 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M14"); + public ref bool M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref bool M23 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M23"); + public ref bool M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref bool M24 => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.M24"); + public ref bool M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Creates a new value with the same value for all its components. @@ -1075,41 +1182,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool2x4 operator -(Bool2x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.-"); + /// 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 Bool2x4 operator -(Bool2x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool2x4 operator +(Bool2x4 left, Bool2x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.+"); + /// 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 Bool2x4 operator +(Bool2x4 left, Bool2x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool2x4 operator /(Bool2x4 left, Bool2x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}./"); + /// 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 Bool2x4 operator /(Bool2x4 left, Bool2x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool2x4 operator *(Bool2x4 left, Bool2x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.*"); + /// 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 Bool2x4 operator *(Bool2x4 left, Bool2x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool2x4 operator -(Bool2x4 left, Bool2x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool2x4)}.-"); + /// 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 Bool2x4 operator -(Bool2x4 left, Bool2x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct Bool3x1 + public unsafe partial struct Bool3x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool3x1), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -1136,14 +1253,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref bool this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}[{typeof(int)}]"); + /// 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 ref bool this[int row] => ref *(bool*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1151,7 +1270,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1160,22 +1280,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Creates a new value with the same value for all its components. @@ -1196,47 +1317,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool3x1 operator -(Bool3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.-"); + /// 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 Bool3x1 operator -(Bool3x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool3x1 operator +(Bool3x1 left, Bool3x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.+"); + /// 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 Bool3x1 operator +(Bool3x1 left, Bool3x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool3x1 operator /(Bool3x1 left, Bool3x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}./"); + /// 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 Bool3x1 operator /(Bool3x1 left, Bool3x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool3x1 operator *(Bool3x1 left, Bool3x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.*"); + /// 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 Bool3x1 operator *(Bool3x1 left, Bool3x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool3x1 operator -(Bool3x1 left, Bool3x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.-"); + /// 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 Bool3x1 operator -(Bool3x1 left, Bool3x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Bool3(Bool3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool3x1)}.{typeof(Bool3)}({typeof(Bool3x1)})"); + public static implicit operator Bool3(Bool3x1 matrix) => *(Bool3*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct Bool3x2 + public unsafe partial struct Bool3x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool3x2), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -1294,14 +1425,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}[{typeof(int)}]"); + /// 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 ref Bool2 this[int row] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1309,7 +1442,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1318,37 +1452,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref bool M32 => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.M32"); + public ref bool M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Creates a new value with the same value for all its components. @@ -1372,41 +1507,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool3x2 operator -(Bool3x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.-"); + /// 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 Bool3x2 operator -(Bool3x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool3x2 operator +(Bool3x2 left, Bool3x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.+"); + /// 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 Bool3x2 operator +(Bool3x2 left, Bool3x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool3x2 operator /(Bool3x2 left, Bool3x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}./"); + /// 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 Bool3x2 operator /(Bool3x2 left, Bool3x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool3x2 operator *(Bool3x2 left, Bool3x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.*"); + /// 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 Bool3x2 operator *(Bool3x2 left, Bool3x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool3x2 operator -(Bool3x2 left, Bool3x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x2)}.-"); + /// 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 Bool3x2 operator -(Bool3x2 left, Bool3x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 36, Pack = 4)] - public partial struct Bool3x3 + public unsafe partial struct Bool3x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool3x3), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -1482,14 +1627,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}[{typeof(int)}]"); + /// 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 ref Bool3 this[int row] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1497,7 +1644,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1506,52 +1654,53 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref bool M23 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M23"); + public ref bool M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref bool M32 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M32"); + public ref bool M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref bool M33 => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.M33"); + public ref bool M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Creates a new value with the same value for all its components. @@ -1578,41 +1727,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool3x3 operator -(Bool3x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.-"); + /// 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 Bool3x3 operator -(Bool3x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool3x3 operator +(Bool3x3 left, Bool3x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.+"); + /// 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 Bool3x3 operator +(Bool3x3 left, Bool3x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool3x3 operator /(Bool3x3 left, Bool3x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}./"); + /// 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 Bool3x3 operator /(Bool3x3 left, Bool3x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool3x3 operator *(Bool3x3 left, Bool3x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.*"); + /// 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 Bool3x3 operator *(Bool3x3 left, Bool3x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool3x3 operator -(Bool3x3 left, Bool3x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x3)}.-"); + /// 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 Bool3x3 operator -(Bool3x3 left, Bool3x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct Bool3x4 + public unsafe partial struct Bool3x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool3x4), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -1706,14 +1865,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}[{typeof(int)}]"); + /// 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 ref Bool4 this[int row] => ref *(Bool4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1721,7 +1882,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1730,67 +1892,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref bool M14 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M14"); + public ref bool M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref bool M23 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M23"); + public ref bool M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref bool M24 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M24"); + public ref bool M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref bool M32 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M32"); + public ref bool M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref bool M33 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M33"); + public ref bool M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref bool M34 => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.M34"); + public ref bool M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Creates a new value with the same value for all its components. @@ -1820,41 +1983,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool3x4 operator -(Bool3x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.-"); + /// 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 Bool3x4 operator -(Bool3x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool3x4 operator +(Bool3x4 left, Bool3x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.+"); + /// 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 Bool3x4 operator +(Bool3x4 left, Bool3x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool3x4 operator /(Bool3x4 left, Bool3x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}./"); + /// 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 Bool3x4 operator /(Bool3x4 left, Bool3x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool3x4 operator *(Bool3x4 left, Bool3x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.*"); + /// 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 Bool3x4 operator *(Bool3x4 left, Bool3x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool3x4 operator -(Bool3x4 left, Bool3x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool3x4)}.-"); + /// 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 Bool3x4 operator -(Bool3x4 left, Bool3x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Bool4x1 + public unsafe partial struct Bool4x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool4x1), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -1886,14 +2059,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref bool this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}[{typeof(int)}]"); + /// 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 ref bool this[int row] => ref *(bool*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1901,7 +2076,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1910,27 +2086,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref bool M41 => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.M41"); + public ref bool M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Creates a new value with the same value for all its components. @@ -1952,47 +2129,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool4x1 operator -(Bool4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.-"); + /// 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 Bool4x1 operator -(Bool4x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool4x1 operator +(Bool4x1 left, Bool4x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.+"); + /// 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 Bool4x1 operator +(Bool4x1 left, Bool4x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool4x1 operator /(Bool4x1 left, Bool4x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}./"); + /// 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 Bool4x1 operator /(Bool4x1 left, Bool4x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool4x1 operator *(Bool4x1 left, Bool4x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.*"); + /// 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 Bool4x1 operator *(Bool4x1 left, Bool4x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool4x1 operator -(Bool4x1 left, Bool4x1 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.-"); + /// 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 Bool4x1 operator -(Bool4x1 left, Bool4x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Bool4(Bool4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool4x1)}.{typeof(Bool4)}({typeof(Bool4x1)})"); + public static implicit operator Bool4(Bool4x1 matrix) => *(Bool4*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct Bool4x2 + public unsafe partial struct Bool4x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool4x2), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -2063,14 +2250,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}[{typeof(int)}]"); + /// 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 ref Bool2 this[int row] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2078,7 +2267,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2087,47 +2277,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref bool M32 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M32"); + public ref bool M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref bool M41 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M41"); + public ref bool M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref bool M42 => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.M42"); + public ref bool M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Creates a new value with the same value for all its components. @@ -2153,41 +2344,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool4x2 operator -(Bool4x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.-"); + /// 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 Bool4x2 operator -(Bool4x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool4x2 operator +(Bool4x2 left, Bool4x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.+"); + /// 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 Bool4x2 operator +(Bool4x2 left, Bool4x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool4x2 operator /(Bool4x2 left, Bool4x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}./"); + /// 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 Bool4x2 operator /(Bool4x2 left, Bool4x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool4x2 operator *(Bool4x2 left, Bool4x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.*"); + /// 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 Bool4x2 operator *(Bool4x2 left, Bool4x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool4x2 operator -(Bool4x2 left, Bool4x2 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x2)}.-"); + /// 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 Bool4x2 operator -(Bool4x2 left, Bool4x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct Bool4x3 + public unsafe partial struct Bool4x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool4x3), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -2282,14 +2483,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}[{typeof(int)}]"); + /// 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 ref Bool3 this[int row] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2297,7 +2500,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2306,67 +2510,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref bool M23 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M23"); + public ref bool M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref bool M32 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M32"); + public ref bool M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref bool M33 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M33"); + public ref bool M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref bool M41 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M41"); + public ref bool M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref bool M42 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M42"); + public ref bool M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref bool M43 => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.M43"); + public ref bool M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Creates a new value with the same value for all its components. @@ -2396,41 +2601,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool4x3 operator -(Bool4x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.-"); + /// 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 Bool4x3 operator -(Bool4x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool4x3 operator +(Bool4x3 left, Bool4x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.+"); + /// 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 Bool4x3 operator +(Bool4x3 left, Bool4x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool4x3 operator /(Bool4x3 left, Bool4x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}./"); + /// 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 Bool4x3 operator /(Bool4x3 left, Bool4x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool4x3 operator *(Bool4x3 left, Bool4x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.*"); + /// 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 Bool4x3 operator *(Bool4x3 left, Bool4x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool4x3 operator -(Bool4x3 left, Bool4x3 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x3)}.-"); + /// 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 Bool4x3 operator -(Bool4x3 left, Bool4x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 64, Pack = 4)] - public partial struct Bool4x4 + public unsafe partial struct Bool4x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool4x4), sizeof(Bool4)); + [FieldOffset(0)] private bool m11; @@ -2549,14 +2764,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Bool4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}[{typeof(int)}]"); + /// 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 ref Bool4 this[int row] => ref *(Bool4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Bool2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2564,7 +2781,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Bool3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2573,87 +2791,88 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Bool4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Bool4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref bool M11 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M11"); + public ref bool M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref bool M12 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M12"); + public ref bool M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref bool M13 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M13"); + public ref bool M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref bool M14 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M14"); + public ref bool M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref bool M21 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M21"); + public ref bool M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref bool M22 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M22"); + public ref bool M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref bool M23 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M23"); + public ref bool M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref bool M24 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M24"); + public ref bool M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref bool M31 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M31"); + public ref bool M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref bool M32 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M32"); + public ref bool M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref bool M33 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M33"); + public ref bool M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref bool M34 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M34"); + public ref bool M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref bool M41 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M41"); + public ref bool M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref bool M42 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M42"); + public ref bool M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref bool M43 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M43"); + public ref bool M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Gets a reference to the value representing the component at position [4, 4]. /// - public ref bool M44 => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.M44"); + public ref bool M44 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m44, 1)); /// /// Creates a new value with the same value for all its components. @@ -2687,34 +2906,39 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Bool4x4 operator -(Bool4x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.-"); + /// 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 Bool4x4 operator -(Bool4x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Bool4x4 operator +(Bool4x4 left, Bool4x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.+"); + /// 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 Bool4x4 operator +(Bool4x4 left, Bool4x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Bool4x4 operator /(Bool4x4 left, Bool4x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}./"); + /// 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 Bool4x4 operator /(Bool4x4 left, Bool4x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Bool4x4 operator *(Bool4x4 left, Bool4x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.*"); + /// 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 Bool4x4 operator *(Bool4x4 left, Bool4x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Bool4x4 operator -(Bool4x4 left, Bool4x4 right) => throw new InvalidExecutionContextException($"{typeof(Bool4x4)}.-"); + /// 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 Bool4x4 operator -(Bool4x4 left, Bool4x4 right) => default; } } diff --git a/src/ComputeSharp/Core/Primitives/Double/Double2.cs b/src/ComputeSharp/Core/Primitives/Double/Double2.cs index 1f80b209..45b9cafc 100644 --- a/src/ComputeSharp/Core/Primitives/Double/Double2.cs +++ b/src/ComputeSharp/Core/Primitives/Double/Double2.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Double/Double3.cs b/src/ComputeSharp/Core/Primitives/Double/Double3.cs index 646e2d47..508e6c09 100644 --- a/src/ComputeSharp/Core/Primitives/Double/Double3.cs +++ b/src/ComputeSharp/Core/Primitives/Double/Double3.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Double/Double4.cs b/src/ComputeSharp/Core/Primitives/Double/Double4.cs index b80bb514..c4e231bd 100644 --- a/src/ComputeSharp/Core/Primitives/Double/Double4.cs +++ b/src/ComputeSharp/Core/Primitives/Double/Double4.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs b/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs index f095b1ef..f5f465d8 100644 --- a/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs +++ b/src/ComputeSharp/Core/Primitives/Double/DoubleMxN.g.cs @@ -1,12 +1,17 @@ -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ComputeSharp { /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 8)] - public partial struct Double1x1 + public unsafe partial struct Double1x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double1x1), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -23,14 +28,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref double this[int row] => throw new InvalidExecutionContextException($"{typeof(Double1x1)}[{typeof(int)}]"); + /// 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 ref double this[int row] => ref *(double*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -38,7 +45,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -47,12 +55,13 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double1x1)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Creates a new value with the same value for all its components. @@ -71,41 +80,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double1x1 operator -(Double1x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Double1x1)}.-"); + /// 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 Double1x1 operator -(Double1x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double1x1 operator +(Double1x1 left, Double1x1 right) => throw new InvalidExecutionContextException($"{typeof(Double1x1)}.+"); + /// 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 Double1x1 operator +(Double1x1 left, Double1x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double1x1 operator /(Double1x1 left, Double1x1 right) => throw new InvalidExecutionContextException($"{typeof(Double1x1)}./"); + /// 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 Double1x1 operator /(Double1x1 left, Double1x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double1x1 operator *(Double1x1 left, Double1x1 right) => throw new InvalidExecutionContextException($"{typeof(Double1x1)}.*"); + /// 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 Double1x1 operator *(Double1x1 left, Double1x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double1x1 operator -(Double1x1 left, Double1x1 right) => throw new InvalidExecutionContextException($"{typeof(Double1x1)}.-"); + /// 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 Double1x1 operator -(Double1x1 left, Double1x1 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 8)] - public partial struct Double1x2 + public unsafe partial struct Double1x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double1x2), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -127,14 +146,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double1x2)}[{typeof(int)}]"); + /// 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 ref Double2 this[int row] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -142,7 +163,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -151,17 +173,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double1x2)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double1x2)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Creates a new value with the same value for all its components. @@ -181,47 +204,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double1x2 operator -(Double1x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Double1x2)}.-"); + /// 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 Double1x2 operator -(Double1x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double1x2 operator +(Double1x2 left, Double1x2 right) => throw new InvalidExecutionContextException($"{typeof(Double1x2)}.+"); + /// 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 Double1x2 operator +(Double1x2 left, Double1x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double1x2 operator /(Double1x2 left, Double1x2 right) => throw new InvalidExecutionContextException($"{typeof(Double1x2)}./"); + /// 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 Double1x2 operator /(Double1x2 left, Double1x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double1x2 operator *(Double1x2 left, Double1x2 right) => throw new InvalidExecutionContextException($"{typeof(Double1x2)}.*"); + /// 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 Double1x2 operator *(Double1x2 left, Double1x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double1x2 operator -(Double1x2 left, Double1x2 right) => throw new InvalidExecutionContextException($"{typeof(Double1x2)}.-"); + /// 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 Double1x2 operator -(Double1x2 left, Double1x2 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Double1x2(Double2 vector) => throw new InvalidExecutionContextException($"{typeof(Double1x2)}.{typeof(Double1x2)}({typeof(Double2)})"); + public static implicit operator Double1x2(Double2 vector) => *(Double1x2*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 8)] - public partial struct Double1x3 + public unsafe partial struct Double1x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double1x3), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -248,14 +281,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double1x3)}[{typeof(int)}]"); + /// 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 ref Double3 this[int row] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -263,7 +298,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -272,22 +308,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Creates a new value with the same value for all its components. @@ -308,47 +345,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double1x3 operator -(Double1x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.-"); + /// 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 Double1x3 operator -(Double1x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double1x3 operator +(Double1x3 left, Double1x3 right) => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.+"); + /// 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 Double1x3 operator +(Double1x3 left, Double1x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double1x3 operator /(Double1x3 left, Double1x3 right) => throw new InvalidExecutionContextException($"{typeof(Double1x3)}./"); + /// 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 Double1x3 operator /(Double1x3 left, Double1x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double1x3 operator *(Double1x3 left, Double1x3 right) => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.*"); + /// 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 Double1x3 operator *(Double1x3 left, Double1x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double1x3 operator -(Double1x3 left, Double1x3 right) => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.-"); + /// 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 Double1x3 operator -(Double1x3 left, Double1x3 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Double1x3(Double3 vector) => throw new InvalidExecutionContextException($"{typeof(Double1x3)}.{typeof(Double1x3)}({typeof(Double3)})"); + public static implicit operator Double1x3(Double3 vector) => *(Double1x3*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 8)] - public partial struct Double1x4 + public unsafe partial struct Double1x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double1x4), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -380,14 +427,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double1x4)}[{typeof(int)}]"); + /// 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 ref Double4 this[int row] => ref *(Double4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -395,7 +444,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -404,27 +454,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref double M14 => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.M14"); + public ref double M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Creates a new value with the same value for all its components. @@ -446,47 +497,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double1x4 operator -(Double1x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.-"); + /// 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 Double1x4 operator -(Double1x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double1x4 operator +(Double1x4 left, Double1x4 right) => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.+"); + /// 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 Double1x4 operator +(Double1x4 left, Double1x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double1x4 operator /(Double1x4 left, Double1x4 right) => throw new InvalidExecutionContextException($"{typeof(Double1x4)}./"); + /// 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 Double1x4 operator /(Double1x4 left, Double1x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double1x4 operator *(Double1x4 left, Double1x4 right) => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.*"); + /// 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 Double1x4 operator *(Double1x4 left, Double1x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double1x4 operator -(Double1x4 left, Double1x4 right) => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.-"); + /// 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 Double1x4 operator -(Double1x4 left, Double1x4 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Double1x4(Double4 vector) => throw new InvalidExecutionContextException($"{typeof(Double1x4)}.{typeof(Double1x4)}({typeof(Double4)})"); + public static implicit operator Double1x4(Double4 vector) => *(Double1x4*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 8)] - public partial struct Double2x1 + public unsafe partial struct Double2x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double2x1), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -508,14 +569,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref double this[int row] => throw new InvalidExecutionContextException($"{typeof(Double2x1)}[{typeof(int)}]"); + /// 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 ref double this[int row] => ref *(double*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -523,7 +586,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -532,17 +596,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double2x1)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double2x1)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Creates a new value with the same value for all its components. @@ -562,47 +627,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double2x1 operator -(Double2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Double2x1)}.-"); + /// 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 Double2x1 operator -(Double2x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double2x1 operator +(Double2x1 left, Double2x1 right) => throw new InvalidExecutionContextException($"{typeof(Double2x1)}.+"); + /// 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 Double2x1 operator +(Double2x1 left, Double2x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double2x1 operator /(Double2x1 left, Double2x1 right) => throw new InvalidExecutionContextException($"{typeof(Double2x1)}./"); + /// 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 Double2x1 operator /(Double2x1 left, Double2x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double2x1 operator *(Double2x1 left, Double2x1 right) => throw new InvalidExecutionContextException($"{typeof(Double2x1)}.*"); + /// 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 Double2x1 operator *(Double2x1 left, Double2x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double2x1 operator -(Double2x1 left, Double2x1 right) => throw new InvalidExecutionContextException($"{typeof(Double2x1)}.-"); + /// 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 Double2x1 operator -(Double2x1 left, Double2x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Double2(Double2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Double2x1)}.{typeof(Double2)}({typeof(Double2x1)})"); + public static implicit operator Double2(Double2x1 matrix) => *(Double2*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 8)] - public partial struct Double2x2 + public unsafe partial struct Double2x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double2x2), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -647,14 +722,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double2x2)}[{typeof(int)}]"); + /// 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 ref Double2 this[int row] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -662,7 +739,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -671,27 +749,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Creates a new value with the same value for all its components. @@ -713,41 +792,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double2x2 operator -(Double2x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.-"); + /// 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 Double2x2 operator -(Double2x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double2x2 operator +(Double2x2 left, Double2x2 right) => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.+"); + /// 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 Double2x2 operator +(Double2x2 left, Double2x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double2x2 operator /(Double2x2 left, Double2x2 right) => throw new InvalidExecutionContextException($"{typeof(Double2x2)}./"); + /// 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 Double2x2 operator /(Double2x2 left, Double2x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double2x2 operator *(Double2x2 left, Double2x2 right) => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.*"); + /// 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 Double2x2 operator *(Double2x2 left, Double2x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double2x2 operator -(Double2x2 left, Double2x2 right) => throw new InvalidExecutionContextException($"{typeof(Double2x2)}.-"); + /// 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 Double2x2 operator -(Double2x2 left, Double2x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 8)] - public partial struct Double2x3 + public unsafe partial struct Double2x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double2x3), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -804,14 +893,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double2x3)}[{typeof(int)}]"); + /// 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 ref Double3 this[int row] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -819,7 +910,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -828,37 +920,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref double M23 => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.M23"); + public ref double M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Creates a new value with the same value for all its components. @@ -882,41 +975,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double2x3 operator -(Double2x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.-"); + /// 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 Double2x3 operator -(Double2x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double2x3 operator +(Double2x3 left, Double2x3 right) => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.+"); + /// 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 Double2x3 operator +(Double2x3 left, Double2x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double2x3 operator /(Double2x3 left, Double2x3 right) => throw new InvalidExecutionContextException($"{typeof(Double2x3)}./"); + /// 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 Double2x3 operator /(Double2x3 left, Double2x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double2x3 operator *(Double2x3 left, Double2x3 right) => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.*"); + /// 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 Double2x3 operator *(Double2x3 left, Double2x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double2x3 operator -(Double2x3 left, Double2x3 right) => throw new InvalidExecutionContextException($"{typeof(Double2x3)}.-"); + /// 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 Double2x3 operator -(Double2x3 left, Double2x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 64, Pack = 8)] - public partial struct Double2x4 + public unsafe partial struct Double2x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double2x4), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -985,14 +1088,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double2x4)}[{typeof(int)}]"); + /// 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 ref Double4 this[int row] => ref *(Double4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1000,7 +1105,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1009,47 +1115,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref double M14 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M14"); + public ref double M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref double M23 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M23"); + public ref double M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref double M24 => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.M24"); + public ref double M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Creates a new value with the same value for all its components. @@ -1075,41 +1182,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double2x4 operator -(Double2x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.-"); + /// 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 Double2x4 operator -(Double2x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double2x4 operator +(Double2x4 left, Double2x4 right) => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.+"); + /// 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 Double2x4 operator +(Double2x4 left, Double2x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double2x4 operator /(Double2x4 left, Double2x4 right) => throw new InvalidExecutionContextException($"{typeof(Double2x4)}./"); + /// 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 Double2x4 operator /(Double2x4 left, Double2x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double2x4 operator *(Double2x4 left, Double2x4 right) => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.*"); + /// 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 Double2x4 operator *(Double2x4 left, Double2x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double2x4 operator -(Double2x4 left, Double2x4 right) => throw new InvalidExecutionContextException($"{typeof(Double2x4)}.-"); + /// 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 Double2x4 operator -(Double2x4 left, Double2x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 8)] - public partial struct Double3x1 + public unsafe partial struct Double3x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double3x1), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -1136,14 +1253,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref double this[int row] => throw new InvalidExecutionContextException($"{typeof(Double3x1)}[{typeof(int)}]"); + /// 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 ref double this[int row] => ref *(double*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1151,7 +1270,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1160,22 +1280,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Creates a new value with the same value for all its components. @@ -1196,47 +1317,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double3x1 operator -(Double3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.-"); + /// 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 Double3x1 operator -(Double3x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double3x1 operator +(Double3x1 left, Double3x1 right) => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.+"); + /// 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 Double3x1 operator +(Double3x1 left, Double3x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double3x1 operator /(Double3x1 left, Double3x1 right) => throw new InvalidExecutionContextException($"{typeof(Double3x1)}./"); + /// 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 Double3x1 operator /(Double3x1 left, Double3x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double3x1 operator *(Double3x1 left, Double3x1 right) => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.*"); + /// 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 Double3x1 operator *(Double3x1 left, Double3x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double3x1 operator -(Double3x1 left, Double3x1 right) => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.-"); + /// 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 Double3x1 operator -(Double3x1 left, Double3x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Double3(Double3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Double3x1)}.{typeof(Double3)}({typeof(Double3x1)})"); + public static implicit operator Double3(Double3x1 matrix) => *(Double3*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 8)] - public partial struct Double3x2 + public unsafe partial struct Double3x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double3x2), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -1294,14 +1425,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double3x2)}[{typeof(int)}]"); + /// 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 ref Double2 this[int row] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1309,7 +1442,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1318,37 +1452,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref double M32 => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.M32"); + public ref double M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Creates a new value with the same value for all its components. @@ -1372,41 +1507,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double3x2 operator -(Double3x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.-"); + /// 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 Double3x2 operator -(Double3x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double3x2 operator +(Double3x2 left, Double3x2 right) => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.+"); + /// 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 Double3x2 operator +(Double3x2 left, Double3x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double3x2 operator /(Double3x2 left, Double3x2 right) => throw new InvalidExecutionContextException($"{typeof(Double3x2)}./"); + /// 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 Double3x2 operator /(Double3x2 left, Double3x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double3x2 operator *(Double3x2 left, Double3x2 right) => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.*"); + /// 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 Double3x2 operator *(Double3x2 left, Double3x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double3x2 operator -(Double3x2 left, Double3x2 right) => throw new InvalidExecutionContextException($"{typeof(Double3x2)}.-"); + /// 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 Double3x2 operator -(Double3x2 left, Double3x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 72, Pack = 8)] - public partial struct Double3x3 + public unsafe partial struct Double3x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double3x3), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -1482,14 +1627,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double3x3)}[{typeof(int)}]"); + /// 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 ref Double3 this[int row] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1497,7 +1644,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1506,52 +1654,53 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref double M23 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M23"); + public ref double M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref double M32 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M32"); + public ref double M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref double M33 => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.M33"); + public ref double M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Creates a new value with the same value for all its components. @@ -1578,41 +1727,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double3x3 operator -(Double3x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.-"); + /// 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 Double3x3 operator -(Double3x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double3x3 operator +(Double3x3 left, Double3x3 right) => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.+"); + /// 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 Double3x3 operator +(Double3x3 left, Double3x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double3x3 operator /(Double3x3 left, Double3x3 right) => throw new InvalidExecutionContextException($"{typeof(Double3x3)}./"); + /// 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 Double3x3 operator /(Double3x3 left, Double3x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double3x3 operator *(Double3x3 left, Double3x3 right) => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.*"); + /// 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 Double3x3 operator *(Double3x3 left, Double3x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double3x3 operator -(Double3x3 left, Double3x3 right) => throw new InvalidExecutionContextException($"{typeof(Double3x3)}.-"); + /// 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 Double3x3 operator -(Double3x3 left, Double3x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 96, Pack = 8)] - public partial struct Double3x4 + public unsafe partial struct Double3x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double3x4), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -1706,14 +1865,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double3x4)}[{typeof(int)}]"); + /// 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 ref Double4 this[int row] => ref *(Double4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1721,7 +1882,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1730,67 +1892,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref double M14 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M14"); + public ref double M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref double M23 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M23"); + public ref double M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref double M24 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M24"); + public ref double M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref double M32 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M32"); + public ref double M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref double M33 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M33"); + public ref double M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref double M34 => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.M34"); + public ref double M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Creates a new value with the same value for all its components. @@ -1820,41 +1983,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double3x4 operator -(Double3x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.-"); + /// 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 Double3x4 operator -(Double3x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double3x4 operator +(Double3x4 left, Double3x4 right) => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.+"); + /// 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 Double3x4 operator +(Double3x4 left, Double3x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double3x4 operator /(Double3x4 left, Double3x4 right) => throw new InvalidExecutionContextException($"{typeof(Double3x4)}./"); + /// 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 Double3x4 operator /(Double3x4 left, Double3x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double3x4 operator *(Double3x4 left, Double3x4 right) => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.*"); + /// 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 Double3x4 operator *(Double3x4 left, Double3x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double3x4 operator -(Double3x4 left, Double3x4 right) => throw new InvalidExecutionContextException($"{typeof(Double3x4)}.-"); + /// 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 Double3x4 operator -(Double3x4 left, Double3x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 8)] - public partial struct Double4x1 + public unsafe partial struct Double4x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double4x1), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -1886,14 +2059,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref double this[int row] => throw new InvalidExecutionContextException($"{typeof(Double4x1)}[{typeof(int)}]"); + /// 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 ref double this[int row] => ref *(double*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1901,7 +2076,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1910,27 +2086,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref double M41 => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.M41"); + public ref double M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Creates a new value with the same value for all its components. @@ -1952,47 +2129,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double4x1 operator -(Double4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.-"); + /// 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 Double4x1 operator -(Double4x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double4x1 operator +(Double4x1 left, Double4x1 right) => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.+"); + /// 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 Double4x1 operator +(Double4x1 left, Double4x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double4x1 operator /(Double4x1 left, Double4x1 right) => throw new InvalidExecutionContextException($"{typeof(Double4x1)}./"); + /// 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 Double4x1 operator /(Double4x1 left, Double4x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double4x1 operator *(Double4x1 left, Double4x1 right) => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.*"); + /// 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 Double4x1 operator *(Double4x1 left, Double4x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double4x1 operator -(Double4x1 left, Double4x1 right) => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.-"); + /// 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 Double4x1 operator -(Double4x1 left, Double4x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Double4(Double4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Double4x1)}.{typeof(Double4)}({typeof(Double4x1)})"); + public static implicit operator Double4(Double4x1 matrix) => *(Double4*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 64, Pack = 8)] - public partial struct Double4x2 + public unsafe partial struct Double4x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double4x2), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -2063,14 +2250,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double4x2)}[{typeof(int)}]"); + /// 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 ref Double2 this[int row] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2078,7 +2267,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2087,47 +2277,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref double M32 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M32"); + public ref double M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref double M41 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M41"); + public ref double M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref double M42 => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.M42"); + public ref double M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Creates a new value with the same value for all its components. @@ -2153,41 +2344,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double4x2 operator -(Double4x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.-"); + /// 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 Double4x2 operator -(Double4x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double4x2 operator +(Double4x2 left, Double4x2 right) => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.+"); + /// 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 Double4x2 operator +(Double4x2 left, Double4x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double4x2 operator /(Double4x2 left, Double4x2 right) => throw new InvalidExecutionContextException($"{typeof(Double4x2)}./"); + /// 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 Double4x2 operator /(Double4x2 left, Double4x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double4x2 operator *(Double4x2 left, Double4x2 right) => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.*"); + /// 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 Double4x2 operator *(Double4x2 left, Double4x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double4x2 operator -(Double4x2 left, Double4x2 right) => throw new InvalidExecutionContextException($"{typeof(Double4x2)}.-"); + /// 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 Double4x2 operator -(Double4x2 left, Double4x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 96, Pack = 8)] - public partial struct Double4x3 + public unsafe partial struct Double4x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double4x3), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -2282,14 +2483,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double4x3)}[{typeof(int)}]"); + /// 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 ref Double3 this[int row] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2297,7 +2500,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2306,67 +2510,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref double M23 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M23"); + public ref double M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref double M32 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M32"); + public ref double M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref double M33 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M33"); + public ref double M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref double M41 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M41"); + public ref double M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref double M42 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M42"); + public ref double M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref double M43 => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.M43"); + public ref double M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Creates a new value with the same value for all its components. @@ -2396,41 +2601,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double4x3 operator -(Double4x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.-"); + /// 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 Double4x3 operator -(Double4x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double4x3 operator +(Double4x3 left, Double4x3 right) => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.+"); + /// 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 Double4x3 operator +(Double4x3 left, Double4x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double4x3 operator /(Double4x3 left, Double4x3 right) => throw new InvalidExecutionContextException($"{typeof(Double4x3)}./"); + /// 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 Double4x3 operator /(Double4x3 left, Double4x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double4x3 operator *(Double4x3 left, Double4x3 right) => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.*"); + /// 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 Double4x3 operator *(Double4x3 left, Double4x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double4x3 operator -(Double4x3 left, Double4x3 right) => throw new InvalidExecutionContextException($"{typeof(Double4x3)}.-"); + /// 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 Double4x3 operator -(Double4x3 left, Double4x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 128, Pack = 8)] - public partial struct Double4x4 + public unsafe partial struct Double4x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Double4x4), sizeof(Double4)); + [FieldOffset(0)] private double m11; @@ -2549,14 +2764,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Double4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Double4x4)}[{typeof(int)}]"); + /// 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 ref Double4 this[int row] => ref *(Double4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Double4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Double2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2564,7 +2781,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Double4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Double3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2573,87 +2791,88 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Double4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Double4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Double4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref double M11 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M11"); + public ref double M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref double M12 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M12"); + public ref double M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref double M13 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M13"); + public ref double M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref double M14 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M14"); + public ref double M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref double M21 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M21"); + public ref double M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref double M22 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M22"); + public ref double M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref double M23 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M23"); + public ref double M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref double M24 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M24"); + public ref double M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref double M31 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M31"); + public ref double M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref double M32 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M32"); + public ref double M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref double M33 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M33"); + public ref double M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref double M34 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M34"); + public ref double M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref double M41 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M41"); + public ref double M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref double M42 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M42"); + public ref double M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref double M43 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M43"); + public ref double M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Gets a reference to the value representing the component at position [4, 4]. /// - public ref double M44 => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.M44"); + public ref double M44 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m44, 1)); /// /// Creates a new value with the same value for all its components. @@ -2687,34 +2906,39 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Double4x4 operator -(Double4x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.-"); + /// 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 Double4x4 operator -(Double4x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Double4x4 operator +(Double4x4 left, Double4x4 right) => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.+"); + /// 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 Double4x4 operator +(Double4x4 left, Double4x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Double4x4 operator /(Double4x4 left, Double4x4 right) => throw new InvalidExecutionContextException($"{typeof(Double4x4)}./"); + /// 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 Double4x4 operator /(Double4x4 left, Double4x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Double4x4 operator *(Double4x4 left, Double4x4 right) => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.*"); + /// 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 Double4x4 operator *(Double4x4 left, Double4x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Double4x4 operator -(Double4x4 left, Double4x4 right) => throw new InvalidExecutionContextException($"{typeof(Double4x4)}.-"); + /// 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 Double4x4 operator -(Double4x4 left, Double4x4 right) => default; } } diff --git a/src/ComputeSharp/Core/Primitives/Float/Float2.cs b/src/ComputeSharp/Core/Primitives/Float/Float2.cs index 586bbb3a..50eaaa9d 100644 --- a/src/ComputeSharp/Core/Primitives/Float/Float2.cs +++ b/src/ComputeSharp/Core/Primitives/Float/Float2.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Numerics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Float/Float3.cs b/src/ComputeSharp/Core/Primitives/Float/Float3.cs index 1cb9dad2..5ecfbf25 100644 --- a/src/ComputeSharp/Core/Primitives/Float/Float3.cs +++ b/src/ComputeSharp/Core/Primitives/Float/Float3.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Numerics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Float/Float4.cs b/src/ComputeSharp/Core/Primitives/Float/Float4.cs index 1410aac9..44916723 100644 --- a/src/ComputeSharp/Core/Primitives/Float/Float4.cs +++ b/src/ComputeSharp/Core/Primitives/Float/Float4.cs @@ -1,6 +1,5 @@ using System.Diagnostics; using System.Numerics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs b/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs index a5e7b2ca..349c57e5 100644 --- a/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs +++ b/src/ComputeSharp/Core/Primitives/Float/FloatMxN.g.cs @@ -1,12 +1,17 @@ -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ComputeSharp { /// [StructLayout(LayoutKind.Explicit, Size = 4, Pack = 4)] - public partial struct Float1x1 + public unsafe partial struct Float1x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float1x1), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -23,14 +28,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref float this[int row] => throw new InvalidExecutionContextException($"{typeof(Float1x1)}[{typeof(int)}]"); + /// 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 ref float this[int row] => ref *(float*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -38,7 +45,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -47,12 +55,13 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float1x1)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Creates a new value with the same value for all its components. @@ -71,41 +80,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float1x1 operator -(Float1x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Float1x1)}.-"); + /// 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 Float1x1 operator -(Float1x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float1x1 operator +(Float1x1 left, Float1x1 right) => throw new InvalidExecutionContextException($"{typeof(Float1x1)}.+"); + /// 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 Float1x1 operator +(Float1x1 left, Float1x1 right) => default; /// /// 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($"{typeof(Float1x1)}./"); + /// 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 Float1x1 operator /(Float1x1 left, Float1x1 right) => default; /// /// 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($"{typeof(Float1x1)}.*"); + /// 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 Float1x1 operator *(Float1x1 left, Float1x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float1x1 operator -(Float1x1 left, Float1x1 right) => throw new InvalidExecutionContextException($"{typeof(Float1x1)}.-"); + /// 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 Float1x1 operator -(Float1x1 left, Float1x1 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct Float1x2 + public unsafe partial struct Float1x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float1x2), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -127,14 +146,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float1x2)}[{typeof(int)}]"); + /// 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 ref Float2 this[int row] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -142,7 +163,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -151,17 +173,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float1x2)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float1x2)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Creates a new value with the same value for all its components. @@ -181,47 +204,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float1x2 operator -(Float1x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Float1x2)}.-"); + /// 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 Float1x2 operator -(Float1x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float1x2 operator +(Float1x2 left, Float1x2 right) => throw new InvalidExecutionContextException($"{typeof(Float1x2)}.+"); + /// 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 Float1x2 operator +(Float1x2 left, Float1x2 right) => default; /// /// 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($"{typeof(Float1x2)}./"); + /// 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 Float1x2 operator /(Float1x2 left, Float1x2 right) => default; /// /// 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($"{typeof(Float1x2)}.*"); + /// 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 Float1x2 operator *(Float1x2 left, Float1x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float1x2 operator -(Float1x2 left, Float1x2 right) => throw new InvalidExecutionContextException($"{typeof(Float1x2)}.-"); + /// 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 Float1x2 operator -(Float1x2 left, Float1x2 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Float1x2(Float2 vector) => throw new InvalidExecutionContextException($"{typeof(Float1x2)}.{typeof(Float1x2)}({typeof(Float2)})"); + public static implicit operator Float1x2(Float2 vector) => *(Float1x2*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct Float1x3 + public unsafe partial struct Float1x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float1x3), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -248,14 +281,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float1x3)}[{typeof(int)}]"); + /// 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 ref Float3 this[int row] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -263,7 +298,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -272,22 +308,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float1x3)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float1x3)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float1x3)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Creates a new value with the same value for all its components. @@ -308,47 +345,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float1x3 operator -(Float1x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Float1x3)}.-"); + /// 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 Float1x3 operator -(Float1x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float1x3 operator +(Float1x3 left, Float1x3 right) => throw new InvalidExecutionContextException($"{typeof(Float1x3)}.+"); + /// 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 Float1x3 operator +(Float1x3 left, Float1x3 right) => default; /// /// 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($"{typeof(Float1x3)}./"); + /// 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 Float1x3 operator /(Float1x3 left, Float1x3 right) => default; /// /// 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($"{typeof(Float1x3)}.*"); + /// 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 Float1x3 operator *(Float1x3 left, Float1x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float1x3 operator -(Float1x3 left, Float1x3 right) => throw new InvalidExecutionContextException($"{typeof(Float1x3)}.-"); + /// 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 Float1x3 operator -(Float1x3 left, Float1x3 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Float1x3(Float3 vector) => throw new InvalidExecutionContextException($"{typeof(Float1x3)}.{typeof(Float1x3)}({typeof(Float3)})"); + public static implicit operator Float1x3(Float3 vector) => *(Float1x3*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Float1x4 + public unsafe partial struct Float1x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float1x4), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -380,14 +427,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float1x4)}[{typeof(int)}]"); + /// 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 ref Float4 this[int row] => ref *(Float4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -395,7 +444,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -404,27 +454,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref float M14 => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.M14"); + public ref float M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Creates a new value with the same value for all its components. @@ -446,47 +497,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float1x4 operator -(Float1x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.-"); + /// 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 Float1x4 operator -(Float1x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float1x4 operator +(Float1x4 left, Float1x4 right) => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.+"); + /// 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 Float1x4 operator +(Float1x4 left, Float1x4 right) => default; /// /// 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($"{typeof(Float1x4)}./"); + /// 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 Float1x4 operator /(Float1x4 left, Float1x4 right) => default; /// /// 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($"{typeof(Float1x4)}.*"); + /// 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 Float1x4 operator *(Float1x4 left, Float1x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float1x4 operator -(Float1x4 left, Float1x4 right) => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.-"); + /// 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 Float1x4 operator -(Float1x4 left, Float1x4 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Float1x4(Float4 vector) => throw new InvalidExecutionContextException($"{typeof(Float1x4)}.{typeof(Float1x4)}({typeof(Float4)})"); + public static implicit operator Float1x4(Float4 vector) => *(Float1x4*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct Float2x1 + public unsafe partial struct Float2x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float2x1), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -508,14 +569,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref float this[int row] => throw new InvalidExecutionContextException($"{typeof(Float2x1)}[{typeof(int)}]"); + /// 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 ref float this[int row] => ref *(float*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -523,7 +586,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -532,17 +596,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float2x1)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float2x1)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Creates a new value with the same value for all its components. @@ -562,47 +627,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float2x1 operator -(Float2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Float2x1)}.-"); + /// 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 Float2x1 operator -(Float2x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float2x1 operator +(Float2x1 left, Float2x1 right) => throw new InvalidExecutionContextException($"{typeof(Float2x1)}.+"); + /// 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 Float2x1 operator +(Float2x1 left, Float2x1 right) => default; /// /// 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($"{typeof(Float2x1)}./"); + /// 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 Float2x1 operator /(Float2x1 left, Float2x1 right) => default; /// /// 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($"{typeof(Float2x1)}.*"); + /// 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 Float2x1 operator *(Float2x1 left, Float2x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float2x1 operator -(Float2x1 left, Float2x1 right) => throw new InvalidExecutionContextException($"{typeof(Float2x1)}.-"); + /// 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 Float2x1 operator -(Float2x1 left, Float2x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Float2(Float2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Float2x1)}.{typeof(Float2)}({typeof(Float2x1)})"); + public static implicit operator Float2(Float2x1 matrix) => *(Float2*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Float2x2 + public unsafe partial struct Float2x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float2x2), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -647,14 +722,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float2x2)}[{typeof(int)}]"); + /// 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 ref Float2 this[int row] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -662,7 +739,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -671,27 +749,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float2x2)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float2x2)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float2x2)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float2x2)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Creates a new value with the same value for all its components. @@ -713,41 +792,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float2x2 operator -(Float2x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Float2x2)}.-"); + /// 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 Float2x2 operator -(Float2x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float2x2 operator +(Float2x2 left, Float2x2 right) => throw new InvalidExecutionContextException($"{typeof(Float2x2)}.+"); + /// 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 Float2x2 operator +(Float2x2 left, Float2x2 right) => default; /// /// 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($"{typeof(Float2x2)}./"); + /// 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 Float2x2 operator /(Float2x2 left, Float2x2 right) => default; /// /// 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($"{typeof(Float2x2)}.*"); + /// 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 Float2x2 operator *(Float2x2 left, Float2x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float2x2 operator -(Float2x2 left, Float2x2 right) => throw new InvalidExecutionContextException($"{typeof(Float2x2)}.-"); + /// 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 Float2x2 operator -(Float2x2 left, Float2x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct Float2x3 + public unsafe partial struct Float2x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float2x3), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -804,14 +893,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float2x3)}[{typeof(int)}]"); + /// 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 ref Float3 this[int row] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -819,7 +910,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -828,37 +920,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref float M23 => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.M23"); + public ref float M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Creates a new value with the same value for all its components. @@ -882,41 +975,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float2x3 operator -(Float2x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.-"); + /// 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 Float2x3 operator -(Float2x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float2x3 operator +(Float2x3 left, Float2x3 right) => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.+"); + /// 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 Float2x3 operator +(Float2x3 left, Float2x3 right) => default; /// /// 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($"{typeof(Float2x3)}./"); + /// 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 Float2x3 operator /(Float2x3 left, Float2x3 right) => default; /// /// 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($"{typeof(Float2x3)}.*"); + /// 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 Float2x3 operator *(Float2x3 left, Float2x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float2x3 operator -(Float2x3 left, Float2x3 right) => throw new InvalidExecutionContextException($"{typeof(Float2x3)}.-"); + /// 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 Float2x3 operator -(Float2x3 left, Float2x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct Float2x4 + public unsafe partial struct Float2x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float2x4), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -985,14 +1088,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float2x4)}[{typeof(int)}]"); + /// 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 ref Float4 this[int row] => ref *(Float4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1000,7 +1105,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1009,47 +1115,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref float M14 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M14"); + public ref float M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref float M23 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M23"); + public ref float M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref float M24 => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.M24"); + public ref float M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Creates a new value with the same value for all its components. @@ -1075,41 +1182,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float2x4 operator -(Float2x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.-"); + /// 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 Float2x4 operator -(Float2x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float2x4 operator +(Float2x4 left, Float2x4 right) => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.+"); + /// 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 Float2x4 operator +(Float2x4 left, Float2x4 right) => default; /// /// 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($"{typeof(Float2x4)}./"); + /// 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 Float2x4 operator /(Float2x4 left, Float2x4 right) => default; /// /// 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($"{typeof(Float2x4)}.*"); + /// 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 Float2x4 operator *(Float2x4 left, Float2x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float2x4 operator -(Float2x4 left, Float2x4 right) => throw new InvalidExecutionContextException($"{typeof(Float2x4)}.-"); + /// 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 Float2x4 operator -(Float2x4 left, Float2x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct Float3x1 + public unsafe partial struct Float3x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float3x1), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -1136,14 +1253,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref float this[int row] => throw new InvalidExecutionContextException($"{typeof(Float3x1)}[{typeof(int)}]"); + /// 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 ref float this[int row] => ref *(float*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1151,7 +1270,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1160,22 +1280,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float3x1)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float3x1)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float3x1)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Creates a new value with the same value for all its components. @@ -1196,47 +1317,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float3x1 operator -(Float3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Float3x1)}.-"); + /// 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 Float3x1 operator -(Float3x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float3x1 operator +(Float3x1 left, Float3x1 right) => throw new InvalidExecutionContextException($"{typeof(Float3x1)}.+"); + /// 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 Float3x1 operator +(Float3x1 left, Float3x1 right) => default; /// /// 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($"{typeof(Float3x1)}./"); + /// 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 Float3x1 operator /(Float3x1 left, Float3x1 right) => default; /// /// 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($"{typeof(Float3x1)}.*"); + /// 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 Float3x1 operator *(Float3x1 left, Float3x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float3x1 operator -(Float3x1 left, Float3x1 right) => throw new InvalidExecutionContextException($"{typeof(Float3x1)}.-"); + /// 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 Float3x1 operator -(Float3x1 left, Float3x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Float3(Float3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Float3x1)}.{typeof(Float3)}({typeof(Float3x1)})"); + public static implicit operator Float3(Float3x1 matrix) => *(Float3*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct Float3x2 + public unsafe partial struct Float3x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float3x2), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -1294,14 +1425,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float3x2)}[{typeof(int)}]"); + /// 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 ref Float2 this[int row] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1309,7 +1442,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1318,37 +1452,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref float M32 => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.M32"); + public ref float M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Creates a new value with the same value for all its components. @@ -1372,41 +1507,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float3x2 operator -(Float3x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.-"); + /// 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 Float3x2 operator -(Float3x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float3x2 operator +(Float3x2 left, Float3x2 right) => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.+"); + /// 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 Float3x2 operator +(Float3x2 left, Float3x2 right) => default; /// /// 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($"{typeof(Float3x2)}./"); + /// 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 Float3x2 operator /(Float3x2 left, Float3x2 right) => default; /// /// 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($"{typeof(Float3x2)}.*"); + /// 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 Float3x2 operator *(Float3x2 left, Float3x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float3x2 operator -(Float3x2 left, Float3x2 right) => throw new InvalidExecutionContextException($"{typeof(Float3x2)}.-"); + /// 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 Float3x2 operator -(Float3x2 left, Float3x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 36, Pack = 4)] - public partial struct Float3x3 + public unsafe partial struct Float3x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float3x3), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -1482,14 +1627,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float3x3)}[{typeof(int)}]"); + /// 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 ref Float3 this[int row] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1497,7 +1644,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1506,52 +1654,53 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref float M23 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M23"); + public ref float M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref float M32 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M32"); + public ref float M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref float M33 => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.M33"); + public ref float M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Creates a new value with the same value for all its components. @@ -1578,41 +1727,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float3x3 operator -(Float3x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.-"); + /// 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 Float3x3 operator -(Float3x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float3x3 operator +(Float3x3 left, Float3x3 right) => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.+"); + /// 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 Float3x3 operator +(Float3x3 left, Float3x3 right) => default; /// /// 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($"{typeof(Float3x3)}./"); + /// 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 Float3x3 operator /(Float3x3 left, Float3x3 right) => default; /// /// 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($"{typeof(Float3x3)}.*"); + /// 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 Float3x3 operator *(Float3x3 left, Float3x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float3x3 operator -(Float3x3 left, Float3x3 right) => throw new InvalidExecutionContextException($"{typeof(Float3x3)}.-"); + /// 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 Float3x3 operator -(Float3x3 left, Float3x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct Float3x4 + public unsafe partial struct Float3x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float3x4), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -1706,14 +1865,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float3x4)}[{typeof(int)}]"); + /// 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 ref Float4 this[int row] => ref *(Float4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1721,7 +1882,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1730,67 +1892,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref float M14 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M14"); + public ref float M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref float M23 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M23"); + public ref float M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref float M24 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M24"); + public ref float M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref float M32 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M32"); + public ref float M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref float M33 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M33"); + public ref float M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref float M34 => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.M34"); + public ref float M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Creates a new value with the same value for all its components. @@ -1820,41 +1983,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float3x4 operator -(Float3x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.-"); + /// 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 Float3x4 operator -(Float3x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float3x4 operator +(Float3x4 left, Float3x4 right) => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.+"); + /// 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 Float3x4 operator +(Float3x4 left, Float3x4 right) => default; /// /// 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($"{typeof(Float3x4)}./"); + /// 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 Float3x4 operator /(Float3x4 left, Float3x4 right) => default; /// /// 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($"{typeof(Float3x4)}.*"); + /// 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 Float3x4 operator *(Float3x4 left, Float3x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float3x4 operator -(Float3x4 left, Float3x4 right) => throw new InvalidExecutionContextException($"{typeof(Float3x4)}.-"); + /// 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 Float3x4 operator -(Float3x4 left, Float3x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Float4x1 + public unsafe partial struct Float4x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float4x1), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -1886,14 +2059,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref float this[int row] => throw new InvalidExecutionContextException($"{typeof(Float4x1)}[{typeof(int)}]"); + /// 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 ref float this[int row] => ref *(float*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1901,7 +2076,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1910,27 +2086,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref float M41 => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.M41"); + public ref float M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Creates a new value with the same value for all its components. @@ -1952,47 +2129,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float4x1 operator -(Float4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.-"); + /// 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 Float4x1 operator -(Float4x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float4x1 operator +(Float4x1 left, Float4x1 right) => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.+"); + /// 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 Float4x1 operator +(Float4x1 left, Float4x1 right) => default; /// /// 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($"{typeof(Float4x1)}./"); + /// 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 Float4x1 operator /(Float4x1 left, Float4x1 right) => default; /// /// 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($"{typeof(Float4x1)}.*"); + /// 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 Float4x1 operator *(Float4x1 left, Float4x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float4x1 operator -(Float4x1 left, Float4x1 right) => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.-"); + /// 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 Float4x1 operator -(Float4x1 left, Float4x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Float4(Float4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Float4x1)}.{typeof(Float4)}({typeof(Float4x1)})"); + public static implicit operator Float4(Float4x1 matrix) => *(Float4*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct Float4x2 + public unsafe partial struct Float4x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float4x2), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -2063,14 +2250,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float4x2)}[{typeof(int)}]"); + /// 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 ref Float2 this[int row] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2078,7 +2267,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2087,47 +2277,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref float M32 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M32"); + public ref float M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref float M41 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M41"); + public ref float M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref float M42 => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.M42"); + public ref float M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Creates a new value with the same value for all its components. @@ -2153,41 +2344,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float4x2 operator -(Float4x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.-"); + /// 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 Float4x2 operator -(Float4x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float4x2 operator +(Float4x2 left, Float4x2 right) => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.+"); + /// 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 Float4x2 operator +(Float4x2 left, Float4x2 right) => default; /// /// 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($"{typeof(Float4x2)}./"); + /// 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 Float4x2 operator /(Float4x2 left, Float4x2 right) => default; /// /// 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($"{typeof(Float4x2)}.*"); + /// 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 Float4x2 operator *(Float4x2 left, Float4x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float4x2 operator -(Float4x2 left, Float4x2 right) => throw new InvalidExecutionContextException($"{typeof(Float4x2)}.-"); + /// 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 Float4x2 operator -(Float4x2 left, Float4x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct Float4x3 + public unsafe partial struct Float4x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float4x3), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -2282,14 +2483,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float4x3)}[{typeof(int)}]"); + /// 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 ref Float3 this[int row] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2297,7 +2500,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2306,67 +2510,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref float M23 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M23"); + public ref float M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref float M32 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M32"); + public ref float M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref float M33 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M33"); + public ref float M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref float M41 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M41"); + public ref float M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref float M42 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M42"); + public ref float M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref float M43 => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.M43"); + public ref float M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Creates a new value with the same value for all its components. @@ -2396,41 +2601,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float4x3 operator -(Float4x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.-"); + /// 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 Float4x3 operator -(Float4x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float4x3 operator +(Float4x3 left, Float4x3 right) => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.+"); + /// 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 Float4x3 operator +(Float4x3 left, Float4x3 right) => default; /// /// 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($"{typeof(Float4x3)}./"); + /// 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 Float4x3 operator /(Float4x3 left, Float4x3 right) => default; /// /// 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($"{typeof(Float4x3)}.*"); + /// 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 Float4x3 operator *(Float4x3 left, Float4x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float4x3 operator -(Float4x3 left, Float4x3 right) => throw new InvalidExecutionContextException($"{typeof(Float4x3)}.-"); + /// 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 Float4x3 operator -(Float4x3 left, Float4x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 64, Pack = 4)] - public partial struct Float4x4 + public unsafe partial struct Float4x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Float4x4), sizeof(Float4)); + [FieldOffset(0)] private float m11; @@ -2549,14 +2764,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Float4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Float4x4)}[{typeof(int)}]"); + /// 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 ref Float4 this[int row] => ref *(Float4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Float4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Float2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2564,7 +2781,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Float4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Float3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2573,87 +2791,88 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Float4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Float4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Float4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref float M11 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M11"); + public ref float M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref float M12 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M12"); + public ref float M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref float M13 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M13"); + public ref float M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref float M14 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M14"); + public ref float M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref float M21 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M21"); + public ref float M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref float M22 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M22"); + public ref float M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref float M23 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M23"); + public ref float M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref float M24 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M24"); + public ref float M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref float M31 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M31"); + public ref float M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref float M32 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M32"); + public ref float M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref float M33 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M33"); + public ref float M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref float M34 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M34"); + public ref float M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref float M41 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M41"); + public ref float M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref float M42 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M42"); + public ref float M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref float M43 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M43"); + public ref float M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Gets a reference to the value representing the component at position [4, 4]. /// - public ref float M44 => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.M44"); + public ref float M44 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m44, 1)); /// /// Creates a new value with the same value for all its components. @@ -2687,34 +2906,39 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Float4x4 operator -(Float4x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.-"); + /// 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 Float4x4 operator -(Float4x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Float4x4 operator +(Float4x4 left, Float4x4 right) => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.+"); + /// 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 Float4x4 operator +(Float4x4 left, Float4x4 right) => default; /// /// 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($"{typeof(Float4x4)}./"); + /// 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 Float4x4 operator /(Float4x4 left, Float4x4 right) => default; /// /// 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($"{typeof(Float4x4)}.*"); + /// 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 Float4x4 operator *(Float4x4 left, Float4x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Float4x4 operator -(Float4x4 left, Float4x4 right) => throw new InvalidExecutionContextException($"{typeof(Float4x4)}.-"); + /// 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 Float4x4 operator -(Float4x4 left, Float4x4 right) => default; } } diff --git a/src/ComputeSharp/Core/Primitives/Int/Int2.cs b/src/ComputeSharp/Core/Primitives/Int/Int2.cs index ba70bd83..ef13a36f 100644 --- a/src/ComputeSharp/Core/Primitives/Int/Int2.cs +++ b/src/ComputeSharp/Core/Primitives/Int/Int2.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Int/Int3.cs b/src/ComputeSharp/Core/Primitives/Int/Int3.cs index 806ea3ac..8690c048 100644 --- a/src/ComputeSharp/Core/Primitives/Int/Int3.cs +++ b/src/ComputeSharp/Core/Primitives/Int/Int3.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Int/Int4.cs b/src/ComputeSharp/Core/Primitives/Int/Int4.cs index fa00a68a..2b87778e 100644 --- a/src/ComputeSharp/Core/Primitives/Int/Int4.cs +++ b/src/ComputeSharp/Core/Primitives/Int/Int4.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs b/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs index 3662b880..5fceb214 100644 --- a/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs +++ b/src/ComputeSharp/Core/Primitives/Int/IntMxN.g.cs @@ -1,12 +1,17 @@ -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ComputeSharp { /// [StructLayout(LayoutKind.Explicit, Size = 4, Pack = 4)] - public partial struct Int1x1 + public unsafe partial struct Int1x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int1x1), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -23,14 +28,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref int this[int row] => throw new InvalidExecutionContextException($"{typeof(Int1x1)}[{typeof(int)}]"); + /// 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 ref int this[int row] => ref *(int*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -38,7 +45,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -47,12 +55,13 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int1x1)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Creates a new value with the same value for all its components. @@ -71,41 +80,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int1x1 operator -(Int1x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Int1x1)}.-"); + /// 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 Int1x1 operator -(Int1x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int1x1 operator +(Int1x1 left, Int1x1 right) => throw new InvalidExecutionContextException($"{typeof(Int1x1)}.+"); + /// 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 Int1x1 operator +(Int1x1 left, Int1x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int1x1 operator /(Int1x1 left, Int1x1 right) => throw new InvalidExecutionContextException($"{typeof(Int1x1)}./"); + /// 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 Int1x1 operator /(Int1x1 left, Int1x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int1x1 operator *(Int1x1 left, Int1x1 right) => throw new InvalidExecutionContextException($"{typeof(Int1x1)}.*"); + /// 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 Int1x1 operator *(Int1x1 left, Int1x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int1x1 operator -(Int1x1 left, Int1x1 right) => throw new InvalidExecutionContextException($"{typeof(Int1x1)}.-"); + /// 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 Int1x1 operator -(Int1x1 left, Int1x1 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct Int1x2 + public unsafe partial struct Int1x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int1x2), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -127,14 +146,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int1x2)}[{typeof(int)}]"); + /// 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 ref Int2 this[int row] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -142,7 +163,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -151,17 +173,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int1x2)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int1x2)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Creates a new value with the same value for all its components. @@ -181,47 +204,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int1x2 operator -(Int1x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Int1x2)}.-"); + /// 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 Int1x2 operator -(Int1x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int1x2 operator +(Int1x2 left, Int1x2 right) => throw new InvalidExecutionContextException($"{typeof(Int1x2)}.+"); + /// 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 Int1x2 operator +(Int1x2 left, Int1x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int1x2 operator /(Int1x2 left, Int1x2 right) => throw new InvalidExecutionContextException($"{typeof(Int1x2)}./"); + /// 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 Int1x2 operator /(Int1x2 left, Int1x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int1x2 operator *(Int1x2 left, Int1x2 right) => throw new InvalidExecutionContextException($"{typeof(Int1x2)}.*"); + /// 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 Int1x2 operator *(Int1x2 left, Int1x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int1x2 operator -(Int1x2 left, Int1x2 right) => throw new InvalidExecutionContextException($"{typeof(Int1x2)}.-"); + /// 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 Int1x2 operator -(Int1x2 left, Int1x2 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Int1x2(Int2 vector) => throw new InvalidExecutionContextException($"{typeof(Int1x2)}.{typeof(Int1x2)}({typeof(Int2)})"); + public static implicit operator Int1x2(Int2 vector) => *(Int1x2*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct Int1x3 + public unsafe partial struct Int1x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int1x3), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -248,14 +281,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int1x3)}[{typeof(int)}]"); + /// 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 ref Int3 this[int row] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -263,7 +298,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -272,22 +308,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Creates a new value with the same value for all its components. @@ -308,47 +345,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int1x3 operator -(Int1x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.-"); + /// 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 Int1x3 operator -(Int1x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int1x3 operator +(Int1x3 left, Int1x3 right) => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.+"); + /// 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 Int1x3 operator +(Int1x3 left, Int1x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int1x3 operator /(Int1x3 left, Int1x3 right) => throw new InvalidExecutionContextException($"{typeof(Int1x3)}./"); + /// 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 Int1x3 operator /(Int1x3 left, Int1x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int1x3 operator *(Int1x3 left, Int1x3 right) => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.*"); + /// 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 Int1x3 operator *(Int1x3 left, Int1x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int1x3 operator -(Int1x3 left, Int1x3 right) => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.-"); + /// 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 Int1x3 operator -(Int1x3 left, Int1x3 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Int1x3(Int3 vector) => throw new InvalidExecutionContextException($"{typeof(Int1x3)}.{typeof(Int1x3)}({typeof(Int3)})"); + public static implicit operator Int1x3(Int3 vector) => *(Int1x3*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Int1x4 + public unsafe partial struct Int1x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int1x4), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -380,14 +427,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int1x4)}[{typeof(int)}]"); + /// 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 ref Int4 this[int row] => ref *(Int4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -395,7 +444,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -404,27 +454,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref int M14 => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.M14"); + public ref int M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Creates a new value with the same value for all its components. @@ -446,47 +497,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int1x4 operator -(Int1x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.-"); + /// 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 Int1x4 operator -(Int1x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int1x4 operator +(Int1x4 left, Int1x4 right) => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.+"); + /// 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 Int1x4 operator +(Int1x4 left, Int1x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int1x4 operator /(Int1x4 left, Int1x4 right) => throw new InvalidExecutionContextException($"{typeof(Int1x4)}./"); + /// 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 Int1x4 operator /(Int1x4 left, Int1x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int1x4 operator *(Int1x4 left, Int1x4 right) => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.*"); + /// 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 Int1x4 operator *(Int1x4 left, Int1x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int1x4 operator -(Int1x4 left, Int1x4 right) => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.-"); + /// 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 Int1x4 operator -(Int1x4 left, Int1x4 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Int1x4(Int4 vector) => throw new InvalidExecutionContextException($"{typeof(Int1x4)}.{typeof(Int1x4)}({typeof(Int4)})"); + public static implicit operator Int1x4(Int4 vector) => *(Int1x4*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct Int2x1 + public unsafe partial struct Int2x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int2x1), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -508,14 +569,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref int this[int row] => throw new InvalidExecutionContextException($"{typeof(Int2x1)}[{typeof(int)}]"); + /// 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 ref int this[int row] => ref *(int*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -523,7 +586,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -532,17 +596,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int2x1)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int2x1)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Creates a new value with the same value for all its components. @@ -562,47 +627,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int2x1 operator -(Int2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Int2x1)}.-"); + /// 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 Int2x1 operator -(Int2x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int2x1 operator +(Int2x1 left, Int2x1 right) => throw new InvalidExecutionContextException($"{typeof(Int2x1)}.+"); + /// 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 Int2x1 operator +(Int2x1 left, Int2x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int2x1 operator /(Int2x1 left, Int2x1 right) => throw new InvalidExecutionContextException($"{typeof(Int2x1)}./"); + /// 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 Int2x1 operator /(Int2x1 left, Int2x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int2x1 operator *(Int2x1 left, Int2x1 right) => throw new InvalidExecutionContextException($"{typeof(Int2x1)}.*"); + /// 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 Int2x1 operator *(Int2x1 left, Int2x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int2x1 operator -(Int2x1 left, Int2x1 right) => throw new InvalidExecutionContextException($"{typeof(Int2x1)}.-"); + /// 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 Int2x1 operator -(Int2x1 left, Int2x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Int2(Int2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Int2x1)}.{typeof(Int2)}({typeof(Int2x1)})"); + public static implicit operator Int2(Int2x1 matrix) => *(Int2*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Int2x2 + public unsafe partial struct Int2x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int2x2), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -647,14 +722,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int2x2)}[{typeof(int)}]"); + /// 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 ref Int2 this[int row] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -662,7 +739,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -671,27 +749,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Creates a new value with the same value for all its components. @@ -713,41 +792,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int2x2 operator -(Int2x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.-"); + /// 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 Int2x2 operator -(Int2x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int2x2 operator +(Int2x2 left, Int2x2 right) => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.+"); + /// 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 Int2x2 operator +(Int2x2 left, Int2x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int2x2 operator /(Int2x2 left, Int2x2 right) => throw new InvalidExecutionContextException($"{typeof(Int2x2)}./"); + /// 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 Int2x2 operator /(Int2x2 left, Int2x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int2x2 operator *(Int2x2 left, Int2x2 right) => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.*"); + /// 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 Int2x2 operator *(Int2x2 left, Int2x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int2x2 operator -(Int2x2 left, Int2x2 right) => throw new InvalidExecutionContextException($"{typeof(Int2x2)}.-"); + /// 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 Int2x2 operator -(Int2x2 left, Int2x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct Int2x3 + public unsafe partial struct Int2x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int2x3), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -804,14 +893,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int2x3)}[{typeof(int)}]"); + /// 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 ref Int3 this[int row] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -819,7 +910,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -828,37 +920,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref int M23 => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.M23"); + public ref int M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Creates a new value with the same value for all its components. @@ -882,41 +975,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int2x3 operator -(Int2x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.-"); + /// 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 Int2x3 operator -(Int2x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int2x3 operator +(Int2x3 left, Int2x3 right) => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.+"); + /// 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 Int2x3 operator +(Int2x3 left, Int2x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int2x3 operator /(Int2x3 left, Int2x3 right) => throw new InvalidExecutionContextException($"{typeof(Int2x3)}./"); + /// 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 Int2x3 operator /(Int2x3 left, Int2x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int2x3 operator *(Int2x3 left, Int2x3 right) => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.*"); + /// 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 Int2x3 operator *(Int2x3 left, Int2x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int2x3 operator -(Int2x3 left, Int2x3 right) => throw new InvalidExecutionContextException($"{typeof(Int2x3)}.-"); + /// 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 Int2x3 operator -(Int2x3 left, Int2x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct Int2x4 + public unsafe partial struct Int2x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int2x4), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -985,14 +1088,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int2x4)}[{typeof(int)}]"); + /// 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 ref Int4 this[int row] => ref *(Int4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1000,7 +1105,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1009,47 +1115,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref int M14 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M14"); + public ref int M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref int M23 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M23"); + public ref int M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref int M24 => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.M24"); + public ref int M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Creates a new value with the same value for all its components. @@ -1075,41 +1182,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int2x4 operator -(Int2x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.-"); + /// 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 Int2x4 operator -(Int2x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int2x4 operator +(Int2x4 left, Int2x4 right) => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.+"); + /// 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 Int2x4 operator +(Int2x4 left, Int2x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int2x4 operator /(Int2x4 left, Int2x4 right) => throw new InvalidExecutionContextException($"{typeof(Int2x4)}./"); + /// 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 Int2x4 operator /(Int2x4 left, Int2x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int2x4 operator *(Int2x4 left, Int2x4 right) => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.*"); + /// 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 Int2x4 operator *(Int2x4 left, Int2x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int2x4 operator -(Int2x4 left, Int2x4 right) => throw new InvalidExecutionContextException($"{typeof(Int2x4)}.-"); + /// 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 Int2x4 operator -(Int2x4 left, Int2x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct Int3x1 + public unsafe partial struct Int3x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int3x1), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -1136,14 +1253,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref int this[int row] => throw new InvalidExecutionContextException($"{typeof(Int3x1)}[{typeof(int)}]"); + /// 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 ref int this[int row] => ref *(int*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1151,7 +1270,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1160,22 +1280,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Creates a new value with the same value for all its components. @@ -1196,47 +1317,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int3x1 operator -(Int3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.-"); + /// 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 Int3x1 operator -(Int3x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int3x1 operator +(Int3x1 left, Int3x1 right) => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.+"); + /// 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 Int3x1 operator +(Int3x1 left, Int3x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int3x1 operator /(Int3x1 left, Int3x1 right) => throw new InvalidExecutionContextException($"{typeof(Int3x1)}./"); + /// 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 Int3x1 operator /(Int3x1 left, Int3x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int3x1 operator *(Int3x1 left, Int3x1 right) => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.*"); + /// 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 Int3x1 operator *(Int3x1 left, Int3x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int3x1 operator -(Int3x1 left, Int3x1 right) => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.-"); + /// 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 Int3x1 operator -(Int3x1 left, Int3x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Int3(Int3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Int3x1)}.{typeof(Int3)}({typeof(Int3x1)})"); + public static implicit operator Int3(Int3x1 matrix) => *(Int3*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct Int3x2 + public unsafe partial struct Int3x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int3x2), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -1294,14 +1425,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int3x2)}[{typeof(int)}]"); + /// 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 ref Int2 this[int row] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1309,7 +1442,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1318,37 +1452,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref int M32 => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.M32"); + public ref int M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Creates a new value with the same value for all its components. @@ -1372,41 +1507,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int3x2 operator -(Int3x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.-"); + /// 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 Int3x2 operator -(Int3x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int3x2 operator +(Int3x2 left, Int3x2 right) => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.+"); + /// 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 Int3x2 operator +(Int3x2 left, Int3x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int3x2 operator /(Int3x2 left, Int3x2 right) => throw new InvalidExecutionContextException($"{typeof(Int3x2)}./"); + /// 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 Int3x2 operator /(Int3x2 left, Int3x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int3x2 operator *(Int3x2 left, Int3x2 right) => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.*"); + /// 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 Int3x2 operator *(Int3x2 left, Int3x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int3x2 operator -(Int3x2 left, Int3x2 right) => throw new InvalidExecutionContextException($"{typeof(Int3x2)}.-"); + /// 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 Int3x2 operator -(Int3x2 left, Int3x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 36, Pack = 4)] - public partial struct Int3x3 + public unsafe partial struct Int3x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int3x3), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -1482,14 +1627,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int3x3)}[{typeof(int)}]"); + /// 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 ref Int3 this[int row] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1497,7 +1644,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1506,52 +1654,53 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref int M23 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M23"); + public ref int M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref int M32 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M32"); + public ref int M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref int M33 => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.M33"); + public ref int M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Creates a new value with the same value for all its components. @@ -1578,41 +1727,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int3x3 operator -(Int3x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.-"); + /// 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 Int3x3 operator -(Int3x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int3x3 operator +(Int3x3 left, Int3x3 right) => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.+"); + /// 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 Int3x3 operator +(Int3x3 left, Int3x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int3x3 operator /(Int3x3 left, Int3x3 right) => throw new InvalidExecutionContextException($"{typeof(Int3x3)}./"); + /// 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 Int3x3 operator /(Int3x3 left, Int3x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int3x3 operator *(Int3x3 left, Int3x3 right) => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.*"); + /// 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 Int3x3 operator *(Int3x3 left, Int3x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int3x3 operator -(Int3x3 left, Int3x3 right) => throw new InvalidExecutionContextException($"{typeof(Int3x3)}.-"); + /// 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 Int3x3 operator -(Int3x3 left, Int3x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct Int3x4 + public unsafe partial struct Int3x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int3x4), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -1706,14 +1865,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int3x4)}[{typeof(int)}]"); + /// 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 ref Int4 this[int row] => ref *(Int4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1721,7 +1882,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1730,67 +1892,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref int M14 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M14"); + public ref int M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref int M23 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M23"); + public ref int M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref int M24 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M24"); + public ref int M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref int M32 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M32"); + public ref int M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref int M33 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M33"); + public ref int M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref int M34 => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.M34"); + public ref int M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Creates a new value with the same value for all its components. @@ -1820,41 +1983,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int3x4 operator -(Int3x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.-"); + /// 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 Int3x4 operator -(Int3x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int3x4 operator +(Int3x4 left, Int3x4 right) => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.+"); + /// 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 Int3x4 operator +(Int3x4 left, Int3x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int3x4 operator /(Int3x4 left, Int3x4 right) => throw new InvalidExecutionContextException($"{typeof(Int3x4)}./"); + /// 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 Int3x4 operator /(Int3x4 left, Int3x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int3x4 operator *(Int3x4 left, Int3x4 right) => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.*"); + /// 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 Int3x4 operator *(Int3x4 left, Int3x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int3x4 operator -(Int3x4 left, Int3x4 right) => throw new InvalidExecutionContextException($"{typeof(Int3x4)}.-"); + /// 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 Int3x4 operator -(Int3x4 left, Int3x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct Int4x1 + public unsafe partial struct Int4x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int4x1), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -1886,14 +2059,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref int this[int row] => throw new InvalidExecutionContextException($"{typeof(Int4x1)}[{typeof(int)}]"); + /// 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 ref int this[int row] => ref *(int*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1901,7 +2076,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1910,27 +2086,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref int M41 => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.M41"); + public ref int M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Creates a new value with the same value for all its components. @@ -1952,47 +2129,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int4x1 operator -(Int4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.-"); + /// 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 Int4x1 operator -(Int4x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int4x1 operator +(Int4x1 left, Int4x1 right) => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.+"); + /// 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 Int4x1 operator +(Int4x1 left, Int4x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int4x1 operator /(Int4x1 left, Int4x1 right) => throw new InvalidExecutionContextException($"{typeof(Int4x1)}./"); + /// 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 Int4x1 operator /(Int4x1 left, Int4x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int4x1 operator *(Int4x1 left, Int4x1 right) => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.*"); + /// 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 Int4x1 operator *(Int4x1 left, Int4x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int4x1 operator -(Int4x1 left, Int4x1 right) => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.-"); + /// 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 Int4x1 operator -(Int4x1 left, Int4x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator Int4(Int4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(Int4x1)}.{typeof(Int4)}({typeof(Int4x1)})"); + public static implicit operator Int4(Int4x1 matrix) => *(Int4*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct Int4x2 + public unsafe partial struct Int4x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int4x2), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -2063,14 +2250,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int2 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int4x2)}[{typeof(int)}]"); + /// 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 ref Int2 this[int row] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2078,7 +2267,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2087,47 +2277,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref int M32 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M32"); + public ref int M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref int M41 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M41"); + public ref int M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref int M42 => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.M42"); + public ref int M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Creates a new value with the same value for all its components. @@ -2153,41 +2344,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int4x2 operator -(Int4x2 matrix) => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.-"); + /// 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 Int4x2 operator -(Int4x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int4x2 operator +(Int4x2 left, Int4x2 right) => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.+"); + /// 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 Int4x2 operator +(Int4x2 left, Int4x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int4x2 operator /(Int4x2 left, Int4x2 right) => throw new InvalidExecutionContextException($"{typeof(Int4x2)}./"); + /// 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 Int4x2 operator /(Int4x2 left, Int4x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int4x2 operator *(Int4x2 left, Int4x2 right) => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.*"); + /// 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 Int4x2 operator *(Int4x2 left, Int4x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int4x2 operator -(Int4x2 left, Int4x2 right) => throw new InvalidExecutionContextException($"{typeof(Int4x2)}.-"); + /// 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 Int4x2 operator -(Int4x2 left, Int4x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct Int4x3 + public unsafe partial struct Int4x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int4x3), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -2282,14 +2483,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int3 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int4x3)}[{typeof(int)}]"); + /// 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 ref Int3 this[int row] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2297,7 +2500,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2306,67 +2510,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref int M23 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M23"); + public ref int M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref int M32 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M32"); + public ref int M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref int M33 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M33"); + public ref int M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref int M41 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M41"); + public ref int M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref int M42 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M42"); + public ref int M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref int M43 => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.M43"); + public ref int M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Creates a new value with the same value for all its components. @@ -2396,41 +2601,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int4x3 operator -(Int4x3 matrix) => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.-"); + /// 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 Int4x3 operator -(Int4x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int4x3 operator +(Int4x3 left, Int4x3 right) => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.+"); + /// 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 Int4x3 operator +(Int4x3 left, Int4x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int4x3 operator /(Int4x3 left, Int4x3 right) => throw new InvalidExecutionContextException($"{typeof(Int4x3)}./"); + /// 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 Int4x3 operator /(Int4x3 left, Int4x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int4x3 operator *(Int4x3 left, Int4x3 right) => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.*"); + /// 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 Int4x3 operator *(Int4x3 left, Int4x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int4x3 operator -(Int4x3 left, Int4x3 right) => throw new InvalidExecutionContextException($"{typeof(Int4x3)}.-"); + /// 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 Int4x3 operator -(Int4x3 left, Int4x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 64, Pack = 4)] - public partial struct Int4x4 + public unsafe partial struct Int4x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Int4x4), sizeof(Int4)); + [FieldOffset(0)] private int m11; @@ -2549,14 +2764,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref Int4 this[int row] => throw new InvalidExecutionContextException($"{typeof(Int4x4)}[{typeof(int)}]"); + /// 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 ref Int4 this[int row] => ref *(Int4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(Int4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(Int2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2564,7 +2781,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(Int4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(Int3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2573,87 +2791,88 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(Int4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref Int4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(Int4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref int M11 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M11"); + public ref int M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref int M12 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M12"); + public ref int M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref int M13 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M13"); + public ref int M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref int M14 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M14"); + public ref int M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref int M21 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M21"); + public ref int M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref int M22 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M22"); + public ref int M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref int M23 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M23"); + public ref int M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref int M24 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M24"); + public ref int M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref int M31 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M31"); + public ref int M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref int M32 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M32"); + public ref int M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref int M33 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M33"); + public ref int M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref int M34 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M34"); + public ref int M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref int M41 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M41"); + public ref int M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref int M42 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M42"); + public ref int M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref int M43 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M43"); + public ref int M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Gets a reference to the value representing the component at position [4, 4]. /// - public ref int M44 => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.M44"); + public ref int M44 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m44, 1)); /// /// Creates a new value with the same value for all its components. @@ -2687,34 +2906,39 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static Int4x4 operator -(Int4x4 matrix) => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.-"); + /// 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 Int4x4 operator -(Int4x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static Int4x4 operator +(Int4x4 left, Int4x4 right) => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.+"); + /// 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 Int4x4 operator +(Int4x4 left, Int4x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static Int4x4 operator /(Int4x4 left, Int4x4 right) => throw new InvalidExecutionContextException($"{typeof(Int4x4)}./"); + /// 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 Int4x4 operator /(Int4x4 left, Int4x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static Int4x4 operator *(Int4x4 left, Int4x4 right) => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.*"); + /// 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 Int4x4 operator *(Int4x4 left, Int4x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static Int4x4 operator -(Int4x4 left, Int4x4 right) => throw new InvalidExecutionContextException($"{typeof(Int4x4)}.-"); + /// 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 Int4x4 operator -(Int4x4 left, Int4x4 right) => default; } } diff --git a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude index e6fdfe14..8bbddd7f 100644 --- a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude +++ b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude @@ -10,8 +10,8 @@ void GenerateAllMatrixProperties(string typeName, int elementSize) { #> +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; namespace ComputeSharp { @@ -38,9 +38,14 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen #> /// [StructLayout(LayoutKind.Explicit, Size = <#=(elementSize * rows * columns)#>, Pack = <#=elementSize#>)] - public partial struct <#=fullTypeName#> + public unsafe partial struct <#=fullTypeName#> { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(<#=fullTypeName#>), sizeof(<#=typeName#>4)); <# + WriteLine(""); PushIndent(" "); PushIndent(" "); @@ -121,14 +126,16 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref <#=rowTypeName#> this[int row] => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}[{typeof(int)}]"); + /// 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 ref <#=rowTypeName#> this[int row] => ref *(<#=rowTypeName#>*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref <#=typeName#>2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref <#=typeName#>2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(<#=typeName#>2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -136,7 +143,8 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref <#=typeName#>3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref <#=typeName#>3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(<#=typeName#>3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -145,7 +153,8 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref <#=typeName#>4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref <#=typeName#>4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(<#=typeName#>4*)UndefinedData; <# for (int i = 1; i <= rows; i++) for (int j = 1; j <= columns; j++) @@ -155,7 +164,7 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// /// Gets a reference to the value representing the component at position [<#=i#>, <#=j#>]. /// - public ref <#=elementTypeName#> M<#=i#><#=j#> => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}.M<#=i#><#=j#>"); + public ref <#=elementTypeName#> M<#=i#><#=j#> => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m<#=i#><#=j#>, 1)); <# } @@ -198,7 +207,8 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// Negates a value. /// /// The value to negate. - public static <#=fullTypeName#> operator -(<#=fullTypeName#> matrix) => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}.-"); + /// 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 <#=fullTypeName#> operator -(<#=fullTypeName#> matrix) => default; <# } @@ -212,28 +222,32 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// /// The first value to sum. /// The second value to sum. - public static <#=fullTypeName#> operator +(<#=fullTypeName#> left, <#=fullTypeName#> right) => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}.+"); + /// 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 <#=fullTypeName#> operator +(<#=fullTypeName#> left, <#=fullTypeName#> right) => default; /// /// 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($"{typeof(<#=fullTypeName#>)}./"); + /// 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 <#=fullTypeName#> operator /(<#=fullTypeName#> left, <#=fullTypeName#> right) => default; /// /// 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($"{typeof(<#=fullTypeName#>)}.*"); + /// 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 <#=fullTypeName#> operator *(<#=fullTypeName#> left, <#=fullTypeName#> right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static <#=fullTypeName#> operator -(<#=fullTypeName#> left, <#=fullTypeName#> right) => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}.-"); + /// 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 <#=fullTypeName#> operator -(<#=fullTypeName#> left, <#=fullTypeName#> right) => default; <# } @@ -246,7 +260,7 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator <#=fullTypeName#>(<#=typeName#><#=columns#> vector) => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}.{typeof(<#=fullTypeName#>)}({typeof(<#=typeName#><#=columns#>)})"); + public static implicit operator <#=fullTypeName#>(<#=typeName#><#=columns#> vector) => *(<#=fullTypeName#>*)&vector; <# } @@ -258,7 +272,7 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator <#=typeName#><#=rows#>(<#=fullTypeName#> matrix) => throw new InvalidExecutionContextException($"{typeof(<#=fullTypeName#>)}.{typeof(<#=typeName#><#=rows#>)}({typeof(<#=fullTypeName#>)})"); + public static implicit operator <#=typeName#><#=rows#>(<#=fullTypeName#> matrix) => *(<#=typeName#><#=rows#>*)&matrix; <# } #> diff --git a/src/ComputeSharp/Core/Primitives/UInt/UInt2.cs b/src/ComputeSharp/Core/Primitives/UInt/UInt2.cs index a14513eb..6db3e55f 100644 --- a/src/ComputeSharp/Core/Primitives/UInt/UInt2.cs +++ b/src/ComputeSharp/Core/Primitives/UInt/UInt2.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/UInt/UInt3.cs b/src/ComputeSharp/Core/Primitives/UInt/UInt3.cs index a8e769a9..2b04f6ab 100644 --- a/src/ComputeSharp/Core/Primitives/UInt/UInt3.cs +++ b/src/ComputeSharp/Core/Primitives/UInt/UInt3.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/UInt/UInt4.cs b/src/ComputeSharp/Core/Primitives/UInt/UInt4.cs index f397e5e9..a4ac74d8 100644 --- a/src/ComputeSharp/Core/Primitives/UInt/UInt4.cs +++ b/src/ComputeSharp/Core/Primitives/UInt/UInt4.cs @@ -1,5 +1,4 @@ using System.Diagnostics; -using ComputeSharp.Exceptions; namespace ComputeSharp { diff --git a/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs b/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs index 921d28cd..79dfc564 100644 --- a/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs +++ b/src/ComputeSharp/Core/Primitives/UInt/UIntMxN.g.cs @@ -1,12 +1,17 @@ -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace ComputeSharp { /// [StructLayout(LayoutKind.Explicit, Size = 4, Pack = 4)] - public partial struct UInt1x1 + public unsafe partial struct UInt1x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt1x1), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -23,14 +28,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref uint this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}[{typeof(int)}]"); + /// 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 ref uint this[int row] => ref *(uint*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -38,7 +45,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -47,12 +55,13 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Creates a new value with the same value for all its components. @@ -71,41 +80,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt1x1 operator -(UInt1x1 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}.-"); + /// 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 UInt1x1 operator -(UInt1x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt1x1 operator +(UInt1x1 left, UInt1x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}.+"); + /// 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 UInt1x1 operator +(UInt1x1 left, UInt1x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt1x1 operator /(UInt1x1 left, UInt1x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}./"); + /// 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 UInt1x1 operator /(UInt1x1 left, UInt1x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt1x1 operator *(UInt1x1 left, UInt1x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}.*"); + /// 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 UInt1x1 operator *(UInt1x1 left, UInt1x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt1x1 operator -(UInt1x1 left, UInt1x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x1)}.-"); + /// 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 UInt1x1 operator -(UInt1x1 left, UInt1x1 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct UInt1x2 + public unsafe partial struct UInt1x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt1x2), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -127,14 +146,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt2 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}[{typeof(int)}]"); + /// 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 ref UInt2 this[int row] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -142,7 +163,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -151,17 +173,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Creates a new value with the same value for all its components. @@ -181,47 +204,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt1x2 operator -(UInt1x2 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}.-"); + /// 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 UInt1x2 operator -(UInt1x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt1x2 operator +(UInt1x2 left, UInt1x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}.+"); + /// 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 UInt1x2 operator +(UInt1x2 left, UInt1x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt1x2 operator /(UInt1x2 left, UInt1x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}./"); + /// 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 UInt1x2 operator /(UInt1x2 left, UInt1x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt1x2 operator *(UInt1x2 left, UInt1x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}.*"); + /// 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 UInt1x2 operator *(UInt1x2 left, UInt1x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt1x2 operator -(UInt1x2 left, UInt1x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}.-"); + /// 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 UInt1x2 operator -(UInt1x2 left, UInt1x2 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator UInt1x2(UInt2 vector) => throw new InvalidExecutionContextException($"{typeof(UInt1x2)}.{typeof(UInt1x2)}({typeof(UInt2)})"); + public static implicit operator UInt1x2(UInt2 vector) => *(UInt1x2*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct UInt1x3 + public unsafe partial struct UInt1x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt1x3), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -248,14 +281,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt3 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}[{typeof(int)}]"); + /// 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 ref UInt3 this[int row] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -263,7 +298,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -272,22 +308,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Creates a new value with the same value for all its components. @@ -308,47 +345,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt1x3 operator -(UInt1x3 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.-"); + /// 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 UInt1x3 operator -(UInt1x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt1x3 operator +(UInt1x3 left, UInt1x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.+"); + /// 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 UInt1x3 operator +(UInt1x3 left, UInt1x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt1x3 operator /(UInt1x3 left, UInt1x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}./"); + /// 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 UInt1x3 operator /(UInt1x3 left, UInt1x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt1x3 operator *(UInt1x3 left, UInt1x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.*"); + /// 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 UInt1x3 operator *(UInt1x3 left, UInt1x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt1x3 operator -(UInt1x3 left, UInt1x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.-"); + /// 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 UInt1x3 operator -(UInt1x3 left, UInt1x3 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator UInt1x3(UInt3 vector) => throw new InvalidExecutionContextException($"{typeof(UInt1x3)}.{typeof(UInt1x3)}({typeof(UInt3)})"); + public static implicit operator UInt1x3(UInt3 vector) => *(UInt1x3*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct UInt1x4 + public unsafe partial struct UInt1x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt1x4), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -380,14 +427,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt4 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}[{typeof(int)}]"); + /// 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 ref UInt4 this[int row] => ref *(UInt4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -395,7 +444,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -404,27 +454,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref uint M14 => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.M14"); + public ref uint M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Creates a new value with the same value for all its components. @@ -446,47 +497,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt1x4 operator -(UInt1x4 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.-"); + /// 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 UInt1x4 operator -(UInt1x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt1x4 operator +(UInt1x4 left, UInt1x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.+"); + /// 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 UInt1x4 operator +(UInt1x4 left, UInt1x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt1x4 operator /(UInt1x4 left, UInt1x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}./"); + /// 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 UInt1x4 operator /(UInt1x4 left, UInt1x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt1x4 operator *(UInt1x4 left, UInt1x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.*"); + /// 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 UInt1x4 operator *(UInt1x4 left, UInt1x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt1x4 operator -(UInt1x4 left, UInt1x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.-"); + /// 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 UInt1x4 operator -(UInt1x4 left, UInt1x4 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator UInt1x4(UInt4 vector) => throw new InvalidExecutionContextException($"{typeof(UInt1x4)}.{typeof(UInt1x4)}({typeof(UInt4)})"); + public static implicit operator UInt1x4(UInt4 vector) => *(UInt1x4*)&vector; } /// [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 4)] - public partial struct UInt2x1 + public unsafe partial struct UInt2x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt2x1), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -508,14 +569,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref uint this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}[{typeof(int)}]"); + /// 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 ref uint this[int row] => ref *(uint*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -523,7 +586,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -532,17 +596,18 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Creates a new value with the same value for all its components. @@ -562,47 +627,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt2x1 operator -(UInt2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}.-"); + /// 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 UInt2x1 operator -(UInt2x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt2x1 operator +(UInt2x1 left, UInt2x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}.+"); + /// 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 UInt2x1 operator +(UInt2x1 left, UInt2x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt2x1 operator /(UInt2x1 left, UInt2x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}./"); + /// 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 UInt2x1 operator /(UInt2x1 left, UInt2x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt2x1 operator *(UInt2x1 left, UInt2x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}.*"); + /// 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 UInt2x1 operator *(UInt2x1 left, UInt2x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt2x1 operator -(UInt2x1 left, UInt2x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}.-"); + /// 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 UInt2x1 operator -(UInt2x1 left, UInt2x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator UInt2(UInt2x1 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt2x1)}.{typeof(UInt2)}({typeof(UInt2x1)})"); + public static implicit operator UInt2(UInt2x1 matrix) => *(UInt2*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct UInt2x2 + public unsafe partial struct UInt2x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt2x2), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -647,14 +722,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt2 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}[{typeof(int)}]"); + /// 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 ref UInt2 this[int row] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -662,7 +739,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -671,27 +749,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Creates a new value with the same value for all its components. @@ -713,41 +792,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt2x2 operator -(UInt2x2 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.-"); + /// 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 UInt2x2 operator -(UInt2x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt2x2 operator +(UInt2x2 left, UInt2x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.+"); + /// 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 UInt2x2 operator +(UInt2x2 left, UInt2x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt2x2 operator /(UInt2x2 left, UInt2x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}./"); + /// 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 UInt2x2 operator /(UInt2x2 left, UInt2x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt2x2 operator *(UInt2x2 left, UInt2x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.*"); + /// 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 UInt2x2 operator *(UInt2x2 left, UInt2x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt2x2 operator -(UInt2x2 left, UInt2x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x2)}.-"); + /// 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 UInt2x2 operator -(UInt2x2 left, UInt2x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct UInt2x3 + public unsafe partial struct UInt2x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt2x3), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -804,14 +893,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt3 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}[{typeof(int)}]"); + /// 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 ref UInt3 this[int row] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -819,7 +910,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -828,37 +920,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref uint M23 => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.M23"); + public ref uint M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Creates a new value with the same value for all its components. @@ -882,41 +975,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt2x3 operator -(UInt2x3 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.-"); + /// 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 UInt2x3 operator -(UInt2x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt2x3 operator +(UInt2x3 left, UInt2x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.+"); + /// 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 UInt2x3 operator +(UInt2x3 left, UInt2x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt2x3 operator /(UInt2x3 left, UInt2x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}./"); + /// 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 UInt2x3 operator /(UInt2x3 left, UInt2x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt2x3 operator *(UInt2x3 left, UInt2x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.*"); + /// 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 UInt2x3 operator *(UInt2x3 left, UInt2x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt2x3 operator -(UInt2x3 left, UInt2x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x3)}.-"); + /// 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 UInt2x3 operator -(UInt2x3 left, UInt2x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct UInt2x4 + public unsafe partial struct UInt2x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt2x4), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -985,14 +1088,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt4 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}[{typeof(int)}]"); + /// 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 ref UInt4 this[int row] => ref *(UInt4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1000,7 +1105,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1009,47 +1115,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref uint M14 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M14"); + public ref uint M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref uint M23 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M23"); + public ref uint M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref uint M24 => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.M24"); + public ref uint M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Creates a new value with the same value for all its components. @@ -1075,41 +1182,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt2x4 operator -(UInt2x4 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.-"); + /// 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 UInt2x4 operator -(UInt2x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt2x4 operator +(UInt2x4 left, UInt2x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.+"); + /// 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 UInt2x4 operator +(UInt2x4 left, UInt2x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt2x4 operator /(UInt2x4 left, UInt2x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}./"); + /// 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 UInt2x4 operator /(UInt2x4 left, UInt2x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt2x4 operator *(UInt2x4 left, UInt2x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.*"); + /// 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 UInt2x4 operator *(UInt2x4 left, UInt2x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt2x4 operator -(UInt2x4 left, UInt2x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt2x4)}.-"); + /// 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 UInt2x4 operator -(UInt2x4 left, UInt2x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 12, Pack = 4)] - public partial struct UInt3x1 + public unsafe partial struct UInt3x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt3x1), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -1136,14 +1253,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref uint this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}[{typeof(int)}]"); + /// 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 ref uint this[int row] => ref *(uint*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1151,7 +1270,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1160,22 +1280,23 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Creates a new value with the same value for all its components. @@ -1196,47 +1317,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt3x1 operator -(UInt3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.-"); + /// 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 UInt3x1 operator -(UInt3x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt3x1 operator +(UInt3x1 left, UInt3x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.+"); + /// 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 UInt3x1 operator +(UInt3x1 left, UInt3x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt3x1 operator /(UInt3x1 left, UInt3x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}./"); + /// 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 UInt3x1 operator /(UInt3x1 left, UInt3x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt3x1 operator *(UInt3x1 left, UInt3x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.*"); + /// 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 UInt3x1 operator *(UInt3x1 left, UInt3x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt3x1 operator -(UInt3x1 left, UInt3x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.-"); + /// 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 UInt3x1 operator -(UInt3x1 left, UInt3x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator UInt3(UInt3x1 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt3x1)}.{typeof(UInt3)}({typeof(UInt3x1)})"); + public static implicit operator UInt3(UInt3x1 matrix) => *(UInt3*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 4)] - public partial struct UInt3x2 + public unsafe partial struct UInt3x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt3x2), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -1294,14 +1425,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt2 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}[{typeof(int)}]"); + /// 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 ref UInt2 this[int row] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1309,7 +1442,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1318,37 +1452,38 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref uint M32 => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.M32"); + public ref uint M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Creates a new value with the same value for all its components. @@ -1372,41 +1507,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt3x2 operator -(UInt3x2 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.-"); + /// 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 UInt3x2 operator -(UInt3x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt3x2 operator +(UInt3x2 left, UInt3x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.+"); + /// 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 UInt3x2 operator +(UInt3x2 left, UInt3x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt3x2 operator /(UInt3x2 left, UInt3x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}./"); + /// 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 UInt3x2 operator /(UInt3x2 left, UInt3x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt3x2 operator *(UInt3x2 left, UInt3x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.*"); + /// 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 UInt3x2 operator *(UInt3x2 left, UInt3x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt3x2 operator -(UInt3x2 left, UInt3x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x2)}.-"); + /// 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 UInt3x2 operator -(UInt3x2 left, UInt3x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 36, Pack = 4)] - public partial struct UInt3x3 + public unsafe partial struct UInt3x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt3x3), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -1482,14 +1627,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt3 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}[{typeof(int)}]"); + /// 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 ref UInt3 this[int row] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1497,7 +1644,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1506,52 +1654,53 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref uint M23 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M23"); + public ref uint M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref uint M32 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M32"); + public ref uint M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref uint M33 => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.M33"); + public ref uint M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Creates a new value with the same value for all its components. @@ -1578,41 +1727,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt3x3 operator -(UInt3x3 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.-"); + /// 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 UInt3x3 operator -(UInt3x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt3x3 operator +(UInt3x3 left, UInt3x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.+"); + /// 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 UInt3x3 operator +(UInt3x3 left, UInt3x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt3x3 operator /(UInt3x3 left, UInt3x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}./"); + /// 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 UInt3x3 operator /(UInt3x3 left, UInt3x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt3x3 operator *(UInt3x3 left, UInt3x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.*"); + /// 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 UInt3x3 operator *(UInt3x3 left, UInt3x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt3x3 operator -(UInt3x3 left, UInt3x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x3)}.-"); + /// 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 UInt3x3 operator -(UInt3x3 left, UInt3x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct UInt3x4 + public unsafe partial struct UInt3x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt3x4), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -1706,14 +1865,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt4 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}[{typeof(int)}]"); + /// 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 ref UInt4 this[int row] => ref *(UInt4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1721,7 +1882,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1730,67 +1892,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref uint M14 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M14"); + public ref uint M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref uint M23 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M23"); + public ref uint M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref uint M24 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M24"); + public ref uint M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref uint M32 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M32"); + public ref uint M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref uint M33 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M33"); + public ref uint M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref uint M34 => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.M34"); + public ref uint M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Creates a new value with the same value for all its components. @@ -1820,41 +1983,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt3x4 operator -(UInt3x4 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.-"); + /// 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 UInt3x4 operator -(UInt3x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt3x4 operator +(UInt3x4 left, UInt3x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.+"); + /// 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 UInt3x4 operator +(UInt3x4 left, UInt3x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt3x4 operator /(UInt3x4 left, UInt3x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}./"); + /// 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 UInt3x4 operator /(UInt3x4 left, UInt3x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt3x4 operator *(UInt3x4 left, UInt3x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.*"); + /// 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 UInt3x4 operator *(UInt3x4 left, UInt3x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt3x4 operator -(UInt3x4 left, UInt3x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt3x4)}.-"); + /// 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 UInt3x4 operator -(UInt3x4 left, UInt3x4 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 16, Pack = 4)] - public partial struct UInt4x1 + public unsafe partial struct UInt4x1 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt4x1), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -1886,14 +2059,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref uint this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}[{typeof(int)}]"); + /// 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 ref uint this[int row] => ref *(uint*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1901,7 +2076,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -1910,27 +2086,28 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref uint M41 => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.M41"); + public ref uint M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Creates a new value with the same value for all its components. @@ -1952,47 +2129,57 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt4x1 operator -(UInt4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.-"); + /// 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 UInt4x1 operator -(UInt4x1 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt4x1 operator +(UInt4x1 left, UInt4x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.+"); + /// 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 UInt4x1 operator +(UInt4x1 left, UInt4x1 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt4x1 operator /(UInt4x1 left, UInt4x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}./"); + /// 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 UInt4x1 operator /(UInt4x1 left, UInt4x1 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt4x1 operator *(UInt4x1 left, UInt4x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.*"); + /// 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 UInt4x1 operator *(UInt4x1 left, UInt4x1 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt4x1 operator -(UInt4x1 left, UInt4x1 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.-"); + /// 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 UInt4x1 operator -(UInt4x1 left, UInt4x1 right) => default; /// /// Casts a value to a one. /// /// The input value to cast. - public static implicit operator UInt4(UInt4x1 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt4x1)}.{typeof(UInt4)}({typeof(UInt4x1)})"); + public static implicit operator UInt4(UInt4x1 matrix) => *(UInt4*)&matrix; } /// [StructLayout(LayoutKind.Explicit, Size = 32, Pack = 4)] - public partial struct UInt4x2 + public unsafe partial struct UInt4x2 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt4x2), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -2063,14 +2250,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt2 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}[{typeof(int)}]"); + /// 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 ref UInt2 this[int row] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2078,7 +2267,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2087,47 +2277,48 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref uint M32 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M32"); + public ref uint M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref uint M41 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M41"); + public ref uint M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref uint M42 => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.M42"); + public ref uint M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Creates a new value with the same value for all its components. @@ -2153,41 +2344,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt4x2 operator -(UInt4x2 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.-"); + /// 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 UInt4x2 operator -(UInt4x2 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt4x2 operator +(UInt4x2 left, UInt4x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.+"); + /// 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 UInt4x2 operator +(UInt4x2 left, UInt4x2 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt4x2 operator /(UInt4x2 left, UInt4x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}./"); + /// 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 UInt4x2 operator /(UInt4x2 left, UInt4x2 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt4x2 operator *(UInt4x2 left, UInt4x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.*"); + /// 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 UInt4x2 operator *(UInt4x2 left, UInt4x2 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt4x2 operator -(UInt4x2 left, UInt4x2 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x2)}.-"); + /// 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 UInt4x2 operator -(UInt4x2 left, UInt4x2 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 48, Pack = 4)] - public partial struct UInt4x3 + public unsafe partial struct UInt4x3 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt4x3), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -2282,14 +2483,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt3 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}[{typeof(int)}]"); + /// 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 ref UInt3 this[int row] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2297,7 +2500,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2306,67 +2510,68 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref uint M23 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M23"); + public ref uint M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref uint M32 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M32"); + public ref uint M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref uint M33 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M33"); + public ref uint M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref uint M41 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M41"); + public ref uint M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref uint M42 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M42"); + public ref uint M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref uint M43 => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.M43"); + public ref uint M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Creates a new value with the same value for all its components. @@ -2396,41 +2601,51 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt4x3 operator -(UInt4x3 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.-"); + /// 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 UInt4x3 operator -(UInt4x3 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt4x3 operator +(UInt4x3 left, UInt4x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.+"); + /// 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 UInt4x3 operator +(UInt4x3 left, UInt4x3 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt4x3 operator /(UInt4x3 left, UInt4x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}./"); + /// 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 UInt4x3 operator /(UInt4x3 left, UInt4x3 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt4x3 operator *(UInt4x3 left, UInt4x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.*"); + /// 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 UInt4x3 operator *(UInt4x3 left, UInt4x3 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt4x3 operator -(UInt4x3 left, UInt4x3 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x3)}.-"); + /// 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 UInt4x3 operator -(UInt4x3 left, UInt4x3 right) => default; } /// [StructLayout(LayoutKind.Explicit, Size = 64, Pack = 4)] - public partial struct UInt4x4 + public unsafe partial struct UInt4x4 { + /// + /// A private buffer to which the undefined properties will point to. + /// + private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UInt4x4), sizeof(UInt4)); + [FieldOffset(0)] private uint m11; @@ -2549,14 +2764,16 @@ namespace ComputeSharp /// Gets a reference to a specific row in the current instance. /// /// The row to access. - public ref UInt4 this[int row] => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}[{typeof(int)}]"); + /// 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 ref UInt4 this[int row] => ref *(UInt4*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. /// /// The identifier of the first item to index. /// The identifier of the second item to index. - public ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt2 this[MatrixIndex xy0, MatrixIndex xy1] => ref *(UInt2*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2564,7 +2781,8 @@ namespace ComputeSharp /// The identifier of the first item to index. /// The identifier of the second item to index. /// The identifier of the third item to index. - public ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt3 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2] => ref *(UInt3*)UndefinedData; /// /// Gets a swizzled reference to a specific sequence of items in the current instance. @@ -2573,87 +2791,88 @@ namespace ComputeSharp /// The identifier of the second item to index. /// The identifier of the third item to index. /// The identifier of the fourth item to index. - public ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}[{typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}, {typeof(MatrixIndex)}]"); + /// 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 ref UInt4 this[MatrixIndex xy0, MatrixIndex xy1, MatrixIndex xy2, MatrixIndex xy3] => ref *(UInt4*)UndefinedData; /// /// Gets a reference to the value representing the component at position [1, 1]. /// - public ref uint M11 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M11"); + public ref uint M11 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m11, 1)); /// /// Gets a reference to the value representing the component at position [1, 2]. /// - public ref uint M12 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M12"); + public ref uint M12 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m12, 1)); /// /// Gets a reference to the value representing the component at position [1, 3]. /// - public ref uint M13 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M13"); + public ref uint M13 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m13, 1)); /// /// Gets a reference to the value representing the component at position [1, 4]. /// - public ref uint M14 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M14"); + public ref uint M14 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m14, 1)); /// /// Gets a reference to the value representing the component at position [2, 1]. /// - public ref uint M21 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M21"); + public ref uint M21 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m21, 1)); /// /// Gets a reference to the value representing the component at position [2, 2]. /// - public ref uint M22 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M22"); + public ref uint M22 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m22, 1)); /// /// Gets a reference to the value representing the component at position [2, 3]. /// - public ref uint M23 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M23"); + public ref uint M23 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m23, 1)); /// /// Gets a reference to the value representing the component at position [2, 4]. /// - public ref uint M24 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M24"); + public ref uint M24 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m24, 1)); /// /// Gets a reference to the value representing the component at position [3, 1]. /// - public ref uint M31 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M31"); + public ref uint M31 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m31, 1)); /// /// Gets a reference to the value representing the component at position [3, 2]. /// - public ref uint M32 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M32"); + public ref uint M32 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m32, 1)); /// /// Gets a reference to the value representing the component at position [3, 3]. /// - public ref uint M33 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M33"); + public ref uint M33 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m33, 1)); /// /// Gets a reference to the value representing the component at position [3, 4]. /// - public ref uint M34 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M34"); + public ref uint M34 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m34, 1)); /// /// Gets a reference to the value representing the component at position [4, 1]. /// - public ref uint M41 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M41"); + public ref uint M41 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m41, 1)); /// /// Gets a reference to the value representing the component at position [4, 2]. /// - public ref uint M42 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M42"); + public ref uint M42 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m42, 1)); /// /// Gets a reference to the value representing the component at position [4, 3]. /// - public ref uint M43 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M43"); + public ref uint M43 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m43, 1)); /// /// Gets a reference to the value representing the component at position [4, 4]. /// - public ref uint M44 => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.M44"); + public ref uint M44 => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref this.m44, 1)); /// /// Creates a new value with the same value for all its components. @@ -2687,34 +2906,39 @@ namespace ComputeSharp /// Negates a value. /// /// The value to negate. - public static UInt4x4 operator -(UInt4x4 matrix) => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.-"); + /// 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 UInt4x4 operator -(UInt4x4 matrix) => default; /// /// Sums two values. /// /// The first value to sum. /// The second value to sum. - public static UInt4x4 operator +(UInt4x4 left, UInt4x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.+"); + /// 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 UInt4x4 operator +(UInt4x4 left, UInt4x4 right) => default; /// /// Divides two values (elementwise division). /// /// The first value to divide. /// The second value to divide. - public static UInt4x4 operator /(UInt4x4 left, UInt4x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}./"); + /// 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 UInt4x4 operator /(UInt4x4 left, UInt4x4 right) => default; /// /// Multiplies two values (elementwise product). /// /// The first value to multiply. /// The second value to multiply. - public static UInt4x4 operator *(UInt4x4 left, UInt4x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.*"); + /// 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 UInt4x4 operator *(UInt4x4 left, UInt4x4 right) => default; /// /// Subtracts two values. /// /// The first value to subtract. /// The second value to subtract. - public static UInt4x4 operator -(UInt4x4 left, UInt4x4 right) => throw new InvalidExecutionContextException($"{typeof(UInt4x4)}.-"); + /// 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 UInt4x4 operator -(UInt4x4 left, UInt4x4 right) => default; } }