diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index 6d523ad1..20cbbcce 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -295,6 +295,19 @@ public static class D2D1PixelShader return shader.InputCount; } + /// + /// Gets the number of resource textures for a D2D1 pixel shader. + /// + /// The type of D2D1 pixel shader to get the resource texture count for. + /// The number of resource texture for the D2D1 pixel shader of type . + public static int GetResourceTextureCount() + where T : unmanaged, ID2D1PixelShader + { + Unsafe.SkipInit(out T shader); + + return shader.ResourceTextureCount; + } + /// /// Gets the input types for a D2D1 pixel shader. /// diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs index e8405d0a..5dfd2639 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs @@ -235,6 +235,43 @@ public partial class D2D1PixelShaderTests Assert.AreEqual(span[3].Dimensions, 2); } + [TestMethod] + public unsafe void GetResourceTextureCount_IsCorrect() + { + Assert.AreEqual(0, D2D1PixelShader.GetResourceTextureCount()); + Assert.AreEqual(1, D2D1PixelShader.GetResourceTextureCount()); + Assert.AreEqual(4, D2D1PixelShader.GetResourceTextureCount()); + } + + [D2DInputCount(4)] + [D2DInputSimple(0)] + [D2DInputSimple(2)] + [D2DInputComplex(1)] + [D2DInputComplex(3)] + [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + [AutoConstructor] + partial struct ShaderWithoutResourceTextures : ID2D1PixelShader + { + public Float4 Execute() + { + return 0; + } + } + + [D2DInputCount(0)] + [D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] + [AutoConstructor] + partial struct ShaderWithJustOneResourceTextures : ID2D1PixelShader + { + [D2DResourceTextureIndex(0)] + D2D1ResourceTexture1D myTexture; + + public Float4 Execute() + { + return this.myTexture.Sample(0); + } + } + [D2DInputCount(4)] [D2DInputSimple(0)] [D2DInputSimple(2)]