diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs similarity index 87% rename from src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.cs rename to src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index d4dbe25c..b7c80bb6 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -13,7 +13,7 @@ namespace ComputeSharp.D2D1.Interop; /// /// Provides methods to interop with D2D1 APIs and compile shaders or extract their constant buffer data. /// -public static unsafe class D2D1InteropServices +public static class D2D1PixelShader { /// /// Loads the bytecode from an input D2D1 pixel shader. @@ -27,10 +27,10 @@ public static unsafe class D2D1InteropServices /// If the shader was compiled at runtime, the returned instance will wrap a array with the bytecode. /// /// - public static ReadOnlyMemory LoadPixelShaderBytecode() + public static ReadOnlyMemory LoadBytecode() where T : unmanaged, ID2D1PixelShader { - return LoadOrCompilePixelShaderBytecode(null); + return LoadOrCompileBytecode(null); } /// @@ -43,10 +43,10 @@ public static unsafe class D2D1InteropServices /// If the input shader was precompiled, the returned instance will wrap a pinned memory buffer (from the PE section). /// If the shader was compiled at runtime, the returned instance will wrap a array with the bytecode. /// - public static ReadOnlyMemory LoadPixelShaderBytecode(D2D1ShaderProfile shaderProfile) + public static ReadOnlyMemory LoadBytecode(D2D1ShaderProfile shaderProfile) where T : unmanaged, ID2D1PixelShader { - return LoadOrCompilePixelShaderBytecode(shaderProfile); + return LoadOrCompileBytecode(shaderProfile); } /// @@ -56,7 +56,7 @@ public static unsafe class D2D1InteropServices /// The shader profile to use to get the shader bytecode. /// A instance with the resulting shader bytecode. /// Thrown if the input shader has not been precompiled. - private static ReadOnlyMemory LoadOrCompilePixelShaderBytecode(D2D1ShaderProfile? shaderProfile) + private static unsafe ReadOnlyMemory LoadOrCompileBytecode(D2D1ShaderProfile? shaderProfile) where T : unmanaged, ID2D1PixelShader { D2D1ShaderBytecodeLoader bytecodeLoader = default; @@ -85,7 +85,7 @@ public static unsafe class D2D1InteropServices /// /// 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() + public static uint GetInputCount() where T : unmanaged, ID2D1PixelShader { Unsafe.SkipInit(out T shader); @@ -100,7 +100,7 @@ public static unsafe class D2D1InteropServices /// The index of the input to get the type for. /// The type of the input of the target D2D1 pixel shader at the specified index. /// Thrown if is not in range for the available inputs for the shader type. - public static D2D1PixelShaderInputType GetPixelShaderInputType(uint index) + public static D2D1PixelShaderInputType GetInputType(uint index) where T : unmanaged, ID2D1PixelShader { Unsafe.SkipInit(out T shader); @@ -121,8 +121,8 @@ public static unsafe class D2D1InteropServices /// A instance with the pixel shader constant buffer. /// /// This method will allocate a buffer every time it is invoked. - /// For a zero-allocation alternative, use . - public static ReadOnlyMemory GetPixelShaderConstantBuffer(in T shader) + /// For a zero-allocation alternative, use . + public static ReadOnlyMemory GetConstantBuffer(in T shader) where T : unmanaged, ID2D1PixelShader { D2D1ByteArrayDispatchDataLoader dataLoader = default; @@ -139,7 +139,7 @@ public static unsafe class D2D1InteropServices /// The input D2D1 pixel shader to set the contant buffer for. /// A pointer to the ID2D1DrawInfo instance to use. /// For more info, see . - public static void SetPixelShaderConstantBufferForD2D1DrawInfo(in T shader, void* d2D1DrawInfo) + public static unsafe void SetConstantBufferForD2D1DrawInfo(in T shader, void* d2D1DrawInfo) where T : unmanaged, ID2D1PixelShader { D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs index e2be11a9..ed6f8f1b 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.For{T}.cs @@ -89,8 +89,8 @@ internal unsafe partial struct PixelShaderEffect { // Load all shader properties Guid guid = typeof(T).GUID; - int inputCount = (int)D2D1InteropServices.GetPixelShaderInputCount(); - ReadOnlyMemory buffer = D2D1InteropServices.LoadPixelShaderBytecode(); + int inputCount = (int)D2D1PixelShader.GetInputCount(); + ReadOnlyMemory buffer = D2D1PixelShader.LoadBytecode(); byte* typeAssociatedMemory = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For), buffer.Length); // Copy the bytecode to the target buffer diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs index 9916fff0..14cd09c4 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1InteropServicesTests.cs @@ -11,21 +11,21 @@ public partial class D2D1InteropServicesTests [TestMethod] public unsafe void GetInputCount() { - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount(), 1u); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount(), 1u); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount(), 0u); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputCount(), 7u); + Assert.AreEqual(D2D1PixelShader.GetInputCount(), 1u); + Assert.AreEqual(D2D1PixelShader.GetInputCount(), 1u); + Assert.AreEqual(D2D1PixelShader.GetInputCount(), 0u); + Assert.AreEqual(D2D1PixelShader.GetInputCount(), 7u); } [TestMethod] public unsafe void GetInputType() { - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType(0), D2D1PixelShaderInputType.Simple); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType(1), D2D1PixelShaderInputType.Complex); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType(2), D2D1PixelShaderInputType.Simple); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType(3), D2D1PixelShaderInputType.Complex); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType(4), D2D1PixelShaderInputType.Complex); - Assert.AreEqual(D2D1InteropServices.GetPixelShaderInputType(5), D2D1PixelShaderInputType.Complex); + Assert.AreEqual(D2D1PixelShader.GetInputType(0), D2D1PixelShaderInputType.Simple); + Assert.AreEqual(D2D1PixelShader.GetInputType(1), D2D1PixelShaderInputType.Complex); + Assert.AreEqual(D2D1PixelShader.GetInputType(2), D2D1PixelShaderInputType.Simple); + Assert.AreEqual(D2D1PixelShader.GetInputType(3), D2D1PixelShaderInputType.Complex); + Assert.AreEqual(D2D1PixelShader.GetInputType(4), D2D1PixelShaderInputType.Complex); + Assert.AreEqual(D2D1PixelShader.GetInputType(5), D2D1PixelShaderInputType.Complex); } [D2DInputCount(7)]