From 9d3188cec5dc6578693d38809d6857787939d0c5 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 30 Sep 2023 03:31:42 +0200 Subject: [PATCH] Remove unnecessary D2D1BufferSizeDispatchDataLoader type --- .../Shaders/Interop/D2D1PixelShader.cs | 4 +- .../D2D1BufferSizeDispatchDataLoader.cs | 63 ------------------- 2 files changed, 3 insertions(+), 64 deletions(-) delete mode 100644 src/ComputeSharp.D2D1/Shaders/Loaders/D2D1BufferSizeDispatchDataLoader.cs diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs index 473af757..6d523ad1 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShader.cs @@ -387,7 +387,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