Switch ID2D1Shader.HlslSource to a property
このコミットが含まれているのは:
1 親
ca77bab1f2
コミット
60028ce00c
6ファイル変更
+16
-25
検索条件に一致するファイルはありません
+8
-16
@@ -16,32 +16,24 @@ partial class ID2D1ShaderGenerator
|
||||
partial class BuildHlslSource
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslSource</c> method.
|
||||
/// Creates a <see cref="PropertyDeclarationSyntax"/> instance for the <c>HlslSource</c> property.
|
||||
/// </summary>
|
||||
/// <param name="hlslSource">The input HLSL source.</param>
|
||||
/// <param name="hierarchyDepth">The depth of the hierarchy for this type (used to calculate the right indentation).</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>BuildHlslSource</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth)
|
||||
/// <returns>The resulting <see cref="PropertyDeclarationSyntax"/> instance for the <c>HlslSource</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetSyntax(string hlslSource, int hierarchyDepth)
|
||||
{
|
||||
SyntaxToken hlslSourceLiteralExpression = SyntaxTokenHelper.CreateRawMultilineStringLiteral(hlslSource, hierarchyDepth);
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
// This code produces a property declaration as follows:
|
||||
//
|
||||
// readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.BuildHlslSource(out string hlslSource)
|
||||
// {
|
||||
// hlslSource = <HLSL_SOURCE>;
|
||||
// }
|
||||
// readonly string global::ComputeSharp.D2D1.__Internals.ID2D1Shader.HlslSource => <HLSL_SOURCE>;
|
||||
return
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(nameof(BuildHlslSource)))
|
||||
PropertyDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier("HlslSource"))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("hlslSource")).AddModifiers(Token(SyntaxKind.OutKeyword)).WithType(PredefinedType(Token(SyntaxKind.StringKeyword))))
|
||||
.WithBody(Block(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("hlslSource"),
|
||||
LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))));
|
||||
.WithExpressionBody(ArrowExpressionClause(LiteralExpression(SyntaxKind.StringLiteralExpression, hlslSourceLiteralExpression)))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -79,7 +79,7 @@ partial class ID2D1ShaderGenerator
|
||||
.AddArgumentListArguments(Argument(IdentifierName("bytes"))))
|
||||
.WithRefOrOutKeyword(Token(SyntaxKind.RefKeyword)))));
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
// This code produces a property declaration as follows:
|
||||
//
|
||||
// readonly ref readonly global::System.Guid global::ComputeSharp.D2D1.__Internals.ID2D1Shader.EffectId
|
||||
// {
|
||||
|
||||
@@ -321,10 +321,10 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
// Generate the BuildHlslSource() methods
|
||||
context.RegisterSourceOutput(hlslSourceInfo, static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax buildHlslStringMethod = BuildHlslSource.GetSyntax(item.HlslSource, item.Hierarchy.Hierarchy.Length);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, buildHlslStringMethod, canUseSkipLocalsInit: false);
|
||||
PropertyDeclarationSyntax hlslStringProperty = BuildHlslSource.GetSyntax(item.Info.HlslSource, item.Info.Hierarchy.Hierarchy.Length);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Info.Hierarchy, hlslStringProperty, canUseSkipLocalsInit: false);
|
||||
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(BuildHlslSource)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
context.AddSource($"{item.Info.Hierarchy.FullyQualifiedMetadataName}.HlslSource.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get a filtered sequence to enable caching for the HLSL source info, before the shader compilation step
|
||||
|
||||
@@ -122,12 +122,11 @@ public interface ID2D1Shader
|
||||
where TLoader : struct, ID2D1DispatchDataLoader;
|
||||
|
||||
/// <summary>
|
||||
/// Builds the HLSL source code for the current shader instance.
|
||||
/// Gets the HLSL source code for the current shader instance.
|
||||
/// </summary>
|
||||
/// <param name="hlslSource">The resulting HLSL source.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be called directly by user code")]
|
||||
void BuildHlslSource(out string hlslSource);
|
||||
string HlslSource { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads the bytecode for the current shader.
|
||||
|
||||
@@ -33,7 +33,7 @@ public static class D2D1ReflectionServices
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.BuildHlslSource(out string hlslSource);
|
||||
string hlslSource = shader.HlslSource;
|
||||
|
||||
D2D1ShaderBytecodeLoader bytecodeLoader = default;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public static class D2D1ShaderCompiler
|
||||
where TLoader : struct, ID2D1BytecodeLoader
|
||||
where T : struct, ID2D1Shader
|
||||
{
|
||||
Unsafe.AsRef(in shader).BuildHlslSource(out string hlslSource);
|
||||
string hlslSource = Unsafe.AsRef(in shader).HlslSource;
|
||||
|
||||
using ComPtr<ID3DBlob> d3DBlobBytecode = Shaders.Translation.D3DCompiler.Compile(
|
||||
hlslSource.AsSpan(),
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする