Optimize D2D1InteropServices.SetConstantBufferForD2D1Effect

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:04:30 +02:00
1 親 d21cc4066c
コミット ad7d1bd706
2ファイル変更
+47 -16

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

+41
ファイルの表示
@@ -0,0 +1,41 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1Interop.__Internals;
using ComputeSharp.D2D1Interop.Extensions;
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="ID2D1Effect"/>.
/// </summary>
internal readonly unsafe struct D2D1EffectDispatchDataLoader : ID2D1DispatchDataLoader
{
/// <summary>
/// The <see cref="ID2D1Effect"/> object in use.
/// </summary>
private readonly ID2D1Effect* d2D1Effect;
/// <summary>
/// Creates a new <see cref="D2D1EffectDispatchDataLoader"/> instance.
/// </summary>
/// <param name="d2D1Effect">The <see cref="ID2D1Effect"/> object to use.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1EffectDispatchDataLoader(ID2D1Effect* d2D1Effect)
{
this.d2D1Effect = d2D1Effect;
}
/// <inheritdoc/>
public void LoadConstantBuffer(ReadOnlySpan<uint> data)
{
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 * sizeof(uint)).Assert();
}
}
+6 -16
ファイルの表示
@@ -1,13 +1,17 @@
using System;
using System.Runtime.CompilerServices;
#if !NET6_0_OR_GREATER
using System.Runtime.InteropServices;
#endif
using System.Text;
using ComputeSharp.D2D1Interop.Extensions;
using ComputeSharp.D2D1Interop.Interop.Effects;
using ComputeSharp.D2D1Interop.Shaders.Dispatching;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1Interop;
/// <inheritdoc/>
@@ -115,22 +119,8 @@ unsafe partial class D2D1InteropServices
public static unsafe void SetConstantBufferForD2D1Effect<T>(in T shader, void* d2D1Effect)
where T : unmanaged, ID2D1PixelShader
{
// Get the shader state
ReadOnlyMemory<byte> buffer = D2D1InteropServices.GetPixelShaderConstantBufferForD2D1DrawInfo(in shader);
D2D1EffectDispatchDataLoader dataLoader = new((ID2D1Effect*)d2D1Effect);
if (buffer.Length > 0)
{
fixed (byte* p = buffer.Span)
{
// Load the effect buffer
((ID2D1Effect*)d2D1Effect)->SetValue(
index: 0,
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BLOB,
data: p,
dataSize: (uint)buffer.Length).Assert();
}
}
// TODO: optimize with a custom dispatch data loader
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
}
}