diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
index 67129912..09697080 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj
@@ -80,12 +80,12 @@
-
+
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs
index 08312b7a..53127aed 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputDescriptionsProperty.Syntax.cs
@@ -46,10 +46,7 @@ partial class ID2D1ShaderGenerator
// This code produces a method declaration as follows:
//
- // readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadInputDescriptions(ref TLoader loader)
- // {
- //
- // }
+ // readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputDescriptions => ;
return
PropertyDeclaration(
GenericName(Identifier("global::System.ReadOnlyMemory"))
@@ -110,7 +107,7 @@ partial class ID2D1ShaderGenerator
// Declare the singleton property to get the memory instance:
//
- // /// The singleton instance for the memory manager.
+ // /// The singleton array instance.
// public static readonly global::ComputeSharp.D2D1.Interop.D2D1InputDescription[] InputDescriptions = { };
FieldDeclarationSyntax fieldDeclaration =
FieldDeclaration(
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.Syntax.cs
deleted file mode 100644
index 805f7726..00000000
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.Syntax.cs
+++ /dev/null
@@ -1,140 +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;
-
-///
-partial class ID2D1ShaderGenerator
-{
- ///
- private static partial class LoadResourceTextureDescriptions
- {
- ///
- /// Creates a instance for the LoadResourceTextureDescriptions method.
- ///
- /// The resource texture descriptions info gathered for the current shader.
- /// The resulting instance for the LoadResourceTextureDescriptions method.
- public static MethodDeclarationSyntax GetSyntax(ResourceTextureDescriptionsInfo resourceTextureDescriptionsInfo)
- {
- // This code produces a method declaration as follows:
- //
- // readonly void global::ComputeSharp.D2D1.__Internals.ID2D1Shader.LoadResourceTextureDescriptions(ref TLoader loader)
- // {
- //
- // }
- return
- MethodDeclaration(PredefinedType(Token(SyntaxKind.VoidKeyword)), Identifier(nameof(LoadResourceTextureDescriptions)))
- .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(resourceTextureDescriptionsInfo.ResourceTextureDescriptions)));
- }
-
- ///
- /// Gets a sequence of statements to load the resource texture descriptions for a given shader.
- ///
- /// The array of values for all available resource texture descriptions.
- /// The sequence of instances to load the resource texture descriptions data.
- private static ImmutableArray GetInputDescriptionsLoadingStatements(ImmutableArray resourceTextureDescriptionsInfo)
- {
- // If there are no resource texture descriptions available, just load an empty buffer
- if (resourceTextureDescriptionsInfo.IsEmpty)
- {
- // loader.LoadResourceTextureDescriptions(default);
- return
- ImmutableArray.Create(
- ExpressionStatement(
- InvocationExpression(
- MemberAccessExpression(
- SyntaxKind.SimpleMemberAccessExpression,
- IdentifierName("loader"),
- IdentifierName("LoadResourceTextureDescriptions")))
- .AddArgumentListArguments(Argument(
- LiteralExpression(
- SyntaxKind.DefaultLiteralExpression,
- Token(SyntaxKind.DefaultKeyword))))));
- }
-
- using ImmutableArrayBuilder statements = ImmutableArrayBuilder.Rent();
-
- // The size of the buffer with the resource texture descriptions is the number of resurce textures descriptions,
- // times the size of each input description, which is a struct containing two int-sized fields (index and rank).
- int resourceTextureDescriptionSizeInBytes = resourceTextureDescriptionsInfo.Length * sizeof(int) * 2;
-
- // global::System.Span data = stackalloc byte[];
- 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(
- LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(resourceTextureDescriptionSizeInBytes)))))))))));
-
- // 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 resource texture description
- foreach (ResourceTextureDescription resourceTextureDescription in resourceTextureDescriptionsInfo)
- {
- // Write the index of the current resource texture description:
- //
- // global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint))) = ;
- statements.Add(ExpressionStatement(
- AssignmentExpression(
- SyntaxKind.SimpleAssignmentExpression,
- ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){offset}))"),
- LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)resourceTextureDescription.Index)))));
-
- // Write the rank of the current resource texture description:
- //
- // global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint) + 4)) = ;
- statements.Add(ExpressionStatement(
- AssignmentExpression(
- SyntaxKind.SimpleAssignmentExpression,
- ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){offset + 4}))"),
- LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)resourceTextureDescription.Rank)))));
-
- offset += sizeof(int) * 2;
- }
-
- // loader.LoadInputDescriptions(data);
- statements.Add(
- ExpressionStatement(
- InvocationExpression(
- MemberAccessExpression(
- SyntaxKind.SimpleMemberAccessExpression,
- IdentifierName("loader"),
- IdentifierName("LoadResourceTextureDescriptions")))
- .AddArgumentListArguments(Argument(IdentifierName("data")))));
-
- return statements.ToImmutable();
- }
- }
-}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.Syntax.cs
new file mode 100644
index 00000000..9748945f
--- /dev/null
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.Syntax.cs
@@ -0,0 +1,135 @@
+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;
+
+///
+partial class ID2D1ShaderGenerator
+{
+ ///
+ private static partial class ResourceTextureDescriptions
+ {
+ ///
+ /// Creates a instance for the ResourceTextureDescriptions property.
+ ///
+ /// The resource texture descriptions info gathered for the current shader.
+ /// Any additional instances needed by the generated code, if needed.
+ /// The resulting instance for the ResourceTextureDescriptions property.
+ public static PropertyDeclarationSyntax GetSyntax(ResourceTextureDescriptionsInfo resourceTextureDescriptionsInfo, out TypeDeclarationSyntax[] additionalTypes)
+ {
+ ExpressionSyntax memoryExpression;
+
+ // If there are no resource texture descriptions, just return a default expression.
+ // Otherwise, declare the shared array and return it from the property.
+ if (resourceTextureDescriptionsInfo.ResourceTextureDescriptions.Length == 0)
+ {
+ memoryExpression = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword));
+ additionalTypes = Array.Empty();
+ }
+ else
+ {
+ memoryExpression = MemberAccessExpression(
+ SyntaxKind.SimpleMemberAccessExpression,
+ IdentifierName("Data"),
+ IdentifierName(nameof(ResourceTextureDescriptions)));
+
+ additionalTypes = new[] { GetArrayDeclaration(resourceTextureDescriptionsInfo) };
+ }
+
+ // This code produces a method declaration as follows:
+ //
+ // readonly global::System.ReadOnlyMemory global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ResourceTextureDescriptions => ;
+ return
+ PropertyDeclaration(
+ GenericName(Identifier("global::System.ReadOnlyMemory"))
+ .AddTypeArgumentListArguments(IdentifierName("global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription")),
+ Identifier(nameof(ResourceTextureDescriptions)))
+ .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1.__Internals.{nameof(ID2D1Shader)}")))
+ .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword))
+ .WithExpressionBody(ArrowExpressionClause(memoryExpression))
+ .WithSemicolonToken(Token(SyntaxKind.SemicolonToken));
+ }
+
+ ///
+ /// Gets the array declaration for the given resource texture descriptions.
+ ///
+ /// The resource texture descriptions info gathered for the current shader.
+ /// The array declaration for the given resource texture descriptions.
+ private static TypeDeclarationSyntax GetArrayDeclaration(ResourceTextureDescriptionsInfo resourceTextureDescriptionsInfo)
+ {
+ using ImmutableArrayBuilder resourceTextureDescriptionExpressions = ImmutableArrayBuilder.Rent();
+
+ foreach (ResourceTextureDescription resourceTextureDescription in resourceTextureDescriptionsInfo.ResourceTextureDescriptions)
+ {
+ // Create the description expression:
+ //
+ // new(, )
+ resourceTextureDescriptionExpressions.Add(
+ ImplicitObjectCreationExpression()
+ .AddArgumentListArguments(
+ Argument(LiteralExpression(
+ SyntaxKind.NumericLiteralExpression,
+ Literal(resourceTextureDescription.Index))),
+ Argument(LiteralExpression(
+ SyntaxKind.NumericLiteralExpression,
+ Literal(resourceTextureDescription.Rank)))));
+ }
+
+ // Declare the singleton property to get the memory instance:
+ //
+ // /// The singleton array instance.
+ // public static readonly global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription[] ResourceTextureDescriptions = { };
+ FieldDeclarationSyntax fieldDeclaration =
+ FieldDeclaration(
+ VariableDeclaration(
+ ArrayType(IdentifierName("global::ComputeSharp.D2D1.Interop.D2D1ResourceTextureDescription"))
+ .AddRankSpecifiers(ArrayRankSpecifier(SingletonSeparatedList(OmittedArraySizeExpression()))))
+ .AddVariables(
+ VariableDeclarator(Identifier(nameof(ResourceTextureDescriptions)))
+ .WithInitializer(EqualsValueClause(
+ InitializerExpression(SyntaxKind.ArrayInitializerExpression)
+ .AddExpressions(resourceTextureDescriptionExpressions.ToArray())))))
+ .AddModifiers(
+ Token(SyntaxKind.PublicKeyword),
+ Token(SyntaxKind.StaticKeyword),
+ Token(SyntaxKind.ReadOnlyKeyword))
+ .WithLeadingTrivia(Comment("""/// The singleton array instance."""));
+
+ // Create the container type declaration:
+ //
+ // ///
+ // /// A container type for input descriptions.
+ // ///
+ // [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
+ // [global::System.Diagnostics.DebuggerNonUserCode]
+ // [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
+ // file static class Data
+ // {
+ //
+ // }
+ 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("/// "),
+ Comment("/// A container type for resource texture descriptions."),
+ Comment("/// "));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.cs
similarity index 96%
rename from src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs
rename to src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.cs
index 726f08b4..79dbdce9 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateResourceTextureDescriptionsProperty.cs
@@ -14,9 +14,9 @@ namespace ComputeSharp.D2D1.SourceGenerators;
partial class ID2D1ShaderGenerator
{
///
- /// A helper with all logic to generate the LoadResourceTextureDescriptions method.
+ /// A helper with all logic to generate the ResourceTextureDescriptions property.
///
- private static partial class LoadResourceTextureDescriptions
+ private static partial class ResourceTextureDescriptions
{
///
/// Extracts the resource texture descriptions for the current shader.
@@ -76,7 +76,7 @@ partial class ID2D1ShaderGenerator
{
foreach ((int? index, int rank) in resourceTextureInfos.WrittenSpan)
{
- resourceTextureDescriptionsBuilder.Add(new ResourceTextureDescription((uint)(index ?? 0), (uint)rank));
+ resourceTextureDescriptionsBuilder.Add(new ResourceTextureDescription(index ?? 0, rank));
}
resourceTextureDescriptions = resourceTextureDescriptionsBuilder.ToImmutable();
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
index 93f432e5..a9b53915 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
@@ -100,8 +100,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
out ImmutableArray inputComplexIndices,
out ImmutableArray inputTypes);
- // Get the resource texture info for LoadResourceTextureDescriptions()
- LoadResourceTextureDescriptions.GetInfo(
+ // Get the resource texture info for ResourceTextureDescriptions
+ ResourceTextureDescriptions.GetInfo(
diagnostics,
typeSymbol,
inputCount,
@@ -265,24 +265,24 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
// Generate the InputTypes properties
context.RegisterSourceOutput(inputTypesInfo, static (context, item) =>
{
- MemberDeclarationSyntax inputTypesProperty = InputTypes.GetSyntax(item.InputTypes.InputTypes, out TypeDeclarationSyntax[] additionalTypes);
+ PropertyDeclarationSyntax inputTypesProperty = InputTypes.GetSyntax(item.InputTypes.InputTypes, out TypeDeclarationSyntax[] additionalTypes);
CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, inputTypesProperty, canUseSkipLocalsInit: false, additionalMemberDeclarations: additionalTypes);
context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(InputTypes)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
});
- // Get the LoadResourceTextureDescriptions() info (hierarchy and resource texture descriptions)
+ // Get the ResourceTextureDescriptions info (hierarchy and resource texture descriptions)
IncrementalValuesProvider<(HierarchyInfo Hierarchy, ResourceTextureDescriptionsInfo ResourceTextureDescriptions)> resourceTextureDescriptionsInfo =
shaderInfoWithErrors
.Select(static (item, _) => (item.Hierarchy, item.ResourceTextureDescriptions));
- // Generate the LoadResourceTextureDescriptions() methods
+ // Generate the ResourceTextureDescriptions properties
context.RegisterSourceOutput(resourceTextureDescriptionsInfo, static (context, item) =>
{
- MethodDeclarationSyntax getInputTypeMethod = LoadResourceTextureDescriptions.GetSyntax(item.ResourceTextureDescriptions);
- CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, getInputTypeMethod, canUseSkipLocalsInit: false);
+ PropertyDeclarationSyntax resourceTextureDescriptionsProperty = ResourceTextureDescriptions.GetSyntax(item.ResourceTextureDescriptions, out TypeDeclarationSyntax[] additionalTypes);
+ CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMember(item.Hierarchy, resourceTextureDescriptionsProperty, canUseSkipLocalsInit: false, additionalMemberDeclarations: additionalTypes);
- context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(LoadResourceTextureDescriptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
+ context.AddSource($"{item.Hierarchy.FullyQualifiedMetadataName}.{nameof(ResourceTextureDescriptions)}.g.cs", compilationUnit.GetText(Encoding.UTF8));
});
// Get the info for InitializeFromDispatchData() (hierarchy and dispatch data)
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescription.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescription.cs
index 65eee9b3..c14ed920 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescription.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/ResourceTextureDescription.cs
@@ -5,4 +5,4 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models;
///
/// The index of the resource texture resource the description is for.
/// The rank of the resource texture.
-internal sealed record ResourceTextureDescription(uint Index, uint Rank);
\ No newline at end of file
+internal sealed record ResourceTextureDescription(int Index, int Rank);
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems
index 16149cbc..d83501cc 100644
--- a/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems
+++ b/src/ComputeSharp.D2D1.UI/ComputeSharp.D2D1.UI.projitems
@@ -37,8 +37,6 @@
-
-
diff --git a/src/ComputeSharp.D2D1.UI/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1.UI/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs
deleted file mode 100644
index 86ba37e6..00000000
--- a/src/ComputeSharp.D2D1.UI/Loaders/D2D1ImmutableArrayResourceTextureDescriptionsLoader.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using System;
-using System.Collections.Immutable;
-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;
-
-///
-/// A resource texture index array loader for D2D1 pixel shaders.
-///
-internal struct D2D1ImmutableArrayResourceTextureDescriptionsLoader : ID2D1ResourceTextureDescriptionsLoader
-{
- ///
- /// The array of indices for resource textures for the current effect.
- ///
- private ImmutableArray indices;
-
- ///
- /// Gets the resulting array of indices for resource textures for the current effect.
- ///
- /// An array of indices for resource textures for the current effect.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly ImmutableArray GetResultingIndices()
- {
- return this.indices;
- }
-
- ///
- void ID2D1ResourceTextureDescriptionsLoader.LoadResourceTextureDescriptions(ReadOnlySpan data)
- {
- if (data.IsEmpty)
- {
- this.indices = ImmutableArray.Empty;
- }
- else
- {
- ReadOnlySpan descriptions = MemoryMarshal.Cast(data);
-
- int[] indices = new int[descriptions.Length];
-
- for (int i = 0; i < descriptions.Length; i++)
- {
- indices[i] = descriptions[i].Index;
- }
-
- this.indices = Unsafe.As>(ref indices);
- }
- }
-}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.UI/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1.UI/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs
deleted file mode 100644
index 354f6980..00000000
--- a/src/ComputeSharp.D2D1.UI/Loaders/D2D1IndexBitmaskResourceTextureDescriptionsLoader.cs
+++ /dev/null
@@ -1,43 +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;
-
-///
-/// A resource texture index bitmask loader for D2D1 pixel shaders.
-///
-internal struct D2D1IndexBitmaskResourceTextureDescriptionsLoader : ID2D1ResourceTextureDescriptionsLoader
-{
- ///
- /// The bitmask of indices for resource textures in the target shader.
- ///
- private int indexBitmask;
-
- ///
- /// Gets the resulting bitmask of indices for resource textures in the target shader.
- ///
- /// A bitmask of indices for resource textures in the target shader.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly int GetResultingIndexBitmask()
- {
- return this.indexBitmask;
- }
-
- ///
- void ID2D1ResourceTextureDescriptionsLoader.LoadResourceTextureDescriptions(ReadOnlySpan data)
- {
- int indexBitmask = 0;
-
- foreach (ref readonly D2D1ResourceTextureDescription description in MemoryMarshal.Cast(data))
- {
- indexBitmask |= 1 << description.Index;
- }
-
- this.indexBitmask = indexBitmask;
- }
-}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs
index 1a1630ad..8a7cd163 100644
--- a/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs
+++ b/src/ComputeSharp.D2D1.UI/PixelShaderEffect{T}.Properties.ResourceTextureManagerCollection.cs
@@ -5,7 +5,6 @@ using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Interop;
-using ComputeSharp.D2D1.Shaders.Loaders;
#if WINDOWS_UWP
using ComputeSharp.D2D1.Uwp.Buffers;
using ComputeSharp.D2D1.Uwp.Collections;
@@ -233,13 +232,16 @@ partial class PixelShaderEffect
/// The bitmask of indices for resource textures in the target shader.
private static int GetIndexBitmask()
{
- D2D1IndexBitmaskResourceTextureDescriptionsLoader bitmaskLoader = default;
-
Unsafe.SkipInit(out T shader);
- shader.LoadResourceTextureDescriptions(ref bitmaskLoader);
+ int indexBitmask = 0;
- return bitmaskLoader.GetResultingIndexBitmask();
+ foreach (ref readonly D2D1ResourceTextureDescription description in shader.ResourceTextureDescriptions.Span)
+ {
+ indexBitmask |= 1 << description.Index;
+ }
+
+ return indexBitmask;
}
///
@@ -248,13 +250,24 @@ partial class PixelShaderEffect
/// The collection of valid indices for the current effect.
private static ImmutableArray GetIndices()
{
- D2D1ImmutableArrayResourceTextureDescriptionsLoader indicesLoader = default;
-
Unsafe.SkipInit(out T shader);
- shader.LoadResourceTextureDescriptions(ref indicesLoader);
+ ReadOnlySpan descriptions = shader.ResourceTextureDescriptions.Span;
- return indicesLoader.GetResultingIndices();
+ // Skip the array allocation if there are no resource texture descriptions
+ if (descriptions.IsEmpty)
+ {
+ return ImmutableArray.Empty;
+ }
+
+ int[] indices = new int[descriptions.Length];
+
+ for (int i = 0; i < descriptions.Length; i++)
+ {
+ indices[i] = descriptions[i].Index;
+ }
+
+ return Unsafe.As>(ref indices);
}
}
}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1ResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1ResourceTextureDescriptionsLoader.cs
deleted file mode 100644
index c0dc2ec5..00000000
--- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1ResourceTextureDescriptionsLoader.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System;
-using System.ComponentModel;
-
-namespace ComputeSharp.D2D1.__Internals;
-
-///
-/// A base representing a loader for resource texture descriptions in a D2D1 shader.
-///
-[EditorBrowsable(EditorBrowsableState.Never)]
-[Obsolete("This interface is not intended to be used directly by user code")]
-public interface ID2D1ResourceTextureDescriptionsLoader
-{
- ///
- /// Loads the available resource texture descriptions for the shader.
- ///
- /// The sequence of serialized resource texture descriptions.
- void LoadResourceTextureDescriptions(ReadOnlySpan data);
-}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
index f5ca18f5..ef33bcde 100644
--- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
+++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
@@ -92,14 +92,11 @@ public interface ID2D1Shader
ReadOnlyMemory InputDescriptions { get; }
///
- /// Loads the resource texture descriptions for the shader, if any.
+ /// Gets the resource texture descriptions for the shader.
///
- /// The type of resource texture descriptions loader being used.
- /// The instance to use to load the resource texture descriptions.
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be used directly by user code")]
- void LoadResourceTextureDescriptions(ref TLoader loader)
- where TLoader : struct, ID2D1ResourceTextureDescriptionsLoader;
+ ReadOnlyMemory ResourceTextureDescriptions { get; }
///
/// Gets the output buffer precision and depth for the shader.
diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs
index d968c8c6..c10cb2b1 100644
--- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs
+++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs
@@ -292,13 +292,9 @@ public static class D2D1PixelShader
public static ReadOnlyMemory GetResourceTextureDescriptions()
where T : unmanaged, ID2D1PixelShader
{
- D2D1ByteArrayResourceTextureDescriptionsLoader resourceTextureDescriptionsLoader = default;
-
Unsafe.SkipInit(out T shader);
- shader.LoadResourceTextureDescriptions(ref resourceTextureDescriptionsLoader);
-
- return resourceTextureDescriptionsLoader.GetResultingResourceTextureDescriptions();
+ return shader.ResourceTextureDescriptions;
}
///
diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs
index f842ec65..ce924f0a 100644
--- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs
+++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ResourceTextureDescription.cs
@@ -19,6 +19,17 @@ public readonly struct D2D1ResourceTextureDescription
///
private readonly int dimensions;
+ ///
+ /// Creates a new instance with the specified parameters.
+ ///
+ /// The index of the resource texture the description belongs to.
+ /// The number of dimensions of the resource texture the description belongs to.
+ public D2D1ResourceTextureDescription(int index, int dimensions)
+ {
+ this.index = index;
+ this.dimensions = dimensions;
+ }
+
///
/// Gets the index of the resource texture the description belongs to.
///
diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayResourceTextureDescriptionsLoader.cs
deleted file mode 100644
index 76f75c4a..00000000
--- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayResourceTextureDescriptionsLoader.cs
+++ /dev/null
@@ -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;
-
-///
-/// A resource texture descriptions loader for D2D1 pixel shaders.
-///
-internal struct D2D1ByteArrayResourceTextureDescriptionsLoader : ID2D1ResourceTextureDescriptionsLoader
-{
- ///
- /// The resulting array.
- ///
- private D2D1ResourceTextureDescription[]? resourceTextureDescriptions;
-
- ///
- /// Gets the resulting resource texture descriptions.
- ///
- /// A array with the available resource texture descriptions.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public readonly D2D1ResourceTextureDescription[] GetResultingResourceTextureDescriptions()
- {
- return this.resourceTextureDescriptions!;
- }
-
- ///
- void ID2D1ResourceTextureDescriptionsLoader.LoadResourceTextureDescriptions(ReadOnlySpan data)
- {
- this.resourceTextureDescriptions = MemoryMarshal.Cast(data).ToArray();
- }
-}
\ No newline at end of file
diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs
index 815651b5..689e3890 100644
--- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs
+++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs
@@ -222,16 +222,16 @@ public partial class D2D1PixelShaderTests
ReadOnlySpan span = resourceTextureDescriptions.Span;
- Assert.AreEqual(span[0].Index, 5);
+ Assert.AreEqual(span[0].Index, 4);
Assert.AreEqual(span[0].Dimensions, 1);
- Assert.AreEqual(span[1].Index, 6);
+ Assert.AreEqual(span[1].Index, 5);
Assert.AreEqual(span[1].Dimensions, 2);
- Assert.AreEqual(span[2].Index, 7);
+ Assert.AreEqual(span[2].Index, 6);
Assert.AreEqual(span[2].Dimensions, 3);
- Assert.AreEqual(span[3].Index, 8);
+ Assert.AreEqual(span[3].Index, 7);
Assert.AreEqual(span[3].Dimensions, 2);
}
@@ -246,16 +246,16 @@ public partial class D2D1PixelShaderTests
{
float number;
- [D2DResourceTextureIndex(5)]
+ [D2DResourceTextureIndex(4)]
D2D1ResourceTexture1D myTexture1;
- [D2DResourceTextureIndex(6)]
+ [D2DResourceTextureIndex(5)]
D2D1ResourceTexture2D myTexture2;
- [D2DResourceTextureIndex(7)]
+ [D2DResourceTextureIndex(6)]
D2D1ResourceTexture3D myTexture3;
- [D2DResourceTextureIndex(8)]
+ [D2DResourceTextureIndex(7)]
D2D1ResourceTexture2D myTexture4;
public Float4 Execute()