diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs index d220fc37..5124e94b 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool2.g.cs @@ -24,8 +24,8 @@ public unsafe partial struct Bool2 /// The value to assign to the second vector component. public Bool2(bool x, bool y) { - this.x = x; - this.y = y; + this.x = x ? 1 : 0; + this.y = y ? 1 : 0; } /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs index 9df378c1..2c96a276 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool3.g.cs @@ -28,9 +28,9 @@ public unsafe partial struct Bool3 /// The value to assign to the third vector component. public Bool3(bool x, bool y, bool z) { - this.x = x; - this.y = y; - this.z = z; + this.x = x ? 1 : 0; + this.y = y ? 1 : 0; + this.z = z ? 1 : 0; } /// @@ -40,9 +40,9 @@ public unsafe partial struct Bool3 /// The value to assign to the third vector component. public Bool3(Bool2 xy, bool z) { - this.x = xy.X; - this.y = xy.Y; - this.z = z; + this.x = xy.X ? 1 : 0; + this.y = xy.Y ? 1 : 0; + this.z = z ? 1 : 0; } /// @@ -52,9 +52,9 @@ public unsafe partial struct Bool3 /// The value to assign to the third vector component. public Bool3(Bool1x2 xy, bool z) { - this.x = xy.M11; - this.y = xy.M12; - this.z = z; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M12 ? 1 : 0; + this.z = z ? 1 : 0; } /// @@ -64,9 +64,9 @@ public unsafe partial struct Bool3 /// The value to assign to the third vector component. public Bool3(Bool2x1 xy, bool z) { - this.x = xy.M11; - this.y = xy.M21; - this.z = z; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M21 ? 1 : 0; + this.z = z ? 1 : 0; } /// @@ -76,9 +76,9 @@ public unsafe partial struct Bool3 /// The value to assign to the first, second and third vector components. public Bool3(bool x, Bool2 yz) { - this.x = x; - this.y = yz.X; - this.z = yz.Y; + this.x = x ? 1 : 0; + this.y = yz.X ? 1 : 0; + this.z = yz.Y ? 1 : 0; } /// @@ -88,9 +88,9 @@ public unsafe partial struct Bool3 /// The value to assign to the first, second and third vector components. public Bool3(bool x, Bool1x2 yz) { - this.x = x; - this.y = yz.M11; - this.z = yz.M12; + this.x = x ? 1 : 0; + this.y = yz.M11 ? 1 : 0; + this.z = yz.M12 ? 1 : 0; } /// @@ -100,9 +100,9 @@ public unsafe partial struct Bool3 /// The value to assign to the first, second and third vector components. public Bool3(bool x, Bool2x1 yz) { - this.x = x; - this.y = yz.M11; - this.z = yz.M21; + this.x = x ? 1 : 0; + this.y = yz.M11 ? 1 : 0; + this.z = yz.M21 ? 1 : 0; } /// diff --git a/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs b/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs index 123994b5..b24da5de 100644 --- a/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs +++ b/src/ComputeSharp.Core/Primitives/Bool/Bool4.g.cs @@ -32,10 +32,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(bool x, bool y, bool z, bool w) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; + this.x = x ? 1 : 0; + this.y = y ? 1 : 0; + this.z = z ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -46,10 +46,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(Bool2 xy, bool z, bool w) { - this.x = xy.X; - this.y = xy.Y; - this.z = z; - this.w = w; + this.x = xy.X ? 1 : 0; + this.y = xy.Y ? 1 : 0; + this.z = z ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -60,10 +60,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(Bool1x2 xy, bool z, bool w) { - this.x = xy.M11; - this.y = xy.M12; - this.z = z; - this.w = w; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M12 ? 1 : 0; + this.z = z ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -74,10 +74,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(Bool2x1 xy, bool z, bool w) { - this.x = xy.M11; - this.y = xy.M21; - this.z = z; - this.w = w; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M21 ? 1 : 0; + this.z = z ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -88,10 +88,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(bool x, Bool2 yz, bool w) { - this.x = x; - this.y = yz.X; - this.z = yz.Y; - this.w = w; + this.x = x ? 1 : 0; + this.y = yz.X ? 1 : 0; + this.z = yz.Y ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -102,10 +102,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(bool x, Bool1x2 yz, bool w) { - this.x = x; - this.y = yz.M11; - this.z = yz.M12; - this.w = w; + this.x = x ? 1 : 0; + this.y = yz.M11 ? 1 : 0; + this.z = yz.M12 ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -116,10 +116,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(bool x, Bool2x1 yz, bool w) { - this.x = x; - this.y = yz.M11; - this.z = yz.M21; - this.w = w; + this.x = x ? 1 : 0; + this.y = yz.M11 ? 1 : 0; + this.z = yz.M21 ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -130,10 +130,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(bool x, bool y, Bool2 zw) { - this.x = x; - this.y = y; - this.z = zw.X; - this.w = zw.Y; + this.x = x ? 1 : 0; + this.y = y ? 1 : 0; + this.z = zw.X ? 1 : 0; + this.w = zw.Y ? 1 : 0; } /// @@ -144,10 +144,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(bool x, bool y, Bool1x2 zw) { - this.x = x; - this.y = y; - this.z = zw.M11; - this.w = zw.M12; + this.x = x ? 1 : 0; + this.y = y ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M12 ? 1 : 0; } /// @@ -158,10 +158,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(bool x, bool y, Bool2x1 zw) { - this.x = x; - this.y = y; - this.z = zw.M11; - this.w = zw.M21; + this.x = x ? 1 : 0; + this.y = y ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M21 ? 1 : 0; } /// @@ -171,10 +171,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool2 xy, Bool2 zw) { - this.x = xy.X; - this.y = xy.Y; - this.z = zw.X; - this.w = zw.Y; + this.x = xy.X ? 1 : 0; + this.y = xy.Y ? 1 : 0; + this.z = zw.X ? 1 : 0; + this.w = zw.Y ? 1 : 0; } /// @@ -184,10 +184,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool2 xy, Bool1x2 zw) { - this.x = xy.X; - this.y = xy.Y; - this.z = zw.M11; - this.w = zw.M12; + this.x = xy.X ? 1 : 0; + this.y = xy.Y ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M12 ? 1 : 0; } /// @@ -197,10 +197,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool2 xy, Bool2x1 zw) { - this.x = xy.X; - this.y = xy.Y; - this.z = zw.M11; - this.w = zw.M21; + this.x = xy.X ? 1 : 0; + this.y = xy.Y ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M21 ? 1 : 0; } /// @@ -210,10 +210,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool1x2 xy, Bool2 zw) { - this.x = xy.M11; - this.y = xy.M12; - this.z = zw.X; - this.w = zw.Y; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M12 ? 1 : 0; + this.z = zw.X ? 1 : 0; + this.w = zw.Y ? 1 : 0; } /// @@ -223,10 +223,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool1x2 xy, Bool1x2 zw) { - this.x = xy.M11; - this.y = xy.M12; - this.z = zw.M11; - this.w = zw.M12; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M12 ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M12 ? 1 : 0; } /// @@ -236,10 +236,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool1x2 xy, Bool2x1 zw) { - this.x = xy.M11; - this.y = xy.M12; - this.z = zw.M11; - this.w = zw.M21; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M12 ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M21 ? 1 : 0; } /// @@ -249,10 +249,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool2x1 xy, Bool2 zw) { - this.x = xy.M11; - this.y = xy.M21; - this.z = zw.X; - this.w = zw.Y; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M21 ? 1 : 0; + this.z = zw.X ? 1 : 0; + this.w = zw.Y ? 1 : 0; } /// @@ -262,10 +262,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool2x1 xy, Bool1x2 zw) { - this.x = xy.M11; - this.y = xy.M21; - this.z = zw.M11; - this.w = zw.M12; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M21 ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M12 ? 1 : 0; } /// @@ -275,10 +275,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(Bool2x1 xy, Bool2x1 zw) { - this.x = xy.M11; - this.y = xy.M21; - this.z = zw.M11; - this.w = zw.M21; + this.x = xy.M11 ? 1 : 0; + this.y = xy.M21 ? 1 : 0; + this.z = zw.M11 ? 1 : 0; + this.w = zw.M21 ? 1 : 0; } /// @@ -288,10 +288,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(Bool3 xyz, bool w) { - this.x = xyz.X; - this.y = xyz.Y; - this.z = xyz.Z; - this.w = w; + this.x = xyz.X ? 1 : 0; + this.y = xyz.Y ? 1 : 0; + this.z = xyz.Z ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -301,10 +301,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(Bool1x3 xyz, bool w) { - this.x = xyz.M11; - this.y = xyz.M12; - this.z = xyz.M13; - this.w = w; + this.x = xyz.M11 ? 1 : 0; + this.y = xyz.M12 ? 1 : 0; + this.z = xyz.M13 ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -314,10 +314,10 @@ public unsafe partial struct Bool4 /// The value to assign to the fourth vector component. public Bool4(Bool3x1 xyz, bool w) { - this.x = xyz.M11; - this.y = xyz.M21; - this.z = xyz.M31; - this.w = w; + this.x = xyz.M11 ? 1 : 0; + this.y = xyz.M21 ? 1 : 0; + this.z = xyz.M31 ? 1 : 0; + this.w = w ? 1 : 0; } /// @@ -327,10 +327,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(bool x, Bool3 yzw) { - this.x = x; - this.y = yzw.X; - this.z = yzw.Y; - this.w = yzw.Z; + this.x = x ? 1 : 0; + this.y = yzw.X ? 1 : 0; + this.z = yzw.Y ? 1 : 0; + this.w = yzw.Z ? 1 : 0; } /// @@ -340,10 +340,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(bool x, Bool1x3 yzw) { - this.x = x; - this.y = yzw.M11; - this.z = yzw.M12; - this.w = yzw.M13; + this.x = x ? 1 : 0; + this.y = yzw.M11 ? 1 : 0; + this.z = yzw.M12 ? 1 : 0; + this.w = yzw.M13 ? 1 : 0; } /// @@ -353,10 +353,10 @@ public unsafe partial struct Bool4 /// The value to assign to the first, second, third and fourth vector components. public Bool4(bool x, Bool3x1 yzw) { - this.x = x; - this.y = yzw.M11; - this.z = yzw.M21; - this.w = yzw.M31; + this.x = x ? 1 : 0; + this.y = yzw.M11 ? 1 : 0; + this.z = yzw.M21 ? 1 : 0; + this.w = yzw.M31 ? 1 : 0; } /// diff --git a/src/ComputeSharp.Core/Primitives/VectorType.Ctors.ttinclude b/src/ComputeSharp.Core/Primitives/VectorType.Ctors.ttinclude index a7f4f3d3..c0e75381 100644 --- a/src/ComputeSharp.Core/Primitives/VectorType.Ctors.ttinclude +++ b/src/ComputeSharp.Core/Primitives/VectorType.Ctors.ttinclude @@ -153,22 +153,28 @@ void GenerateConstructors(string typeName, int elementSize) { Write($"this.{"xyzw"[inputOffset++]} = "); + string expression; + if (parameters[i].EndsWith("x1")) { - WriteLine($"{parameterNames[i]}.M{j + 1}1;"); + expression = $"{parameterNames[i]}.M{j + 1}1"; } else if (parameters[i].Contains('x')) { - WriteLine($"{parameterNames[i]}.M1{j + 1};"); + expression = $"{parameterNames[i]}.M1{j + 1}"; } else if (parameterSizes[i] > 1) { - WriteLine($"{parameterNames[i]}.{char.ToUpperInvariant("xyzw"[j])};"); + expression = $"{parameterNames[i]}.{char.ToUpperInvariant("xyzw"[j])}"; } else { - WriteLine($"{parameterNames[i]};"); + expression = $"{parameterNames[i]}"; } + + WriteLine(typeName.StartsWith("Bool") + ? $"{expression} ? 1 : 0;" + : $"{expression};"); } }