diff --git a/src/ComputeSharp.Core/Primitives/ThreadIds.cs b/src/ComputeSharp.Core/Primitives/ThreadIds.cs index f5370ec8..69f58032 100644 --- a/src/ComputeSharp.Core/Primitives/ThreadIds.cs +++ b/src/ComputeSharp.Core/Primitives/ThreadIds.cs @@ -5,7 +5,7 @@ namespace ComputeSharp /// /// A that indicates the ids of a given GPU thread running a compute shader. /// - public readonly struct ThreadIds + public readonly ref struct ThreadIds { /// /// Gets the X id of the current thread. @@ -21,5 +21,185 @@ namespace ComputeSharp /// Gets the Z id of the current thread. /// public int Z => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(Z)}"); + + /// + /// Gets an value with the value for all components. + /// + public Int2 XX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public Int2 XY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public Int2 XZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public Int2 YX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YX)}"); + + /// + /// Gets an value with the value for all components. + /// + public Int2 YY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public Int2 YZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public Int2 ZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public Int2 ZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZ)}"); + + /// + /// Gets an value with the value for all components. + /// + public Int3 XXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXX)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 XXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXY)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 XYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYX)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 XYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 XZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public Int3 XZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZY)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(XZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 YXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXX)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 YXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 YYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYX)}"); + + /// + /// Gets an value with the value for all components. + /// + public Int3 YYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYY)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YYZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public Int3 YZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZX)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 YZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZY)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(YZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXY)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZXZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYX)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYY)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZX)}"); + + /// + /// Gets an value with the , and values. + /// + public Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(ThreadIds)}.{nameof(ZZZ)}"); } } diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs index 874b4cfe..2ac0c8bf 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMembers.cs @@ -25,10 +25,6 @@ namespace ComputeSharp.SourceGenerators.Mappings { Dictionary knownMembers = new() { - [$"{typeof(ThreadIds).FullName}.{nameof(ThreadIds.X)}"] = "x", - [$"{typeof(ThreadIds).FullName}.{nameof(ThreadIds.Y)}"] = "y", - [$"{typeof(ThreadIds).FullName}.{nameof(ThreadIds.Z)}"] = "z", - [$"{typeof(Vector2).FullName}.{nameof(Vector2.X)}"] = "x", [$"{typeof(Vector2).FullName}.{nameof(Vector2.Y)}"] = "y", [$"{typeof(Vector2).FullName}.{nameof(Vector2.Zero)}"] = "(float2)0", diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs index d4719ae8..2d2b0f32 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -47,14 +47,15 @@ namespace ComputeSharp.SourceGenerators.Mappings /// /// Gets the known HLSL vector types available as mapped types. /// - public static IReadOnlyCollection HlslMappedVectorTypes { get; } = new HashSet(new[] + public static IReadOnlyCollection HlslMappedVectorTypes { get; } = new[] { + typeof(ThreadIds), typeof(Bool2), typeof(Bool3), typeof(Bool4), typeof(Int2), typeof(Int3), typeof(Int4), typeof(UInt2), typeof(UInt3), typeof(UInt4), typeof(Float2), typeof(Float3), typeof(Float4), typeof(Double2), typeof(Double3), typeof(Double4) - }); + }; /// /// Checks whether or not a given type name matches a typed resource type. diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs index c6496a8a..cf23220f 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.cs @@ -161,7 +161,7 @@ namespace ComputeSharp.Tests public void Execute(ThreadIds ids) { - destination[ids.Y * 32 + ids.X] = source[new(ids.X, ids.Y)]; + destination[ids.Y * 32 + ids.X] = source[ids.XY]; } } @@ -190,7 +190,7 @@ namespace ComputeSharp.Tests public void Execute(ThreadIds ids) { - destination[new(ids.X, ids.Y)] = source[new(ids.X, ids.Y)]; + destination[ids.XY] = source[ids.XY]; } } } diff --git a/tests/ComputeSharp.Tests/Texture3DTests.cs b/tests/ComputeSharp.Tests/Texture3DTests.cs index c2218a55..b68e02f6 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.cs @@ -195,7 +195,7 @@ namespace ComputeSharp.Tests public void Execute(ThreadIds ids) { - destination[ids.Z * 32 * 32 + ids.Y * 32 + ids.X] = source[new(ids.X, ids.Y, ids.Z)]; + destination[ids.Z * 32 * 32 + ids.Y * 32 + ids.X] = source[ids.XYZ]; } } @@ -224,7 +224,7 @@ namespace ComputeSharp.Tests public void Execute(ThreadIds ids) { - destination[new(ids.X, ids.Y, ids.Z)] = source[new(ids.X, ids.Y, ids.Z)]; + destination[ids.XYZ] = source[ids.XYZ]; } } }