From 7bac8a5a4212f7cc9dfe0c6388247401cdc2d026 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 24 Feb 2021 19:03:30 +0100 Subject: [PATCH] Added byref single component properties --- .../Primitives/Bool/Bool2.cs | 49 +--------- .../Primitives/Bool/Bool2.g.cs | 30 +++++- .../Primitives/Bool/Bool2.tt | 2 +- .../Primitives/Bool/Bool3.cs | 72 +------------- .../Primitives/Bool/Bool3.g.cs | 43 ++++++++- .../Primitives/Bool/Bool3.tt | 2 +- .../Primitives/Bool/Bool4.cs | 95 +------------------ .../Primitives/Bool/Bool4.g.cs | 56 ++++++++++- .../Primitives/Bool/Bool4.tt | 2 +- .../Primitives/Double/Double2.cs | 34 +------ .../Primitives/Double/Double2.g.cs | 30 +++++- .../Primitives/Double/Double2.tt | 2 +- .../Primitives/Double/Double3.cs | 50 +--------- .../Primitives/Double/Double3.g.cs | 43 ++++++++- .../Primitives/Double/Double3.tt | 2 +- .../Primitives/Double/Double4.cs | 66 +------------ .../Primitives/Double/Double4.g.cs | 56 ++++++++++- .../Primitives/Double/Double4.tt | 2 +- .../Primitives/Float/Float2.cs | 34 +------ .../Primitives/Float/Float2.g.cs | 30 +++++- .../Primitives/Float/Float2.tt | 2 +- .../Primitives/Float/Float3.cs | 50 +--------- .../Primitives/Float/Float3.g.cs | 43 ++++++++- .../Primitives/Float/Float3.tt | 2 +- .../Primitives/Float/Float4.cs | 66 +------------ .../Primitives/Float/Float4.g.cs | 56 ++++++++++- .../Primitives/Float/Float4.tt | 2 +- src/ComputeSharp.Core/Primitives/Int/Int2.cs | 34 +------ .../Primitives/Int/Int2.g.cs | 30 +++++- src/ComputeSharp.Core/Primitives/Int/Int2.tt | 2 +- src/ComputeSharp.Core/Primitives/Int/Int3.cs | 48 +--------- .../Primitives/Int/Int3.g.cs | 43 ++++++++- src/ComputeSharp.Core/Primitives/Int/Int3.tt | 2 +- src/ComputeSharp.Core/Primitives/Int/Int4.cs | 66 +------------ .../Primitives/Int/Int4.g.cs | 56 ++++++++++- src/ComputeSharp.Core/Primitives/Int/Int4.tt | 2 +- .../Primitives/UInt/UInt2.cs | 34 +------ .../Primitives/UInt/UInt2.g.cs | 30 +++++- .../Primitives/UInt/UInt2.tt | 2 +- .../Primitives/UInt/UInt3.cs | 50 +--------- .../Primitives/UInt/UInt3.g.cs | 43 ++++++++- .../Primitives/UInt/UInt3.tt | 2 +- .../Primitives/UInt/UInt4.cs | 66 +------------ .../Primitives/UInt/UInt4.g.cs | 56 ++++++++++- .../Primitives/UInt/UInt4.tt | 2 +- .../Primitives/VectorType.ttinclude | 43 +++++++-- 46 files changed, 724 insertions(+), 808 deletions(-) diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs index 80313e55..ad578a8a 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.cs @@ -1,6 +1,4 @@ using System.Diagnostics; -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; namespace ComputeSharp { @@ -8,7 +6,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y})")] - [StructLayout(LayoutKind.Explicit, Size = sizeof(int) * 2)] public partial struct Bool2 { /// @@ -38,50 +35,8 @@ namespace ComputeSharp /// The value to assign to the second vector component. public Bool2(bool x, bool y) { - _X = x; - _Y = y; - } - - [FieldOffset(0)] - private bool _X; - - /// - /// Gets or sets the value of the first vector component. - /// - public bool X - { - get => _X; - set => _X = value; - } - - [FieldOffset(4)] - private bool _Y; - - /// - /// Gets or sets the value of the second vector component. - /// - public bool Y - { - get => _Y; - set => _Y = value; - } - - /// - /// Gets or sets the value of the first color component. - /// - public bool R - { - get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public bool G - { - get => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(G)}"); + this.x = x; + this.y = y; } /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs index ea249769..e59cfd0b 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs @@ -1,16 +1,44 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 8)] public partial struct Bool2 { + [FieldOffset(0)] + private bool x; + + [FieldOffset(4)] + private bool y; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref bool this[int i] => throw new InvalidExecutionContextException($"{nameof(Bool2)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref bool X => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref bool Y => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref bool R => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref bool G => throw new InvalidExecutionContextException($"{nameof(Bool2)}.{nameof(G)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.tt b/src/ComputeSharp.Core/Primitives/Bool/Bool2.tt index ceef264a..801f6c2b 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool2.tt +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Bool2"); +GenerateVectorProperties("Bool2", sizeof(int)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs index e8456dc1..1dfeb51b 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool3.cs @@ -1,6 +1,4 @@ using System.Diagnostics; -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; namespace ComputeSharp { @@ -8,7 +6,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z})")] - [StructLayout(LayoutKind.Explicit, Size = sizeof(int) * 3)] public partial struct Bool3 { /// @@ -44,72 +41,9 @@ namespace ComputeSharp /// The value to assign to the third vector component. public Bool3(bool x, bool y, bool z) { - _X = x; - _Y = y; - _Z = z; - } - - [FieldOffset(0)] - private bool _X; - - /// - /// Gets or sets the value of the first vector component. - /// - public bool X - { - get => _X; - set => _X = value; - } - - [FieldOffset(4)] - private bool _Y; - - /// - /// Gets or sets the value of the second vector component. - /// - public bool Y - { - get => _Y; - set => _Y = value; - } - - [FieldOffset(8)] - private bool _Z; - - /// - /// Gets or sets the value of the third vector component. - /// - public bool Z - { - get => _Z; - set => _Z = value; - } - - /// - /// Gets or sets the value of the first color component. - /// - public bool R - { - get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public bool G - { - get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public bool B - { - get => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(B)}"); + this.x = x; + this.y = y; + this.z = z; } /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs index 4ef8a2cf..24379f6a 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs @@ -1,16 +1,57 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 12)] public partial struct Bool3 { + [FieldOffset(0)] + private bool x; + + [FieldOffset(4)] + private bool y; + + [FieldOffset(8)] + private bool z; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref bool this[int i] => throw new InvalidExecutionContextException($"{nameof(Bool3)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref bool X => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref bool Y => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref bool Z => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref bool R => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref bool G => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref bool B => throw new InvalidExecutionContextException($"{nameof(Bool3)}.{nameof(B)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool3.tt b/src/ComputeSharp.Core/Primitives/Bool/Bool3.tt index 69c22122..6488af44 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool3.tt +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool3.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Bool3"); +GenerateVectorProperties("Bool3", sizeof(int)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs index de9daba1..4c315e3d 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool4.cs @@ -1,6 +1,4 @@ using System.Diagnostics; -using System.Runtime.InteropServices; -using ComputeSharp.Exceptions; namespace ComputeSharp { @@ -8,7 +6,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z}, {W})")] - [StructLayout(LayoutKind.Explicit, Size = sizeof(int) * 4)] public partial struct Bool4 { /// @@ -50,94 +47,10 @@ namespace ComputeSharp /// The value to assign to the fourth vector component. public Bool4(bool x, bool y, bool z, bool w) { - _X = x; - _Y = y; - _Z = z; - _W = w; - } - - [FieldOffset(0)] - private bool _X; - - /// - /// Gets or sets the value of the first vector component. - /// - public bool X - { - get => _X; - set => _X = value; - } - - [FieldOffset(4)] - private bool _Y; - - /// - /// Gets or sets the value of the second vector component. - /// - public bool Y - { - get => _Y; - set => _Y = value; - } - - [FieldOffset(8)] - private bool _Z; - - /// - /// Gets or sets the value of the third vector component. - /// - public bool Z - { - get => _Z; - set => _Z = value; - } - - [FieldOffset(12)] - private bool _W; - - /// - /// Gets or sets the value of the fourth vector component. - /// - public bool W - { - get => _W; - set => _W = value; - } - - /// - /// Gets or sets the value of the first color component. - /// - public bool R - { - get => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public bool G - { - get => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public bool B - { - get => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(B)}"); - } - - /// - /// Gets or sets the value of the fourth color component. - /// - public bool A - { - get => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(A)}"); - set => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(A)}"); + this.x = x; + this.y = y; + this.z = z; + this.w = w; } /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs index 6795cb4c..1439e669 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs @@ -1,16 +1,70 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 16)] public partial struct Bool4 { + [FieldOffset(0)] + private bool x; + + [FieldOffset(4)] + private bool y; + + [FieldOffset(8)] + private bool z; + + [FieldOffset(12)] + private bool w; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref bool this[int i] => throw new InvalidExecutionContextException($"{nameof(Bool4)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref bool X => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref bool Y => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref bool Z => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the W component. + /// + public ref bool W => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(W)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref bool R => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref bool G => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref bool B => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(B)}"); + + /// + /// Gets a reference to the value representing the A component. + /// + public ref bool A => throw new InvalidExecutionContextException($"{nameof(Bool4)}.{nameof(A)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool4.tt b/src/ComputeSharp.Core/Primitives/Bool/Bool4.tt index 5e11b40c..0d039431 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool4.tt +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool4.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Bool4"); +GenerateVectorProperties("Bool4", sizeof(int)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Double/Double2.cs b/src/ComputeSharp.Core/Primitives/Double/Double2.cs index 6d0fc441..b28fa948 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(double) * 2)] public partial struct Double2 { /// @@ -38,36 +36,8 @@ namespace ComputeSharp /// The value to assign to the second vector component. public Double2(double x, double y) { - X = x; - Y = y; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public double X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public double Y { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public double R - { - get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public double G - { - get => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(G)}"); + this.x = x; + this.y = y; } /// diff --git a/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs b/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs index 252cfbc0..438c7697 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Double/Double2.g.cs @@ -1,16 +1,44 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 16)] public partial struct Double2 { + [FieldOffset(0)] + private double x; + + [FieldOffset(8)] + private double y; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref double this[int i] => throw new InvalidExecutionContextException($"{nameof(Double2)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref double X => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref double Y => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref double R => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref double G => throw new InvalidExecutionContextException($"{nameof(Double2)}.{nameof(G)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Double/Double2.tt b/src/ComputeSharp.Core/Primitives/Double/Double2.tt index 5e92c98d..bf4dba72 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double2.tt +++ b/src/ComputeSharp.Core/Primitives/Double/Double2.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Double2"); +GenerateVectorProperties("Double2", sizeof(double)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Double/Double3.cs b/src/ComputeSharp.Core/Primitives/Double/Double3.cs index 74c975fc..3240fdbb 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(double) * 3)] public partial struct Double3 { /// @@ -44,51 +42,9 @@ namespace ComputeSharp /// The value to assign to the third vector component. public Double3(double x, double y, double z) { - X = x; - Y = y; - Z = z; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public double X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public double Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public double Z { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public double R - { - get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public double G - { - get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public double B - { - get => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(B)}"); + this.x = x; + this.y = y; + this.z = z; } /// diff --git a/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs b/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs index aa11515f..624a8823 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Double/Double3.g.cs @@ -1,16 +1,57 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 24)] public partial struct Double3 { + [FieldOffset(0)] + private double x; + + [FieldOffset(8)] + private double y; + + [FieldOffset(16)] + private double z; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref double this[int i] => throw new InvalidExecutionContextException($"{nameof(Double3)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref double X => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref double Y => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref double Z => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref double R => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref double G => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref double B => throw new InvalidExecutionContextException($"{nameof(Double3)}.{nameof(B)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Double/Double3.tt b/src/ComputeSharp.Core/Primitives/Double/Double3.tt index 7b885990..5f03bf2e 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double3.tt +++ b/src/ComputeSharp.Core/Primitives/Double/Double3.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Double3"); +GenerateVectorProperties("Double3", sizeof(double)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Double/Double4.cs b/src/ComputeSharp.Core/Primitives/Double/Double4.cs index 2258f421..339b7033 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z}, {W})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(double) * 4)] public partial struct Double4 { /// @@ -50,66 +48,10 @@ namespace ComputeSharp /// The value to assign to the fourth vector component. public Double4(double x, double y, double z, double w) { - X = x; - Y = y; - Z = z; - W = w; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public double X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public double Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public double Z { get; set; } - - /// - /// Gets or sets the value of the fourth vector component. - /// - public double W { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public double R - { - get => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public double G - { - get => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public double B - { - get => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(B)}"); - } - - /// - /// Gets or sets the value of the fourth color component. - /// - public double A - { - get => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(A)}"); - set => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(A)}"); + this.x = x; + this.y = y; + this.z = z; + this.w = w; } /// diff --git a/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs b/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs index c325d68f..255f979e 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Double/Double4.g.cs @@ -1,16 +1,70 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 32)] public partial struct Double4 { + [FieldOffset(0)] + private double x; + + [FieldOffset(8)] + private double y; + + [FieldOffset(16)] + private double z; + + [FieldOffset(24)] + private double w; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref double this[int i] => throw new InvalidExecutionContextException($"{nameof(Double4)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref double X => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref double Y => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref double Z => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the W component. + /// + public ref double W => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(W)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref double R => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref double G => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref double B => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(B)}"); + + /// + /// Gets a reference to the value representing the A component. + /// + public ref double A => throw new InvalidExecutionContextException($"{nameof(Double4)}.{nameof(A)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Double/Double4.tt b/src/ComputeSharp.Core/Primitives/Double/Double4.tt index 88645305..f953afbc 100644 --- a/src/ComputeSharp.Core/Primitives/Double/Double4.tt +++ b/src/ComputeSharp.Core/Primitives/Double/Double4.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Double4"); +GenerateVectorProperties("Double4", sizeof(double)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Float/Float2.cs b/src/ComputeSharp.Core/Primitives/Float/Float2.cs index 0bac51b6..9ca796f5 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -9,7 +8,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(float) * 2)] public partial struct Float2 { /// @@ -39,36 +37,8 @@ namespace ComputeSharp /// The value to assign to the second vector component. public Float2(float x, float y) { - X = x; - Y = y; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public float X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public float Y { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public float R - { - get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public float G - { - get => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(G)}"); + this.x = x; + this.y = y; } /// diff --git a/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs b/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs index 29d4b33c..ed10f07d 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float2.g.cs @@ -1,16 +1,44 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 8)] public partial struct Float2 { + [FieldOffset(0)] + private float x; + + [FieldOffset(4)] + private float y; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref float this[int i] => throw new InvalidExecutionContextException($"{nameof(Float2)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref float X => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref float Y => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref float R => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref float G => throw new InvalidExecutionContextException($"{nameof(Float2)}.{nameof(G)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Float/Float2.tt b/src/ComputeSharp.Core/Primitives/Float/Float2.tt index 1dbfbdf5..d2da688a 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float2.tt +++ b/src/ComputeSharp.Core/Primitives/Float/Float2.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Float2"); +GenerateVectorProperties("Float2", sizeof(float)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Float/Float3.cs b/src/ComputeSharp.Core/Primitives/Float/Float3.cs index 9672290b..5de3117b 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -9,7 +8,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(float) * 3)] public partial struct Float3 { /// @@ -45,51 +43,9 @@ namespace ComputeSharp /// The value to assign to the third vector component. public Float3(float x, float y, float z) { - X = x; - Y = y; - Z = z; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public float X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public float Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public float Z { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public float R - { - get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public float G - { - get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public float B - { - get => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(B)}"); + this.x = x; + this.y = y; + this.z = z; } /// diff --git a/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs b/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs index 5434796b..27480ae0 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float3.g.cs @@ -1,16 +1,57 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 12)] public partial struct Float3 { + [FieldOffset(0)] + private float x; + + [FieldOffset(4)] + private float y; + + [FieldOffset(8)] + private float z; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref float this[int i] => throw new InvalidExecutionContextException($"{nameof(Float3)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref float X => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref float Y => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref float Z => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref float R => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref float G => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref float B => throw new InvalidExecutionContextException($"{nameof(Float3)}.{nameof(B)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Float/Float3.tt b/src/ComputeSharp.Core/Primitives/Float/Float3.tt index 1380be33..3b3852bc 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float3.tt +++ b/src/ComputeSharp.Core/Primitives/Float/Float3.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Float3"); +GenerateVectorProperties("Float3", sizeof(float)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Float/Float4.cs b/src/ComputeSharp.Core/Primitives/Float/Float4.cs index 54c93eda..67a4692c 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -9,7 +8,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z}, {W})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(float) * 4)] public partial struct Float4 { /// @@ -51,66 +49,10 @@ namespace ComputeSharp /// The value to assign to the fourth vector component. public Float4(float x, float y, float z, float w) { - X = x; - Y = y; - Z = z; - W = w; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public float X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public float Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public float Z { get; set; } - - /// - /// Gets or sets the value of the fourth vector component. - /// - public float W { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public float R - { - get => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public float G - { - get => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public float B - { - get => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(B)}"); - } - - /// - /// Gets or sets the value of the fourth color component. - /// - public float A - { - get => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(A)}"); - set => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(A)}"); + this.x = x; + this.y = y; + this.z = z; + this.w = w; } /// diff --git a/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs b/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs index 821e6d6c..ba577799 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Float/Float4.g.cs @@ -1,16 +1,70 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 16)] public partial struct Float4 { + [FieldOffset(0)] + private float x; + + [FieldOffset(4)] + private float y; + + [FieldOffset(8)] + private float z; + + [FieldOffset(12)] + private float w; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref float this[int i] => throw new InvalidExecutionContextException($"{nameof(Float4)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref float X => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref float Y => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref float Z => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the W component. + /// + public ref float W => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(W)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref float R => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref float G => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref float B => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(B)}"); + + /// + /// Gets a reference to the value representing the A component. + /// + public ref float A => throw new InvalidExecutionContextException($"{nameof(Float4)}.{nameof(A)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Float/Float4.tt b/src/ComputeSharp.Core/Primitives/Float/Float4.tt index ebb416f9..7bcc833d 100644 --- a/src/ComputeSharp.Core/Primitives/Float/Float4.tt +++ b/src/ComputeSharp.Core/Primitives/Float/Float4.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Float4"); +GenerateVectorProperties("Float4", sizeof(float)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Int/Int2.cs b/src/ComputeSharp.Core/Primitives/Int/Int2.cs index 4c6b122d..8cc711ff 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(int) * 2)] public partial struct Int2 { /// @@ -38,36 +36,8 @@ namespace ComputeSharp /// The value to assign to the second vector component. public Int2(int x, int y) { - X = x; - Y = y; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public int X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public int Y { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public int R - { - get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public int G - { - get => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(G)}"); + this.x = x; + this.y = y; } /// diff --git a/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs b/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs index f54dc208..6923bd5d 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int2.g.cs @@ -1,16 +1,44 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 8)] public partial struct Int2 { + [FieldOffset(0)] + private int x; + + [FieldOffset(4)] + private int y; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref int this[int i] => throw new InvalidExecutionContextException($"{nameof(Int2)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref int X => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref int Y => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref int R => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref int G => throw new InvalidExecutionContextException($"{nameof(Int2)}.{nameof(G)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Int/Int2.tt b/src/ComputeSharp.Core/Primitives/Int/Int2.tt index ee48a8d5..cbd0613b 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int2.tt +++ b/src/ComputeSharp.Core/Primitives/Int/Int2.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Int2"); +GenerateVectorProperties("Int2", sizeof(int)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Int/Int3.cs b/src/ComputeSharp.Core/Primitives/Int/Int3.cs index 0fa549e3..52d2f12b 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int3.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int3.cs @@ -44,51 +44,9 @@ namespace ComputeSharp /// The value to assign to the third vector component. public Int3(int x, int y, int z) { - X = x; - Y = y; - Z = z; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public int X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public int Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public int Z { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public int R - { - get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public int G - { - get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public int B - { - get => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(B)}"); + this.x = x; + this.y = y; + this.z = z; } /// diff --git a/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs b/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs index 19b6946f..f5563a84 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int3.g.cs @@ -1,16 +1,57 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 12)] public partial struct Int3 { + [FieldOffset(0)] + private int x; + + [FieldOffset(4)] + private int y; + + [FieldOffset(8)] + private int z; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref int this[int i] => throw new InvalidExecutionContextException($"{nameof(Int3)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref int X => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref int Y => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref int Z => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref int R => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref int G => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref int B => throw new InvalidExecutionContextException($"{nameof(Int3)}.{nameof(B)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Int/Int3.tt b/src/ComputeSharp.Core/Primitives/Int/Int3.tt index 4333982b..78b16504 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int3.tt +++ b/src/ComputeSharp.Core/Primitives/Int/Int3.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Int3"); +GenerateVectorProperties("Int3", sizeof(int)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/Int/Int4.cs b/src/ComputeSharp.Core/Primitives/Int/Int4.cs index 2b33a0aa..a11f745c 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z}, {W})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(int) * 4)] public partial struct Int4 { /// @@ -50,66 +48,10 @@ namespace ComputeSharp /// The value to assign to the fourth vector component. public Int4(int x, int y, int z, int w) { - X = x; - Y = y; - Z = z; - W = w; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public int X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public int Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public int Z { get; set; } - - /// - /// Gets or sets the value of the fourth vector component. - /// - public int W { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public int R - { - get => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public int G - { - get => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public int B - { - get => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(B)}"); - } - - /// - /// Gets or sets the value of the fourth color component. - /// - public int A - { - get => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(A)}"); - set => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(A)}"); + this.x = x; + this.y = y; + this.z = z; + this.w = w; } /// diff --git a/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs b/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs index 274e3aa6..2f53cb8b 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Int/Int4.g.cs @@ -1,16 +1,70 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 16)] public partial struct Int4 { + [FieldOffset(0)] + private int x; + + [FieldOffset(4)] + private int y; + + [FieldOffset(8)] + private int z; + + [FieldOffset(12)] + private int w; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref int this[int i] => throw new InvalidExecutionContextException($"{nameof(Int4)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref int X => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref int Y => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref int Z => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the W component. + /// + public ref int W => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(W)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref int R => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref int G => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref int B => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(B)}"); + + /// + /// Gets a reference to the value representing the A component. + /// + public ref int A => throw new InvalidExecutionContextException($"{nameof(Int4)}.{nameof(A)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/Int/Int4.tt b/src/ComputeSharp.Core/Primitives/Int/Int4.tt index 45dc5823..655b092c 100644 --- a/src/ComputeSharp.Core/Primitives/Int/Int4.tt +++ b/src/ComputeSharp.Core/Primitives/Int/Int4.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("Int4"); +GenerateVectorProperties("Int4", sizeof(int)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt2.cs index dedffc20..54c8d69a 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(uint) * 2)] public partial struct UInt2 { /// @@ -38,36 +36,8 @@ namespace ComputeSharp /// The value to assign to the second vector component. public UInt2(uint x, uint y) { - X = x; - Y = y; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public uint X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public uint Y { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public uint R - { - get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public uint G - { - get => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(G)}"); + this.x = x; + this.y = y; } /// diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs index b7fa55ce..367822ad 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt2.g.cs @@ -1,16 +1,44 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 8)] public partial struct UInt2 { + [FieldOffset(0)] + private uint x; + + [FieldOffset(4)] + private uint y; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref uint this[int i] => throw new InvalidExecutionContextException($"{nameof(UInt2)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref uint X => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref uint Y => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref uint R => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref uint G => throw new InvalidExecutionContextException($"{nameof(UInt2)}.{nameof(G)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt2.tt b/src/ComputeSharp.Core/Primitives/UInt/UInt2.tt index 2636f195..0b505c6e 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt2.tt +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt2.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("UInt2"); +GenerateVectorProperties("UInt2", sizeof(uint)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt3.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt3.cs index f22ff6a2..ea4124ed 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(uint) * 3)] public partial struct UInt3 { /// @@ -44,51 +42,9 @@ namespace ComputeSharp /// The value to assign to the third vector component. public UInt3(uint x, uint y, uint z) { - X = x; - Y = y; - Z = z; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public uint X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public uint Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public uint Z { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public uint R - { - get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public uint G - { - get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public uint B - { - get => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(B)}"); + this.x = x; + this.y = y; + this.z = z; } /// diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs index c4e06bdf..6148b840 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt3.g.cs @@ -1,16 +1,57 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 12)] public partial struct UInt3 { + [FieldOffset(0)] + private uint x; + + [FieldOffset(4)] + private uint y; + + [FieldOffset(8)] + private uint z; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref uint this[int i] => throw new InvalidExecutionContextException($"{nameof(UInt3)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref uint X => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref uint Y => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref uint Z => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref uint R => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref uint G => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref uint B => throw new InvalidExecutionContextException($"{nameof(UInt3)}.{nameof(B)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt3.tt b/src/ComputeSharp.Core/Primitives/UInt/UInt3.tt index 62bf7ea4..eac79629 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt3.tt +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt3.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("UInt3"); +GenerateVectorProperties("UInt3", sizeof(uint)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt4.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt4.cs index 4c41f41b..a9253987 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 System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp @@ -8,7 +7,6 @@ namespace ComputeSharp /// A that maps the HLSL type. /// [DebuggerDisplay("({X}, {Y}, {Z}, {W})")] - [StructLayout(LayoutKind.Sequential, Size = sizeof(uint) * 4)] public partial struct UInt4 { /// @@ -50,66 +48,10 @@ namespace ComputeSharp /// The value to assign to the fourth vector component. public UInt4(uint x, uint y, uint z, uint w) { - X = x; - Y = y; - Z = z; - W = w; - } - - /// - /// Gets or sets the value of the first vector component. - /// - public uint X { get; set; } - - /// - /// Gets or sets the value of the second vector component. - /// - public uint Y { get; set; } - - /// - /// Gets or sets the value of the third vector component. - /// - public uint Z { get; set; } - - /// - /// Gets or sets the value of the fourth vector component. - /// - public uint W { get; set; } - - /// - /// Gets or sets the value of the first color component. - /// - public uint R - { - get => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(R)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(R)}"); - } - - /// - /// Gets or sets the value of the second color component. - /// - public uint G - { - get => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(G)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(G)}"); - } - - /// - /// Gets or sets the value of the third color component. - /// - public uint B - { - get => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(B)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(B)}"); - } - - /// - /// Gets or sets the value of the fourth color component. - /// - public uint A - { - get => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(A)}"); - set => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(A)}"); + this.x = x; + this.y = y; + this.z = z; + this.w = w; } /// diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs b/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs index 349dc8e5..c2d0d60b 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt4.g.cs @@ -1,16 +1,70 @@ -using ComputeSharp.Exceptions; +using System.Runtime.InteropServices; +using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = 16)] public partial struct UInt4 { + [FieldOffset(0)] + private uint x; + + [FieldOffset(4)] + private uint y; + + [FieldOffset(8)] + private uint z; + + [FieldOffset(12)] + private uint w; + /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref uint this[int i] => throw new InvalidExecutionContextException($"{nameof(UInt4)}[int]"); + /// + /// Gets a reference to the value representing the X component. + /// + public ref uint X => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(X)}"); + + /// + /// Gets a reference to the value representing the Y component. + /// + public ref uint Y => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(Y)}"); + + /// + /// Gets a reference to the value representing the Z component. + /// + public ref uint Z => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(Z)}"); + + /// + /// Gets a reference to the value representing the W component. + /// + public ref uint W => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(W)}"); + + /// + /// Gets a reference to the value representing the R component. + /// + public ref uint R => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(R)}"); + + /// + /// Gets a reference to the value representing the G component. + /// + public ref uint G => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(G)}"); + + /// + /// Gets a reference to the value representing the B component. + /// + public ref uint B => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(B)}"); + + /// + /// Gets a reference to the value representing the A component. + /// + public ref uint A => throw new InvalidExecutionContextException($"{nameof(UInt4)}.{nameof(A)}"); + /// /// Gets a readonly reference to the value with the components , . /// diff --git a/src/ComputeSharp.Core/Primitives/UInt/UInt4.tt b/src/ComputeSharp.Core/Primitives/UInt/UInt4.tt index ef981244..ccbf0ae8 100644 --- a/src/ComputeSharp.Core/Primitives/UInt/UInt4.tt +++ b/src/ComputeSharp.Core/Primitives/UInt/UInt4.tt @@ -1,4 +1,4 @@ <#@include file="..\VectorType.ttinclude" #> <# -GenerateVectorProperties("UInt4"); +GenerateVectorProperties("UInt4", sizeof(uint)); #> \ No newline at end of file diff --git a/src/ComputeSharp.Core/Primitives/VectorType.ttinclude b/src/ComputeSharp.Core/Primitives/VectorType.ttinclude index d2c5ec70..e41584da 100644 --- a/src/ComputeSharp.Core/Primitives/VectorType.ttinclude +++ b/src/ComputeSharp.Core/Primitives/VectorType.ttinclude @@ -20,36 +20,54 @@ IEnumerable EnumerateCombinations(string text) } // Generates all vector access properties for a specified type -void GenerateVectorProperties(string typeName) +void GenerateVectorProperties(string typeName, int elementSize) { string elementTypeName = Regex.Match(typeName, @"^[A-Za-z]+").Value; string hlslElementTypeName = elementTypeName.ToLower(); int i = int.Parse(Regex.Match(typeName, @"\d+$").Value); #> +using System.Runtime.InteropServices; using ComputeSharp.Exceptions; namespace ComputeSharp { /// + [StructLayout(LayoutKind.Explicit, Size = <#=(elementSize * i)#>)] public partial struct <#=typeName#> { +<# + PushIndent(" "); + PushIndent(" "); + + // Generate the private fields + foreach (char name in "xyzw".Substring(0, i)) + { + WriteLine($"[FieldOffset({"xyzw".IndexOf(name) * elementSize})]"); + WriteLine($"private {hlslElementTypeName} {name};"); + WriteLine(""); + } + + PopIndent(); + PopIndent(); +#> /// /// Gets a reference to a specific component in the current instance. /// /// The index of the component to access. public ref <#=hlslElementTypeName#> this[int i] => throw new InvalidExecutionContextException($"{nameof(<#=typeName#>)}[int]"); <# - PushIndent(" "); PushIndent(" "); // Generate the combinatorial swizzling properties foreach ( - var property in + (string Name, int Length) property in + "XYZW".Substring(0, i).Select(c => (c.ToString(), 1)).Concat( + "RGBA".Substring(0, i).Select(c => (c.ToString(), 1))).Concat( from j in Enumerable.Range(2, i - 1) from source in new[] { "XYZW", "RGBA" } from name in EnumerateCombinations(source.Substring(0, j)) - select (Name: name, Length: j)) + select (name, j))) { WriteLine(""); @@ -59,11 +77,18 @@ namespace ComputeSharp // XML docs WriteLine("/// "); - Write("/// Gets a "); - if (isReadonly) Write("readonly "); - Write($"reference to the value with the components "); - Write(string.Join(", ", property.Name.Select(c => $""))); - WriteLine("."); + if (property.Length == 1) + { + WriteLine($"/// Gets a reference to the value representing the {property.Name} component."); + } + else + { + Write("/// Gets a "); + if (isReadonly) Write("readonly "); + Write($"reference to the value with the components "); + Write(string.Join(", ", property.Name.Select(c => $""))); + WriteLine("."); + } WriteLine("/// "); // Property