Implement D2D1DrawInfoUpdateContext<T> type

このコミットが含まれているのは:
Sergio Pedri committed 2022-11-29 22:34:06 +01:00
1 親 f7b0b74773
コミット 36326f2336
9ファイル変更
+109 -30

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

+43 -4
ファイルの表示
@@ -1,4 +1,10 @@
using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
using ComputeSharp.D2D1.Shaders.Loaders;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Interop;
@@ -6,16 +12,47 @@ namespace ComputeSharp.D2D1.Interop;
/// An object allowing <see cref="D2D1TransformMapper{T}.MapInputsToOutput"/> to interact with the shader data from within a transform.
/// </summary>
/// <typeparam name="T">The type of shader the transform will interact with.</typeparam>
public readonly ref struct D2D1DrawInfoUpdateContext<T>
public readonly unsafe ref struct D2D1DrawInfoUpdateContext<T>
where T : unmanaged, ID2D1PixelShader
{
/// <summary>
/// The <see cref="ID2D1DrawInfoUpdateContext"/> instance associated with the current object.
/// </summary>
private readonly ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext;
/// <summary>
/// Creates a new <see cref="D2D1DrawInfoUpdateContext{T}"/> instance with the specified parameters.
/// </summary>
/// <param name="d2D1DrawInfoUpdateContext">The <see cref="ID2D1DrawInfoUpdateContext"/> instance associated with the current object.</param>
internal D2D1DrawInfoUpdateContext(ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext)
{
this.d2D1DrawInfoUpdateContext = d2D1DrawInfoUpdateContext;
}
/// <summary>
/// Retrieves the <typeparamref name="T"/> instance currently being used in the associated effect.
/// </summary>
/// <returns>The <typeparamref name="T"/> instance currently being used in the associated effect.</returns>
public T GetConstantBuffer()
{
throw new NotImplementedException();
uint constantBufferSize;
this.d2D1DrawInfoUpdateContext->GetConstantBufferSize(&constantBufferSize).Assert();
byte[] buffer = ArrayPool<byte>.Shared.Rent((int)constantBufferSize);
fixed (byte* pBuffer = buffer)
{
this.d2D1DrawInfoUpdateContext->GetConstantBuffer(pBuffer, constantBufferSize).Assert();
}
Unsafe.SkipInit(out T shader);
shader.InitializeFromDispatchData(buffer);
ArrayPool<byte>.Shared.Return(buffer);
return shader;
}
/// <summary>
@@ -24,6 +61,8 @@ public readonly ref struct D2D1DrawInfoUpdateContext<T>
/// <param name="shader">The <typeparamref name="T"/> instance to be used in the associated effect.</param>
public void SetConstantBuffer(in T shader)
{
throw new NotImplementedException();
D2D1DrawInfoUpdateContextDispatchDataLoader dataLoader = new(this.d2D1DrawInfoUpdateContext);
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
}
}
@@ -192,7 +192,7 @@ partial struct PixelShaderEffect
// Forward the call to the input ID2D1TransformMapper instance
hresult = @this->d2D1TransformMapper->MapInputRectsToOutputRect(
updateContext: (ID2D1DrawInfoUpdateContex*)d2D1DrawInfoUpdateContext.Get(),
updateContext: (ID2D1DrawInfoUpdateContext*)d2D1DrawInfoUpdateContext.Get(),
inputRects: inputRects,
inputOpaqueSubRects: inputOpaqueSubRects,
inputRectCount: inputRectCount,
@@ -11,7 +11,7 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
partial struct D2D1DrawInfoUpdateContextImpl
{
/// <summary>
/// The implementation for <see cref="ID2D1DrawInfoUpdateContex"/>.
/// The implementation for <see cref="ID2D1DrawInfoUpdateContext"/>.
/// </summary>
private static unsafe class ID2D1DrawInfoUpdateContexMethods
{
@@ -80,7 +80,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
return @this->Release();
}
/// <inheritdoc cref="ID2D1DrawInfoUpdateContex.GetConstantBufferSize"/>
/// <inheritdoc cref="ID2D1DrawInfoUpdateContext.GetConstantBufferSize"/>
[UnmanagedCallersOnly]
public static int GetConstantBufferSize(D2D1DrawInfoUpdateContextImpl* @this, uint* size)
{
@@ -99,7 +99,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
return S.S_OK;
}
/// <inheritdoc cref="ID2D1DrawInfoUpdateContex.GetConstantBuffer"/>
/// <inheritdoc cref="ID2D1DrawInfoUpdateContext.GetConstantBuffer"/>
[UnmanagedCallersOnly]
public static int GetConstantBuffer(D2D1DrawInfoUpdateContextImpl* @this, byte* buffer, uint bufferCount)
{
@@ -131,7 +131,7 @@ partial struct D2D1DrawInfoUpdateContextImpl
return S.S_OK;
}
/// <inheritdoc cref="ID2D1DrawInfoUpdateContex.SetConstantBuffer"/>
/// <inheritdoc cref="ID2D1DrawInfoUpdateContext.SetConstantBuffer"/>
[UnmanagedCallersOnly]
public static int SetConstantBuffer(D2D1DrawInfoUpdateContextImpl* @this, byte* buffer, uint bufferCount)
{
@@ -13,7 +13,7 @@ using RuntimeHelpers = ComputeSharp.D2D1.NetStandard.System.Runtime.CompilerServ
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
/// <summary>
/// An implementation of the <see cref="ID2D1DrawInfoUpdateContex"/> and <see cref="ID2D1DrawInfoUpdateContexInternal"/> interfaces.
/// An implementation of the <see cref="ID2D1DrawInfoUpdateContext"/> and <see cref="ID2D1DrawInfoUpdateContexInternal"/> interfaces.
/// </summary>
internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
{
@@ -32,7 +32,7 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
#endif
/// <summary>
/// The shared vtable pointer for <see cref="D2D1DrawInfoUpdateContextImpl"/> instance, for <see cref="ID2D1DrawInfoUpdateContex"/>.
/// The shared vtable pointer for <see cref="D2D1DrawInfoUpdateContextImpl"/> instance, for <see cref="ID2D1DrawInfoUpdateContext"/>.
/// </summary>
private static readonly void** VtblForID2D1DrawInfoUpdateContex = InitVtblForID2D1DrawInfoUpdateContexAndID2D1DrawInfoUpdateContexInternal();
@@ -42,9 +42,9 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
private static readonly void** VtblForID2D1DrawInfoUpdateContexInternal = &VtblForID2D1DrawInfoUpdateContex[5];
/// <summary>
/// Initializes the combined vtable for <see cref="ID2D1DrawInfoUpdateContex"/> and <see cref="ID2D1DrawInfoUpdateContexInternal"/>.
/// Initializes the combined vtable for <see cref="ID2D1DrawInfoUpdateContext"/> and <see cref="ID2D1DrawInfoUpdateContexInternal"/>.
/// </summary>
/// <returns>The combined vtable for <see cref="ID2D1DrawInfoUpdateContex"/> and <see cref="ID2D1DrawInfoUpdateContexInternal"/>.</returns>
/// <returns>The combined vtable for <see cref="ID2D1DrawInfoUpdateContext"/> and <see cref="ID2D1DrawInfoUpdateContexInternal"/>.</returns>
private static void** InitVtblForID2D1DrawInfoUpdateContexAndID2D1DrawInfoUpdateContexInternal()
{
void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(D2D1DrawInfoUpdateContextImpl), sizeof(void*) * 10);
@@ -83,7 +83,7 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
}
/// <summary>
/// The vtable pointer for the current instance, for <see cref="ID2D1DrawInfoUpdateContex"/>.
/// The vtable pointer for the current instance, for <see cref="ID2D1DrawInfoUpdateContext"/>.
/// </summary>
private void** lpVtblForID2D1DrawInfoUpdateContex;
@@ -161,7 +161,7 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl
// ID2D1DrawInfoUpdateContex
if (riid->Equals(Windows.__uuidof<IUnknown>()) ||
riid->Equals(ID2D1DrawInfoUpdateContex.Guid))
riid->Equals(ID2D1DrawInfoUpdateContext.Guid))
{
_ = Interlocked.Increment(ref this.referenceCount);
@@ -11,10 +11,10 @@ namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
/// The updater for <see cref="TerraFX.Interop.DirectX.ID2D1DrawInfo"/> type to use with built-in effects.
/// </summary>
[Guid("430C5B40-AE16-485F-90E6-4FA4915144B6")]
internal unsafe struct ID2D1DrawInfoUpdateContex
internal unsafe struct ID2D1DrawInfoUpdateContext
{
/// <summary>
/// Gets the <see cref="System.Guid"/> for <see cref="ID2D1DrawInfoUpdateContex"/> (<c>430C5B40-AE16-485F-90E6-4FA4915144B6</c>).
/// Gets the <see cref="System.Guid"/> for <see cref="ID2D1DrawInfoUpdateContext"/> (<c>430C5B40-AE16-485F-90E6-4FA4915144B6</c>).
/// </summary>
public static ref readonly Guid Guid
{
@@ -50,8 +50,8 @@ internal unsafe struct ID2D1DrawInfoUpdateContex
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public HRESULT GetConstantBufferSize(uint* size)
{
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContex*, uint*, int>)this.lpVtbl[3])(
(ID2D1DrawInfoUpdateContex*)Unsafe.AsPointer(ref this),
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContext*, uint*, int>)this.lpVtbl[3])(
(ID2D1DrawInfoUpdateContext*)Unsafe.AsPointer(ref this),
size);
}
@@ -64,8 +64,8 @@ internal unsafe struct ID2D1DrawInfoUpdateContex
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public HRESULT GetConstantBuffer(byte* buffer, uint bufferCount)
{
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContex*, byte*, uint, int>)this.lpVtbl[4])(
(ID2D1DrawInfoUpdateContex*)Unsafe.AsPointer(ref this),
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContext*, byte*, uint, int>)this.lpVtbl[4])(
(ID2D1DrawInfoUpdateContext*)Unsafe.AsPointer(ref this),
buffer,
bufferCount);
}
@@ -79,8 +79,8 @@ internal unsafe struct ID2D1DrawInfoUpdateContex
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public HRESULT SetConstantBuffer(byte* buffer, uint bufferCount)
{
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContex*, byte*, uint, int>)this.lpVtbl[5])(
(ID2D1DrawInfoUpdateContex*)Unsafe.AsPointer(ref this),
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContext*, byte*, uint, int>)this.lpVtbl[5])(
(ID2D1DrawInfoUpdateContext*)Unsafe.AsPointer(ref this),
buffer,
bufferCount);
}
@@ -8,7 +8,7 @@ using TerraFX.Interop.Windows;
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
/// <summary>
/// An internal version of <see cref="ID2D1DrawInfoUpdateContex"/> that supports being closed, to manage lifetime scopes.
/// An internal version of <see cref="ID2D1DrawInfoUpdateContext"/> that supports being closed, to manage lifetime scopes.
/// </summary>
[Guid("CF2F5BB0-3F5E-4D6E-8FF1-D9A7EB6C0250")]
internal unsafe struct ID2D1DrawInfoUpdateContexInternal
@@ -49,6 +49,6 @@ internal unsafe struct ID2D1DrawInfoUpdateContexInternal
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public HRESULT Close()
{
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContex*, int>)this.lpVtbl[3])((ID2D1DrawInfoUpdateContex*)Unsafe.AsPointer(ref this));
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfoUpdateContext*, int>)this.lpVtbl[3])((ID2D1DrawInfoUpdateContext*)Unsafe.AsPointer(ref this));
}
}
+3 -3
ファイルの表示
@@ -45,7 +45,7 @@ internal unsafe struct ID2D1TransformMapper
/// <summary>
/// Performs the inverse mapping to <see cref="MapOutputRectToInputRects(RECT*, RECT*, uint)"/>.
/// </summary>
/// <param name="updateContext">The input <see cref="ID2D1DrawInfoUpdateContex"/> instance.</param>
/// <param name="updateContext">The input <see cref="ID2D1DrawInfoUpdateContext"/> instance.</param>
/// <param name="inputRects">An array of input rectangles to be mapped to the output rectangle.</param>
/// <param name="inputOpaqueSubRects">An array of input rectangles to be mapped to the opaque output rectangle.</param>
/// <param name="inputRectCount">The number of inputs specified.</param>
@@ -54,14 +54,14 @@ internal unsafe struct ID2D1TransformMapper
/// <returns>An <see cref="HRESULT"/> for the operation.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public HRESULT MapInputRectsToOutputRect(
ID2D1DrawInfoUpdateContex* updateContext,
ID2D1DrawInfoUpdateContext* updateContext,
RECT* inputRects,
RECT* inputOpaqueSubRects,
uint inputRectCount,
RECT* outputRect,
RECT* outputOpaqueSubRect)
{
return ((delegate* unmanaged[Stdcall]<ID2D1TransformMapper*, ID2D1DrawInfoUpdateContex*, RECT*, RECT*, uint, RECT*, RECT*, int>)this.lpVtbl[3])(
return ((delegate* unmanaged[Stdcall]<ID2D1TransformMapper*, ID2D1DrawInfoUpdateContext*, RECT*, RECT*, uint, RECT*, RECT*, int>)this.lpVtbl[3])(
(ID2D1TransformMapper*)Unsafe.AsPointer(ref this),
updateContext,
inputRects,
+3 -2
ファイルの表示
@@ -2,6 +2,7 @@ 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
@@ -31,8 +32,8 @@ internal readonly unsafe struct D2D1DrawInfoDispatchDataLoader : ID2D1DispatchDa
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
_ = this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
this.d2D1DrawInfo->SetPixelShaderConstantBuffer(
buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
bufferCount: (uint)data.Length);
bufferCount: (uint)data.Length).Assert();
}
}
@@ -0,0 +1,39 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ComputeSharp.D2D1.__Internals;
using ComputeSharp.D2D1.Extensions;
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
#pragma warning disable CS0618
namespace ComputeSharp.D2D1.Shaders.Loaders;
/// <summary>
/// A data loader for D2D1 pixel shaders to be passed onto an <see cref="ID2D1DrawInfoUpdateContext"/> object.
/// </summary>
internal readonly unsafe struct D2D1DrawInfoUpdateContextDispatchDataLoader : ID2D1DispatchDataLoader
{
/// <summary>
/// The <see cref="ID2D1DrawInfoUpdateContext"/> object in use.
/// </summary>
private readonly ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext;
/// <summary>
/// Creates a new <see cref="D2D1DrawInfoUpdateContextDispatchDataLoader"/> instance.
/// </summary>
/// <param name="d2D1DrawInfoUpdateContext">The <see cref="ID2D1DrawInfoUpdateContext"/> object to use.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal D2D1DrawInfoUpdateContextDispatchDataLoader(ID2D1DrawInfoUpdateContext* d2D1DrawInfoUpdateContext)
{
this.d2D1DrawInfoUpdateContext = d2D1DrawInfoUpdateContext;
}
/// <inheritdoc/>
void ID2D1DispatchDataLoader.LoadConstantBuffer(ReadOnlySpan<byte> data)
{
this.d2D1DrawInfoUpdateContext->SetConstantBuffer(
buffer: (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)),
bufferCount: (uint)data.Length).Assert();
}
}