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 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();
}
}
}