Minor code refactorings

このコミットが含まれているのは:
Sergio Pedri committed 2022-10-29 16:03:31 +02:00
1 親 c14dd305ae
コミット b24e6b4c0d
27ファイル変更
+131 -121

検索条件に一致するファイルはありません

+5 -5
ファイルの表示
@@ -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!;
}
@@ -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!;
@@ -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))
{
@@ -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)!;
@@ -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>
@@ -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!;
@@ -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;
@@ -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!;
}
@@ -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.
@@ -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")
@@ -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!;
@@ -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.
+2 -2
ファイルの表示
@@ -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);