Add mapping of static fields to HLSL rewriters
このコミットが含まれているのは:
1 親
4f60d70411
コミット
eefd0de9f0
6ファイル変更
+41
-3
検索条件に一致するファイルはありません
@@ -53,6 +53,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> instanceMethods = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IMethodSymbol, (MethodDeclarationSyntax, MethodDeclarationSyntax)> constructors = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IFieldSymbol, string> constantDefinitions = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions = new(SymbolEqualityComparer.Default);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
@@ -78,6 +79,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
instanceMethods,
|
||||
constructors,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
token,
|
||||
out bool methodsNeedD2D1RequiresScenePosition);
|
||||
|
||||
@@ -89,6 +91,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
structDeclarationSymbol,
|
||||
discoveredTypes,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
token,
|
||||
out bool fieldsNeedD2D1RequiresScenePosition);
|
||||
|
||||
@@ -238,6 +241,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
|
||||
/// <param name="needsD2D1RequiresScenePosition">Whether or not the shader needs the <c>[D2DRequiresScenePosition]</c> annotation.</param>
|
||||
/// <returns>A sequence of static constant fields in <paramref name="structDeclarationSymbol"/>.</returns>
|
||||
@@ -247,6 +251,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
CancellationToken token,
|
||||
out bool needsD2D1RequiresScenePosition)
|
||||
{
|
||||
@@ -267,6 +272,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
semanticModel,
|
||||
discoveredTypes,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
diagnostics,
|
||||
token,
|
||||
out string? name,
|
||||
@@ -294,6 +300,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
/// <param name="instanceMethods">The collection of discovered instance methods for custom struct types.</param>
|
||||
/// <param name="constructors">The collection of discovered constructors for custom struct types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="needsD2D1RequiresScenePosition">Whether or not the shader needs the <c>[D2DRequiresScenePosition]</c> annotation.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
|
||||
/// <returns>A sequence of processed methods in <paramref name="structDeclarationSymbol"/>, and the entry point.</returns>
|
||||
@@ -306,6 +313,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> instanceMethods,
|
||||
IDictionary<IMethodSymbol, (MethodDeclarationSyntax, MethodDeclarationSyntax)> constructors,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
CancellationToken token,
|
||||
out bool needsD2D1RequiresScenePosition)
|
||||
{
|
||||
@@ -350,6 +358,7 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
instanceMethods,
|
||||
constructors,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
diagnostics,
|
||||
token,
|
||||
isShaderEntryPoint);
|
||||
|
||||
+3
@@ -49,6 +49,7 @@ internal static class HlslDefinitionsSyntaxProcessor
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the type to process.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
|
||||
/// <param name="name">The mapped name for the field.</param>
|
||||
@@ -62,6 +63,7 @@ internal static class HlslDefinitionsSyntaxProcessor
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
|
||||
CancellationToken token,
|
||||
[NotNullWhen(true)] out string? name,
|
||||
@@ -112,6 +114,7 @@ internal static class HlslDefinitionsSyntaxProcessor
|
||||
semanticModel,
|
||||
discoveredTypes,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
diagnostics,
|
||||
token);
|
||||
|
||||
|
||||
@@ -33,18 +33,21 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
/// <param name="semanticModel">The <see cref="Microsoft.CodeAnalysis.SemanticModel"/> instance for the target syntax tree.</param>
|
||||
/// <param name="discoveredTypes">The set of discovered custom types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
/// <param name="token">The <see cref="System.Threading.CancellationToken"/> value for the current operation.</param>
|
||||
protected HlslSourceRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
|
||||
CancellationToken token)
|
||||
{
|
||||
SemanticModel = semanticModel;
|
||||
DiscoveredTypes = discoveredTypes;
|
||||
ConstantDefinitions = constantDefinitions;
|
||||
StaticFieldDefinitions = staticFieldDefinitions;
|
||||
Diagnostics = diagnostics;
|
||||
CancellationToken = token;
|
||||
}
|
||||
@@ -64,6 +67,11 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
/// </summary>
|
||||
protected IDictionary<IFieldSymbol, string> ConstantDefinitions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of discovered static field definitions.
|
||||
/// </summary>
|
||||
protected IDictionary<IFieldSymbol, (string, string, string?)> StaticFieldDefinitions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of produced <see cref="DiagnosticInfo"/> instances.
|
||||
/// </summary>
|
||||
|
||||
@@ -77,6 +77,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
/// <param name="instanceMethods">The collection of discovered instance methods for custom struct types.</param>
|
||||
/// <param name="constructors">The collection of discovered constructors for custom struct types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> value for the current operation.</param>
|
||||
/// <param name="isEntryPoint">Whether or not the current instance is processing a shader entry point.</param>
|
||||
@@ -88,10 +89,11 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> instanceMethods,
|
||||
IDictionary<IMethodSymbol, (MethodDeclarationSyntax, MethodDeclarationSyntax)> constructors,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
|
||||
CancellationToken token,
|
||||
bool isEntryPoint)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, diagnostics, token)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, staticFieldDefinitions, diagnostics, token)
|
||||
{
|
||||
this.shaderType = shaderType;
|
||||
this.staticMethods = staticMethods;
|
||||
@@ -111,6 +113,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
/// <param name="instanceMethods">The collection of discovered instance methods for custom struct types.</param>
|
||||
/// <param name="constructors">The collection of discovered constructors for custom struct types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> value for the current operation.</param>
|
||||
private ShaderSourceRewriter(
|
||||
@@ -120,9 +123,10 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> instanceMethods,
|
||||
IDictionary<IMethodSymbol, (MethodDeclarationSyntax, MethodDeclarationSyntax)> constructors,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
|
||||
CancellationToken token)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, diagnostics, token)
|
||||
: base(semanticModel, discoveredTypes, constantDefinitions, staticFieldDefinitions, diagnostics, token)
|
||||
{
|
||||
this.staticMethods = staticMethods;
|
||||
this.instanceMethods = instanceMethods;
|
||||
@@ -545,6 +549,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
this.instanceMethods,
|
||||
this.constructors,
|
||||
ConstantDefinitions,
|
||||
StaticFieldDefinitions,
|
||||
Diagnostics,
|
||||
CancellationToken);
|
||||
|
||||
@@ -598,6 +603,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
this.instanceMethods,
|
||||
this.constructors,
|
||||
ConstantDefinitions,
|
||||
StaticFieldDefinitions,
|
||||
Diagnostics,
|
||||
CancellationToken);
|
||||
|
||||
@@ -685,6 +691,7 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
this.instanceMethods,
|
||||
this.constructors,
|
||||
ConstantDefinitions,
|
||||
StaticFieldDefinitions,
|
||||
Diagnostics,
|
||||
CancellationToken);
|
||||
|
||||
|
||||
@@ -23,15 +23,17 @@ namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
|
||||
/// <param name="semanticModel">The <see cref="SemanticModelProvider"/> instance for the target syntax tree.</param>
|
||||
/// <param name="discoveredTypes">The set of discovered custom types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="diagnostics">The collection of produced <see cref="DiagnosticInfo"/> instances.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> value for the current operation.</param>
|
||||
internal sealed partial class StaticFieldRewriter(
|
||||
SemanticModelProvider semanticModel,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
ImmutableArrayBuilder<DiagnosticInfo> diagnostics,
|
||||
CancellationToken token)
|
||||
: HlslSourceRewriter(semanticModel, discoveredTypes, constantDefinitions, diagnostics, token)
|
||||
: HlslSourceRewriter(semanticModel, discoveredTypes, constantDefinitions, staticFieldDefinitions, diagnostics, token)
|
||||
{
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
public ExpressionSyntax? Visit(VariableDeclaratorSyntax? node)
|
||||
|
||||
@@ -59,6 +59,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> instanceMethods = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IMethodSymbol, (MethodDeclarationSyntax, MethodDeclarationSyntax)> constructors = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IFieldSymbol, string> constantDefinitions = new(SymbolEqualityComparer.Default);
|
||||
Dictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions = new(SymbolEqualityComparer.Default);
|
||||
|
||||
// Setup the semantic model and basic properties
|
||||
INamedTypeSymbol? pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: "IComputeShader" });
|
||||
@@ -93,6 +94,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
instanceMethods,
|
||||
constructors,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
isComputeShader,
|
||||
token);
|
||||
|
||||
@@ -105,6 +107,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
structDeclarationSymbol,
|
||||
discoveredTypes,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
token);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
@@ -251,6 +254,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
|
||||
/// <param name="discoveredTypes">The collection of currently discovered types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
|
||||
/// <returns>A sequence of static constant fields in <paramref name="structDeclarationSymbol"/>.</returns>
|
||||
private static ImmutableArray<(string Name, string TypeDeclaration, string? Assignment)> GetStaticFields(
|
||||
@@ -259,6 +263,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
ICollection<INamedTypeSymbol> discoveredTypes,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
CancellationToken token)
|
||||
{
|
||||
using ImmutableArrayBuilder<(string, string, string?)> builder = new();
|
||||
@@ -283,6 +288,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
semanticModel,
|
||||
discoveredTypes,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
diagnostics,
|
||||
token,
|
||||
out string? name,
|
||||
@@ -349,6 +355,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
/// <param name="instanceMethods">The collection of discovered instance methods for custom struct types.</param>
|
||||
/// <param name="constructors">The collection of discovered constructors for custom struct types.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <param name="staticFieldDefinitions">The collection of discovered static field definitions.</param>
|
||||
/// <param name="isComputeShader">Indicates whether or not <paramref name="structDeclarationSymbol"/> represents a compute shader.</param>
|
||||
/// <param name="token">The <see cref="CancellationToken"/> used to cancel the operation, if needed.</param>
|
||||
/// <returns>A sequence of processed methods in <paramref name="structDeclarationSymbol"/>, and the entry point.</returns>
|
||||
@@ -361,6 +368,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
IDictionary<IMethodSymbol, MethodDeclarationSyntax> instanceMethods,
|
||||
IDictionary<IMethodSymbol, (MethodDeclarationSyntax, MethodDeclarationSyntax)> constructors,
|
||||
IDictionary<IFieldSymbol, string> constantDefinitions,
|
||||
IDictionary<IFieldSymbol, (string, string, string?)> staticFieldDefinitions,
|
||||
bool isComputeShader,
|
||||
CancellationToken token)
|
||||
{
|
||||
@@ -411,6 +419,7 @@ partial class ComputeShaderDescriptorGenerator
|
||||
instanceMethods,
|
||||
constructors,
|
||||
constantDefinitions,
|
||||
staticFieldDefinitions,
|
||||
diagnostics,
|
||||
token,
|
||||
isShaderEntryPoint);
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする