Minor code refactorings
このコミットが含まれているのは:
1 親
c14dd305ae
コミット
b24e6b4c0d
27ファイル変更
+131
-121
検索条件に一致するファイルはありません
@@ -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)
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ partial class D2DPixelShaderSourceGenerator
|
||||
/// <returns>The HLSL source to compile, if present.</returns>
|
||||
public static string GetHlslSource(ImmutableArrayBuilder<DiagnosticInfo> 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
|
||||
/// <returns>The shader profile to use to compile the shader, if present.</returns>
|
||||
public static D2D1ShaderProfile GetShaderProfile(ImmutableArrayBuilder<DiagnosticInfo> 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
|
||||
/// <returns>The compile options to use to compile the shader, if present.</returns>
|
||||
public static D2D1CompileOptions GetCompileOptions(ImmutableArrayBuilder<DiagnosticInfo> 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!;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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!;
|
||||
|
||||
|
||||
+2
-2
@@ -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))
|
||||
{
|
||||
|
||||
+1
-1
@@ -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)!;
|
||||
|
||||
+7
-7
@@ -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
|
||||
/// <remarks>Whether <paramref name="structDeclarationSymbol"/> requires the scene position.</remarks>
|
||||
private static bool GetD2DRequiresScenePositionInfo(INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
return structDeclarationSymbol.TryGetAttributeWithFullMetadataName("ComputeSharp.D2D1.D2DRequiresScenePositionAttribute", out _);
|
||||
return structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.D2D1.D2DRequiresScenePositionAttribute", out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+1
-1
@@ -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!;
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ partial class ID2D1ShaderGenerator
|
||||
/// <param name="pixelOptions">The pixel options for the shader.</param>
|
||||
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!;
|
||||
}
|
||||
|
||||
+5
-5
@@ -33,12 +33,12 @@ partial class ID2D1ShaderGenerator
|
||||
/// <returns>The shader profile to use to compile the shader, if present.</returns>
|
||||
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
|
||||
/// <returns>The compile options to use to compile the shader, if present.</returns>
|
||||
public static D2D1CompileOptions? GetCompileOptions(ImmutableArrayBuilder<DiagnosticInfo> 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.
|
||||
|
||||
+1
-1
@@ -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")
|
||||
|
||||
+1
-1
@@ -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!;
|
||||
|
||||
+2
-2
@@ -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.
|
||||
|
||||
@@ -26,12 +26,12 @@ partial class HlslKnownTypes
|
||||
/// <inheritdoc/>
|
||||
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);
|
||||
|
||||
@@ -167,7 +167,7 @@ internal static partial class HlslKnownTypes
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
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);
|
||||
|
||||
@@ -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 = <INTRINSIC>(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 => <INTRINSIC>(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!))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -41,88 +41,49 @@ internal static class ISymbolExtensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid filename for a given <see cref="ITypeSymbol"/> instance.
|
||||
/// Gets the fully qualified metadata name for a given <see cref="ITypeSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="ITypeSymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/> that is also a valid filename.</returns>
|
||||
public static string GetFullMetadataName(this ITypeSymbol symbol)
|
||||
/// <returns>The fully qualified metadata name for <paramref name="symbol"/>.</returns>
|
||||
public static string GetFullyQualifiedMetadataName(this ITypeSymbol symbol)
|
||||
{
|
||||
using ImmutableArrayBuilder<char> builder = ImmutableArrayBuilder<char>.Rent();
|
||||
|
||||
static void BuildFrom(ISymbol? symbol, in ImmutableArrayBuilder<char> 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IMethodSymbol"/> instance.
|
||||
/// Gets the fully qualified metadata name for a given <see cref="IMethodSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IMethodSymbol"/> instance.</param>
|
||||
/// <param name="includeParameters">Whether or not to also include parameter types.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
public static string GetFullMetadataName(this IMethodSymbol symbol, bool includeParameters = false)
|
||||
/// <returns>The fully qualified metadata name for <paramref name="symbol"/>.</returns>
|
||||
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}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IPropertySymbol"/> instance.
|
||||
/// Gets the fully qualified metadata name for a given <see cref="IPropertySymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IPropertySymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
public static string GetFullMetadataName(this IPropertySymbol symbol)
|
||||
/// <returns>The fully qualified metadata name for <paramref name="symbol"/>.</returns>
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IFieldSymbol"/> instance.
|
||||
/// Gets the fully qualified metadata name for a given <see cref="IFieldSymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IFieldSymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
public static string GetFullMetadataName(this IFieldSymbol symbol)
|
||||
/// <returns>The fully qualified metadata name for <paramref name="symbol"/>.</returns>
|
||||
public static string GetFullyQualifiedMetadataName(this IFieldSymbol symbol)
|
||||
{
|
||||
return $"{symbol.ContainingType.GetFullMetadataName()}.{symbol.Name}";
|
||||
return $"{symbol.ContainingType.GetFullyQualifiedMetadataName()}.{symbol.Name}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get an attribute with the specified full metadata name.
|
||||
/// Tries to get an attribute with the specified fully qualified metadata name.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="ISymbol"/> instance to check.</param>
|
||||
/// <param name="name">The attribute name to look for.</param>
|
||||
/// <param name="attributeData">The resulting attribute data, if found.</param>
|
||||
/// <returns>Whether or not <paramref name="symbol"/> has an attribute with the specified name.</returns>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the fully qualified metadata name for a given symbol to a target builder.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="ITypeSymbol"/> instance.</param>
|
||||
/// <param name="builder">The target <see cref="ImmutableArrayBuilder{T}"/> instance.</param>
|
||||
private static void AppendFullyQualifiedMetadataName(this ITypeSymbol symbol, in ImmutableArrayBuilder<char> builder)
|
||||
{
|
||||
static void BuildFrom(ISymbol? symbol, in ImmutableArrayBuilder<char> 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);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader.</returns>
|
||||
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))
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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")
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする