From c4908ba85b1ad1404529e68df14609936270e10f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 2 Mar 2021 12:43:03 +0100 Subject: [PATCH] Added matrix constructors with single components --- .../Primitives/Float/Matrix/FloatMxN.g.cs | 642 +++++++++++++----- .../Core/Primitives/MatrixType.ttinclude | 33 +- 2 files changed, 507 insertions(+), 168 deletions(-) diff --git a/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs index b7ee1fd3..0670a69b 100644 --- a/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs +++ b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs @@ -8,7 +8,16 @@ namespace ComputeSharp public partial struct Float1x1 { [FieldOffset(0)] - private float m00; + private float m11; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + public Float1x1(float m11) + { + this.m11 = m11; + } /// /// Gets a reference to a specific row in the current instance. @@ -80,10 +89,21 @@ namespace ComputeSharp public partial struct Float1x2 { [FieldOffset(0)] - private float m00; + private float m11; [FieldOffset(4)] - private float m01; + private float m12; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + public Float1x2(float m11, float m12) + { + this.m11 = m11; + this.m12 = m12; + } /// /// Gets a reference to a specific row in the current instance. @@ -155,13 +175,26 @@ namespace ComputeSharp public partial struct Float1x3 { [FieldOffset(0)] - private float m00; + private float m11; [FieldOffset(4)] - private float m01; + private float m12; [FieldOffset(8)] - private float m02; + private float m13; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + public Float1x3(float m11, float m12, float m13) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + } /// /// Gets a reference to a specific row in the current instance. @@ -233,16 +266,31 @@ namespace ComputeSharp public partial struct Float1x4 { [FieldOffset(0)] - private float m00; + private float m11; [FieldOffset(4)] - private float m01; + private float m12; [FieldOffset(8)] - private float m02; + private float m13; [FieldOffset(12)] - private float m03; + private float m14; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + /// The value to assign to the component at position [1, 4]. + public Float1x4(float m11, float m12, float m13, float m14) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m14 = m14; + } /// /// Gets a reference to a specific row in the current instance. @@ -314,10 +362,21 @@ namespace ComputeSharp public partial struct Float2x1 { [FieldOffset(0)] - private float m00; + private float m11; [FieldOffset(4)] - private float m10; + private float m21; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [2, 1]. + public Float2x1(float m11, float m21) + { + this.m11 = m11; + this.m21 = m21; + } /// /// Gets a reference to a specific row in the current instance. @@ -389,16 +448,31 @@ namespace ComputeSharp public partial struct Float2x2 { [FieldOffset(0)] - private float m00; + private float m11; [FieldOffset(4)] - private float m01; + private float m12; [FieldOffset(8)] - private float m10; + private float m21; [FieldOffset(12)] - private float m11; + private float m22; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + public Float2x2(float m11, float m12, float m21, float m22) + { + this.m11 = m11; + this.m12 = m12; + this.m21 = m21; + this.m22 = m22; + } /// /// Gets a reference to a specific row in the current instance. @@ -470,23 +544,42 @@ namespace ComputeSharp public partial struct Float2x3 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m02; - - [FieldOffset(12)] - private float m10; - - [FieldOffset(16)] private float m11; - [FieldOffset(20)] + [FieldOffset(4)] private float m12; + [FieldOffset(8)] + private float m13; + + [FieldOffset(12)] + private float m21; + + [FieldOffset(16)] + private float m22; + + [FieldOffset(20)] + private float m23; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [2, 3]. + public Float2x3(float m11, float m12, float m13, float m21, float m22, float m23) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m21 = m21; + this.m22 = m22; + this.m23 = m23; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -557,29 +650,52 @@ namespace ComputeSharp public partial struct Float2x4 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m02; - - [FieldOffset(12)] - private float m03; - - [FieldOffset(16)] - private float m10; - - [FieldOffset(20)] private float m11; - [FieldOffset(24)] + [FieldOffset(4)] private float m12; - [FieldOffset(28)] + [FieldOffset(8)] private float m13; + [FieldOffset(12)] + private float m14; + + [FieldOffset(16)] + private float m21; + + [FieldOffset(20)] + private float m22; + + [FieldOffset(24)] + private float m23; + + [FieldOffset(28)] + private float m24; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + /// The value to assign to the component at position [1, 4]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [2, 3]. + /// The value to assign to the component at position [2, 4]. + public Float2x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m14 = m14; + this.m21 = m21; + this.m22 = m22; + this.m23 = m23; + this.m24 = m24; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -650,13 +766,26 @@ namespace ComputeSharp public partial struct Float3x1 { [FieldOffset(0)] - private float m00; + private float m11; [FieldOffset(4)] - private float m10; + private float m21; [FieldOffset(8)] - private float m20; + private float m31; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [3, 1]. + public Float3x1(float m11, float m21, float m31) + { + this.m11 = m11; + this.m21 = m21; + this.m31 = m31; + } /// /// Gets a reference to a specific row in the current instance. @@ -728,22 +857,41 @@ namespace ComputeSharp public partial struct Float3x2 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m10; - - [FieldOffset(12)] private float m11; + [FieldOffset(4)] + private float m12; + + [FieldOffset(8)] + private float m21; + + [FieldOffset(12)] + private float m22; + [FieldOffset(16)] - private float m20; + private float m31; [FieldOffset(20)] - private float m21; + private float m32; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [3, 1]. + /// The value to assign to the component at position [3, 2]. + public Float3x2(float m11, float m12, float m21, float m22, float m31, float m32) + { + this.m11 = m11; + this.m12 = m12; + this.m21 = m21; + this.m22 = m22; + this.m31 = m31; + this.m32 = m32; + } /// /// Gets a reference to a specific row in the current instance. @@ -815,32 +963,57 @@ namespace ComputeSharp public partial struct Float3x3 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m02; - - [FieldOffset(12)] - private float m10; - - [FieldOffset(16)] private float m11; - [FieldOffset(20)] + [FieldOffset(4)] private float m12; - [FieldOffset(24)] - private float m20; + [FieldOffset(8)] + private float m13; - [FieldOffset(28)] + [FieldOffset(12)] private float m21; - [FieldOffset(32)] + [FieldOffset(16)] private float m22; + [FieldOffset(20)] + private float m23; + + [FieldOffset(24)] + private float m31; + + [FieldOffset(28)] + private float m32; + + [FieldOffset(32)] + private float m33; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [2, 3]. + /// The value to assign to the component at position [3, 1]. + /// The value to assign to the component at position [3, 2]. + /// The value to assign to the component at position [3, 3]. + public Float3x3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m21 = m21; + this.m22 = m22; + this.m23 = m23; + this.m31 = m31; + this.m32 = m32; + this.m33 = m33; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -911,41 +1084,72 @@ namespace ComputeSharp public partial struct Float3x4 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m02; - - [FieldOffset(12)] - private float m03; - - [FieldOffset(16)] - private float m10; - - [FieldOffset(20)] private float m11; - [FieldOffset(24)] + [FieldOffset(4)] private float m12; - [FieldOffset(28)] + [FieldOffset(8)] private float m13; - [FieldOffset(32)] - private float m20; + [FieldOffset(12)] + private float m14; - [FieldOffset(36)] + [FieldOffset(16)] private float m21; - [FieldOffset(40)] + [FieldOffset(20)] private float m22; - [FieldOffset(44)] + [FieldOffset(24)] private float m23; + [FieldOffset(28)] + private float m24; + + [FieldOffset(32)] + private float m31; + + [FieldOffset(36)] + private float m32; + + [FieldOffset(40)] + private float m33; + + [FieldOffset(44)] + private float m34; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + /// The value to assign to the component at position [1, 4]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [2, 3]. + /// The value to assign to the component at position [2, 4]. + /// The value to assign to the component at position [3, 1]. + /// The value to assign to the component at position [3, 2]. + /// The value to assign to the component at position [3, 3]. + /// The value to assign to the component at position [3, 4]. + public Float3x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m14 = m14; + this.m21 = m21; + this.m22 = m22; + this.m23 = m23; + this.m24 = m24; + this.m31 = m31; + this.m32 = m32; + this.m33 = m33; + this.m34 = m34; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -1016,16 +1220,31 @@ namespace ComputeSharp public partial struct Float4x1 { [FieldOffset(0)] - private float m00; + private float m11; [FieldOffset(4)] - private float m10; + private float m21; [FieldOffset(8)] - private float m20; + private float m31; [FieldOffset(12)] - private float m30; + private float m41; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [3, 1]. + /// The value to assign to the component at position [4, 1]. + public Float4x1(float m11, float m21, float m31, float m41) + { + this.m11 = m11; + this.m21 = m21; + this.m31 = m31; + this.m41 = m41; + } /// /// Gets a reference to a specific row in the current instance. @@ -1097,28 +1316,51 @@ namespace ComputeSharp public partial struct Float4x2 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m10; - - [FieldOffset(12)] private float m11; - [FieldOffset(16)] - private float m20; + [FieldOffset(4)] + private float m12; - [FieldOffset(20)] + [FieldOffset(8)] private float m21; + [FieldOffset(12)] + private float m22; + + [FieldOffset(16)] + private float m31; + + [FieldOffset(20)] + private float m32; + [FieldOffset(24)] - private float m30; + private float m41; [FieldOffset(28)] - private float m31; + private float m42; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [3, 1]. + /// The value to assign to the component at position [3, 2]. + /// The value to assign to the component at position [4, 1]. + /// The value to assign to the component at position [4, 2]. + public Float4x2(float m11, float m12, float m21, float m22, float m31, float m32, float m41, float m42) + { + this.m11 = m11; + this.m12 = m12; + this.m21 = m21; + this.m22 = m22; + this.m31 = m31; + this.m32 = m32; + this.m41 = m41; + this.m42 = m42; + } /// /// Gets a reference to a specific row in the current instance. @@ -1190,41 +1432,72 @@ namespace ComputeSharp public partial struct Float4x3 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m02; - - [FieldOffset(12)] - private float m10; - - [FieldOffset(16)] private float m11; - [FieldOffset(20)] + [FieldOffset(4)] private float m12; - [FieldOffset(24)] - private float m20; + [FieldOffset(8)] + private float m13; - [FieldOffset(28)] + [FieldOffset(12)] private float m21; - [FieldOffset(32)] + [FieldOffset(16)] private float m22; - [FieldOffset(36)] - private float m30; + [FieldOffset(20)] + private float m23; - [FieldOffset(40)] + [FieldOffset(24)] private float m31; - [FieldOffset(44)] + [FieldOffset(28)] private float m32; + [FieldOffset(32)] + private float m33; + + [FieldOffset(36)] + private float m41; + + [FieldOffset(40)] + private float m42; + + [FieldOffset(44)] + private float m43; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [2, 3]. + /// The value to assign to the component at position [3, 1]. + /// The value to assign to the component at position [3, 2]. + /// The value to assign to the component at position [3, 3]. + /// The value to assign to the component at position [4, 1]. + /// The value to assign to the component at position [4, 2]. + /// The value to assign to the component at position [4, 3]. + public Float4x3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33, float m41, float m42, float m43) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m21 = m21; + this.m22 = m22; + this.m23 = m23; + this.m31 = m31; + this.m32 = m32; + this.m33 = m33; + this.m41 = m41; + this.m42 = m42; + this.m43 = m43; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -1295,53 +1568,92 @@ namespace ComputeSharp public partial struct Float4x4 { [FieldOffset(0)] - private float m00; - - [FieldOffset(4)] - private float m01; - - [FieldOffset(8)] - private float m02; - - [FieldOffset(12)] - private float m03; - - [FieldOffset(16)] - private float m10; - - [FieldOffset(20)] private float m11; - [FieldOffset(24)] + [FieldOffset(4)] private float m12; - [FieldOffset(28)] + [FieldOffset(8)] private float m13; - [FieldOffset(32)] - private float m20; + [FieldOffset(12)] + private float m14; - [FieldOffset(36)] + [FieldOffset(16)] private float m21; - [FieldOffset(40)] + [FieldOffset(20)] private float m22; - [FieldOffset(44)] + [FieldOffset(24)] private float m23; - [FieldOffset(48)] - private float m30; + [FieldOffset(28)] + private float m24; - [FieldOffset(52)] + [FieldOffset(32)] private float m31; - [FieldOffset(56)] + [FieldOffset(36)] private float m32; - [FieldOffset(60)] + [FieldOffset(40)] private float m33; + [FieldOffset(44)] + private float m34; + + [FieldOffset(48)] + private float m41; + + [FieldOffset(52)] + private float m42; + + [FieldOffset(56)] + private float m43; + + [FieldOffset(60)] + private float m44; + + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the component at position [1, 1]. + /// The value to assign to the component at position [1, 2]. + /// The value to assign to the component at position [1, 3]. + /// The value to assign to the component at position [1, 4]. + /// The value to assign to the component at position [2, 1]. + /// The value to assign to the component at position [2, 2]. + /// The value to assign to the component at position [2, 3]. + /// The value to assign to the component at position [2, 4]. + /// The value to assign to the component at position [3, 1]. + /// The value to assign to the component at position [3, 2]. + /// The value to assign to the component at position [3, 3]. + /// The value to assign to the component at position [3, 4]. + /// The value to assign to the component at position [4, 1]. + /// The value to assign to the component at position [4, 2]. + /// The value to assign to the component at position [4, 3]. + /// The value to assign to the component at position [4, 4]. + public Float4x4(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) + { + this.m11 = m11; + this.m12 = m12; + this.m13 = m13; + this.m14 = m14; + this.m21 = m21; + this.m22 = m22; + this.m23 = m23; + this.m24 = m24; + this.m31 = m31; + this.m32 = m32; + this.m33 = m33; + this.m34 = m34; + this.m41 = m41; + this.m42 = m42; + this.m43 = m43; + this.m44 = m44; + } + /// /// Gets a reference to a specific row in the current instance. /// diff --git a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude index 2d908082..1a7b96fc 100644 --- a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude +++ b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude @@ -34,6 +34,7 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen string elementTypeName = typeName.ToLower(); string fullTypeName = $"{typeName}{rows}x{columns}"; string rowTypeName = columns > 1 ? $"{typeName}{columns}" : elementTypeName; + List fieldNames = new List(); #> /// [StructLayout(LayoutKind.Explicit, Size = <#=(elementSize * rows * columns)#>)] @@ -44,14 +45,40 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen PushIndent(" "); // Generate the private fields - for (int i = 0; i < rows; i++) - for (int j = 0; j < columns; j++) + for (int i = 1; i <= rows; i++) + for (int j = 1; j <= columns; j++) { - WriteLine($"[FieldOffset({(i * columns + j) * elementSize})]"); + WriteLine($"[FieldOffset({((i - 1) * columns + j - 1) * elementSize})]"); WriteLine($"private {elementTypeName} m{i}{j};"); WriteLine(""); + + fieldNames.Add($"m{i}{j}"); } + // Generate the constructors + WriteLine("/// "); + WriteLine($"/// Creates a new instance with the specified parameters."); + WriteLine("/// "); + + for (int i = 1; i <= rows; i++) + for (int j = 1; j <= columns; j++) + { + WriteLine($"/// The value to assign to the component at position [{i}, {j}]."); + } + + WriteLine($"public {fullTypeName}({string.Join(", ", fieldNames.Select(n => $"{elementTypeName} {n}"))})"); + WriteLine("{"); + PushIndent(" "); + + foreach (string fieldName in fieldNames) + { + WriteLine($"this.{fieldName} = {fieldName};"); + } + + PopIndent(); + WriteLine("}"); + WriteLine(""); + PopIndent(); PopIndent(); #>