Skip generating BuildHlslString body when dynamic support is missing
このコミットが含まれているのは:
1 親
547eff9fd1
コミット
b9313ca6d8
2ファイル変更
+43
-14
検索条件に一致するファイルはありません
+31
-3
@@ -21,14 +21,18 @@ public sealed partial class IShaderGenerator
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.
|
||||
/// </summary>
|
||||
/// <param name="hlslSourceInfo">The input <see cref="HlslShaderSourceInfo"/> instance to use.</param>
|
||||
/// <param name="supportsDynamicShaders">Indicates whether or not dynamic shaders are supported.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslString</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(HlslShaderSourceInfo hlslSourceInfo)
|
||||
public static MethodDeclarationSyntax GetSyntax(HlslShaderSourceInfo hlslSourceInfo, bool supportsDynamicShaders)
|
||||
{
|
||||
ImmutableArray<StatementSyntax> bodyStatements = GenerateRenderMethodBody(hlslSourceInfo);
|
||||
// Generate the necessary body statements depending on whether dynamic shaders are supported
|
||||
ImmutableArray<StatementSyntax> bodyStatements = supportsDynamicShaders
|
||||
? GenerateRenderMethodBody(hlslSourceInfo)
|
||||
: GenerateEmptyMethodBody();
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void global::ComputeSharp.__Internals.IShader.BuildHlslString(ref global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ)
|
||||
// readonly void global::ComputeSharp.__Internals.IShader.BuildHlslString(out global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, int threadsX, int threadsY, int threadsZ)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
@@ -46,6 +50,30 @@ public sealed partial class IShaderGenerator
|
||||
.WithBody(Block(bodyStatements));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces the series of statements for the empty fallback method.
|
||||
/// </summary>
|
||||
/// <returns>A series of statements for when dynamic shaders are not supported.</returns>
|
||||
private static ImmutableArray<StatementSyntax> GenerateEmptyMethodBody()
|
||||
{
|
||||
// builder = global::ComputeSharp.__Internals.ArrayPoolStringBuilder.Create(0);
|
||||
return
|
||||
ImmutableArray.Create<StatementSyntax>(
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("builder"),
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("global::ComputeSharp.__Internals.ArrayPoolStringBuilder"),
|
||||
IdentifierName("Create")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0)))))));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Produces the series of statements to build the current HLSL source.
|
||||
/// </summary>
|
||||
|
||||
@@ -138,18 +138,25 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, loadDispatchDataMethod, item.Right);
|
||||
|
||||
context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadDispatchData)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8));
|
||||
});
|
||||
});
|
||||
|
||||
// Check whether or not dynamic shaders are supported
|
||||
IncrementalValueProvider<bool> supportsDynamicShaders =
|
||||
context.CompilationProvider
|
||||
.Select(static (compilation, token) => compilation.ReferencedAssemblyNames.Any(
|
||||
static identity => identity.Name is "ComputeSharp.Dynamic"));
|
||||
|
||||
// Get the filtered sequence to enable caching
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, HlslShaderSourceInfo SourceInfo)> hlslSourceInfo =
|
||||
IncrementalValuesProvider<(HierarchyInfo Hierarchy, HlslShaderSourceInfo SourceInfo, bool SupportsDynamicShaders)> hlslSourceInfo =
|
||||
shaderInfo
|
||||
.Select(static (item, token) => (item.Dispatch.Hierarchy, item.Hlsl))
|
||||
.WithComparers(HierarchyInfo.Comparer.Default, HlslShaderSourceInfo.Comparer.Default);
|
||||
.Combine(supportsDynamicShaders)
|
||||
.Select(static (item, token) => (item.Left.Dispatch.Hierarchy, item.Left.Hlsl, item.Right))
|
||||
.WithComparers(HierarchyInfo.Comparer.Default, HlslShaderSourceInfo.Comparer.Default, EqualityComparer<bool>.Default);
|
||||
|
||||
// Generate the BuildHlslString() methods
|
||||
context.RegisterSourceOutput(hlslSourceInfo.Combine(canUseSkipLocalsInit), static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax buildHlslStringMethod = BuildHlslString.GetSyntax(item.Left.SourceInfo);
|
||||
MethodDeclarationSyntax buildHlslStringMethod = BuildHlslString.GetSyntax(item.Left.SourceInfo, item.Left.SupportsDynamicShaders);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, buildHlslStringMethod, item.Right);
|
||||
|
||||
context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(BuildHlslString)}", SourceText.From(compilationUnit.ToFullString(), Encoding.UTF8));
|
||||
@@ -224,12 +231,6 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
|
||||
.Select(static (item, token) => (item.Hierarchy, item.BytecodeInfo))
|
||||
.WithComparers(HierarchyInfo.Comparer.Default, EmbeddedBytecodeInfo.Comparer.Default);
|
||||
|
||||
// Check whether or not dynamic shaders are supported
|
||||
IncrementalValueProvider<bool> supportsDynamicShaders =
|
||||
context.CompilationProvider
|
||||
.Select(static (compilation, token) => compilation.ReferencedAssemblyNames.Any(
|
||||
static identity => identity.Name is "ComputeSharp.Dynamic"));
|
||||
|
||||
// Generate the TryGetBytecode() methods
|
||||
context.RegisterSourceOutput(embeddedBytecode.Combine(supportsDynamicShaders), static (context, item) =>
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする