Merge pull request #571 from Sergio0694/dev/shader-descriptions-memory
Generate D2D1 input descriptions as file local ReadOnlyMemory<T>
このコミットが含まれているのは:
12ファイル変更
+194
-229
検索条件に一致するファイルはありません
@@ -80,11 +80,11 @@
|
||||
<Compile Include="..\ComputeSharp.D2D1\Interfaces\ID2D1PixelShader.cs" Link="ComputeSharp.D2D1\Interfaces\ID2D1PixelShader.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1BytecodeLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1BytecodeLoader.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1DispatchDataLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1DispatchDataLoader.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1InputDescriptionsLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1InputDescriptionsLoader.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1ResourceTextureDescriptionsLoader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1ResourceTextureDescriptionsLoader.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" Link="ComputeSharp.D2D1\Interfaces\__Internals\ID2D1Shader.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Intrinsics\D2D.cs" Link="ComputeSharp.D2D1\Intrinsics\D2D.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" Link="ComputeSharp.D2D1\Shaders\Exceptions\FxcCompilationException.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1InputDescription.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Shaders\Interop\D2D1PixelShaderInputType.cs" Link="ComputeSharp.D2D1\Shaders\Interop\D2D1PixelShaderInputType.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.cs" Link="ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.cs" />
|
||||
<Compile Include="..\ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.ID3DInclude.cs" Link="ComputeSharp.D2D1\Shaders\Translation\D3DCompiler.ID3DInclude.cs" />
|
||||
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <inheritoc/>
|
||||
private static partial class InputDescriptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="PropertyDeclarationSyntax"/> instance for the <c>InputDescriptions</c> property.
|
||||
/// </summary>
|
||||
/// <param name="inputDescriptionsInfo">The input descriptions info gathered for the current shader.</param>
|
||||
/// <param name="additionalTypes">Any additional <see cref="TypeDeclarationSyntax"/> instances needed by the generated code, if needed.</param>
|
||||
/// <returns>The resulting <see cref="PropertyDeclarationSyntax"/> instance for the <c>InputDescriptions</c> property.</returns>
|
||||
public static PropertyDeclarationSyntax GetSyntax(InputDescriptionsInfo inputDescriptionsInfo, out TypeDeclarationSyntax[] additionalTypes)
|
||||
{
|
||||
ExpressionSyntax memoryExpression;
|
||||
|
||||
// If there are no input descriptions, just return a default expression.
|
||||
// Otherwise, declare the shared array and return it from the property.
|
||||
if (inputDescriptionsInfo.InputDescriptions.Length == 0)
|
||||
{
|
||||
memoryExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
|
||||
additionalTypes = Array.Empty<TypeDeclarationSyntax>();
|
||||
}
|
||||
else
|
||||
{
|
||||
memoryExpression = MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("Data"),
|
||||
IdentifierName(nameof(InputDescriptions)));
|
||||
|
||||
additionalTypes = new[] { GetArrayDeclaration(inputDescriptionsInfo) };
|
||||
}
|
||||
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadInputDescriptions<TLoader>(ref TLoader loader)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
PropertyDeclaration(
|
||||
GenericName(Identifier("global::System.ReadOnlyMemory"))
|
||||
.AddTypeArgumentListArguments(IdentifierName("global::ComputeSharp.D2D1.Interop.D2D1InputDescription")),
|
||||
Identifier(nameof(InputDescriptions)))
|
||||
.WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
|
||||
.AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithExpressionBody(ArrowExpressionClause(memoryExpression))
|
||||
.WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the array declaration for the given input descriptions.
|
||||
/// </summary>
|
||||
/// <param name="inputDescriptionsInfo">The input descriptions info gathered for the current shader.</param>
|
||||
/// <returns>The array declaration for the given input descriptions.</returns>
|
||||
private static TypeDeclarationSyntax GetArrayDeclaration(InputDescriptionsInfo inputDescriptionsInfo)
|
||||
{
|
||||
using ImmutableArrayBuilder<ExpressionSyntax> inputDescriptionExpressions = ImmutableArrayBuilder<ExpressionSyntax>.Rent();
|
||||
|
||||
foreach (InputDescription inputDescription in inputDescriptionsInfo.InputDescriptions)
|
||||
{
|
||||
// Create the description expression (excluding level of detail):
|
||||
//
|
||||
// new(<INDEX>, <FILTER>)
|
||||
ImplicitObjectCreationExpressionSyntax inputDescriptionExpression =
|
||||
ImplicitObjectCreationExpression()
|
||||
.AddArgumentListArguments(
|
||||
Argument(LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(inputDescription.Index))),
|
||||
Argument(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("global::ComputeSharp.D2D1.D2D1Filter"),
|
||||
IdentifierName(inputDescription.Filter.ToString()))));
|
||||
|
||||
// Add the level of detail, if needed:
|
||||
//
|
||||
// { LevelOfDetailCount = <LEVEL_OF_DETAIL_COUNT> }
|
||||
if (inputDescription.LevelOfDetailCount != 0)
|
||||
{
|
||||
inputDescriptionExpression =
|
||||
inputDescriptionExpression
|
||||
.WithInitializer(
|
||||
InitializerExpression(SyntaxKind.ObjectInitializerExpression)
|
||||
.AddExpressions(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
IdentifierName("LevelOfDetailCount"),
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(inputDescription.LevelOfDetailCount)))));
|
||||
}
|
||||
|
||||
inputDescriptionExpressions.Add(inputDescriptionExpression);
|
||||
}
|
||||
|
||||
// Declare the singleton property to get the memory instance:
|
||||
//
|
||||
// /// <summary>The singleton <see cref="global::System.ReadOnlyMemory{T}"/> instance for the memory manager.</summary>
|
||||
// public static readonly global::ComputeSharp.D2D1.Interop.D2D1InputDescription[] InputDescriptions = { <INPUT_DESCRIPTIONS> };
|
||||
FieldDeclarationSyntax fieldDeclaration =
|
||||
FieldDeclaration(
|
||||
VariableDeclaration(
|
||||
ArrayType(IdentifierName("global::ComputeSharp.D2D1.Interop.D2D1InputDescription"))
|
||||
.AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(OmittedArraySizeExpression()))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier(nameof(InputDescriptions)))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
InitializerExpression(SyntaxKind.ArrayInitializerExpression)
|
||||
.AddExpressions(inputDescriptionExpressions.ToArray())))))
|
||||
.AddModifiers(
|
||||
Token(SyntaxKind.PublicKeyword),
|
||||
Token(SyntaxKind.StaticKeyword),
|
||||
Token(SyntaxKind.ReadOnlyKeyword))
|
||||
.WithLeadingTrivia(Comment("""/// <summary>The singleton <see cref="global::ComputeSharp.D2D1.Interop.D2D1InputDescription"/> array instance.</summary>"""));
|
||||
|
||||
// Create the container type declaration:
|
||||
//
|
||||
// /// <summary>
|
||||
// /// A container type for input descriptions.
|
||||
// /// </summary>
|
||||
// [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
|
||||
// [global::System.Diagnostics.DebuggerNonUserCode]
|
||||
// [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
|
||||
// file static class Data
|
||||
// {
|
||||
// <FIELD_DECLARATION>
|
||||
// }
|
||||
return
|
||||
ClassDeclaration("Data")
|
||||
.AddModifiers(Token(SyntaxKind.FileKeyword), Token(SyntaxKind.StaticKeyword))
|
||||
.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")))))
|
||||
.AddMembers(fieldDeclaration)
|
||||
.WithLeadingTrivia(
|
||||
Comment("/// <summary>"),
|
||||
Comment("/// A container type for input descriptions."),
|
||||
Comment("/// </summary>"));
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -13,9 +13,9 @@ namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper with all logic to generate the <c>LoadInputDescriptions</c> method.
|
||||
/// A helper with all logic to generate the <c>InputDescriptions</c> property.
|
||||
/// </summary>
|
||||
private static partial class LoadInputDescriptions
|
||||
private static partial class InputDescriptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extracts the input descriptions for the current shader.
|
||||
@@ -47,7 +47,7 @@ partial class ID2D1ShaderGenerator
|
||||
|
||||
_ = attributeData.TryGetNamedArgument("LevelOfDetailCount", out int levelOfDetailCount);
|
||||
|
||||
inputDescriptionsBuilder.Add(new InputDescription((uint)index, filter, levelOfDetailCount));
|
||||
inputDescriptionsBuilder.Add(new InputDescription(index, filter, levelOfDetailCount));
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -82,7 +82,7 @@ partial class ID2D1ShaderGenerator
|
||||
// All input description indices must be unique
|
||||
foreach (InputDescription inputDescription in inputDescriptionsBuilder.WrittenSpan)
|
||||
{
|
||||
ref bool isInputDescriptionIndexUsed = ref selectedInputDescriptionIndices[(int)inputDescription.Index];
|
||||
ref bool isInputDescriptionIndexUsed = ref selectedInputDescriptionIndices[inputDescription.Index];
|
||||
|
||||
if (isInputDescriptionIndexUsed)
|
||||
{
|
||||
+1
-1
@@ -75,7 +75,7 @@ partial class ID2D1ShaderGenerator
|
||||
// Create the MemoryManager<T> declaration:
|
||||
//
|
||||
// /// <summary>
|
||||
// /// <see cref="global::System.Buffers.MemoryManager{T}"/> implementation to get the input types.
|
||||
// /// A <see cref="global::System.Buffers.MemoryManager{T}"/> implementation to get the input types.
|
||||
// /// </summary>
|
||||
// [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
|
||||
// [global::System.Diagnostics.DebuggerNonUserCode]
|
||||
|
||||
-149
@@ -1,149 +0,0 @@
|
||||
using System.Collections.Immutable;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
using ComputeSharp.SourceGeneration.Helpers;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.SourceGenerators;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial class ID2D1ShaderGenerator
|
||||
{
|
||||
/// <inheritoc/>
|
||||
private static partial class LoadInputDescriptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadInputDescriptions</c> method.
|
||||
/// </summary>
|
||||
/// <param name="inputDescriptionsInfo">The input descriptions info gathered for the current shader.</param>
|
||||
/// <returns>The resulting <see cref="MethodDeclarationSyntax"/> instance for the <c>LoadInputDescriptions</c> method.</returns>
|
||||
public static MethodDeclarationSyntax GetSyntax(InputDescriptionsInfo inputDescriptionsInfo)
|
||||
{
|
||||
// This code produces a method declaration as follows:
|
||||
//
|
||||
// readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadInputDescriptions<TLoader>(ref TLoader loader)
|
||||
// {
|
||||
// <BODY>
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(nameof(LoadInputDescriptions)))
|
||||
.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")))
|
||||
.WithBody(Block(GetInputDescriptionsLoadingStatements(inputDescriptionsInfo.InputDescriptions)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a sequence of statements to load the input descriptions for a given shader.
|
||||
/// </summary>
|
||||
/// <param name="inputDescriptions">The array of <see cref="InputDescription"/> values for all available input descriptions.</param>
|
||||
/// <returns>The sequence of <see cref="StatementSyntax"/> instances to load the input descriptions data.</returns>
|
||||
private static ImmutableArray<StatementSyntax> GetInputDescriptionsLoadingStatements(ImmutableArray<InputDescription> inputDescriptions)
|
||||
{
|
||||
// If there are no input descriptions available, just load an empty buffer
|
||||
if (inputDescriptions.IsEmpty)
|
||||
{
|
||||
// loader.LoadInputDescriptions(default);
|
||||
return
|
||||
ImmutableArray.Create<StatementSyntax>(
|
||||
ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("loader"),
|
||||
IdentifierName("LoadInputDescriptions")))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.DefaultLiteralExpression,
|
||||
Token(SyntaxKind.DefaultKeyword))))));
|
||||
}
|
||||
|
||||
using ImmutableArrayBuilder<StatementSyntax> statements = ImmutableArrayBuilder<StatementSyntax>.Rent();
|
||||
|
||||
// The size of the buffer with the input descriptions is the number of input descriptions, times the size of each
|
||||
// input description, which is a struct containing three int-sized fields (index, filter, and level of detail).
|
||||
int inputDescriptionSizeInBytes = inputDescriptions.Length * sizeof(int) * 3;
|
||||
|
||||
// global::System.Span<byte> data = stackalloc byte[<INPUT_DESCRIPTIONS_SIZE>];
|
||||
statements.Add(
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(
|
||||
GenericName(Identifier("global::System.Span"))
|
||||
.AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("data"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
StackAllocArrayCreationExpression(
|
||||
ArrayType(PredefinedType(Token(SyntaxKind.ByteKeyword)))
|
||||
.AddRankSpecifiers(
|
||||
ArrayRankSpecifier(SingletonSeparatedList<ExpressionSyntax>(
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(inputDescriptionSizeInBytes)))))))))));
|
||||
|
||||
// ref byte r0 = ref data[0];
|
||||
statements.Add(
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.ByteKeyword))))
|
||||
.AddVariables(
|
||||
VariableDeclarator(Identifier("r0"))
|
||||
.WithInitializer(EqualsValueClause(
|
||||
RefExpression(
|
||||
ElementAccessExpression(IdentifierName("data"))
|
||||
.AddArgumentListArguments(Argument(
|
||||
LiteralExpression(
|
||||
SyntaxKind.NumericLiteralExpression,
|
||||
Literal(0))))))))));
|
||||
|
||||
int offset = 0;
|
||||
|
||||
// Generate loading statements for each input description
|
||||
foreach (InputDescription inputDescription in inputDescriptions)
|
||||
{
|
||||
// Write the index of the current input description:
|
||||
//
|
||||
// global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint)<OFFSET>)) = <INDEX>;
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){offset}))"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)inputDescription.Index)))));
|
||||
|
||||
// Write the filter of the current input description:
|
||||
//
|
||||
// global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint)<OFFSET> + 4)) = <FILTER>;
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){offset + 4}))"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)inputDescription.Filter)))));
|
||||
|
||||
// Write the level of detail of the current input description:
|
||||
//
|
||||
// global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint)<OFFSET> + 8)) = <LEVEL_OF_DETAIL>;
|
||||
statements.Add(ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As<byte, uint>(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){offset + 8}))"),
|
||||
LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(inputDescription.LevelOfDetail)))));
|
||||
|
||||
offset += sizeof(int) * 3;
|
||||
}
|
||||
|
||||
// loader.LoadInputDescriptions(data);
|
||||
statements.Add(
|
||||
ExpressionStatement(
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("loader"),
|
||||
IdentifierName("LoadInputDescriptions")))
|
||||
.AddArgumentListArguments(Argument(IdentifierName("data")))));
|
||||
|
||||
return statements.ToImmutable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,8 +131,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
// Get the info for LoadInputDescriptions()
|
||||
LoadInputDescriptions.GetInfo(
|
||||
// Get the info for InputDescriptions
|
||||
InputDescriptions.GetInfo(
|
||||
diagnostics,
|
||||
typeSymbol,
|
||||
out ImmutableArray<InputDescription> inputDescriptions);
|
||||
@@ -400,19 +400,19 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
|
||||
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(GetOutputBuffer)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get the LoadInputDescriptions() info (hierarchy and input descriptions)
|
||||
// Get the InputDescriptions info (hierarchy and input descriptions)
|
||||
IncrementalValuesProvider<((HierarchyInfo Hierarchy, InputDescriptionsInfo InputDescriptions) Info, bool CanUseSkipLocalsInit)> inputDescriptionsInfo =
|
||||
shaderInfoWithErrors
|
||||
.Select(static (item, _) => (item.Hierarchy, item.InputDescriptions))
|
||||
.Combine(canUseSkipLocalsInit);
|
||||
|
||||
// Generate the LoadInputDescriptions() methods
|
||||
// Generate the InputDescriptions properties
|
||||
context.RegisterSourceOutput(inputDescriptionsInfo, static (context, item) =>
|
||||
{
|
||||
MethodDeclarationSyntax loadInputDescriptionsMethod = LoadInputDescriptions.GetSyntax(item.Info.InputDescriptions);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Info.Hierarchy, loadInputDescriptionsMethod, item.CanUseSkipLocalsInit);
|
||||
PropertyDeclarationSyntax inputDescriptionsProperty = InputDescriptions.GetSyntax(item.Info.InputDescriptions, out TypeDeclarationSyntax[] additionalTypes);
|
||||
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Info.Hierarchy, inputDescriptionsProperty, item.CanUseSkipLocalsInit, additionalMemberDeclarations: additionalTypes);
|
||||
|
||||
context.AddSource($"{item.Info.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadInputDescriptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
context.AddSource($"{item.Info.Hierarchy.FullyQualifiedMetadataName}.{nameof(InputDescriptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
|
||||
});
|
||||
|
||||
// Get the GetPixelOptions() info (hierarchy and pixel options)
|
||||
|
||||
@@ -5,5 +5,5 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
|
||||
/// </summary>
|
||||
/// <param name="Index">The index of the input resource the description is for.</param>
|
||||
/// <param name="Filter">The input filter to use.</param>
|
||||
/// <param name="LevelOfDetail">The level of detail to use.</param>
|
||||
internal sealed record InputDescription(uint Index, D2D1Filter Filter, int LevelOfDetail);
|
||||
/// <param name="LevelOfDetailCount">The level of detail to use.</param>
|
||||
internal sealed record InputDescription(int Index, D2D1Filter Filter, int LevelOfDetailCount);
|
||||
@@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ComputeSharp.D2D1.__Internals;
|
||||
|
||||
/// <summary>
|
||||
/// A base <see langword="interface"/> representing a loader for input descriptions in a D2D1 shader.
|
||||
/// </summary>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This interface is not intended to be used directly by user code")]
|
||||
public interface ID2D1InputDescriptionsLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the available input descriptions for the shader.
|
||||
/// </summary>
|
||||
/// <param name="data">The sequence of serialized input descriptions.</param>
|
||||
void LoadInputDescriptions(ReadOnlySpan<byte> data);
|
||||
}
|
||||
@@ -85,14 +85,11 @@ public interface ID2D1Shader
|
||||
ReadOnlyMemory<D2D1PixelShaderInputType> InputTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads the input descriptions for the shader, if any.
|
||||
/// Gets the input descriptions for the current shader.
|
||||
/// </summary>
|
||||
/// <typeparam name="TLoader">The type of input descriptions loader being used.</typeparam>
|
||||
/// <param name="loader">The <typeparamref name="TLoader"/> instance to use to load the input descriptions.</param>
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
[Obsolete("This method is not intended to be used directly by user code")]
|
||||
void LoadInputDescriptions<TLoader>(ref TLoader loader)
|
||||
where TLoader : struct, ID2D1InputDescriptionsLoader;
|
||||
ReadOnlyMemory<D2D1InputDescription> InputDescriptions { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Loads the resource texture descriptions for the shader, if any.
|
||||
|
||||
@@ -33,6 +33,17 @@ public readonly struct D2D1InputDescription
|
||||
/// </summary>
|
||||
private readonly int levelOfDetailCount;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1InputDescription"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the resource the description belongs to.</param>
|
||||
/// <param name="filter">The type of filter to apply to the input texture.</param>
|
||||
public D2D1InputDescription(int index, D2D1Filter filter)
|
||||
{
|
||||
this.index = index;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the resource the description belongs to.
|
||||
/// </summary>
|
||||
@@ -46,5 +57,9 @@ public readonly struct D2D1InputDescription
|
||||
/// <summary>
|
||||
/// Gets the mip level to retrieve from the upstream transform, if specified.
|
||||
/// </summary>
|
||||
public int LevelOfDetailCount => this.levelOfDetailCount;
|
||||
public int LevelOfDetailCount
|
||||
{
|
||||
get => this.levelOfDetailCount;
|
||||
init => this.levelOfDetailCount = value;
|
||||
}
|
||||
}
|
||||
@@ -279,13 +279,9 @@ public static class D2D1PixelShader
|
||||
public static ReadOnlyMemory<D2D1InputDescription> GetInputDescriptions<T>()
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
D2D1ByteArrayInputDescriptionsLoader inputDescriptionsLoader = default;
|
||||
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.LoadInputDescriptions(ref inputDescriptionsLoader);
|
||||
|
||||
return inputDescriptionsLoader.GetResultingInputDescriptions();
|
||||
return shader.InputDescriptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Loaders;
|
||||
|
||||
/// <summary>
|
||||
/// An input descriptions loader for D2D1 pixel shaders.
|
||||
/// </summary>
|
||||
internal struct D2D1ByteArrayInputDescriptionsLoader : ID2D1InputDescriptionsLoader
|
||||
{
|
||||
/// <summary>
|
||||
/// The resulting <see cref="D2D1InputDescription"/> array.
|
||||
/// </summary>
|
||||
private D2D1InputDescription[]? inputDescriptions;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resulting input descriptions.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="D2D1InputDescription"/> array with the available input descriptions.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly D2D1InputDescription[] GetResultingInputDescriptions()
|
||||
{
|
||||
return this.inputDescriptions!;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ID2D1InputDescriptionsLoader.LoadInputDescriptions(ReadOnlySpan<byte> data)
|
||||
{
|
||||
this.inputDescriptions = MemoryMarshal.Cast<byte, D2D1InputDescription>(data).ToArray();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする