Fixed handling of constants in parent type hierarchy
このコミットが含まれているのは:
1 親
27438f7a69
コミット
ad58397e1d
3ファイル変更
+21
-20
検索条件に一致するファイルはありません
@@ -32,26 +32,30 @@ namespace ComputeSharp.Shaders.Renderer
|
||||
builder.AppendLine("// ================================================");
|
||||
builder.AppendLine("// This shader was created by ComputeSharp.");
|
||||
builder.AppendLine("// See: https://github.com/Sergio0694/ComputeSharp.");
|
||||
builder.AppendLine();
|
||||
|
||||
// Constants
|
||||
foreach (var constant in info.ConstantsInfo)
|
||||
if (info.ConstantsInfo.Count > 0)
|
||||
{
|
||||
builder.Append("#define ");
|
||||
builder.Append(constant.Key);
|
||||
builder.Append(' ');
|
||||
builder.AppendLine(constant.Value);
|
||||
builder.AppendLine();
|
||||
|
||||
foreach (var constant in info.ConstantsInfo)
|
||||
{
|
||||
builder.Append("#define ");
|
||||
builder.Append(constant.Key);
|
||||
builder.Append(' ');
|
||||
builder.AppendLine(constant.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// Declared types
|
||||
foreach (var type in info.DeclaredTypes)
|
||||
{
|
||||
builder.AppendLine(type);
|
||||
builder.AppendLine();
|
||||
builder.AppendLine(type);
|
||||
}
|
||||
|
||||
// Captured variables
|
||||
builder.AppendLine();
|
||||
builder.AppendLine("cbuffer _ : register(b0)");
|
||||
builder.AppendLine('{');
|
||||
builder.AppendLine(" uint __x;");
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
var (entryPoint, localFunctions) = GetProcessedMethods(structDeclaration, structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods, constantDefinitions);
|
||||
var processedTypes = GetProcessedTypes(discoveredTypes).ToArray();
|
||||
var processedMethods = localFunctions.Concat(staticMethods.Values).Select(static method => method.NormalizeWhitespace().ToFullString()).ToArray();
|
||||
var processedConstants = GetProcessedConstants(structDeclarationSymbol, constantDefinitions);
|
||||
var processedConstants = GetProcessedConstants(constantDefinitions);
|
||||
|
||||
// Create the compilation unit with the source attribute
|
||||
var source =
|
||||
@@ -197,25 +197,17 @@ namespace ComputeSharp.SourceGenerators
|
||||
/// <summary>
|
||||
/// Gets a sequence of discovered constants.
|
||||
/// </summary>
|
||||
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
|
||||
/// <param name="constantDefinitions">The collection of discovered constant definitions.</param>
|
||||
/// <returns>A sequence of discovered constants to declare in the shader.</returns>
|
||||
[Pure]
|
||||
private static IEnumerable<IEnumerable<string>> GetProcessedConstants(INamedTypeSymbol structDeclarationSymbol, IReadOnlyDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
private static IEnumerable<IEnumerable<string>> GetProcessedConstants(IReadOnlyDictionary<IFieldSymbol, string> constantDefinitions)
|
||||
{
|
||||
foreach (var constant in constantDefinitions)
|
||||
{
|
||||
if (SymbolEqualityComparer.Default.Equals(structDeclarationSymbol, constant.Key.ContainingSymbol))
|
||||
{
|
||||
yield return new string[] { constant.Key.Name, constant.Value };
|
||||
}
|
||||
else
|
||||
{
|
||||
var ownerTypeName = ((INamedTypeSymbol)constant.Key.ContainingSymbol).GetFullMetadataName().Replace(".", "__");
|
||||
var constantName = $"{ownerTypeName}__{constant.Key.Name}";
|
||||
var ownerTypeName = ((INamedTypeSymbol)constant.Key.ContainingSymbol).ToDisplayString().Replace(".", "__");
|
||||
var constantName = $"__{ownerTypeName}__{constant.Key.Name}";
|
||||
|
||||
yield return new string[] { constantName, constant.Value };
|
||||
}
|
||||
yield return new string[] { constantName, constant.Value };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -473,6 +473,11 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
!this.constantDefinitions.ContainsKey(operation.Field))
|
||||
{
|
||||
this.constantDefinitions.Add(operation.Field, operation.Field.ConstantValue!.ToString());
|
||||
|
||||
var ownerTypeName = ((INamedTypeSymbol)operation.Field.ContainingSymbol).ToDisplayString().Replace(".", "__");
|
||||
var constantName = $"__{ownerTypeName}__{operation.Field.Name}";
|
||||
|
||||
return IdentifierName(constantName);
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする