From b156b3c98a87e8636a328f4001a27a0b8aaae7fb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 27 Apr 2022 23:59:25 +0200 Subject: [PATCH] Add D2D1InteropServices.GetPixelShaderInputCount() API --- .../Shaders/Interop/D2D1InteropServices.cs | 13 +++++++++++++ .../D2D1InteropServicesTests.cs | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.cs index 957cacd7..0ee94a6b 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.cs @@ -79,6 +79,19 @@ public static unsafe class D2D1InteropServices return new ReadOnlySpan(bytecodePtr, bytecodeSize).ToArray(); } + /// + /// Gets the number of inputs from an input D2D1 pixel shader. + /// + /// The type of D2D1 pixel shader to get the input count for. + /// The number of inputs for the D2D1 pixel shader of type . + public static uint GetPixelShaderInputCount() + where T : unmanaged, ID2D1PixelShader + { + Unsafe.SkipInit(out T shader); + + return shader.GetInputCount(); + } + /// /// Gets the constant buffer from an input D2D1 pixel shader. /// diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs new file mode 100644 index 00000000..0e8ef2d8 --- /dev/null +++ b/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs @@ -0,0 +1,18 @@ +using ComputeSharp.D2D1.Interop; +using ComputeSharp.D2D1.Tests.Effects; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.D2D1.Tests; + +[TestClass] +[TestCategory("D2D1InteropServices")] +public class D2D1InteropServicesTests +{ + [TestMethod] + public unsafe void GetInputCount() + { + Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount(), 1u); + Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount(), 1u); + Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount(), 0u); + } +} \ No newline at end of file