diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownKeywords.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownKeywords.cs index 6d706a5a..5d412298 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownKeywords.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownKeywords.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Reflection; using ComputeSharp.Core.Intrinsics.Attributes; +#pragma warning disable IDE0055 + namespace ComputeSharp.SourceGeneration.Mappings; /// @@ -22,8 +24,8 @@ internal static partial class HlslKnownKeywords private static IReadOnlyCollection BuildKnownKeywordsMap() { // HLSL keywords - HashSet knownKeywords = new(new[] - { + HashSet knownKeywords = new( + [ "asm", "asm_fragment", "cbuffer", "buffer", "texture", "centroid", "column_major", "compile", "discard", "dword", "export", "fxgroup", "groupshared", "half", "inline", "inout", "line", "lineadj", "linear", @@ -40,9 +42,9 @@ internal static partial class HlslKnownKeywords "Texture3D", "Texture2DMS", "Texture2DMSArray", "TextureCube", "TextureCubeArray", "SV_DispatchThreadID", "SV_DomainLocation", "SV_GroupID", "SV_GroupIndex", "SV_GroupThreadID", "SV_GSInstanceID", "SV_InsideTessFactor", "SV_OutputControlPointID", "SV_TessFactor", - "SV_InnerCoverage", "SV_StencilRef" + "SV_InnerCoverage", "SV_StencilRef", "globallycoherent" - }); + ]); // HLSL primitive names foreach (Type? type in HlslKnownTypes.KnownVectorTypes.Concat(HlslKnownTypes.KnownMatrixTypes)) diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs index ed3798bc..febbcfbe 100644 --- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs +++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslSource.cs @@ -137,10 +137,10 @@ partial class ComputeShaderDescriptorGenerator continue; } - AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass?.ToDisplayString() == "ComputeSharp.GroupSharedAttribute"); + AttributeData? groupSharedAttribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass?.ToDisplayString() == "ComputeSharp.GroupSharedAttribute"); // Group shared fields must be static - if (attribute is not null) + if (groupSharedAttribute is not null) { diagnostics.Add(InvalidGroupSharedFieldDeclaration, fieldSymbol, structDeclarationSymbol, fieldName); } @@ -169,6 +169,13 @@ partial class ComputeShaderDescriptorGenerator types.Add((INamedTypeSymbol)typeSymbol.TypeArguments[0]); } + // Check whether the resource is a globallycoherent writeable buffer + if (HlslKnownTypes.IsReadWriteBufferType(metadataName) && + fieldSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.GloballyCoherentAttribute", out _)) + { + typeName = "globallycoherent " + typeName; + } + // Add the current mapping for the name (if the name used a reserved keyword) resources.Add((metadataName, mapping ?? fieldName, typeName)); } diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs index 887e985b..3f9b8879 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -29,6 +29,16 @@ partial class HlslKnownTypes return typeName == "ComputeSharp.ConstantBuffer`1"; } + /// + /// Checks whether or not a given type name matches a read write buffer type. + /// + /// The input type name to check. + /// Whether or not represents a read write buffer type. + public static bool IsReadWriteBufferType(string typeName) + { + return typeName == "ComputeSharp.ReadWriteBuffer`1"; + } + /// /// Checks whether or not a given type name matches a structured buffer type. ///