diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj index 84a806b7..37fac13b 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1.SourceGenerators/ComputeSharp.D2D1.SourceGenerators.csproj @@ -82,6 +82,7 @@ + diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index 3679a1f7..83149d16 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -214,6 +214,23 @@ public static class D2D1PixelShader return inputDescriptionsLoader.GetResultingInputDescriptions(); } + /// + /// Gets the available resource texture descriptions for a D2D1 pixel shader. + /// + /// The type of D2D1 pixel shader to get the resource texture descriptions for. + /// A with the available resource texture descriptions for the shader. + public static ReadOnlyMemory GetResourceTextureDescriptions() + where T : unmanaged, ID2D1PixelShader + { + D2D1ByteArrayResourceTextureDescriptionsLoader resourceTextureDescriptionsLoader = default; + + Unsafe.SkipInit(out T shader); + + shader.LoadResourceTextureDescriptions(ref resourceTextureDescriptionsLoader); + + return resourceTextureDescriptionsLoader.GetResultingResourceTextureDescriptions(); + } + /// /// Gets the buffer precision for the output buffer of a D2D1 pixel shader. /// diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayInputDescriptionsLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayInputDescriptionsLoader.cs index 7c871f1b..dffefa81 100644 --- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayInputDescriptionsLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayInputDescriptionsLoader.cs @@ -3,7 +3,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.D2D1.__Internals; using ComputeSharp.D2D1.Interop; -using TerraFX.Interop.DirectX; #pragma warning disable CS0618 @@ -15,7 +14,7 @@ namespace ComputeSharp.D2D1.Shaders.Loaders; internal struct D2D1ByteArrayInputDescriptionsLoader : ID2D1InputDescriptionsLoader { /// - /// The object in use. + /// The resulting array. /// private D2D1InputDescription[]? inputDescriptions; diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayResourceTextureDescriptionsLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayResourceTextureDescriptionsLoader.cs new file mode 100644 index 00000000..1a375e82 --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayResourceTextureDescriptionsLoader.cs @@ -0,0 +1,36 @@ +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 D2D1ResourceTextureDescription[] GetResultingResourceTextureDescriptions() + { + return this.resourceTextureDescriptions!; + } + + /// + void ID2D1ResourceTextureDescriptionsLoader.LoadResourceTextureDescriptions(ReadOnlySpan data) + { + this.resourceTextureDescriptions = MemoryMarshal.Cast(data).ToArray(); + } +}