Normalize bool HLSL types to use int-s as backing storage
このコミットが含まれているのは:
1 親
581eb40ed1
コミット
797d06cdb7
10ファイル変更
+615
-566
検索条件に一致するファイルはありません
@@ -6,14 +6,14 @@ namespace ComputeSharp;
|
||||
/// <summary>
|
||||
/// A <see langword="struct"/> that can be used in place of the <see cref="bool"/> type in HLSL shaders.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Explicit, Size = sizeof(int), Pack = 4)]
|
||||
[StructLayout(LayoutKind.Explicit, Size = 4, Pack = 4)]
|
||||
public readonly struct Bool
|
||||
{
|
||||
/// <summary>
|
||||
/// The wrapped <see cref="bool"/> value for the current instance.
|
||||
/// The wrapped <see cref="int"/> value for the current instance.
|
||||
/// </summary>
|
||||
[FieldOffset(0)]
|
||||
private readonly bool Value;
|
||||
private readonly int Value;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Bool"/> instance for a given <see cref="bool"/> value.
|
||||
@@ -21,7 +21,7 @@ public readonly struct Bool
|
||||
/// <param name="value">.</param>
|
||||
private Bool(bool value)
|
||||
{
|
||||
Value = value;
|
||||
Value = value ? 1 : 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -39,20 +39,20 @@ public readonly struct Bool
|
||||
/// <inheritdoc/>
|
||||
public override string ToString()
|
||||
{
|
||||
return Value.ToString();
|
||||
return ((bool)this).ToString();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="bool.ToString(IFormatProvider?)"/>
|
||||
public string ToString(IFormatProvider? formatProvider)
|
||||
{
|
||||
return Value.ToString();
|
||||
return ((bool)this).ToString(formatProvider);
|
||||
}
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
/// <inheritdoc cref="bool.TryFormat(Span{char}, out int)"/>
|
||||
public bool TryFormat(Span<char> destination, out int charsWritten)
|
||||
{
|
||||
return Value.TryFormat(destination, out charsWritten);
|
||||
return ((bool)this).TryFormat(destination, out charsWritten);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -60,7 +60,7 @@ public readonly struct Bool
|
||||
/// Inverts the <see cref="bool"/> value represented by a given <see cref="Bool"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="Bool"/> instance.</param>
|
||||
public static Bool operator !(Bool x) => new(!x.Value);
|
||||
public static Bool operator !(Bool x) => new(!(bool)x);
|
||||
|
||||
/// <summary>
|
||||
/// Ands two <see cref="Bool"/> values.
|
||||
@@ -107,7 +107,7 @@ public readonly struct Bool
|
||||
/// Converts a given <see cref="Bool"/> instance to its corresponding <see cref="bool"/> value.
|
||||
/// </summary>
|
||||
/// <param name="x">The input <see cref="Bool"/> instance.</param>
|
||||
public static implicit operator bool(Bool x) => x.Value;
|
||||
public static implicit operator bool(Bool x) => x.Value != 0;
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="bool"/> value to a corresponding <see cref="Bool"/> instance.
|
||||
|
||||
@@ -14,8 +14,8 @@ public partial struct Bool2
|
||||
/// <param name="y">The value to assign to the second vector component.</param>
|
||||
public Bool2(bool x, bool y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.x = x ? 1 : 0;
|
||||
this.y = y ? 1 : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,10 +20,10 @@ public unsafe partial struct Bool2
|
||||
private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool2), sizeof(Bool4));
|
||||
|
||||
[FieldOffset(0)]
|
||||
private bool x;
|
||||
private int x;
|
||||
|
||||
[FieldOffset(4)]
|
||||
private bool y;
|
||||
private int y;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to a specific component in the current <see cref="Bool2"/> instance.
|
||||
@@ -55,12 +55,12 @@ public unsafe partial struct Bool2
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>X</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.x)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>Y</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.y)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
@@ -233,12 +233,12 @@ public unsafe partial struct Bool2
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>R</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.x)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>G</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.y)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="R"/>, <see cref="R"/>.
|
||||
@@ -414,9 +414,9 @@ public unsafe partial struct Bool2
|
||||
public override readonly string ToString()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return string.Create(null, stackalloc char[32], $"<{this.x}, {this.y}>");
|
||||
return string.Create(null, stackalloc char[32], $"<{this.x != 0}, {this.y != 0}>");
|
||||
#else
|
||||
return $"<{this.x}, {this.y}>";
|
||||
return $"<{this.x != 0}, {this.y != 0}>";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ public partial struct Bool3
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -27,9 +27,9 @@ public partial struct Bool3
|
||||
/// <param name="z">The value to assign to the third vector component.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,9 +39,9 @@ public partial struct Bool3
|
||||
/// <param name="yz">The value to assign to the second and thirt vector components.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,13 +20,13 @@ public unsafe partial struct Bool3
|
||||
private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool3), sizeof(Bool4));
|
||||
|
||||
[FieldOffset(0)]
|
||||
private bool x;
|
||||
private int x;
|
||||
|
||||
[FieldOffset(4)]
|
||||
private bool y;
|
||||
private int y;
|
||||
|
||||
[FieldOffset(8)]
|
||||
private bool z;
|
||||
private int z;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to a specific component in the current <see cref="Bool3"/> instance.
|
||||
@@ -63,17 +63,17 @@ public unsafe partial struct Bool3
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>X</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.x)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>Y</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.y)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>Z</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool Z => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.z), 1));
|
||||
public readonly ref bool Z => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.z)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
@@ -780,17 +780,17 @@ public unsafe partial struct Bool3
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>R</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.x)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>G</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.y)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>B</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool B => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.z), 1));
|
||||
public readonly ref bool B => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.z)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="R"/>, <see cref="R"/>.
|
||||
@@ -1500,9 +1500,9 @@ public unsafe partial struct Bool3
|
||||
public override readonly string ToString()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return string.Create(null, stackalloc char[32], $"<{this.x}, {this.y}, {this.z}>");
|
||||
return string.Create(null, stackalloc char[32], $"<{this.x != 0}, {this.y != 0}, {this.z != 0}>");
|
||||
#else
|
||||
return $"<{this.x}, {this.y}, {this.z}>";
|
||||
return $"<{this.x != 0}, {this.y != 0}, {this.z != 0}>";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ public partial struct Bool4
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -30,10 +30,10 @@ public partial struct Bool4
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,10 +44,10 @@ public partial struct Bool4
|
||||
/// <param name="zw">The value to assign to the third and fourth vector components.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,10 +57,10 @@ public partial struct Bool4
|
||||
/// <param name="zw">The value to assign to the third and fourth vector components.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,10 +70,10 @@ public partial struct Bool4
|
||||
/// <param name="w">The value to assign to the fourth vector component.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,10 +83,10 @@ public partial struct Bool4
|
||||
/// <param name="yzw">The value to assign to the second, third and fourth vector components.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -20,16 +20,16 @@ public unsafe partial struct Bool4
|
||||
private static readonly void* UndefinedData = (void*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(Bool4), sizeof(Bool4));
|
||||
|
||||
[FieldOffset(0)]
|
||||
private bool x;
|
||||
private int x;
|
||||
|
||||
[FieldOffset(4)]
|
||||
private bool y;
|
||||
private int y;
|
||||
|
||||
[FieldOffset(8)]
|
||||
private bool z;
|
||||
private int z;
|
||||
|
||||
[FieldOffset(12)]
|
||||
private bool w;
|
||||
private int w;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to a specific component in the current <see cref="Bool4"/> instance.
|
||||
@@ -71,22 +71,22 @@ public unsafe partial struct Bool4
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>X</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
public readonly ref bool X => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.x)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>Y</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
public readonly ref bool Y => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.y)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>Z</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool Z => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.z), 1));
|
||||
public readonly ref bool Z => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.z)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>W</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool W => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.w), 1));
|
||||
public readonly ref bool W => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.w)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="X"/>, <see cref="X"/>.
|
||||
@@ -2107,22 +2107,22 @@ public unsafe partial struct Bool4
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>R</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.x), 1));
|
||||
public readonly ref bool R => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.x)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>G</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.y), 1));
|
||||
public readonly ref bool G => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.y)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>B</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool B => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.z), 1));
|
||||
public readonly ref bool B => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.z)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="bool"/> value representing the <c>A</c> component.
|
||||
/// </summary>
|
||||
public readonly ref bool A => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.w), 1));
|
||||
public readonly ref bool A => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.w)), 1));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a readonly reference to the <see cref="Bool2"/> value with the components <see cref="R"/>, <see cref="R"/>.
|
||||
@@ -4146,9 +4146,9 @@ public unsafe partial struct Bool4
|
||||
public override readonly string ToString()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return string.Create(null, stackalloc char[32], $"<{this.x}, {this.y}, {this.z}, {this.w}>");
|
||||
return string.Create(null, stackalloc char[32], $"<{this.x != 0}, {this.y != 0}, {this.z != 0}, {this.w != 0}>");
|
||||
#else
|
||||
return $"<{this.x}, {this.y}, {this.z}, {this.w}>";
|
||||
return $"<{this.x != 0}, {this.y != 0}, {this.z != 0}, {this.w != 0}>";
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -35,6 +35,8 @@ namespace ComputeSharp;
|
||||
void GenerateMatrixProperties(string typeName, int rows, int columns, int elementSize)
|
||||
{
|
||||
string elementTypeName = typeName.ToLower();
|
||||
bool isBoolType = elementTypeName == "bool";
|
||||
string fieldElementTypeName = isBoolType ? "int" : elementTypeName;
|
||||
string fullTypeName = $"{typeName}{rows}x{columns}";
|
||||
string rowTypeName = columns > 1 ? $"{typeName}{columns}" : elementTypeName;
|
||||
List<string> fieldNames = new List<string>();
|
||||
@@ -56,7 +58,7 @@ public unsafe partial struct <#=fullTypeName#>
|
||||
for (int j = 1; j <= columns; j++)
|
||||
{
|
||||
WriteLine($"[FieldOffset({((i - 1) * columns + j - 1) * elementSize})]");
|
||||
WriteLine($"private {elementTypeName} m{i}{j};");
|
||||
WriteLine($"private {fieldElementTypeName} m{i}{j};");
|
||||
WriteLine("");
|
||||
|
||||
fieldNames.Add($"m{i}{j}");
|
||||
@@ -79,7 +81,15 @@ public unsafe partial struct <#=fullTypeName#>
|
||||
|
||||
foreach (string fieldName in fieldNames)
|
||||
{
|
||||
WriteLine($"this.{fieldName} = {fieldName};");
|
||||
if (isBoolType)
|
||||
{
|
||||
// For bools, normalize from bool to int
|
||||
WriteLine($"this.{fieldName} = {fieldName} ? 1 : 0;");
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine($"this.{fieldName} = {fieldName};");
|
||||
}
|
||||
}
|
||||
|
||||
PopIndent();
|
||||
@@ -113,7 +123,15 @@ public unsafe partial struct <#=fullTypeName#>
|
||||
for (int i = 1; i <= rows; i++)
|
||||
for (int j = 1; j <= columns; j++)
|
||||
{
|
||||
WriteLine($"this.m{i}{j} = row{i}.{"XYZW"[j - 1]};");
|
||||
if (isBoolType)
|
||||
{
|
||||
// Also normalize bools here as well
|
||||
WriteLine($"this.m{i}{j} = row{i}.{"XYZW"[j - 1]} ? 1 : 0;");
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine($"this.m{i}{j} = row{i}.{"XYZW"[j - 1]};");
|
||||
}
|
||||
}
|
||||
|
||||
PopIndent();
|
||||
@@ -165,7 +183,20 @@ public unsafe partial struct <#=fullTypeName#>
|
||||
/// <summary>
|
||||
/// Gets a reference to the <see cref="<#=elementTypeName#>"/> value representing the component at position [<#=i#>, <#=j#>].
|
||||
/// </summary>
|
||||
<#
|
||||
if (isBoolType)
|
||||
{
|
||||
#>
|
||||
public readonly ref <#=elementTypeName#> M<#=i#><#=j#> => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.m<#=i#><#=j#>)), 1));
|
||||
<#
|
||||
}
|
||||
else
|
||||
{
|
||||
#>
|
||||
public readonly ref <#=elementTypeName#> M<#=i#><#=j#> => ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.m<#=i#><#=j#>), 1));
|
||||
<#
|
||||
}
|
||||
#>
|
||||
<#
|
||||
}
|
||||
|
||||
@@ -187,7 +218,14 @@ public unsafe partial struct <#=fullTypeName#>
|
||||
for (int i = 1; i <= rows; i++)
|
||||
for (int j = 1; j <= columns; j++)
|
||||
{
|
||||
WriteLine($"matrix.m{i}{j} = x;");
|
||||
if (isBoolType)
|
||||
{
|
||||
WriteLine($"matrix.m{i}{j} = x ? 1 : 0;");
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine($"matrix.m{i}{j} = x;");
|
||||
}
|
||||
}
|
||||
|
||||
WriteLine("");
|
||||
|
||||
@@ -49,6 +49,8 @@ void GenerateVectorProperties(string typeName, int elementSize)
|
||||
{
|
||||
string elementTypeName = Regex.Match(typeName, @"^[A-Za-z]+").Value;
|
||||
string hlslElementTypeName = elementTypeName.ToLower();
|
||||
bool isBoolType = hlslElementTypeName == "bool";
|
||||
string fieldElementTypeName = isBoolType ? "int" : hlslElementTypeName;
|
||||
int i = int.Parse(Regex.Match(typeName, @"\d+$").Value);
|
||||
string formattable = elementTypeName == "Bool" ? "" : "ISpanFormattable";
|
||||
|
||||
@@ -96,7 +98,7 @@ public unsafe partial struct <#=typeName#>
|
||||
foreach (char name in "xyzw".Substring(0, i))
|
||||
{
|
||||
WriteLine($"[FieldOffset({"xyzw".IndexOf(name) * elementSize})]");
|
||||
WriteLine($"private {hlslElementTypeName} {name};");
|
||||
WriteLine($"private {fieldElementTypeName} {name};");
|
||||
WriteLine("");
|
||||
}
|
||||
|
||||
@@ -201,7 +203,16 @@ public unsafe partial struct <#=typeName#>
|
||||
|
||||
// Property
|
||||
Write($"public readonly {refType} {propertyType} {propertyName} ");
|
||||
WriteLine($"=> ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.{fieldName}), 1));");
|
||||
|
||||
if (isBoolType)
|
||||
{
|
||||
// For bool types, also reinterpret cast from int to bool (the backing field is int to ensure all 4 bytes are initialized)
|
||||
WriteLine($"=> ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.As<int, bool>(ref Unsafe.AsRef(in this.{fieldName})), 1));");
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine($"=> ref MemoryMarshal.GetReference(MemoryMarshal.CreateSpan(ref Unsafe.AsRef(in this.{fieldName}), 1));");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -233,9 +244,9 @@ public unsafe partial struct <#=typeName#>
|
||||
public override readonly string ToString()
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return string.Create(null, stackalloc char[32], $"<<#=string.Join(", ", "xyzw".Take(i).Select(c => $"{{this.{c}}}"))#>>");
|
||||
return string.Create(null, stackalloc char[32], $"<<#=string.Join(", ", "xyzw".Take(i).Select(c => $"{{this.{c} != 0}}"))#>>");
|
||||
#else
|
||||
return $"<<#=string.Join(", ", "xyzw".Take(i).Select(c => $"{{this.{c}}}"))#>>";
|
||||
return $"<<#=string.Join(", ", "xyzw".Take(i).Select(c => $"{{this.{c} != 0}}"))#>>";
|
||||
#endif
|
||||
}
|
||||
<#
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする