From 073cfa64ab0a378e3a2ae5bb57e7e51875b69e8b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 13 Jan 2021 19:35:04 +0100 Subject: [PATCH] Added WarpIds type --- src/ComputeSharp.Core/Dispatch/WarpIds.cs | 205 ++++++++++++++++++ .../ComputeSharp.SourceGenerators.csproj | 1 + .../Mappings/HlslKnownTypes.cs | 4 +- .../SyntaxRewriters/ExecuteMethodRewriter.cs | 3 +- .../SyntaxRewriters/ShaderSourceRewriter.cs | 1 - 5 files changed, 211 insertions(+), 3 deletions(-) create mode 100644 src/ComputeSharp.Core/Dispatch/WarpIds.cs diff --git a/src/ComputeSharp.Core/Dispatch/WarpIds.cs b/src/ComputeSharp.Core/Dispatch/WarpIds.cs new file mode 100644 index 00000000..2c02cdbb --- /dev/null +++ b/src/ComputeSharp.Core/Dispatch/WarpIds.cs @@ -0,0 +1,205 @@ +using ComputeSharp.Exceptions; + +namespace ComputeSharp +{ + /// + /// A that indicates the ids of a given dispatch warp (a group of threads). + /// + public static class WarpIds + { + /// + /// Gets the X id of the current thread with respect to the dispatch group. + /// + public static int X => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(X)}"); + + /// + /// Gets the Y id of the current thread with respect to the dispatch group. + /// + public static int Y => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(Y)}"); + + /// + /// Gets the Z id of the current thread with respect to the dispatch group. + /// + public static int Z => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(Z)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 XX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 XZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 YY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YY)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 YZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZ)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZX)}"); + + /// + /// Gets or sets an value with the and values. + /// + public static Int2 ZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int2 ZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZ)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 XXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 XZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 XZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(XZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXY)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YXZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYX)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 YYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YYZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 YZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 YZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(YZZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXX)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZXY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZXZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZXZ)}"); + + /// + /// Gets or sets an value with the , and values. + /// + public static Int3 ZYX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYY)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZYZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZYZ)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZX => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZX)}"); + + /// + /// Gets an value with the , and values. + /// + public static Int3 ZZY => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZY)}"); + + /// + /// Gets an value with the value for all components. + /// + public static Int3 ZZZ => throw new InvalidExecutionContextException($"{nameof(WarpIds)}.{nameof(ZZZ)}"); + } +} diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index d007ccd6..e40e29f9 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -20,6 +20,7 @@ + diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs index 041a3bb0..c6716afd 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -61,7 +61,9 @@ namespace ComputeSharp.SourceGenerators.Mappings /// public static IReadOnlyCollection HlslDispatchTypes { get; } = new[] { - typeof(ThreadIds), typeof(GroupIds) + typeof(ThreadIds), + typeof(GroupIds), + typeof(WarpIds) }; /// diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs index 58908f46..bdfce306 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ExecuteMethodRewriter.cs @@ -25,7 +25,8 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters return updatedNode.AddParameters( Parameter(Identifier($"uint3 {nameof(ThreadIds)} : SV_DispatchThreadID")), Parameter(Identifier($"uint3 {nameof(GroupIds)} : SV_GroupThreadID")), - Parameter(Identifier($"uint __{nameof(GroupIds)}__get_Index : SV_GroupIndex"))); + Parameter(Identifier($"uint __{nameof(GroupIds)}__get_Index : SV_GroupIndex")), + Parameter(Identifier($"uint3 {nameof(WarpIds)} : SV_GroupID"))); } /// diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 80112469..fe593c2a 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using ComputeSharp.SourceGenerators.Extensions; using ComputeSharp.SourceGenerators.Mappings;