using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Shaders.Loaders;
///
/// A data loader for D2D1 pixel shaders dispatched via .
///
internal readonly unsafe struct D2D1EffectDispatchDataLoader : ID2D1DispatchDataLoader
{
///
/// The object in use.
///
private readonly ID2D1Effect* d2D1Effect;
///
/// Creates a new instance.
///
/// The object to use.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1EffectDispatchDataLoader(ID2D1Effect* d2D1Effect)
{
this.d2D1Effect = d2D1Effect;
}
///
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan data)
{
if (data.IsEmpty)
{
return;
}
this.d2D1Effect->SetValue(
index: 0,
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BLOB,
data: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
dataSize: (uint)data.Length).Assert();
}
}