diff --git a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj index 3c4ea32d..1caa0d0e 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj +++ b/src/ComputeSharp.SourceGenerators/ComputeSharp.SourceGenerators.csproj @@ -26,8 +26,9 @@ - + + diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownKeywords.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownKeywords.cs index c760404a..5aec5569 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownKeywords.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownKeywords.cs @@ -42,17 +42,11 @@ namespace ComputeSharp.SourceGenerators.Mappings knownKeywords.Add(nameof(WarpIds)); // HLSL intrinsics method names - foreach (var method in - from method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static) - group method by method.Name - into groups - select (Name: groups.Key, MethodInfo: groups.First())) + foreach (var method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static)) { - string hlslName = method.MethodInfo.GetCustomAttribute() != null - ? method.Name - : method.Name.ToLowerInvariant(); + string name = method.GetCustomAttribute()?.Name ?? method.Name; - knownKeywords.Add(hlslName); + knownKeywords.Add(name); } return knownKeywords; diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs index 26eadfb5..b33dd8b0 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownMethods.cs @@ -107,14 +107,12 @@ namespace ComputeSharp.SourceGenerators.Mappings from method in typeof(Hlsl).GetMethods(BindingFlags.Public | BindingFlags.Static) group method by method.Name into groups - select (Name: groups.Key, MethodInfo: groups.First())) + select groups.First()) { // Check whether the current method should be translated with the original name // or with the lowercase version. This is needed because all C# methods are exposed // with the upper camel case format, while HLSL intrinsics use multiple different formats. - string hlslName = method.MethodInfo.GetCustomAttribute() != null - ? method.Name - : method.Name.ToLowerInvariant(); + string hlslName = method.GetCustomAttribute()?.Name ?? method.Name; knownMethods.Add($"{typeof(Hlsl).FullName}{Type.Delimiter}{method.Name}", hlslName); } diff --git a/src/ComputeSharp/Core/Intrinsics/Attributes/PreserveMemberNameAttribute.cs b/src/ComputeSharp/Core/Intrinsics/Attributes/PreserveMemberNameAttribute.cs deleted file mode 100644 index 5f789ece..00000000 --- a/src/ComputeSharp/Core/Intrinsics/Attributes/PreserveMemberNameAttribute.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace ComputeSharp.Core.Intrinsics.Attributes -{ - /// - /// An attribute to indicate that a given member has the same name when mapped to HLSL. - /// - internal sealed class PreserveMemberNameAttribute : Attribute - { - } -} diff --git a/src/ComputeSharp/Core/Intrinsics/Hlsl.cs b/src/ComputeSharp/Core/Intrinsics/Hlsl.cs index 7645ab0a..868a6f2b 100644 --- a/src/ComputeSharp/Core/Intrinsics/Hlsl.cs +++ b/src/ComputeSharp/Core/Intrinsics/Hlsl.cs @@ -1,5 +1,4 @@ -using ComputeSharp.Core.Intrinsics.Attributes; -using ComputeSharp.Exceptions; +using ComputeSharp.Exceptions; namespace ComputeSharp { @@ -53,16 +52,14 @@ namespace ComputeSharp /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedAdd(int destination, int value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAdd)}(int,int)"); + public static void InterlockedAdd(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic add of a value to a destination. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedAdd(uint destination, uint value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAdd)}(uint,uint)"); + public static void InterlockedAdd(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic add of a value to a destination. @@ -70,8 +67,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original input value. - [PreserveMemberName] - public static void InterlockedAdd(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAdd)}(int,int,int)"); + public static void InterlockedAdd(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic add of a value to a destination. @@ -79,24 +75,21 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original input value. - [PreserveMemberName] - public static void InterlockedAdd(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAdd)}(uint,uint,uint)"); + public static void InterlockedAdd(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAdd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic and of a value to a destination. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedAnd(int destination, int value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAnd)}(int,int)"); + public static void InterlockedAnd(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic and of a value to a destination. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedAnd(uint destination, uint value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAnd)}(uint,uint)"); + public static void InterlockedAnd(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic and of a value to a destination. @@ -104,8 +97,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original input value. - [PreserveMemberName] - public static void InterlockedAnd(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAnd)}(int,int,int)"); + public static void InterlockedAnd(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic and of a value to a destination. @@ -113,8 +105,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original input value. - [PreserveMemberName] - public static void InterlockedAnd(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedAnd)}(uint,uint,uint)"); + public static void InterlockedAnd(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedAnd)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Atomically compares the destination with the comparison value. If they are identical, the destination @@ -124,8 +115,7 @@ namespace ComputeSharp /// The comparison value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedCompareExchange(int destination, int comparison, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedCompareExchange)}(int,int,int,int)"); + public static void InterlockedCompareExchange(int destination, int comparison, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Atomically compares the destination with the comparison value. If they are identical, the destination @@ -135,8 +125,7 @@ namespace ComputeSharp /// The comparison value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedCompareExchange(uint destination, uint comparison, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedCompareExchange)}(uint,uint,uint,uint)"); + public static void InterlockedCompareExchange(uint destination, uint comparison, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Atomically compares the destination to the comparison value. If they @@ -145,8 +134,7 @@ namespace ComputeSharp /// The destination value. /// The comparison value. /// The input value. - [PreserveMemberName] - public static void InterlockedCompareStore(int destination, int comparison, int value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedCompareStore)}(int,int,int)"); + public static void InterlockedCompareStore(int destination, int comparison, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Atomically compares the destination to the comparison value. If they @@ -155,8 +143,7 @@ namespace ComputeSharp /// The destination value. /// The comparison value. /// The input value. - [PreserveMemberName] - public static void InterlockedCompareStore(uint destination, uint comparison, uint value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedCompareStore)}(uint,uint,uint)"); + public static void InterlockedCompareStore(uint destination, uint comparison, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedCompareStore)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Assigns value to dest and returns the original value. @@ -164,8 +151,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedExchange(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedExchange)}(int,int,int)"); + public static void InterlockedExchange(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Assigns value to dest and returns the original value. @@ -173,24 +159,21 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedExchange(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedExchange)}(uint,uint,uint)"); + public static void InterlockedExchange(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedExchange)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic max. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedMax(int destination, int value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMax)}(int,int)"); + public static void InterlockedMax(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic max. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedMax(uint destination, uint value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMax)}(uint,uint)"); + public static void InterlockedMax(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic max. @@ -198,8 +181,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedMax(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMax)}(int,int,int)"); + public static void InterlockedMax(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic max. @@ -207,24 +189,21 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedMax(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMax)}(uint,uint,uint)"); + public static void InterlockedMax(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMax)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic min. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedMin(int destination, int value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMin)}(int,int)"); + public static void InterlockedMin(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic min. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedMin(uint destination, uint value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMin)}(uint,uint)"); + public static void InterlockedMin(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic min. @@ -232,8 +211,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedMin(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMin)}(int,int,int)"); + public static void InterlockedMin(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic min. @@ -241,24 +219,21 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedMin(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedMin)}(uint,uint,uint)"); + public static void InterlockedMin(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedMin)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic or. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedOr(int destination, int value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedOr)}(int,int)"); + public static void InterlockedOr(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic or. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedOr(uint destination, uint value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedOr)}(uint,uint)"); + public static void InterlockedOr(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic or. @@ -266,8 +241,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedOr(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedOr)}(int,int,int)"); + public static void InterlockedOr(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic or. @@ -275,24 +249,21 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedOr(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedOr)}(uint,uint,uint)"); + public static void InterlockedOr(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedOr)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic xor. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedXor(int destination, int value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedXor)}(int,int)"); + public static void InterlockedXor(int destination, int value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic xor. /// /// The destination value. /// The input value. - [PreserveMemberName] - public static void InterlockedXor(uint destination, uint value) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedXor)}(uint,uint)"); + public static void InterlockedXor(uint destination, uint value) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)})"); /// /// Performs a guaranteed atomic xor. @@ -300,8 +271,7 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedXor(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedXor)}(int,int,int)"); + public static void InterlockedXor(int destination, int value, out int original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(int)}, {typeof(int)}, {typeof(int)})"); /// /// Performs a guaranteed atomic xor. @@ -309,7 +279,6 @@ namespace ComputeSharp /// The destination value. /// The input value. /// The original value. - [PreserveMemberName] - public static void InterlockedXor(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{nameof(Hlsl)}.{nameof(InterlockedXor)}(uint,uint,uint)"); + public static void InterlockedXor(uint destination, uint value, out uint original) => throw new InvalidExecutionContextException($"{typeof(Hlsl)}.{nameof(InterlockedXor)}({typeof(uint)}, {typeof(uint)}, {typeof(uint)})"); } }