Improve source generator support for dynamic shaders

このコミットが含まれているのは:
Sergio Pedri committed 2021-12-19 16:45:12 +01:00
1 親 80044d69fd
コミット 23b500fe81
5ファイル変更
+27 -32

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

+8 -23
ファイルの表示
@@ -169,8 +169,7 @@ public sealed partial class IShaderGenerator
// This code produces a method declaration as follows:
//
// BuildHlslString(out global::ComputeSharp.__Internals.ArrayPoolStringBuilder builder, threadsX, threadsY, threadsZ);
// global::System.IntPtr bytecode = ShaderCompiler.CompileShader(builder.WrittenSpan);
// builder.Dispose();
// global::System.IntPtr bytecode = ShaderCompiler.CompileShader(ref builder);
// loader.LoadDynamicBytecode(bytecode);
dynamicStatements = ImmutableArray.Create<StatementSyntax>(
ExpressionStatement(
@@ -194,24 +193,15 @@ public sealed partial class IShaderGenerator
IdentifierName("ShaderCompiler"),
IdentifierName("CompileShader")))
.AddArgumentListArguments(
Argument(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("builder"),
IdentifierName("WrittenSpan")))))))),
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("builder"),
IdentifierName("Dispose")))),
Argument(IdentifierName("builder"))
.WithRefKindKeyword(Token(SyntaxKind.RefKeyword))))))),
ExpressionStatement(
InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("loader"),
IdentifierName("LoadDynamicBytecode")))
.AddArgumentListArguments(Argument(IdentifierName("bytecode")))));
.AddArgumentListArguments(Argument(IdentifierName("bytecode")))));;
}
return dynamicStatements;
@@ -232,7 +222,7 @@ public sealed partial class IShaderGenerator
{
// This code produces a faulting call as follows:
//
// loader.LoadDynamicBytecode(global::System.IntPtr.Zero);
// loader.LoadDynamicBytecode(default);
return
ExpressionStatement(
InvocationExpression(
@@ -241,14 +231,9 @@ public sealed partial class IShaderGenerator
IdentifierName("loader"),
IdentifierName("LoadDynamicBytecode")))
.AddArgumentListArguments(
Argument(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
IdentifierName("global::System.IntPtr"),
IdentifierName("IntPtr")),
IdentifierName("Zero")))));
Argument(LiteralExpression(
SyntaxKind.DefaultLiteralExpression,
Token(SyntaxKind.DefaultKeyword)))));
}
return dynamicFaultStatement;
+2 -1
ファイルの表示
@@ -227,7 +227,8 @@ public sealed partial class IShaderGenerator : IIncrementalGenerator
// Check whether or not dynamic shaders are supported
IncrementalValueProvider<bool> supportsDynamicShaders =
context.CompilationProvider
.Select(static (compilation, token) => compilation.GetTypeByMetadataName("ComputeSharp.__Internals.ShaderCompiler") is not null);
.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) =>