Use explicit types everywhere
このコミットが含まれているのは:
1 親
27c629f3b4
コミット
16c0fc9aab
74ファイル変更
+455
-446
検索条件に一致するファイルはありません
+1
-1
@@ -154,7 +154,7 @@ partial class IShaderGenerator
|
||||
prologueStatements++;
|
||||
|
||||
// <NAME>.Add("<ITEM>");
|
||||
foreach (var item in items)
|
||||
foreach (string item in items)
|
||||
{
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
|
||||
@@ -58,20 +58,20 @@ partial class IShaderGenerator
|
||||
}
|
||||
|
||||
// Explore the syntax tree and extract the processed info
|
||||
var semanticModelProvider = new SemanticModelProvider(compilation);
|
||||
var pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader<byte>) });
|
||||
var isComputeShader = pixelShaderSymbol is null;
|
||||
var implicitTextureType = isComputeShader ? null : HlslKnownTypes.GetMappedNameForPixelShaderType(pixelShaderSymbol!);
|
||||
var (resourceFields, valueFields) = GetInstanceFields(diagnostics, structDeclarationSymbol, discoveredTypes, isComputeShader);
|
||||
var delegateInstanceFields = GetDispatchId.GetInfo(structDeclarationSymbol);
|
||||
var sharedBuffers = GetSharedBuffers(diagnostics, structDeclarationSymbol, discoveredTypes);
|
||||
var (entryPoint, processedMethods, isSamplerUsed) = GetProcessedMethods(diagnostics, structDeclaration, structDeclarationSymbol, semanticModelProvider, discoveredTypes, staticMethods, instanceMethods, constantDefinitions, isComputeShader);
|
||||
var implicitSamplerField = isSamplerUsed ? ("SamplerState", "__sampler") : default((string, string)?);
|
||||
var staticFields = GetStaticFields(diagnostics, semanticModelProvider, structDeclaration, structDeclarationSymbol, discoveredTypes, constantDefinitions);
|
||||
SemanticModelProvider semanticModelProvider = new SemanticModelProvider(compilation);
|
||||
INamedTypeSymbol? pixelShaderSymbol = structDeclarationSymbol.AllInterfaces.FirstOrDefault(static interfaceSymbol => interfaceSymbol is { IsGenericType: true, Name: nameof(IPixelShader<byte>) });
|
||||
bool isComputeShader = pixelShaderSymbol is null;
|
||||
string? implicitTextureType = isComputeShader ? null : HlslKnownTypes.GetMappedNameForPixelShaderType(pixelShaderSymbol!);
|
||||
(ImmutableArray<(string MetadataName, string Name, string HlslType)> resourceFields, ImmutableArray<(string Name, string HlslType)> valueFields) = GetInstanceFields(diagnostics, structDeclarationSymbol, discoveredTypes, isComputeShader);
|
||||
ImmutableArray<string> delegateInstanceFields = GetDispatchId.GetInfo(structDeclarationSymbol);
|
||||
ImmutableArray<(string Name, string Type, int? Count)> sharedBuffers = GetSharedBuffers(diagnostics, structDeclarationSymbol, discoveredTypes);
|
||||
(string entryPoint, ImmutableArray<(string Signature, string Definition)> processedMethods, bool isSamplerUsed) = GetProcessedMethods(diagnostics, structDeclaration, structDeclarationSymbol, semanticModelProvider, discoveredTypes, staticMethods, instanceMethods, constantDefinitions, isComputeShader);
|
||||
(string, string)? implicitSamplerField = isSamplerUsed ? ("SamplerState", "__sampler") : default((string, string)?);
|
||||
ImmutableArray<(string Name, string TypeDeclaration, string? Assignment)> staticFields = GetStaticFields(diagnostics, semanticModelProvider, structDeclaration, structDeclarationSymbol, discoveredTypes, constantDefinitions);
|
||||
|
||||
// Process the discovered types and constants
|
||||
var declaredTypes = GetDeclaredTypes(diagnostics, structDeclarationSymbol, discoveredTypes, instanceMethods);
|
||||
var definedConstants = GetDefinedConstants(constantDefinitions);
|
||||
ImmutableArray<(string Name, string Definition)> declaredTypes = GetDeclaredTypes(diagnostics, structDeclarationSymbol, discoveredTypes, instanceMethods);
|
||||
ImmutableArray<(string Name, string Value)> definedConstants = GetDefinedConstants(constantDefinitions);
|
||||
|
||||
// Get the HLSL source data with the intermediate info
|
||||
return GetHlslSourceInfo(
|
||||
@@ -111,7 +111,7 @@ partial class IShaderGenerator
|
||||
|
||||
bool hlslResourceFound = false;
|
||||
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (fieldSymbol.IsStatic)
|
||||
{
|
||||
@@ -202,9 +202,9 @@ partial class IShaderGenerator
|
||||
{
|
||||
using ImmutableArrayBuilder<(string, string, string?)> builder = ImmutableArrayBuilder<(string, string, string?)>.Rent();
|
||||
|
||||
foreach (var fieldDeclaration in structDeclaration.Members.OfType<FieldDeclarationSyntax>())
|
||||
foreach (FieldDeclarationSyntax fieldDeclaration in structDeclaration.Members.OfType<FieldDeclarationSyntax>())
|
||||
{
|
||||
foreach (var variableDeclarator in fieldDeclaration.Declaration.Variables)
|
||||
foreach (VariableDeclaratorSyntax variableDeclarator in fieldDeclaration.Declaration.Variables)
|
||||
{
|
||||
IFieldSymbol fieldSymbol = (IFieldSymbol)semanticModel.For(variableDeclarator).GetDeclaredSymbol(variableDeclarator)!;
|
||||
|
||||
@@ -266,7 +266,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
using ImmutableArrayBuilder<(string, string, int?)> builder = ImmutableArrayBuilder<(string, string, int?)>.Rent();
|
||||
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
foreach (IFieldSymbol fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (!fieldSymbol.IsStatic)
|
||||
{
|
||||
@@ -382,7 +382,7 @@ partial class IShaderGenerator
|
||||
isSamplerUsed = isSamplerUsed || shaderSourceRewriter.IsSamplerUsed;
|
||||
|
||||
// Emit the extracted local functions first
|
||||
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
foreach (KeyValuePair<string, LocalFunctionStatementSyntax> localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
{
|
||||
methods.Add((
|
||||
localFunction.Value.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString(),
|
||||
@@ -428,10 +428,10 @@ partial class IShaderGenerator
|
||||
{
|
||||
using ImmutableArrayBuilder<(string, string)> builder = ImmutableArrayBuilder<(string, string)>.Rent();
|
||||
|
||||
foreach (var constant in constantDefinitions)
|
||||
foreach (KeyValuePair<IFieldSymbol, string> constant in constantDefinitions)
|
||||
{
|
||||
var ownerTypeName = ((INamedTypeSymbol)constant.Key.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
var constantName = $"__{ownerTypeName}__{constant.Key.Name}";
|
||||
string ownerTypeName = ((INamedTypeSymbol)constant.Key.ContainingSymbol).ToDisplayString().ToHlslIdentifierName();
|
||||
string constantName = $"__{ownerTypeName}__{constant.Key.Name}";
|
||||
|
||||
builder.Add((constantName, constant.Value));
|
||||
}
|
||||
@@ -458,13 +458,13 @@ partial class IShaderGenerator
|
||||
IReadOnlyCollection<INamedTypeSymbol> invalidTypes;
|
||||
|
||||
// Process the discovered types
|
||||
foreach (var type in HlslKnownTypes.GetCustomTypes(types, out invalidTypes))
|
||||
foreach (INamedTypeSymbol type in HlslKnownTypes.GetCustomTypes(types, out invalidTypes))
|
||||
{
|
||||
var structType = type.GetFullMetadataName().ToHlslIdentifierName();
|
||||
var structDeclaration = StructDeclaration(structType);
|
||||
string structType = type.GetFullMetadataName().ToHlslIdentifierName();
|
||||
StructDeclarationSyntax structDeclaration = StructDeclaration(structType);
|
||||
|
||||
// Declare the fields of the current type
|
||||
foreach (var field in type.GetMembers().OfType<IFieldSymbol>())
|
||||
foreach (IFieldSymbol field in type.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (field.IsStatic) continue;
|
||||
|
||||
@@ -489,7 +489,7 @@ partial class IShaderGenerator
|
||||
}
|
||||
|
||||
// Declare the methods of the current type
|
||||
foreach (var method in instanceMethods.Where(pair => SymbolEqualityComparer.Default.Equals(pair.Key.ContainingType, type)))
|
||||
foreach (KeyValuePair<IMethodSymbol, MethodDeclarationSyntax> method in instanceMethods.Where(pair => SymbolEqualityComparer.Default.Equals(pair.Key.ContainingType, type)))
|
||||
{
|
||||
structDeclaration = structDeclaration.AddMembers(method.Value);
|
||||
}
|
||||
@@ -519,7 +519,7 @@ partial class IShaderGenerator
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
private static void DetectAndReportInvalidPropertyDeclarations(ImmutableArrayBuilder<DiagnosticInfo> diagnostics, INamedTypeSymbol structDeclarationSymbol)
|
||||
{
|
||||
foreach (var memberSymbol in structDeclarationSymbol.GetMembers())
|
||||
foreach (ISymbol memberSymbol in structDeclarationSymbol.GetMembers())
|
||||
{
|
||||
// Detect properties that are not explicit interface implementations
|
||||
if (memberSymbol is IPropertySymbol { ExplicitInterfaceImplementations.IsEmpty: true })
|
||||
@@ -625,7 +625,7 @@ partial class IShaderGenerator
|
||||
AppendLF();
|
||||
|
||||
// Define declarations
|
||||
foreach (var (name, value) in definedConstants)
|
||||
foreach ((string name, string value) in definedConstants)
|
||||
{
|
||||
AppendLineAndLF($"#define {name} {value}");
|
||||
}
|
||||
@@ -637,7 +637,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
AppendLF();
|
||||
|
||||
foreach (var field in staticFields)
|
||||
foreach ((string Name, string TypeDeclaration, string? Assignment) field in staticFields)
|
||||
{
|
||||
if (field.Assignment is string assignment)
|
||||
{
|
||||
@@ -651,7 +651,7 @@ partial class IShaderGenerator
|
||||
}
|
||||
|
||||
// Declared types
|
||||
foreach (var (_, typeDefinition) in declaredTypes)
|
||||
foreach ((string _, string typeDefinition) in declaredTypes)
|
||||
{
|
||||
AppendLF();
|
||||
AppendLineAndLF(typeDefinition);
|
||||
@@ -672,7 +672,7 @@ partial class IShaderGenerator
|
||||
}
|
||||
|
||||
// User-defined values
|
||||
foreach (var (fieldName, fieldType) in valueFields)
|
||||
foreach ((string fieldName, string fieldType) in valueFields)
|
||||
{
|
||||
AppendLineAndLF($" {fieldType} {fieldName};");
|
||||
}
|
||||
@@ -698,7 +698,7 @@ partial class IShaderGenerator
|
||||
}
|
||||
|
||||
// Resources
|
||||
foreach (var (metadataName, fieldName, fieldType) in resourceFields)
|
||||
foreach ((string metadataName, string fieldName, string fieldType) in resourceFields)
|
||||
{
|
||||
if (HlslKnownTypes.IsConstantBufferType(metadataName))
|
||||
{
|
||||
@@ -721,7 +721,7 @@ partial class IShaderGenerator
|
||||
}
|
||||
|
||||
// Shared buffers
|
||||
foreach (var (bufferName, bufferType, bufferCount) in sharedBuffers)
|
||||
foreach ((string bufferName, string bufferType, int? bufferCount) in sharedBuffers)
|
||||
{
|
||||
object count = (object?)bufferCount ?? "__GroupSize__get_X * __GroupSize__get_Y * __GroupSize__get_Z";
|
||||
|
||||
@@ -730,7 +730,7 @@ partial class IShaderGenerator
|
||||
}
|
||||
|
||||
// Forward declarations
|
||||
foreach (var (forwardDeclaration, _) in processedMethods)
|
||||
foreach ((string forwardDeclaration, string _) in processedMethods)
|
||||
{
|
||||
AppendLF();
|
||||
AppendLineAndLF(forwardDeclaration);
|
||||
@@ -739,7 +739,7 @@ partial class IShaderGenerator
|
||||
string capturedFieldsAndResourcesAndForwardDeclarations = FlushText();
|
||||
|
||||
// Captured methods
|
||||
foreach (var (_, method) in processedMethods)
|
||||
foreach ((string _, string method) in processedMethods)
|
||||
{
|
||||
AppendLF();
|
||||
AppendLineAndLF(method);
|
||||
|
||||
@@ -81,7 +81,7 @@ partial class IShaderGenerator
|
||||
else if (fieldSymbol.Type.IsUnmanagedType)
|
||||
{
|
||||
// Custom struct type defined by the user
|
||||
foreach (var fieldInfo in GetCapturedFieldInfos(fieldSymbol.Type, fieldPath.Add(fieldName), resourceOffset, rawDataOffset))
|
||||
foreach (FieldInfo fieldInfo in GetCapturedFieldInfos(fieldSymbol.Type, fieldPath.Add(fieldName), resourceOffset, rawDataOffset))
|
||||
{
|
||||
yield return fieldInfo;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ partial class IShaderGenerator
|
||||
{
|
||||
// For scalar, vector and linear matrix types, serialize the value normally.
|
||||
// Only the initial alignment needs to be considered, while data is packed.
|
||||
var (fieldSize, fieldPack) = HlslKnownSizes.GetTypeInfo(typeName);
|
||||
(int fieldSize, int fieldPack) = HlslKnownSizes.GetTypeInfo(typeName);
|
||||
|
||||
// Check if the current type is a matrix type with more than one row. In this
|
||||
// case, each row is aligned as if it was a separate array, so the start of
|
||||
|
||||
@@ -72,7 +72,7 @@ partial class HlslKnownProperties
|
||||
PropertyInfo groupindexProperty = typeof(GroupIds).GetProperty(nameof(GroupIds.Index), BindingFlags.Static | BindingFlags.Public);
|
||||
|
||||
// Programmatically load mappings for the dispatch types
|
||||
foreach (var item in
|
||||
foreach ((Type Type, PropertyInfo Property) item in
|
||||
from type in HlslKnownTypes.HlslDispatchTypes
|
||||
from property in type.GetProperties(BindingFlags.Static | BindingFlags.Public)
|
||||
select (Type: type, Property: property))
|
||||
@@ -90,7 +90,7 @@ partial class HlslKnownProperties
|
||||
}
|
||||
|
||||
// Programmatically load mappings for the normalized thread ids
|
||||
foreach (var property in typeof(ThreadIds.Normalized).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
foreach (PropertyInfo? property in typeof(ThreadIds.Normalized).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
string key = $"{typeof(ThreadIds).FullName}{Type.Delimiter}{typeof(ThreadIds.Normalized).Name}{Type.Delimiter}{property.Name}";
|
||||
|
||||
@@ -127,7 +127,7 @@ partial class HlslKnownProperties
|
||||
}
|
||||
|
||||
// Programmatically load mappings for the group size
|
||||
foreach (var property in typeof(GroupSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
foreach (PropertyInfo? property in typeof(GroupSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
string key = $"{typeof(GroupSize).FullName}{Type.Delimiter}{property.Name}";
|
||||
|
||||
@@ -149,7 +149,7 @@ partial class HlslKnownProperties
|
||||
}
|
||||
|
||||
// Programmatically load mappings for the dispatch size
|
||||
foreach (var property in typeof(DispatchSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
foreach (PropertyInfo? property in typeof(DispatchSize).GetProperties(BindingFlags.Static | BindingFlags.Public))
|
||||
{
|
||||
string key = $"{typeof(DispatchSize).FullName}{Type.Delimiter}{property.Name}";
|
||||
|
||||
|
||||
@@ -87,10 +87,10 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
|
||||
Dictionary<IMethodSymbol, MethodDeclarationSyntax> instanceMethods = new(SymbolEqualityComparer.Default); // Unused in this generator
|
||||
|
||||
// Explore the syntax tree and extract the processed info
|
||||
var semanticModel = new SemanticModelProvider(compilation);
|
||||
var (entryPoint, dependentMethods) = GetProcessedMethods(builder, methodDeclaration, semanticModel, discoveredTypes, constantDefinitions);
|
||||
var definedTypes = IShaderGenerator.BuildHlslSource.GetDeclaredTypes(builder, methodSymbol, discoveredTypes, instanceMethods);
|
||||
var definedConstants = IShaderGenerator.BuildHlslSource.GetDefinedConstants(constantDefinitions);
|
||||
SemanticModelProvider semanticModel = new SemanticModelProvider(compilation);
|
||||
(string entryPoint, ImmutableArray<(string Signature, string Definition)> dependentMethods) = GetProcessedMethods(builder, methodDeclaration, semanticModel, discoveredTypes, constantDefinitions);
|
||||
ImmutableArray<(string Name, string Definition)> definedTypes = IShaderGenerator.BuildHlslSource.GetDeclaredTypes(builder, methodSymbol, discoveredTypes, instanceMethods);
|
||||
ImmutableArray<(string Name, string Value)> definedConstants = IShaderGenerator.BuildHlslSource.GetDefinedConstants(constantDefinitions);
|
||||
|
||||
diagnostics = builder.ToImmutable();
|
||||
|
||||
@@ -140,7 +140,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
|
||||
using ImmutableArrayBuilder<(string, string)> methods = ImmutableArrayBuilder<(string, string)>.Rent();
|
||||
|
||||
// Emit the extracted local functions
|
||||
foreach (var localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
foreach (KeyValuePair<string, LocalFunctionStatementSyntax> localFunction in shaderSourceRewriter.LocalFunctions)
|
||||
{
|
||||
methods.Add((
|
||||
localFunction.Value.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString(),
|
||||
@@ -148,7 +148,7 @@ public sealed partial class ShaderMethodSourceGenerator : IIncrementalGenerator
|
||||
}
|
||||
|
||||
// Emit the discovered static methods
|
||||
foreach (var staticMethod in staticMethods.Values)
|
||||
foreach (MethodDeclarationSyntax staticMethod in staticMethods.Values)
|
||||
{
|
||||
methods.Add((
|
||||
staticMethod.AsDefinition().NormalizeWhitespace(eol: "\n").ToFullString(),
|
||||
|
||||
@@ -35,7 +35,7 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitParameterList(ParameterListSyntax node)
|
||||
{
|
||||
var updatedNode = (ParameterListSyntax)base.VisitParameterList(node)!;
|
||||
ParameterListSyntax updatedNode = (ParameterListSyntax)base.VisitParameterList(node)!;
|
||||
|
||||
updatedNode = updatedNode.AddParameters(Parameter(Identifier($"uint3 {nameof(ThreadIds)} : SV_DispatchThreadID")));
|
||||
|
||||
@@ -74,7 +74,7 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
MethodDeclarationSyntax updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
|
||||
// When we're rewriting the main compute shader method, we need to insert a range
|
||||
// check to ensure that invocation outside of the requested range are discarded.
|
||||
@@ -129,7 +129,7 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitReturnStatement(ReturnStatementSyntax node)
|
||||
{
|
||||
var updatedNode = (ReturnStatementSyntax)base.VisitReturnStatement(node)!;
|
||||
ReturnStatementSyntax updatedNode = (ReturnStatementSyntax)base.VisitReturnStatement(node)!;
|
||||
|
||||
// {
|
||||
// __outputTexture[ThreadIds.xy] = <RETURN_EXPRESSION>;
|
||||
@@ -154,7 +154,7 @@ internal abstract class ExecuteMethodRewriter : CSharpSyntaxRewriter
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
MethodDeclarationSyntax updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
|
||||
// Change the return type to void
|
||||
updatedNode = updatedNode.WithReturnType(PredefinedType(Token(SyntaxKind.VoidKeyword)));
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする