Add GetPixelShaderConstantBufferForD2D1DrawInfo API

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:03:13 +02:00
1 親 8afb6ba2e1
コミット 60b966cb74
2ファイル変更
+58 -3

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

+36
ファイルの表示
@@ -0,0 +1,36 @@
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 struct D2D1ByteArrayDispatchDataLoader : ID2D1DispatchDataLoader
{
/// <summary>
/// The <see cref="ID2D1DrawInfo"/> object in use.
/// </summary>
private byte[]? data;
/// <summary>
/// Gets the resulting pixel shader constant buffer.
/// </summary>
/// <remarks>A <see cref="byte"/> array with the constant buffer for the current shader.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public byte[] GetResultingDispatchData()
{
return this.data!;
}
/// <inheritdoc/>
public void LoadConstantBuffer(ReadOnlySpan<uint> data)
{
this.data = MemoryMarshal.AsBytes(data).ToArray();
}
}
+22 -3
ファイルの表示
@@ -13,7 +13,7 @@ namespace ComputeSharp.D2D1Interop.Interop;
/// <summary>
/// Provides methods to extract reflection info on D2D1 shaders generated using this library.
/// </summary>
public static class D2D1InteropServices
public static unsafe class D2D1InteropServices
{
/// <summary>
/// Loads the bytecode from an input D2D1 pixel shader.
@@ -25,7 +25,7 @@ public static class D2D1InteropServices
/// If the input shader was precompiled, <paramref name="bytecode"/> will wrap a pinned memory buffer (from the PE section).
/// If the shader was compiled at runtime, <paramref name="bytecode"/> will wrap a <see cref="byte"/> array with the bytecode.
/// </remarks>
public static unsafe void LoadShaderBytecode<T>(in T shader, out ReadOnlyMemory<byte> bytecode)
public static void LoadShaderBytecode<T>(in T shader, out ReadOnlyMemory<byte> bytecode)
where T : unmanaged, ID2D1PixelShader
{
D2D1ShaderBytecodeLoader bytecodeLoader = default;
@@ -47,6 +47,25 @@ public static class D2D1InteropServices
bytecode = new ReadOnlySpan<byte>(bytecodePtr, bytecodeSize).ToArray();
}
/// <summary>
/// Gets the constant buffer from an input D2D1 pixel shader.
/// </summary>
/// <typeparam name="T">The type of D2D1 pixel shader to retrieve info for.</typeparam>
/// <param name="shader">The input D2D1 pixel shader to retrieve info for.</param>
/// <param name="buffer">A <see cref="ReadOnlyMemory{T}"/> instance with the pixel shader constant buffer.</param>
/// <remarks>
/// This method will allocate a buffer every time it is invoked.
/// For a zero-allocation alternative, use <see cref="SetPixelShaderConstantBufferForD2D1DrawInfo"/>.</remarks>
public static void GetPixelShaderConstantBufferForD2D1DrawInfo<T>(in T shader, out ReadOnlyMemory<byte> buffer)
where T : unmanaged, ID2D1PixelShader
{
D2D1ByteArrayDispatchDataLoader dataLoader = default;
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
buffer = dataLoader.GetResultingDispatchData();
}
/// <summary>
/// Sets the constant buffer from an input D2D1 pixel shader, by calling <c>ID2D1DrawInfo::SetPixelShaderConstantBuffer</c>.
/// </summary>
@@ -54,7 +73,7 @@ public static class D2D1InteropServices
/// <param name="shader">The input D2D1 pixel 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)
public static void SetPixelShaderConstantBufferForD2D1DrawInfo<T>(in T shader, void* d2D1DrawInfo)
where T : unmanaged, ID2D1PixelShader
{
D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo);