From b24e6b4c0db67d60468a480cdb732bb7103acbd2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 29 Oct 2022 16:02:21 +0200 Subject: [PATCH] Minor code refactorings --- .../AutoConstructorGenerator.cs | 2 +- .../D2DPixelShaderSourceGenerator.Execute.cs | 10 +- ...alidAssemblyLevelCompileOptionsAnalyzer.cs | 2 +- ...validD2DResourceTextureIndexUseAnalyzer.cs | 4 +- ...eUninitializedFieldDiagnosticSuppressor.cs | 2 +- ...erGenerator.CreateBuildHlslSourceMethod.cs | 14 +- ...haderGenerator.CreateGetInputTypeMethod.cs | 2 +- ...erGenerator.CreateGetOutputBufferMethod.cs | 2 +- ...erGenerator.CreateGetPixelOptionsMethod.cs | 2 +- ...haderGenerator.CreateLoadBytecodeMethod.cs | 10 +- ...rGenerator.CreateLoadDispatchDataMethod.cs | 2 +- ...rator.CreateLoadInputDescriptionsMethod.cs | 2 +- ...teLoadResourceTextureDescriptionsMethod.cs | 4 +- .../Mappings/HlslKnownTypes.cs | 4 +- .../Mappings/HlslKnownTypes.cs | 6 +- .../SyntaxRewriters/HlslSourceRewriter.cs | 12 +- .../SyntaxRewriters/ShaderSourceRewriter.cs | 10 +- .../SyntaxRewriters/StaticFieldRewriter.cs | 2 +- .../Extensions/ISymbolExtensions.cs | 132 ++++++++++-------- .../Models/HierarchyInfo.cs | 2 +- ...erGenerator.CreateBuildHlslSourceMethod.cs | 10 +- ...haderGenerator.CreateLoadBytecodeMethod.cs | 2 +- ...rGenerator.CreateLoadDispatchDataMethod.cs | 2 +- .../Mappings/HlslKnownTypes.cs | 6 +- .../ShaderMethodSourceGenerator.cs | 2 +- .../SyntaxRewriters/ShaderSourceRewriter.cs | 2 +- .../SyntaxRewriters/StaticFieldRewriter.cs | 2 +- 27 files changed, 131 insertions(+), 121 deletions(-) diff --git a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs index 2a176d04..3d6e8ab9 100644 --- a/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs +++ b/src/ComputeSharp.Core.SourceGenerators/AutoConstructorGenerator.cs @@ -78,7 +78,7 @@ public sealed class AutoConstructorGenerator : IIncrementalGenerator } // Check whether the field is annotated to have a special behavior - if (fieldSymbol.Type.TryGetAttributeWithFullMetadataName("ComputeSharp.AutoConstructorBehaviorAttribute", out AttributeData? usageData) && + if (fieldSymbol.Type.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.AutoConstructorBehaviorAttribute", out AttributeData? usageData) && usageData!.ConstructorArguments is { Length: 1 } arguments && arguments[0].Value is (int)AutoConstructorBehavior.IgnoreAndSetToDefault) { diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs index 65a2f074..004ee0ca 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs @@ -61,7 +61,7 @@ partial class D2DPixelShaderSourceGenerator /// The HLSL source to compile, if present. public static string GetHlslSource(ImmutableArrayBuilder diagnostics, IMethodSymbol methodSymbol) { - _ = methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DPixelShaderSourceAttribute", out AttributeData? attributeData); + _ = methodSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DPixelShaderSourceAttribute", out AttributeData? attributeData); if (!attributeData!.TryGetConstructorArgument(0, out string? hlslSource)) { @@ -83,12 +83,12 @@ partial class D2DPixelShaderSourceGenerator /// The shader profile to use to compile the shader, if present. public static D2D1ShaderProfile GetShaderProfile(ImmutableArrayBuilder diagnostics, IMethodSymbol methodSymbol) { - if (methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out AttributeData? attributeData)) + if (methodSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out AttributeData? attributeData)) { return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!; } - if (methodSymbol.ContainingAssembly.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out attributeData)) + if (methodSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out attributeData)) { return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!; } @@ -110,12 +110,12 @@ partial class D2DPixelShaderSourceGenerator /// The compile options to use to compile the shader, if present. public static D2D1CompileOptions GetCompileOptions(ImmutableArrayBuilder diagnostics, IMethodSymbol methodSymbol) { - if (methodSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData)) + if (methodSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData)) { return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!; } - if (methodSymbol.ContainingAssembly.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out attributeData)) + if (methodSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out attributeData)) { return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!; } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidAssemblyLevelCompileOptionsAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidAssemblyLevelCompileOptionsAnalyzer.cs index a0cf5ce7..e3dc2b6c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidAssemblyLevelCompileOptionsAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidAssemblyLevelCompileOptionsAnalyzer.cs @@ -29,7 +29,7 @@ public sealed class InvalidAssemblyLevelCompileOptionsAnalyzer : DiagnosticAnaly // - The type symbol for the assembly, to get the AttributeData object for the [D2D1CompileOptions] attribute, if used. // - The syntax node representing the attribute targeting the assembly, to get a location (this is retrieved from the AttributeData). // - The input D2D1CompileOptions value, which can be retrieved from the constructor arguments of the AttributeData object. - if (assemblySymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData)) + if (assemblySymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData)) { D2D1CompileOptions options = (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!; diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DResourceTextureIndexUseAnalyzer.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DResourceTextureIndexUseAnalyzer.cs index 6981fdc5..e78c4591 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DResourceTextureIndexUseAnalyzer.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Analyzers/InvalidD2DResourceTextureIndexUseAnalyzer.cs @@ -27,9 +27,9 @@ public sealed class InvalidD2DResourceTextureIndexUseAnalyzer : DiagnosticAnalyz { IFieldSymbol fieldSymbol = (IFieldSymbol)context.Symbol; - if (fieldSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute", out _)) + if (fieldSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute", out _)) { - string metadataName = fieldSymbol.Type.GetFullMetadataName(); + string metadataName = fieldSymbol.Type.GetFullyQualifiedMetadataName(); if (!HlslKnownTypes.IsResourceTextureType(metadataName)) { diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Suppressors/D2D1ResourceTextureUninitializedFieldDiagnosticSuppressor.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Suppressors/D2D1ResourceTextureUninitializedFieldDiagnosticSuppressor.cs index d7c3ba60..a570e68f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Suppressors/D2D1ResourceTextureUninitializedFieldDiagnosticSuppressor.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/Suppressors/D2D1ResourceTextureUninitializedFieldDiagnosticSuppressor.cs @@ -49,7 +49,7 @@ public sealed class D2D1ResourceTextureUninitializedFieldDiagnosticSuppressor : // Check if the field is in a struct and it's of a D2D1 resource texture type if (declaredSymbol is IFieldSymbol { ContainingType: { TypeKind: TypeKind.Struct } structSymbol } fieldSymbol && - HlslKnownTypes.IsResourceTextureType(fieldSymbol.Type.GetFullMetadataName())) + HlslKnownTypes.IsResourceTextureType(fieldSymbol.Type.GetFullyQualifiedMetadataName())) { // Get the ID2D1PixelShader interface symbol to the check the containing type of the field INamedTypeSymbol? pixelShaderInterfaceSymbol = semanticModel.Compilation.GetTypeByMetadataName(typeof(ID2D1PixelShader).FullName)!; diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index 8faf1d54..ebe4805c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -126,7 +126,7 @@ partial class ID2D1ShaderGenerator continue; } - string metadataName = typeSymbol.GetFullMetadataName(); + string metadataName = typeSymbol.GetFullyQualifiedMetadataName(); string typeName = HlslKnownTypes.GetMappedName(typeSymbol); _ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping); @@ -153,7 +153,7 @@ partial class ID2D1ShaderGenerator // If [D2DResourceTextureIndex] is present, get the resource texture index. // This generator doesn't need to emit diagnostics, as that's handled separately // by the logic handling the info gathering for LoadResourceTextureDescriptions. - if (fieldSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute", out AttributeData? attributeData)) + if (fieldSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute", out AttributeData? attributeData)) { _ = attributeData!.TryGetConstructorArgument(0, out index); } @@ -218,7 +218,7 @@ partial class ID2D1ShaderGenerator // Constant properties must be of a primitive, vector or matrix type if (fieldSymbol.Type is not INamedTypeSymbol typeSymbol || - !HlslKnownTypes.IsKnownHlslType(typeSymbol.GetFullMetadataName())) + !HlslKnownTypes.IsKnownHlslType(typeSymbol.GetFullyQualifiedMetadataName())) { diagnostics.Add(InvalidShaderStaticFieldType, variableDeclarator, structDeclarationSymbol, fieldSymbol.Name, fieldSymbol.Type); @@ -394,7 +394,7 @@ partial class ID2D1ShaderGenerator // Process the discovered types foreach (INamedTypeSymbol type in HlslKnownTypes.GetCustomTypes(types, out invalidTypes)) { - string structType = type.GetFullMetadataName().ToHlslIdentifierName(); + string structType = type.GetFullyQualifiedMetadataName().ToHlslIdentifierName(); StructDeclarationSyntax structDeclaration = StructDeclaration(structType); // Declare the fields of the current type @@ -408,9 +408,9 @@ partial class ID2D1ShaderGenerator INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type; // Convert the name to the fully qualified HLSL version - if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullMetadataName(), out string? mappedType)) + if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullyQualifiedMetadataName(), out string? mappedType)) { - mappedType = fieldType.GetFullMetadataName().ToHlslIdentifierName(); + mappedType = fieldType.GetFullyQualifiedMetadataName().ToHlslIdentifierName(); } // Get the field name as a valid HLSL identifier @@ -498,7 +498,7 @@ partial class ID2D1ShaderGenerator /// Whether requires the scene position. private static bool GetD2DRequiresScenePositionInfo(INamedTypeSymbol structDeclarationSymbol) { - return structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DRequiresScenePositionAttribute", out _); + return structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DRequiresScenePositionAttribute", out _); } /// diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs index c6e23620..4d79a732 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetInputTypeMethod.cs @@ -46,7 +46,7 @@ partial class ID2D1ShaderGenerator foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes()) { - switch (attributeData.AttributeClass?.GetFullMetadataName()) + switch (attributeData.AttributeClass?.GetFullyQualifiedMetadataName()) { case "ComputeSharp.D2D1.D2DInputCountAttribute": rawInputCount = (int)attributeData.ConstructorArguments[0].Value!; diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetOutputBufferMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetOutputBufferMethod.cs index 3c746fb1..ee9b7966 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetOutputBufferMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetOutputBufferMethod.cs @@ -23,7 +23,7 @@ partial class ID2D1ShaderGenerator out D2D1ChannelDepth channelDepth) { // Try to get the [D2DOutputBuffer] attribute - if (!structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DOutputBufferAttribute", out AttributeData? attributeData)) + if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DOutputBufferAttribute", out AttributeData? attributeData)) { bufferPrecision = D2D1BufferPrecision.Unknown; channelDepth = D2D1ChannelDepth.Default; diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs index 18102a14..7b805a78 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateGetPixelOptionsMethod.cs @@ -18,7 +18,7 @@ partial class ID2D1ShaderGenerator /// The pixel options for the shader. public static void GetInfo(INamedTypeSymbol structDeclarationSymbol, out D2D1PixelOptions pixelOptions) { - if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute", out AttributeData? attributeData)) + if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DPixelOptionsAttribute", out AttributeData? attributeData)) { pixelOptions = (D2D1PixelOptions)attributeData!.ConstructorArguments[0].Value!; } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs index 4eeeca26..1854e959 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs @@ -33,12 +33,12 @@ partial class ID2D1ShaderGenerator /// The shader profile to use to compile the shader, if present. public static D2D1ShaderProfile? GetShaderProfile(INamedTypeSymbol structDeclarationSymbol) { - if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out AttributeData? attributeData)) + if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out AttributeData? attributeData)) { return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!; } - if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out attributeData)) + if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DShaderProfileAttribute", out attributeData)) { return (D2D1ShaderProfile)attributeData!.ConstructorArguments[0].Value!; } @@ -54,7 +54,7 @@ partial class ID2D1ShaderGenerator /// The compile options to use to compile the shader, if present. public static D2D1CompileOptions? GetCompileOptions(ImmutableArrayBuilder diagnostics, INamedTypeSymbol structDeclarationSymbol) { - if (structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData)) + if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out AttributeData? attributeData)) { D2D1CompileOptions options = (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value!; @@ -70,7 +70,7 @@ partial class ID2D1ShaderGenerator return options | D2D1CompileOptions.PackMatrixRowMajor; } - if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out attributeData)) + if (structDeclarationSymbol.ContainingAssembly.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DCompileOptionsAttribute", out attributeData)) { // No need to validate against PackMatrixColumnMajor as that's checked separately return (D2D1CompileOptions)attributeData!.ConstructorArguments[0].Value! | D2D1CompileOptions.PackMatrixRowMajor; @@ -98,7 +98,7 @@ partial class ID2D1ShaderGenerator foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes()) { - switch (attributeData.AttributeClass?.GetFullMetadataName()) + switch (attributeData.AttributeClass?.GetFullyQualifiedMetadataName()) { // Only retrieve indices of simple inputs that are in range. If an input is out of // range, the diagnostic for it will already be emitted by a previous generator step. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs index e3f23d17..46c83eb2 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs @@ -49,7 +49,7 @@ partial class ID2D1ShaderGenerator select fieldSymbol) { string fieldName = fieldSymbol.Name; - string typeName = fieldSymbol.Type.GetFullMetadataName(); + string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName(); // Disambiguates the name of target fields against the current input parameters if (fieldName is "loader") diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs index 55821ef0..02b5362e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs @@ -34,7 +34,7 @@ partial class ID2D1ShaderGenerator foreach (AttributeData attributeData in structDeclarationSymbol.GetAttributes()) { - switch (attributeData.AttributeClass?.GetFullMetadataName()) + switch (attributeData.AttributeClass?.GetFullyQualifiedMetadataName()) { case "ComputeSharp.D2D1.D2DInputCountAttribute": inputCount = (int)attributeData.ConstructorArguments[0].Value!; diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs index 4c6944b0..b8ae3707 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs @@ -42,7 +42,7 @@ partial class ID2D1ShaderGenerator continue; } - string metadataName = typeSymbol.GetFullMetadataName(); + string metadataName = typeSymbol.GetFullyQualifiedMetadataName(); // Check that the field is a resource texture type (if not, it will be processed by the HLSL rewriter too) if (HlslKnownTypes.IsResourceTextureType(metadataName)) @@ -52,7 +52,7 @@ partial class ID2D1ShaderGenerator int? index = null; // Get the index from the [D2DResourceTextureIndex] attribute over the field - if (fieldSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute", out AttributeData? attributeData)) + if (fieldSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DResourceTextureIndexAttribute", out AttributeData? attributeData)) { // If the constructor argument isn't available, it means the code is invalid. Just do nothing then, as the // user will have to fix that to get the code to compile anyway. This way the generator won't crash too. diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownTypes.cs index 1ebec150..30d69af3 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -26,12 +26,12 @@ partial class HlslKnownTypes /// public static partial string GetMappedName(INamedTypeSymbol typeSymbol) { - string typeName = typeSymbol.GetFullMetadataName(); + string typeName = typeSymbol.GetFullyQualifiedMetadataName(); // Special case for resource texture types if (IsResourceTextureType(typeName)) { - string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments[0]).GetFullMetadataName(); + string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments[0]).GetFullyQualifiedMetadataName(); // Get the HLSL name for the type argument (it can only be either float or float4) _ = KnownHlslTypes.TryGetValue(genericArgumentName, out string? mappedElementType); diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs index 58e6c35d..cecae13f 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/Mappings/HlslKnownTypes.cs @@ -167,7 +167,7 @@ internal static partial class HlslKnownTypes /// The HLSL-compatible type name that can be used in an HLSL shader. public static string GetMappedElementName(IArrayTypeSymbol typeSymbol) { - string elementTypeName = ((INamedTypeSymbol)typeSymbol.ElementType).GetFullMetadataName(); + string elementTypeName = ((INamedTypeSymbol)typeSymbol.ElementType).GetFullyQualifiedMetadataName(); if (KnownHlslTypes.TryGetValue(elementTypeName, out string? mapped)) { @@ -227,7 +227,7 @@ internal static partial class HlslKnownTypes return; } - if (KnownHlslTypes.ContainsKey(type.GetFullMetadataName())) + if (KnownHlslTypes.ContainsKey(type.GetFullyQualifiedMetadataName())) { return; } @@ -314,7 +314,7 @@ internal static partial class HlslKnownTypes INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type; - if (!KnownHlslTypes.ContainsKey(fieldType.GetFullMetadataName()) && + if (!KnownHlslTypes.ContainsKey(fieldType.GetFullyQualifiedMetadataName()) && !invalidTypes.Contains(fieldType)) { _ = dependencies.Add(fieldType); diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs index db297fe4..ee44570d 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/HlslSourceRewriter.cs @@ -112,7 +112,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter // Add explicit casts for matrix constructors to help the overload resolution if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol matrixType && - HlslKnownTypes.IsMatrixType(matrixType.GetFullMetadataName())) + HlslKnownTypes.IsMatrixType(matrixType.GetFullyQualifiedMetadataName())) { for (int i = 0; i < node.ArgumentList!.Arguments.Count; i++) { @@ -148,7 +148,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter // Add explicit casts like with the explicit object creation expressions above if (SemanticModel.For(node).GetTypeInfo(node).Type is ITypeSymbol matrixType && - HlslKnownTypes.IsMatrixType(matrixType.GetFullMetadataName())) + HlslKnownTypes.IsMatrixType(matrixType.GetFullyQualifiedMetadataName())) { for (int i = 0; i < node.ArgumentList.Arguments.Count; i++) { @@ -240,7 +240,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter if (SemanticModel.For(node).GetOperation(node) is IPropertyReferenceOperation operation) { - string propertyName = operation.Property.GetFullMetadataName(); + string propertyName = operation.Property.GetFullyQualifiedMetadataName(); // Rewrite texture resource indices taking individual indices a vector argument, as per HLSL spec. // For instance: texture[ThreadIds.X, ThreadIds.Y] will be rewritten as texture[int2(ThreadIds.X, ThreadIds.Y)]. @@ -261,7 +261,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter foreach (ArgumentSyntax argument in node.ArgumentList.Arguments) { if (SemanticModel.For(node).GetOperation(argument.Expression) is not IFieldReferenceOperation fieldReference || - !HlslKnownProperties.IsKnownMatrixIndex(fieldReference.Field.GetFullMetadataName())) + !HlslKnownProperties.IsKnownMatrixIndex(fieldReference.Field.GetFullyQualifiedMetadataName())) { Diagnostics.Add(NonConstantMatrixSwizzledIndex, argument); @@ -302,7 +302,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter // That is, do the following transformation: // // x *= y => x = (x, y) - if (HlslKnownOperators.TryGetMappedName(method.GetFullMetadataName(), method.Parameters.Select(static p => p.Type.Name), out string? mapped)) + if (HlslKnownOperators.TryGetMappedName(method.GetFullyQualifiedMetadataName(), method.Parameters.Select(static p => p.Type.Name), out string? mapped)) { return AssignmentExpression( @@ -330,7 +330,7 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter // That is, do the following transformation: // // x * y => (x, y) - if (HlslKnownOperators.TryGetMappedName(method.GetFullMetadataName(), method.Parameters.Select(static p => p.Type.Name), out string? mapped)) + if (HlslKnownOperators.TryGetMappedName(method.GetFullyQualifiedMetadataName(), method.Parameters.Select(static p => p.Type.Name), out string? mapped)) { return InvocationExpression(IdentifierName(mapped!)) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs index c0b6bc9e..ee9544a2 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/ShaderSourceRewriter.cs @@ -369,7 +369,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter // property access into an invocation of an autogenerated static helper method to get the target // dimension for the buffer in use. The helper method is added to the list of static helpers. if (operation is IPropertyReferenceOperation propertyOperation && - HlslKnownProperties.TryGetAccessorRankAndAxis(propertyOperation.Property.GetFullMetadataName(), out int rank, out int axis)) + HlslKnownProperties.TryGetAccessorRankAndAxis(propertyOperation.Property.GetFullyQualifiedMetadataName(), out int rank, out int axis)) { IMethodSymbol key = propertyOperation.Property.GetMethod!; @@ -427,7 +427,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter { if (method.IsStatic) { - string metadataName = method.GetFullMetadataName(); + string metadataName = method.GetFullyQualifiedMetadataName(); // If the invocation consists of invoking a static method that has a direct // mapping to HLSL, rewrite the expression in the current invocation node. @@ -460,7 +460,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter // type as well, as they will be processed by the generator in a different path. if (!SymbolEqualityComparer.Default.Equals(this.shaderType, method.ContainingType)) { - string methodIdentifier = method.GetFullMetadataName().ToHlslIdentifierName(); + string methodIdentifier = method.GetFullyQualifiedMetadataName().ToHlslIdentifierName(); if (!this.staticMethods.ContainsKey(method)) { @@ -482,7 +482,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter } else { - string metadataName = method.GetFullMetadataName(includeParameters: true); + string metadataName = method.GetFullyQualifiedMetadataName(includeParameters: true); // Check whether this is a Sample(...) call on a normalized texture type if (HlslKnownMethods.TryGetMappedResourceSamplerAccessType(metadataName, out string? mapping)) @@ -505,7 +505,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter { DiscoveredTypes.Add(structTypeSymbol); - string methodIdentifier = method.GetFullMetadataName().ToHlslIdentifierName(); + string methodIdentifier = method.GetFullyQualifiedMetadataName().ToHlslIdentifierName(); // Same as for static methods, ensure the method is available in source, and process it if so if (!this.instanceMethods.ContainsKey(method)) diff --git a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs index bdc85dff..7abe4fb7 100644 --- a/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs +++ b/src/ComputeSharp.SourceGeneration.Hlsl/SyntaxRewriters/StaticFieldRewriter.cs @@ -101,7 +101,7 @@ internal sealed partial class StaticFieldRewriter : HlslSourceRewriter method.IsStatic) { // Rewrite HLSL intrinsic methods - if (HlslKnownMethods.TryGetMappedName(method.GetFullMetadataName(), out string? mapping, out bool requiresParametersMapping)) + if (HlslKnownMethods.TryGetMappedName(method.GetFullyQualifiedMetadataName(), out string? mapping, out bool requiresParametersMapping)) { if (requiresParametersMapping) { diff --git a/src/ComputeSharp.SourceGeneration/Extensions/ISymbolExtensions.cs b/src/ComputeSharp.SourceGeneration/Extensions/ISymbolExtensions.cs index d402f5f0..78c2bf86 100644 --- a/src/ComputeSharp.SourceGeneration/Extensions/ISymbolExtensions.cs +++ b/src/ComputeSharp.SourceGeneration/Extensions/ISymbolExtensions.cs @@ -41,88 +41,49 @@ internal static class ISymbolExtensions } /// - /// Gets a valid filename for a given instance. + /// Gets the fully qualified metadata name for a given instance. /// /// The input instance. - /// The full metadata name for that is also a valid filename. - public static string GetFullMetadataName(this ITypeSymbol symbol) + /// The fully qualified metadata name for . + public static string GetFullyQualifiedMetadataName(this ITypeSymbol symbol) { using ImmutableArrayBuilder builder = ImmutableArrayBuilder.Rent(); - static void BuildFrom(ISymbol? symbol, in ImmutableArrayBuilder builder) - { - switch (symbol) - { - // Namespaces that are nested also append a leading '.' - case INamespaceSymbol { ContainingNamespace.IsGlobalNamespace: false }: - BuildFrom(symbol.ContainingNamespace, in builder); - builder.Add('.'); - builder.AddRange(symbol.MetadataName.AsSpan()); - break; - - // Other namespaces (ie. the one right before global) skip the leading '.' - case INamespaceSymbol { IsGlobalNamespace: false }: - builder.AddRange(symbol.MetadataName.AsSpan()); - break; - - // Types with no namespace just have their metadata name directly written - case ITypeSymbol { ContainingSymbol: INamespaceSymbol { IsGlobalNamespace: true } }: - builder.AddRange(symbol.MetadataName.AsSpan()); - break; - - // Types with a containing non-global namespace also append a leading '.' - case ITypeSymbol { ContainingSymbol: INamespaceSymbol namespaceSymbol }: - BuildFrom(namespaceSymbol, in builder); - builder.Add('.'); - builder.AddRange(symbol.MetadataName.AsSpan()); - break; - - // Nested types append a leading '+' - case ITypeSymbol { ContainingSymbol: ITypeSymbol typeSymbol }: - BuildFrom(typeSymbol, in builder); - builder.Add('+'); - builder.AddRange(symbol.MetadataName.AsSpan()); - break; - default: - break; - } - } - - BuildFrom(symbol, in builder); + AppendFullyQualifiedMetadataName(symbol, in builder); return builder.ToString(); } /// - /// Gets the full metadata name for a given instance. + /// Gets the fully qualified metadata name for a given instance. /// /// The input instance. /// Whether or not to also include parameter types. - /// The full metadata name for . - public static string GetFullMetadataName(this IMethodSymbol symbol, bool includeParameters = false) + /// The fully qualified metadata name for . + public static string GetFullyQualifiedMetadataName(this IMethodSymbol symbol, bool includeParameters = false) { if (includeParameters) { - string parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName())); + string parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullyQualifiedMetadataName())); - return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}({parameters})"; + return $"{symbol.ContainingType.GetFullyQualifiedMetadataName()}.{symbol.Name}({parameters})"; } - return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}"; + return $"{symbol.ContainingType.GetFullyQualifiedMetadataName()}.{symbol.Name}"; } /// - /// Gets the full metadata name for a given instance. + /// Gets the fully qualified metadata name for a given instance. /// /// The input instance. - /// The full metadata name for . - public static string GetFullMetadataName(this IPropertySymbol symbol) + /// The fully qualified metadata name for . + public static string GetFullyQualifiedMetadataName(this IPropertySymbol symbol) { - string declaringTypeName = symbol.ContainingType.GetFullMetadataName(); + string declaringTypeName = symbol.ContainingType.GetFullyQualifiedMetadataName(); if (symbol.IsIndexer) { - string parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName())); + string parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullyQualifiedMetadataName())); return $"{declaringTypeName}.this[{parameters}]"; } @@ -131,27 +92,27 @@ internal static class ISymbolExtensions } /// - /// Gets the full metadata name for a given instance. + /// Gets the fully qualified metadata name for a given instance. /// /// The input instance. - /// The full metadata name for . - public static string GetFullMetadataName(this IFieldSymbol symbol) + /// The fully qualified metadata name for . + public static string GetFullyQualifiedMetadataName(this IFieldSymbol symbol) { - return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}"; + return $"{symbol.ContainingType.GetFullyQualifiedMetadataName()}.{symbol.Name}"; } /// - /// Tries to get an attribute with the specified full metadata name. + /// Tries to get an attribute with the specified fully qualified metadata name. /// /// The input instance to check. /// The attribute name to look for. /// The resulting attribute data, if found. /// Whether or not has an attribute with the specified name. - public static bool TryGetAttributeWithFullMetadataName(this ISymbol symbol, string name, out AttributeData? attributeData) + public static bool TryGetAttributeWithFullyQualifiedMetadataName(this ISymbol symbol, string name, out AttributeData? attributeData) { foreach (AttributeData attribute in symbol.GetAttributes()) { - if (attribute.AttributeClass?.GetFullMetadataName() == name) + if (attribute.AttributeClass?.GetFullyQualifiedMetadataName() == name) { attributeData = attribute; @@ -216,4 +177,53 @@ internal static class ISymbolExtensions accessibility == Accessibility.Public || (accessibility == Accessibility.Internal && symbol.ContainingAssembly.GivesAccessTo(assembly)); } + + /// + /// Appends the fully qualified metadata name for a given symbol to a target builder. + /// + /// The input instance. + /// The target instance. + private static void AppendFullyQualifiedMetadataName(this ITypeSymbol symbol, in ImmutableArrayBuilder builder) + { + static void BuildFrom(ISymbol? symbol, in ImmutableArrayBuilder builder) + { + switch (symbol) + { + // Namespaces that are nested also append a leading '.' + case INamespaceSymbol { ContainingNamespace.IsGlobalNamespace: false }: + BuildFrom(symbol.ContainingNamespace, in builder); + builder.Add('.'); + builder.AddRange(symbol.MetadataName.AsSpan()); + break; + + // Other namespaces (ie. the one right before global) skip the leading '.' + case INamespaceSymbol { IsGlobalNamespace: false }: + builder.AddRange(symbol.MetadataName.AsSpan()); + break; + + // Types with no namespace just have their metadata name directly written + case ITypeSymbol { ContainingSymbol: INamespaceSymbol { IsGlobalNamespace: true } }: + builder.AddRange(symbol.MetadataName.AsSpan()); + break; + + // Types with a containing non-global namespace also append a leading '.' + case ITypeSymbol { ContainingSymbol: INamespaceSymbol namespaceSymbol }: + BuildFrom(namespaceSymbol, in builder); + builder.Add('.'); + builder.AddRange(symbol.MetadataName.AsSpan()); + break; + + // Nested types append a leading '+' + case ITypeSymbol { ContainingSymbol: ITypeSymbol typeSymbol }: + BuildFrom(typeSymbol, in builder); + builder.Add('+'); + builder.AddRange(symbol.MetadataName.AsSpan()); + break; + default: + break; + } + } + + BuildFrom(symbol, in builder); + } } \ No newline at end of file diff --git a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs index bf66c61c..d2118b3e 100644 --- a/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs +++ b/src/ComputeSharp.SourceGeneration/Models/HierarchyInfo.cs @@ -36,7 +36,7 @@ internal sealed partial record HierarchyInfo(string FullyQualifiedMetadataName, } return new( - typeSymbol.GetFullMetadataName(), + typeSymbol.GetFullyQualifiedMetadataName(), typeSymbol.ContainingNamespace.ToDisplayString(new(typeQualificationStyle: NameAndContainingTypesAndNamespaces)), hierarchy.ToImmutable()); } diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs index d17e02e8..d8fbbae0 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -134,7 +134,7 @@ partial class IShaderGenerator continue; } - string metadataName = typeSymbol.GetFullMetadataName(); + string metadataName = typeSymbol.GetFullyQualifiedMetadataName(); string typeName = HlslKnownTypes.GetMappedName(typeSymbol); _ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping); @@ -222,7 +222,7 @@ partial class IShaderGenerator // Constant properties must be of a primitive, vector or matrix type if (fieldSymbol.Type is not INamedTypeSymbol typeSymbol || - !HlslKnownTypes.IsKnownHlslType(typeSymbol.GetFullMetadataName())) + !HlslKnownTypes.IsKnownHlslType(typeSymbol.GetFullyQualifiedMetadataName())) { diagnostics.Add(InvalidShaderStaticFieldType, variableDeclarator, structDeclarationSymbol, fieldSymbol.Name, fieldSymbol.Type); @@ -460,7 +460,7 @@ partial class IShaderGenerator // Process the discovered types foreach (INamedTypeSymbol type in HlslKnownTypes.GetCustomTypes(types, out invalidTypes)) { - string structType = type.GetFullMetadataName().ToHlslIdentifierName(); + string structType = type.GetFullyQualifiedMetadataName().ToHlslIdentifierName(); StructDeclarationSyntax structDeclaration = StructDeclaration(structType); // Declare the fields of the current type @@ -474,9 +474,9 @@ partial class IShaderGenerator INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type; // Convert the name to the fully qualified HLSL version - if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullMetadataName(), out string? mappedType)) + if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullyQualifiedMetadataName(), out string? mappedType)) { - mappedType = fieldType.GetFullMetadataName().ToHlslIdentifierName(); + mappedType = fieldType.GetFullyQualifiedMetadataName().ToHlslIdentifierName(); } // Get the field name as a valid HLSL identifier diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs index 4c432101..69e56563 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadBytecodeMethod.cs @@ -45,7 +45,7 @@ partial class IShaderGenerator bool supportsDynamicShaders) { // Try to get the attribute that controls shader precompilation (has to be present when ComputeSharp.Dynamic is not referenced) - if (!structDeclarationSymbol.TryGetAttributeWithFullMetadataName(typeof(EmbeddedBytecodeAttribute).FullName, out AttributeData? attribute)) + if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName(typeof(EmbeddedBytecodeAttribute).FullName, out AttributeData? attribute)) { // Emit the diagnostics if dynamic shaders are not supported if (!supportsDynamicShaders) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs index cb2604f7..d028a75b 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateLoadDispatchDataMethod.cs @@ -54,7 +54,7 @@ partial class IShaderGenerator select fieldSymbol) { string fieldName = fieldSymbol.Name; - string typeName = fieldSymbol.Type.GetFullMetadataName(); + string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName(); // Disambiguates the name of target fields against the current input parameters if (fieldName is "loader" or "device" or "x" or "y" or "z") diff --git a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs index 5456019b..887e985b 100644 --- a/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs +++ b/src/ComputeSharp.SourceGenerators/Mappings/HlslKnownTypes.cs @@ -141,12 +141,12 @@ partial class HlslKnownTypes return ""; } - string typeName = typeSymbol.GetFullMetadataName(); + string typeName = typeSymbol.GetFullyQualifiedMetadataName(); // Special case for the resource types if (IsTypedResourceType(typeName)) { - string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.Last()).GetFullMetadataName(); + string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.Last()).GetFullyQualifiedMetadataName(); // If the current type is a custom type, format it as needed if (!KnownHlslTypes.TryGetValue(genericArgumentName, out string? mappedElementType)) @@ -202,7 +202,7 @@ partial class HlslKnownTypes /// The HLSL-compatible type name that can be used in an HLSL shader. public static string GetMappedNameForPixelShaderType(INamedTypeSymbol typeSymbol) { - string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.First()).GetFullMetadataName(); + string genericArgumentName = ((INamedTypeSymbol)typeSymbol.TypeArguments.First()).GetFullyQualifiedMetadataName(); // If the current type is a custom type, format it as needed if (!KnownHlslTypes.TryGetValue(genericArgumentName, out string? mappedElementType)) diff --git a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs index 21e5888a..21297442 100644 --- a/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/ShaderMethodSourceGenerator.cs @@ -94,7 +94,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator diagnostics = builder.ToImmutable(); return new( - methodSymbol.GetFullMetadataName(includeParameters: true), + methodSymbol.GetFullyQualifiedMetadataName(includeParameters: true), entryPoint, definedTypes, definedConstants, diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs index 50a7c8aa..4d684730 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/ShaderSourceRewriter.cs @@ -53,7 +53,7 @@ partial class ShaderSourceRewriter // Mark which dispatch properties have been used, to optimize the declaration afterwards if (operation.Member.IsStatic) { - string typeName = operation.Member.ContainingType.GetFullMetadataName(); + string typeName = operation.Member.ContainingType.GetFullyQualifiedMetadataName(); if (mappedName == $"__{nameof(GroupIds)}__get_Index") { diff --git a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs index 0d4e2695..9abfa78d 100644 --- a/src/ComputeSharp.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs +++ b/src/ComputeSharp.SourceGenerators/SyntaxRewriters/StaticFieldRewriter.cs @@ -15,7 +15,7 @@ partial class StaticFieldRewriter { if (operation.Member.IsStatic) { - string typeName = operation.Member.ContainingType.GetFullMetadataName(); + string typeName = operation.Member.ContainingType.GetFullyQualifiedMetadataName(); // Special dispatch types are not supported from static constants DiagnosticDescriptor? descriptor = typeName switch