diff --git a/src/ComputeSharp.D2D1.WinUI/Extensions/ID2D1EffectExtensions.cs b/src/ComputeSharp.D2D1.WinUI/Extensions/ID2D1EffectExtensions.cs index 28fa310d..17ed5183 100644 --- a/src/ComputeSharp.D2D1.WinUI/Extensions/ID2D1EffectExtensions.cs +++ b/src/ComputeSharp.D2D1.WinUI/Extensions/ID2D1EffectExtensions.cs @@ -47,7 +47,7 @@ internal static unsafe class ID2D1EffectExtensions dataSize: (uint)constantBufferSize).Assert(); } - T shader = D2D1PixelShader.CreateFromConstantBuffer(buffer); + T shader = T.CreateFromConstantBuffer(buffer); ArrayPool.Shared.Return(buffer); diff --git a/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1PixelShaderDescriptor{T}.cs b/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1PixelShaderDescriptor{T}.cs index fd010abc..8dfddd6e 100644 --- a/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1PixelShaderDescriptor{T}.cs +++ b/src/ComputeSharp.D2D1/Interfaces/Descriptors/ID2D1PixelShaderDescriptor{T}.cs @@ -130,7 +130,9 @@ public interface ID2D1PixelShaderDescriptor /// Creates a new shader instance from a constant buffer. /// /// The input constant buffer to read. + /// The resulting instance. /// The input buffer must be retrieved from . + /// Thrown if is not large enough for the current shader type. static abstract T CreateFromConstantBuffer(ReadOnlySpan buffer); /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index b5d8b4c8..481d9791 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -441,17 +441,11 @@ public static class D2D1PixelShader /// The type of D2D1 pixel shader value to create. /// The input with the constant buffer data. /// The resulting instance. - /// Thrown if is not large enough to contain the constant buffer. + /// Thrown if is not large enough for the current shader type. public static T CreateFromConstantBuffer(ReadOnlySpan span) where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor { - if (!TryCreateFromConstantBuffer(span, out T shader)) - { - default(ArgumentException).Throw(nameof(span)); - } - - return shader; - + return T.CreateFromConstantBuffer(span); } /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs index efd78524..a17e28b4 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs @@ -176,7 +176,7 @@ public static unsafe class D2D1PixelShaderEffect d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager14].setFunction = &PixelShaderEffect.SetResourceTextureManager14Impl; d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager15].setFunction = &PixelShaderEffect.SetResourceTextureManager15Impl; - fixed (Guid* pGuid = &GetEffectId()) + fixed (Guid* pGuid = &T.EffectId) { // Register the effect ((ID2D1Factory1*)d2D1Factory1)->RegisterEffectFromString( @@ -187,7 +187,7 @@ public static unsafe class D2D1PixelShaderEffect effectFactory: PixelShaderEffect.Globals.Instance.Factory).Assert(); } - effectId = GetEffectId(); + effectId = T.EffectId; } } @@ -383,7 +383,7 @@ public static unsafe class D2D1PixelShaderEffect writer.Dispose(); // Extract the effect id (the same that was encoded in the registration blob) - effectId = GetEffectId(); + effectId = T.EffectId; return registrationBlob; } @@ -407,7 +407,7 @@ public static unsafe class D2D1PixelShaderEffect default(ArgumentNullException).ThrowIfNull(d2D1DeviceContext); default(ArgumentNullException).ThrowIfNull(d2D1Effect); - fixed (Guid* pGuid = &GetEffectId()) + fixed (Guid* pGuid = &T.EffectId) { ((ID2D1DeviceContext*)d2D1DeviceContext)->CreateEffect( effectId: pGuid, diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs index f367e736..a297056a 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1PixelShaderTests.cs @@ -738,7 +738,7 @@ namespace ComputeSharp.D2D1.Tests [DataRow(0)] [DataRow(4)] [DataRow(27)] - [ExpectedException(typeof(ArgumentException))] + [ExpectedException(typeof(ArgumentOutOfRangeException))] public void GetConstantBuffer_BufferTooShort(int size) { byte[] buffer = new byte[size];