Move pixel shader effect APIs to new D2D1PixelShaderEffect type
このコミットが含まれているのは:
1 親
8558af237f
コミット
cab4986cfc
4ファイル変更
+30
-32
検索条件に一致するファイルはありません
@@ -8,8 +8,8 @@ using ComputeSharp.D2D1.NetStandard.System.Text;
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// A helper type used to read and validate effect registration blobs produced by
|
||||
/// <see cref="D2D1InteropServices.GetPixelShaderEffectRegistrationBlob{T}(out Guid)"/>.
|
||||
/// A helper type used to read and validate effect registration blobs produced
|
||||
/// by <see cref="D2D1PixelShaderEffect.GetRegistrationBlob{T}(out Guid)"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
@@ -76,8 +76,8 @@ public unsafe readonly struct D2D1EffectRegistrationData
|
||||
/// <param name="data">The resulting <see cref="D2D1EffectRegistrationData"/> instance, if successful.</param>
|
||||
/// <returns>Whether or not the input blob has been correctly deserialized (if it was not malformed).</returns>
|
||||
/// <remarks>
|
||||
/// The input blob should have been created by a call to any of the overloads of
|
||||
/// <see cref="D2D1InteropServices.GetPixelShaderEffectRegistrationBlob{T}(out Guid)"/>.
|
||||
/// The input blob should have been created by a call to any of the overloads
|
||||
/// of <see cref="D2D1PixelShaderEffect.GetRegistrationBlob{T}(out Guid)"/>.
|
||||
/// </remarks>
|
||||
public static unsafe bool TryLoad(ReadOnlyMemory<byte> blob, out D2D1EffectRegistrationData data)
|
||||
{
|
||||
|
||||
@@ -10,9 +10,9 @@ using TerraFX.Interop.Windows;
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// Provides methods to extract reflection info on D2D1 shaders generated using this library.
|
||||
/// Provides methods to interop with D2D1 APIs and compile shaders or extract their constant buffer data.
|
||||
/// </summary>
|
||||
public static unsafe partial class D2D1InteropServices
|
||||
public static unsafe class D2D1InteropServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads the bytecode from an input D2D1 pixel shader.
|
||||
|
||||
+18
-16
@@ -15,8 +15,10 @@ using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class D2D1InteropServices
|
||||
/// <summary>
|
||||
/// An implementation of a D2D1 pixel shader effect that can be used to instantiate <c>ID2D1Effect</c> objects.
|
||||
/// </summary>
|
||||
public static unsafe class D2D1PixelShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers an effect from an input D2D1 pixel shader, by calling <c>ID2D1Factory1::RegisterEffectFromString</c>.
|
||||
@@ -25,10 +27,10 @@ unsafe partial class D2D1InteropServices
|
||||
/// <param name="d2D1Factory1">A pointer to the <c>ID2D1Factory1</c> instance to use.</param>
|
||||
/// <param name="effectId">The <see cref="Guid"/> of the registered effect, which can be used to call <c>ID2D1DeviceContext::CreateEffect</c>.</param>
|
||||
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1factory1-registereffectfromstring"/>.</remarks>
|
||||
public static unsafe void RegisterPixelShaderEffectForD2D1Factory1<T>(void* d2D1Factory1, out Guid effectId)
|
||||
public static unsafe void RegisterForD2D1Factory1<T>(void* d2D1Factory1, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
RegisterPixelShaderEffectForD2D1Factory1<T>(d2D1Factory1, null, out effectId);
|
||||
RegisterForD2D1Factory1<T>(d2D1Factory1, null, out effectId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,11 +41,11 @@ unsafe partial class D2D1InteropServices
|
||||
/// <param name="d2D1Factory1">A pointer to the <c>ID2D1Factory1</c> instance to use.</param>
|
||||
/// <param name="effectId">The <see cref="Guid"/> of the registered effect, which can be used to call <c>ID2D1DeviceContext::CreateEffect</c>.</param>
|
||||
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1factory1-registereffectfromstring"/>.</remarks>
|
||||
public static unsafe void RegisterPixelShaderEffectForD2D1Factory1<T, TMapper>(void* d2D1Factory1, out Guid effectId)
|
||||
public static unsafe void RegisterForD2D1Factory1<T, TMapper>(void* d2D1Factory1, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
where TMapper : class, ID2D1TransformMapper<T>, new()
|
||||
{
|
||||
RegisterPixelShaderEffectForD2D1Factory1<T>(d2D1Factory1, static () => new TMapper(), out effectId);
|
||||
RegisterForD2D1Factory1<T>(d2D1Factory1, static () => new TMapper(), out effectId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,7 +56,7 @@ unsafe partial class D2D1InteropServices
|
||||
/// <param name="mapperFactory">An optional factory of <see cref="ID2D1TransformMapper{T}"/> instances to use for the transform.</param>
|
||||
/// <param name="effectId">The <see cref="Guid"/> of the registered effect, which can be used to call <c>ID2D1DeviceContext::CreateEffect</c>.</param>
|
||||
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1factory1-registereffectfromstring"/>.</remarks>
|
||||
public static unsafe void RegisterPixelShaderEffectForD2D1Factory1<T>(void* d2D1Factory1, Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
public static unsafe void RegisterForD2D1Factory1<T>(void* d2D1Factory1, Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
effectId = default;
|
||||
@@ -129,11 +131,11 @@ unsafe partial class D2D1InteropServices
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader to register.</typeparam>
|
||||
/// <param name="effectId">The <see cref="Guid"/> of the registered effect, which can be used to call <c>ID2D1DeviceContext::CreateEffect</c>.</param>
|
||||
/// <remarks>For more info and for details on the binary format, see <see cref="GetPixelShaderEffectRegistrationBlob{T}(Func{ID2D1TransformMapper{T}}?, out Guid)"/>.</remarks>
|
||||
public static unsafe ReadOnlyMemory<byte> GetPixelShaderEffectRegistrationBlob<T>(out Guid effectId)
|
||||
/// <remarks>For more info and for details on the binary format, see <see cref="GetRegistrationBlob{T}(Func{ID2D1TransformMapper{T}}?, out Guid)"/>.</remarks>
|
||||
public static unsafe ReadOnlyMemory<byte> GetRegistrationBlob<T>(out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
return GetPixelShaderEffectRegistrationBlob<T>(null, out effectId);
|
||||
return GetRegistrationBlob<T>(null, out effectId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,12 +144,12 @@ unsafe partial class D2D1InteropServices
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader to register.</typeparam>
|
||||
/// <typeparam name="TMapper">The type of <see cref="ID2D1TransformMapper{T}"/> implementation to register.</typeparam>
|
||||
/// <param name="effectId">The <see cref="Guid"/> of the registered effect, which can be used to call <c>ID2D1DeviceContext::CreateEffect</c>.</param>
|
||||
/// <remarks>For more info and for details on the binary format, see <see cref="GetPixelShaderEffectRegistrationBlob{T}(Func{ID2D1TransformMapper{T}}?, out Guid)"/>.</remarks>
|
||||
public static unsafe ReadOnlyMemory<byte> GetPixelShaderEffectRegistrationBlob<T, TMapper>(out Guid effectId)
|
||||
/// <remarks>For more info and for details on the binary format, see <see cref="GetRegistrationBlob{T}(Func{ID2D1TransformMapper{T}}?, out Guid)"/>.</remarks>
|
||||
public static unsafe ReadOnlyMemory<byte> GetRegistrationBlob<T, TMapper>(out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
where TMapper : class, ID2D1TransformMapper<T>, new()
|
||||
{
|
||||
return GetPixelShaderEffectRegistrationBlob(static () => new TMapper(), out effectId);
|
||||
return GetRegistrationBlob(static () => new TMapper(), out effectId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -186,7 +188,7 @@ unsafe partial class D2D1InteropServices
|
||||
/// For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1factory1-registereffectfromstring"/>.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static unsafe ReadOnlyMemory<byte> GetPixelShaderEffectRegistrationBlob<T>(Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
public static unsafe ReadOnlyMemory<byte> GetRegistrationBlob<T>(Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
effectId = default;
|
||||
@@ -261,7 +263,7 @@ unsafe partial class D2D1InteropServices
|
||||
/// <param name="d2D1DeviceContext">A pointer to the <c>ID2D1DeviceContext</c> instance to use.</param>
|
||||
/// <param name="d2D1Effect">A pointer to the resulting <c>ID2D1Effect*</c> pointer to produce.</param>
|
||||
/// <remarks>For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1devicecontext-createeffect"/>.</remarks>
|
||||
public static unsafe void CreatePixelShaderEffectFromD2D1DeviceContext<T>(void* d2D1DeviceContext, void** d2D1Effect)
|
||||
public static unsafe void CreateFromD2D1DeviceContext<T>(void* d2D1DeviceContext, void** d2D1Effect)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
Guid shaderId = typeof(T).GUID;
|
||||
@@ -278,7 +280,7 @@ unsafe partial class D2D1InteropServices
|
||||
/// <param name="shader">The input D2D1 pixel shader to set the contant buffer for.</param>
|
||||
/// <param name="d2D1Effect">A pointer to the <c>ID2D1Effect</c> instance to use.</param>
|
||||
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1properties-setvalue(uint32_d2d1_property_type_constbyte_uint32)"/>.</remarks>
|
||||
public static unsafe void SetConstantBufferForD2D1Effect<T>(in T shader, void* d2D1Effect)
|
||||
public static unsafe void SetConstantBuffer<T>(in T shader, void* d2D1Effect)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
D2D1EffectDispatchDataLoader dataLoader = new((ID2D1Effect*)d2D1Effect);
|
||||
@@ -29,15 +29,13 @@ internal static class D2D1TestRunner
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1InteropServices.RegisterPixelShaderEffectForD2D1Factory1(d2D1Factory2.Get(), transformMapperFactory, out _);
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), transformMapperFactory, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1InteropServices.CreatePixelShaderEffectFromD2D1DeviceContext<T>(
|
||||
d2D1DeviceContext.Get(),
|
||||
(void**)d2D1Effect.GetAddressOf());
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<T>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
D2D1InteropServices.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
|
||||
D2D1PixelShaderEffect.SetConstantBuffer(in shader, d2D1Effect.Get());
|
||||
|
||||
using ComPtr<IWICBitmap> wicBitmap = WICHelper.LoadBitmapFromFile(sourcePath, out uint width, out uint height);
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapSource = D2D1Helper.CreateD2D1BitmapAndSetAsSource(d2D1DeviceContext.Get(), wicBitmap.Get(), d2D1Effect.Get());
|
||||
@@ -72,15 +70,13 @@ internal static class D2D1TestRunner
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1InteropServices.RegisterPixelShaderEffectForD2D1Factory1(d2D1Factory2.Get(), transformMapperFactory, out _);
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), transformMapperFactory, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1InteropServices.CreatePixelShaderEffectFromD2D1DeviceContext<T>(
|
||||
d2D1DeviceContext.Get(),
|
||||
(void**)d2D1Effect.GetAddressOf());
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<T>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
D2D1InteropServices.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
|
||||
D2D1PixelShaderEffect.SetConstantBuffer(in shader, d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)width, (uint)height);
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする