diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
index a7fc292c..7b782c29 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.Syntax.cs
@@ -71,200 +71,232 @@ partial class ID2D1ShaderGenerator
}
///
- /// Creates a instance for the TryGetBytecode method.
+ /// Creates a instance for the HlslBytecode property.
///
/// The input bytecode info.
/// An opaque instance to transform the final tree into text.
- /// The resulting instance for the BuildHlslSource method.
- public static MethodDeclarationSyntax GetSyntax(EmbeddedBytecodeInfo bytecodeInfo, out Func fixup)
+ /// Any additional instances needed by the generated code, if needed.
+ /// The resulting instance for the HlslBytecode property.
+ public static PropertyDeclarationSyntax GetHlslBytecodeSyntax(
+ EmbeddedBytecodeInfo bytecodeInfo,
+ out Func fixup,
+ out TypeDeclarationSyntax[] additionalTypes)
{
- BlockSyntax block = GetShaderBytecodeBody(bytecodeInfo, out string? bytecodeLiterals);
+ ExpressionSyntax memoryExpression;
- if (bytecodeLiterals is not null)
+ // If there is no bytecode, simply return a default expression.
+ // Otherwise, declare the memory manager and access it.
+ if (bytecodeInfo.Bytecode.Length == 0)
{
- fixup = tree => SourceText.From(tree.ToFullString().Replace("__EMBEDDED_SHADER_BYTECODE", bytecodeLiterals), Encoding.UTF8);
+ memoryExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
+ fixup = static tree => tree.GetText(Encoding.UTF8);
+ additionalTypes = Array.Empty();
}
else
{
- fixup = static tree => tree.GetText(Encoding.UTF8);
+ memoryExpression = MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("HlslBytecodeMemoryManager"),
+ IdentifierName("Memory"));
+
+ TypeDeclarationSyntax memoryManagerDeclaration = GetMemoryManagerDeclaration(bytecodeInfo);
+ string bytecodeLiterals = SyntaxFormattingHelper.BuildByteArrayInitializationExpressionString(bytecodeInfo.Bytecode.AsSpan());
+
+ additionalTypes = new TypeDeclarationSyntax[] { memoryManagerDeclaration };
+ fixup = tree => SourceText.From(tree.ToFullString().Replace("__EMBEDDED_SHADER_BYTECODE", bytecodeLiterals), Encoding.UTF8);
}
// This code produces a method declaration as follows:
//
- // readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadBytecode(ref TLoader loader, ref global::ComputeSharp.D2D1.D2D1ShaderProfile? shaderProfile, ref global::ComputeSharp.D2D1.D2D1CompileOptions? compileOptions)
- // {
- //
- // }
+ // readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.__Internals.ID2D1Shader.HlslBytecode => ;
return
- MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(nameof(LoadBytecode)))
+ PropertyDeclaration(
+ GenericName(Identifier("global::System.ReadOnlyMemory"))
+ .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))),
+ Identifier(nameof(ID2D1Shader.HlslBytecode)))
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
- .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader")))
- .AddParameterListParameters(
- Parameter(Identifier("loader")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(IdentifierName("TLoader")),
- Parameter(Identifier("shaderProfile")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(NullableType(IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile"))),
- Parameter(Identifier("compileOptions")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(NullableType(IdentifierName("global::ComputeSharp.D2D1.D2D1CompileOptions"))))
- .WithBody(block);
+ .WithExpressionBody(ArrowExpressionClause(memoryExpression))
+ .WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
}
///
/// Gets a instance with the logic to try to get a compiled shader bytecode.
///
/// The input bytecode info.
- /// The resulting bytecode literals to insert into the final source code.
/// The instance trying to retrieve the precompiled shader.
- private static unsafe BlockSyntax GetShaderBytecodeBody(EmbeddedBytecodeInfo bytecodeInfo, out string? bytecodeLiterals)
+ private static unsafe TypeDeclarationSyntax GetMemoryManagerDeclaration(EmbeddedBytecodeInfo bytecodeInfo)
{
- // This method needs to handle several different scenarions, which are as follows:
- // 1) If [EmbeddedBytecode] is used, then the shader is precompiled and stored as a ReadOnlySpan. In this case,
- // this bytecode would have been generated with some specific D2D1ShaderProfile and D2D1CompileOptions values. So,
- // a branch is generated to try to retrieve this precompiled bytecode, which can be returned if and only if the
- // requested shader profile and compile options are either null, or either matches the values that have been used
- // to generate that bytecode. If this is the case, then no further work is done and that binary data is returned.
- // 2) If either the requested shader profile or options do not match the values used to create the shader bytecode,
- // then a call to the internal D2D1ShaderCompiler.LoadDynamicBytecode API is used, to create the shader on the fly.
- // 3) If [EmbeddedBytecode] is not used, then regardless of the requested profile and options, a new shader is compiled.
- // 4) If this is the case and either the shader profile or the options are null, then this method will manually set the
- // value being null to the default one to use. That is, D2D1ShaderProfile.PixelShader50 will be used as the target,
- // and the options will be set to D2D1CompileOptions.Default (and optionally, D2D1CompileOptions.EnableLinking too).
-
- // Get a formatted representation of the compile options being used
- ExpressionSyntax compileOptionsExpression =
- ParseExpression(
- bytecodeInfo.CompileOptions
- .ToString(CultureInfo.InvariantCulture)
- .Split(',')
- .Select(static name => $"global::ComputeSharp.D2D1.D2D1CompileOptions.{name.Trim()}")
- .Aggregate("", static (left, right) => left.Length > 0 ? $"{left} | {right}" : right));
-
- // Add parantheses if needed
- if (compileOptionsExpression is BinaryExpressionSyntax)
- {
- compileOptionsExpression = ParenthesizedExpression(compileOptionsExpression);
- }
-
- // This code produces a block declaration as follows:
+ // Create the MemoryManager declaration:
//
- // global::ComputeSharp.D2D1.D2D1ShaderProfile effectiveShaderProfile = shaderProfile ??= ;
- // global::ComputeSharp.D2D1.D2D1CompileOptions effectiveCompileOptions = compileOptions ??= ;
- //
- // global::ComputeSharp.D2D1.__Internals.D2D1ShaderCompiler.LoadDynamicBytecode(ref loader, in this, effectiveShaderProfile, effectiveCompileOptions);
- BlockSyntax dynamicLoadingBlock =
- Block(
- LocalDeclarationStatement(
- VariableDeclaration(IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile"))
- .AddVariables(
- VariableDeclarator(Identifier("effectiveShaderProfile"))
- .WithInitializer(EqualsValueClause(
- AssignmentExpression(
- SyntaxKind.CoalesceAssignmentExpression,
- IdentifierName("shaderProfile"),
- IdentifierName($"global::ComputeSharp.D2D1.D2D1ShaderProfile.{D2D1ShaderProfile.PixelShader50}")))))),
- LocalDeclarationStatement(
- VariableDeclaration(IdentifierName("global::ComputeSharp.D2D1.D2D1CompileOptions"))
- .AddVariables(
- VariableDeclarator(Identifier("effectiveCompileOptions"))
- .WithInitializer(EqualsValueClause(
- AssignmentExpression(
- SyntaxKind.CoalesceAssignmentExpression,
- IdentifierName("compileOptions"),
- compileOptionsExpression))))),
- ExpressionStatement(
- InvocationExpression(
- MemberAccessExpression(
- SyntaxKind.SimpleMemberAccessExpression,
- IdentifierName("global::ComputeSharp.D2D1.__Internals.D2D1ShaderCompiler"),
- IdentifierName("LoadDynamicBytecode")))
- .AddArgumentListArguments(
- Argument(IdentifierName("loader")).WithRefKindKeyword(Token(SyntaxKind.RefKeyword)),
- Argument(ThisExpression()).WithRefKindKeyword(Token(SyntaxKind.InKeyword)),
- Argument(IdentifierName("effectiveShaderProfile")),
- Argument(IdentifierName("effectiveCompileOptions")))));
-
- // If there is no precompiled bytecode, just return the dynamic path
- if (bytecodeInfo.Bytecode.IsDefaultOrEmpty)
- {
- bytecodeLiterals = null;
-
- return dynamicLoadingBlock;
- }
-
- bytecodeLiterals = SyntaxFormattingHelper.BuildByteArrayInitializationExpressionString(bytecodeInfo.Bytecode.AsSpan());
-
- // Prepare the expression for the default shader profile to use
- ExpressionSyntax shaderProfileExpression =
- MemberAccessExpression(
- SyntaxKind.SimpleMemberAccessExpression,
- IdentifierName("global::ComputeSharp.D2D1.D2D1ShaderProfile"),
- IdentifierName(bytecodeInfo.ShaderProfile.ToString(CultureInfo.InvariantCulture)));
-
- // This code produces a branch as follows:
- //
- // if (shaderProfile is null or && compileOptions is null or )
+ // ///
+ // /// implementation to get the HLSL bytecode.
+ // ///
+ // [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
+ // [global::System.Diagnostics.DebuggerNonUserCode]
+ // [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
+ // file sealed HlslBytecodeMemoryManager : global::System.Buffers.MemoryManager
// {
- // global::System.ReadOnlySpan bytecode = new byte[] { __EMBEDDED_SHADER_BYTECODE };
- //
- // loader.LoadEmbeddedBytecode(bytecode);
- //
- // shaderProfile = ;
- // compileOptions = ;
// }
- //
- // Note that the __EMBEDDED_SHADER_BYTECODE identifier will be replaced after the string
- // is created by the generator. This greatly speeds up the code generation, as it avoids
- // having to create/parse tens of thousands of literal expression nodes for every shader.
- IfStatementSyntax embeddedBranch =
- IfStatement(
- BinaryExpression(
- SyntaxKind.LogicalAndExpression,
- IsPatternExpression(
- IdentifierName("shaderProfile"),
- BinaryPattern(
- SyntaxKind.OrPattern,
- ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression)),
- ConstantPattern(shaderProfileExpression))),
- IsPatternExpression(
- IdentifierName("compileOptions"),
- BinaryPattern(
- SyntaxKind.OrPattern,
- ConstantPattern(LiteralExpression(SyntaxKind.NullLiteralExpression)),
- ConstantPattern(compileOptionsExpression)))),
- Block(
- LocalDeclarationStatement(
- VariableDeclaration(
- GenericName(Identifier("global::System.ReadOnlySpan"))
- .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))))
- .AddVariables(
- VariableDeclarator(Identifier("bytecode"))
- .WithInitializer(
- EqualsValueClause(
- ArrayCreationExpression(
- ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)))
- .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(OmittedArraySizeExpression()))))
- .WithInitializer(
- InitializerExpression(
- SyntaxKind.ArrayInitializerExpression,
- SingletonSeparatedList(IdentifierName("__EMBEDDED_SHADER_BYTECODE")))))))),
- ExpressionStatement(
- InvocationExpression(
- MemberAccessExpression(
- SyntaxKind.SimpleMemberAccessExpression,
- IdentifierName("loader"),
- IdentifierName("LoadEmbeddedBytecode")))
- .AddArgumentListArguments(Argument(IdentifierName("bytecode")))),
- ExpressionStatement(
- AssignmentExpression(
- SyntaxKind.SimpleAssignmentExpression,
- IdentifierName("shaderProfile"),
- shaderProfileExpression)),
- ExpressionStatement(
- AssignmentExpression(
- SyntaxKind.SimpleAssignmentExpression,
- IdentifierName("compileOptions"),
- compileOptionsExpression))));
+ TypeDeclarationSyntax typeDeclaration =
+ ClassDeclaration("HlslBytecodeMemoryManager")
+ .AddModifiers(Token(SyntaxKind.FileKeyword), Token(SyntaxKind.SealedKeyword))
+ .AddBaseListTypes(SimpleBaseType(
+ GenericName(Identifier("global::System.Buffers.MemoryManager"))
+ .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword)))))
+ .AddAttributeLists(
+ AttributeList(SingletonSeparatedList(
+ Attribute(IdentifierName("global::System.CodeDom.Compiler.GeneratedCode")).AddArgumentListArguments(
+ AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ID2D1ShaderGenerator).FullName))),
+ AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(typeof(ID2D1ShaderGenerator).Assembly.GetName().Version.ToString())))))),
+ AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.DebuggerNonUserCode")))),
+ AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage")))))
+ .WithLeadingTrivia(
+ Comment("/// "),
+ Comment("""/// A implementation to get the HLSL bytecode."""),
+ Comment("/// "));
- // Return the combined block
- return Block(embeddedBranch.WithElse(ElseClause(dynamicLoadingBlock)));
+ using ImmutableArrayBuilder memberDeclarations = ImmutableArrayBuilder.Rent();
+
+ // Declare the singleton property to get the memory instance:
+ //
+ // /// The singleton instance for the memory manager.
+ // public static new readonly global::System.ReadOnlyMemory Memory = new HlslBytecodeMemoryManager().CreateMemory();
+ memberDeclarations.Add(
+ FieldDeclaration(
+ VariableDeclaration(
+ GenericName(Identifier("global::System.ReadOnlyMemory"))
+ .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))))
+ .AddVariables(
+ VariableDeclarator(Identifier("Memory"))
+ .WithInitializer(
+ EqualsValueClause(
+ InvocationExpression(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ ObjectCreationExpression(IdentifierName("HlslBytecodeMemoryManager")).WithArgumentList(ArgumentList()),
+ IdentifierName("CreateMemory")))
+ .AddArgumentListArguments(Argument(
+ LiteralExpression(
+ SyntaxKind.NumericLiteralExpression,
+ Literal(bytecodeInfo.Bytecode.Length))))))))
+ .AddModifiers(
+ Token(SyntaxKind.PublicKeyword),
+ Token(SyntaxKind.StaticKeyword),
+ Token(SyntaxKind.NewKeyword),
+ Token(SyntaxKind.ReadOnlyKeyword))
+ .WithLeadingTrivia(Comment("""/// The singleton instance for the memory manager.""")));
+
+ // Construct the RVA span property:
+ //
+ // /// The RVA data with the HLSL bytecode.
+ // private static global::System.ReadOnlySpan Data => new byte[] { __EMBEDDED_SHADER_BYTECODE };
+ memberDeclarations.Add(
+ PropertyDeclaration(
+ GenericName(Identifier("global::System.ReadOnlySpan"))
+ .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))),
+ Identifier("Data"))
+ .AddModifiers(Token(SyntaxKind.PrivateKeyword), Token(SyntaxKind.StaticKeyword))
+ .WithExpressionBody(
+ ArrowExpressionClause(
+ ArrayCreationExpression(
+ ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)))
+ .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(OmittedArraySizeExpression()))),
+ InitializerExpression(
+ SyntaxKind.ArrayInitializerExpression,
+ SingletonSeparatedList(IdentifierName("__EMBEDDED_SHADER_BYTECODE"))))))
+ .WithSemicolonToken(Token(SyntaxKind.SemicolonToken))
+ .WithLeadingTrivia(Comment("/// The RVA data with the HLSL bytecode.")));
+
+ // Add the GetSpan() method:
+ //
+ // ///
+ // public override unsafe global::System.Span GetSpan
+ // {
+ // return new(global::System.Runtime.CompilerServices.Unsafe.AsPointer(ref global::System.Runtime.InteropServices.MemoryMarshal(Data)), );
+ // }
+ memberDeclarations.Add(
+ MethodDeclaration(
+ GenericName(Identifier("global::System.Span"))
+ .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))),
+ Identifier("GetSpan"))
+ .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.OverrideKeyword), Token(SyntaxKind.UnsafeKeyword))
+ .AddBodyStatements(
+ ReturnStatement(
+ ImplicitObjectCreationExpression()
+ .AddArgumentListArguments(
+ Argument(
+ InvocationExpression(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("global::System.Runtime.CompilerServices.Unsafe"),
+ IdentifierName("AsPointer")))
+ .AddArgumentListArguments(
+ Argument(
+ InvocationExpression(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("global::System.Runtime.InteropServices.MemoryMarshal"),
+ IdentifierName("GetReference")))
+ .AddArgumentListArguments(Argument(IdentifierName("Data"))))
+ .WithRefOrOutKeyword(Token(SyntaxKind.RefKeyword)))),
+ Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(bytecodeInfo.Bytecode.Length))))))
+ .WithLeadingTrivia(Comment("/// ")));
+
+ // Add the Pin(int elementIndex) method:
+ //
+ // ///
+ // public override unsafe global::System.Buffers.MemoryHandle Pin(int elementIndex)
+ // {
+ // return new(Unsafe.AsPointer(ref Unsafe.AsRef(in Data[elementIndex])), pinnable: this);
+ // }
+ memberDeclarations.Add(
+ MethodDeclaration(IdentifierName("global::System.Buffers.MemoryHandle"), Identifier("Pin"))
+ .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.OverrideKeyword), Token(SyntaxKind.UnsafeKeyword))
+ .AddParameterListParameters(Parameter(Identifier("elementIndex")).WithType(PredefinedType(Token(SyntaxKind.IntKeyword))))
+ .AddBodyStatements(
+ ReturnStatement(
+ ImplicitObjectCreationExpression()
+ .AddArgumentListArguments(
+ Argument(
+ InvocationExpression(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("global::System.Runtime.CompilerServices.Unsafe"),
+ IdentifierName("AsPointer")))
+ .AddArgumentListArguments(
+ Argument(
+ InvocationExpression(
+ MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("global::System.Runtime.CompilerServices.Unsafe"),
+ IdentifierName("AsRef")))
+ .AddArgumentListArguments(
+ Argument(
+ ElementAccessExpression(IdentifierName("Data"))
+ .AddArgumentListArguments(Argument(IdentifierName("elementIndex"))))
+ .WithRefOrOutKeyword(Token(SyntaxKind.InKeyword))))
+ .WithRefOrOutKeyword(Token(SyntaxKind.RefKeyword)))),
+ Argument(ThisExpression()).WithNameColon(NameColon(IdentifierName("pinnable"))))))
+ .WithLeadingTrivia(Comment("/// ")));
+
+ // Add the empty Unpin() method
+ memberDeclarations.Add(
+ MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier("Unpin"))
+ .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.OverrideKeyword))
+ .WithBody(Block())
+ .WithLeadingTrivia(Comment("/// ")));
+
+ // Add the empty Dispose(bool disposing) method
+ memberDeclarations.Add(
+ MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier("Dispose"))
+ .AddModifiers(Token(SyntaxKind.ProtectedKeyword), Token(SyntaxKind.OverrideKeyword))
+ .AddParameterListParameters(
+ Parameter(Identifier("disposing")).WithType(PredefinedType(Token(SyntaxKind.BoolKeyword))))
+ .WithBody(Block())
+ .WithLeadingTrivia(Comment("/// ")));
+
+ return typeDeclaration.AddMembers(memberDeclarations.ToArray());
}
}
}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
index f557ce17..7632b4a9 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
@@ -362,11 +362,11 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
// Generate the LoadBytecode() methods
context.RegisterSourceOutput(embeddedBytecode, static (context, item) =>
{
- MethodDeclarationSyntax loadBytecodeMethod = LoadBytecode.GetSyntax(item.BytecodeInfo, out Func fixup);
- CompilationUnitSyntax loadBytecodeCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, loadBytecodeMethod, skipLocalsInit: false);
- SourceText text = fixup(loadBytecodeCompilationUnit);
+ PropertyDeclarationSyntax hlslBytecodeProperty = LoadBytecode.GetHlslBytecodeSyntax(item.BytecodeInfo, out Func fixup, out TypeDeclarationSyntax[] additionalTypes);
+ CompilationUnitSyntax hlslBytecodeCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, hlslBytecodeProperty, skipLocalsInit: false, additionalMemberDeclarations: additionalTypes);
+ SourceText text = fixup(hlslBytecodeCompilationUnit);
- context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadBytecode)}.g.cs", text);
+ context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.HlslBytecode.g.cs", text);
PropertyDeclarationSyntax shaderProfileProperty = LoadBytecode.GetShaderProfileSyntax(item.BytecodeInfo);
CompilationUnitSyntax shaderProfileCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, shaderProfileProperty, skipLocalsInit: false);
@@ -374,7 +374,7 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.ShaderProfile.g.cs", shaderProfileCompilationUnit.GetText(Encoding.UTF8));
PropertyDeclarationSyntax compileOptionsProperty = LoadBytecode.GetCompileOptionsSyntax(item.BytecodeInfo);
- CompilationUnitSyntax compileOptionsCompilationUnit = GetCompilationUnitFromMethod(item.Hierarchy, compileOptionsProperty, canUseSkipLocalsInit: false);
+ CompilationUnitSyntax compileOptionsCompilationUnit = GetCompilationUnitFromMember(item.Hierarchy, compileOptionsProperty, skipLocalsInit: false);
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.CompileOptions.g.cs", compileOptionsCompilationUnit.GetText(Encoding.UTF8));
});
diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
index 60b542fc..3da044d0 100644
--- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
+++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
using ComputeSharp.D2D1.Interop;
namespace ComputeSharp.D2D1.__Internals;
@@ -148,16 +147,12 @@ public interface ID2D1Shader
D2D1CompileOptions CompileOptions { get; }
///
- /// Loads the bytecode for the current shader.
+ /// Gets the HLSL bytecode for the current shader, if available.
///
- /// The type of bytecode loader being used.
- /// The instance to use to load the bytecode.
- /// The shader profile to use to get the shader bytecode (if , the precompiled shader will be used).
- /// The compile options to use to get the shader bytecode (if , the precompiled shader will be used).
- /// Thrown if a precompiled bytecode was requested ( is ), but it wasn't availablle.
- /// When this method returns, and will be set to the effective laues used to create the shader bytecode that was loaded.
+ ///
+ /// If no precompiled HLSL bytecode is available, the returned instance will be empty.
+ ///
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
- void LoadBytecode(ref TLoader loader, [NotNull] ref D2D1ShaderProfile? shaderProfile, [NotNull] ref D2D1CompileOptions? compileOptions)
- where TLoader : struct, ID2D1BytecodeLoader;
+ ReadOnlyMemory HlslBytecode { get; }
}
\ No newline at end of file