diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index 1082ba7a..b0ec5b48 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -1,8 +1,8 @@ using System; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Helpers; -using ComputeSharp.D2D1.Shaders.Dispatching; using ComputeSharp.D2D1.Shaders.Interop.Buffers; +using ComputeSharp.D2D1.Shaders.Loaders; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -113,6 +113,23 @@ public static class D2D1PixelShader return (D2D1PixelShaderInputType)shader.GetInputType((uint)index); } + /// + /// Gets the available input descriptions for a D2D1 pixel shader. + /// + /// The type of D2D1 pixel shader to get the input descriptions for. + /// A with the available input descriptions for the shader. + public static ReadOnlyMemory GetInputDescriptions() + where T : unmanaged, ID2D1PixelShader + { + D2D1ByteArrayInputDescriptionsLoader inputDescriptionsLoader = default; + + Unsafe.SkipInit(out T shader); + + shader.LoadInputDescriptions(ref inputDescriptionsLoader); + + return inputDescriptionsLoader.GetResultingInputDescriptions(); + } + /// /// Gets the buffer precision for the output buffer of a D2D1 pixel shader. /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs index 3600b928..3c1c813e 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs @@ -8,8 +8,8 @@ using System.Text; using ComputeSharp.D2D1.Extensions; using ComputeSharp.D2D1.Helpers; using ComputeSharp.D2D1.Interop.Effects; -using ComputeSharp.D2D1.Shaders.Dispatching; using ComputeSharp.D2D1.Shaders.Interop.Buffers; +using ComputeSharp.D2D1.Shaders.Loaders; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs index c70d4d1e..f82b577c 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.D2D1.Extensions; -using ComputeSharp.D2D1.Shaders.Dispatching; +using ComputeSharp.D2D1.Shaders.Loaders; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; diff --git a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1ByteArrayDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayDispatchDataLoader.cs similarity index 82% rename from src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1ByteArrayDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayDispatchDataLoader.cs index 2b00632a..9e2d13b7 100644 --- a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1ByteArrayDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayDispatchDataLoader.cs @@ -6,7 +6,7 @@ using TerraFX.Interop.DirectX; #pragma warning disable CS0618 -namespace ComputeSharp.D2D1.Shaders.Dispatching; +namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders dispatched via . @@ -14,7 +14,7 @@ namespace ComputeSharp.D2D1.Shaders.Dispatching; internal struct D2D1ByteArrayDispatchDataLoader : ID2D1DispatchDataLoader { /// - /// The object in use. + /// The resulting array with the constant buffer to use. /// private byte[]? data; @@ -29,7 +29,7 @@ internal struct D2D1ByteArrayDispatchDataLoader : ID2D1DispatchDataLoader } /// - public void LoadConstantBuffer(ReadOnlySpan data) + void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) { this.data = MemoryMarshal.AsBytes(data).ToArray(); } diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayInputDescriptionsLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayInputDescriptionsLoader.cs new file mode 100644 index 00000000..f3a65c2f --- /dev/null +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ByteArrayInputDescriptionsLoader.cs @@ -0,0 +1,37 @@ +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using ComputeSharp.D2D1.__Internals; +using ComputeSharp.D2D1.Interop; +using TerraFX.Interop.DirectX; + +#pragma warning disable CS0618 + +namespace ComputeSharp.D2D1.Shaders.Loaders; + +/// +/// An input descriptions loader for D2D1 pixel shaders. +/// +internal struct D2D1ByteArrayInputDescriptionsLoader : ID2D1InputDescriptionsLoader +{ + /// + /// The object in use. + /// + private D2D1InputDescription[]? inputDescriptions; + + /// + /// Gets the resulting input descriptions. + /// + /// A array with the available input descriptions. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public D2D1InputDescription[] GetResultingInputDescriptions() + { + return this.inputDescriptions!; + } + + /// + void ID2D1InputDescriptionsLoader.LoadInputDescriptions(ReadOnlySpan data) + { + this.inputDescriptions = MemoryMarshal.Cast(data).ToArray(); + } +} diff --git a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1DrawInfoDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoDispatchDataLoader.cs similarity index 90% rename from src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1DrawInfoDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoDispatchDataLoader.cs index be47d04c..65142fcd 100644 --- a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1DrawInfoDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1DrawInfoDispatchDataLoader.cs @@ -6,7 +6,7 @@ using TerraFX.Interop.DirectX; #pragma warning disable CS0618 -namespace ComputeSharp.D2D1.Shaders.Dispatching; +namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders dispatched via . @@ -29,7 +29,7 @@ internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDa } /// - public void LoadConstantBuffer(ReadOnlySpan data) + void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) { this.d2D1DrawInfo->SetPixelShaderConstantBuffer( buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)), diff --git a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1EffectDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectDispatchDataLoader.cs similarity index 91% rename from src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1EffectDispatchDataLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectDispatchDataLoader.cs index 69b06622..ce3b0385 100644 --- a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1EffectDispatchDataLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1EffectDispatchDataLoader.cs @@ -7,7 +7,7 @@ using TerraFX.Interop.DirectX; #pragma warning disable CS0618 -namespace ComputeSharp.D2D1.Shaders.Dispatching; +namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A data loader for D2D1 pixel shaders dispatched via . @@ -30,7 +30,7 @@ internal readonly unsafe struct D2D1EffectDispatchDataLoader : ID2D1DispatchData } /// - public void LoadConstantBuffer(ReadOnlySpan data) + void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data) { if (data.IsEmpty) { diff --git a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1ShaderBytecodeLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ShaderBytecodeLoader.cs similarity index 91% rename from src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1ShaderBytecodeLoader.cs rename to src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ShaderBytecodeLoader.cs index 0d0da779..4db265a3 100644 --- a/src/ComputeSharp.D2D1/Shaders/Dispatching/D2D1ShaderBytecodeLoader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1ShaderBytecodeLoader.cs @@ -9,7 +9,7 @@ using TerraFX.Interop.Windows; #pragma warning disable CS0618 -namespace ComputeSharp.D2D1.Shaders.Dispatching; +namespace ComputeSharp.D2D1.Shaders.Loaders; /// /// A bytecode loader for D2D1 shaders. @@ -46,7 +46,8 @@ internal unsafe struct D2D1ShaderBytecodeLoader : ID2D1BytecodeLoader } /// - public unsafe void LoadDynamicBytecode(IntPtr handle) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + unsafe void ID2D1BytecodeLoader.LoadDynamicBytecode(IntPtr handle) { if (this.embeddedBytecodePtr is not null || this.d3DBlob.Get() is not null) @@ -64,7 +65,7 @@ internal unsafe struct D2D1ShaderBytecodeLoader : ID2D1BytecodeLoader /// [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void LoadEmbeddedBytecode(ReadOnlySpan bytecode) + void ID2D1BytecodeLoader.LoadEmbeddedBytecode(ReadOnlySpan bytecode) { if (this.embeddedBytecodePtr is not null || this.d3DBlob.Get() is not null)