Add SetPixelShaderConstantBufferForD2D1DrawInfo API

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:03:13 +02:00
1 親 4f6c0f2d82
コミット 97bfa49d47
2ファイル変更
+67

検索条件に一致するファイルはありません

+38
ファイルの表示
@@ -0,0 +1,38 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.__Internals;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1Interop.Shaders.Dispatching;
/// <summary>
/// A data loader for D2D1 pixel shaders dispatched via <see cref="ID2D1DrawInfo"/>.
/// </summary>
internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDataLoader
{
/// <summary>
/// The <see cref="ID2D1DrawInfo"/> object in use.
/// </summary>
private readonly ID2D1DrawInfo* d2D1DrawInfo;
/// <summary>
/// Creates a new <see cref="D2D1DrawInfoDispatchDataLoader"/> instance.
/// </summary>
/// <param name="d2D1DrawInfo">The <see cref="ID2D1DrawInfo"/> object to use.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1DrawInfoDispatchDataLoader(ID2D1DrawInfo* d2D1DrawInfo)
{
this.d2D1DrawInfo = d2D1DrawInfo;
}
/// <inheritdoc/>
public void LoadConstantBuffer(ReadOnlySpan<uint> data)
{
this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
bufferCount: (uint)data.Length * sizeof(uint));
}
}
+29
ファイルの表示
@@ -0,0 +1,29 @@
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1Interop.__Internals;
using ComputeSharp.D2D1Interop.Shaders.Dispatching;
using TerraFX.Interop.DirectX;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1Interop.Interop;
/// <summary>
/// Provides methods to extract reflection info on compute shaders generated using this library.
/// </summary>
public static class InteropServices
{
/// <summary>
/// Sets the constant buffer from an input D2D1 pixel shader, by calling <c>ID2D1DrawInfo::SetPixelShaderConstantBuffer</c>.
/// </summary>
/// <typeparam name="T">The type of compute shader to retrieve info for.</typeparam>
/// <param name="shader">The input compute shader to retrieve info for.</param>
/// <param name="d2D1DrawInfo">A pointer to the <c>ID2D1DrawInfo</c> instance to use.</param>
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nf-d2d1effectauthor-id2d1drawinfo-setpixelshaderconstantbuffer"/>.</remarks>
public static unsafe void SetPixelShaderConstantBufferForD2D1DrawInfo<T>(in T shader, void* d2D1DrawInfo)
where T : struct, ID2D1Shader
{
D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo);
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
}
}