diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputCountProperty.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputCountProperty.Syntax.cs
deleted file mode 100644
index bbde29e1..00000000
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInputCountProperty.Syntax.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using ComputeSharp.D2D1.SourceGenerators.Models;
-using ComputeSharp.SourceGeneration.Extensions;
-using ComputeSharp.SourceGeneration.Helpers;
-
-namespace ComputeSharp.D2D1.SourceGenerators;
-
-///
-partial class ID2D1ShaderGenerator
-{
- ///
- /// A helper with all logic to generate the InputCount property.
- ///
- private static partial class InputCount
- {
- ///
- /// Writes the InputCount property.
- ///
- /// The input instance with gathered shader info.
- /// The instance to write into.
- public static void WriteSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
- {
- writer.WriteLine("/// ");
- writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
- writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputCount => {info.InputTypes.Length};");
- }
- }
-}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs
new file mode 100644
index 00000000..1bb81881
--- /dev/null
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateNumericProperties.Syntax.cs
@@ -0,0 +1,51 @@
+using ComputeSharp.D2D1.SourceGenerators.Models;
+using ComputeSharp.SourceGeneration.Extensions;
+using ComputeSharp.SourceGeneration.Helpers;
+
+namespace ComputeSharp.D2D1.SourceGenerators;
+
+///
+partial class ID2D1ShaderGenerator
+{
+ ///
+ /// A helper with all logic to generate the available numeric properties.
+ ///
+ private static partial class NumericProperties
+ {
+ ///
+ /// Writes the ConstantBufferSize property.
+ ///
+ /// The input instance with gathered shader info.
+ /// The instance to write into.
+ public static void WriteConstantBufferSizeSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
+ {
+ writer.WriteLine("/// ");
+ writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
+ writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ConstantBufferSize => {info.ConstantBufferSizeInBytes};");
+ }
+
+ ///
+ /// Writes the InputCount property.
+ ///
+ /// The input instance with gathered shader info.
+ /// The instance to write into.
+ public static void WriteInputCountSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
+ {
+ writer.WriteLine("/// ");
+ writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
+ writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.InputCount => {info.InputTypes.Length};");
+ }
+
+ ///
+ /// Writes the ResourceTextureCount property.
+ ///
+ /// The input instance with gathered shader info.
+ /// The instance to write into.
+ public static void WriteResourceTextureCountSyntax(D2D1ShaderInfo info, IndentedTextWriter writer)
+ {
+ writer.WriteLine("/// ");
+ writer.WriteGeneratedAttributes(typeof(ID2D1ShaderGenerator));
+ writer.WriteLine($"readonly int global::ComputeSharp.D2D1.__Internals.ID2D1Shader.ResourceTextureCount => {info.ResourceTextureDescriptions.Length};");
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
index c1a0eb76..ec56e55b 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs
@@ -201,7 +201,9 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator
declaredMembers.Add(EffectMetadata.WriteEffectDescriptionSyntax);
declaredMembers.Add(EffectMetadata.WriteEffectCategorySyntax);
declaredMembers.Add(EffectMetadata.WriteEffectAuthorSyntax);
- declaredMembers.Add(InputCount.WriteSyntax);
+ declaredMembers.Add(NumericProperties.WriteConstantBufferSizeSyntax);
+ declaredMembers.Add(NumericProperties.WriteInputCountSyntax);
+ declaredMembers.Add(NumericProperties.WriteResourceTextureCountSyntax);
declaredMembers.Add(InputTypes.WriteSyntax);
declaredMembers.Add(InputDescriptions.WriteSyntax);
declaredMembers.Add(ResourceTextureDescriptions.WriteSyntax);
diff --git a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
index 3da044d0..4fb00ab4 100644
--- a/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
+++ b/src/ComputeSharp.D2D1/Interfaces/__Internals/ID2D1Shader.cs
@@ -67,6 +67,13 @@ public interface ID2D1Shader
[Obsolete("This method is not intended to be used directly by user code")]
D2D1PixelOptions PixelOptions { get; }
+ ///
+ /// Gets the size in bytes of the constant buffer for the current shader.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("This method is not intended to be used directly by user code")]
+ int ConstantBufferSize { get; }
+
///
/// Gets the number of inputs for the current shader.
///
@@ -74,6 +81,13 @@ public interface ID2D1Shader
[Obsolete("This method is not intended to be used directly by user code")]
int InputCount { get; }
+ ///
+ /// Gets the number of resource textures for the current shader.
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("This method is not intended to be used directly by user code")]
+ int ResourceTextureCount { get; }
+
///
/// Gets the input types for the current shader.
///
diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs
index 473af757..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.
///
@@ -387,7 +400,9 @@ public static class D2D1PixelShader
public static int GetConstantBufferSize()
where T : unmanaged, ID2D1PixelShader
{
- return D2D1BufferSizeDispatchDataLoader.For.ConstantBufferSize;
+ Unsafe.SkipInit(out T shader);
+
+ return shader.ConstantBufferSize;
}
///
diff --git a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1BufferSizeDispatchDataLoader.cs b/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1BufferSizeDispatchDataLoader.cs
deleted file mode 100644
index 24d38972..00000000
--- a/src/ComputeSharp.D2D1/Shaders/Loaders/D2D1BufferSizeDispatchDataLoader.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using System;
-using System.Runtime.CompilerServices;
-using ComputeSharp.D2D1.__Internals;
-using TerraFX.Interop.DirectX;
-
-#pragma warning disable CS0618
-
-namespace ComputeSharp.D2D1.Shaders.Loaders;
-
-///
-/// A data loader for D2D1 pixel shaders dispatched via , to just retrieve the constant buffer size.
-///
-internal unsafe struct D2D1BufferSizeDispatchDataLoader : ID2D1DispatchDataLoader
-{
- ///
- /// The size of the constant buffer.
- ///
- private int size;
-
- ///
- /// Gets the size of the constant buffer.
- ///
- /// The size of the constant buffer.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- private readonly int GetConstantBufferSize()
- {
- return this.size;
- }
-
- ///
- void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data)
- {
- this.size = data.Length;
- }
-
- ///
- /// A helper class caching computed constant buffer sizes for generic shaders.
- ///
- /// The type of D2D1 pixel shader to retrieve info for.
- public static class For
- where T : unmanaged, ID2D1PixelShader
- {
- ///
- /// Gets the constant buffer size for a shader of type .
- ///
- public static int ConstantBufferSize { get; } = GetConstantBufferSize();
-
- ///
- /// Calculates the constant buffer size for a shader of type .
- ///
- /// The constant buffer size for a shader of type .
- private static int GetConstantBufferSize()
- {
- D2D1BufferSizeDispatchDataLoader dataLoader = default;
-
- Unsafe.SkipInit(out T shader);
-
- shader.LoadDispatchData(ref dataLoader);
-
- return dataLoader.GetConstantBufferSize();
- }
- }
-}
\ No newline at end of file
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)]