Merge pull request #347 from Sergio0694/dev/d2d1-resource-texture-manager
Add D2D1 resource texture infrastructure
このコミットが含まれているのは:
50ファイル変更
+5394
-437
検索条件に一致するファイルはありません
@@ -24,9 +24,9 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Intrinsics\Hlsl.Void.g.cs">
|
||||
<DependentUpon>Hlsl.Void.tt</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Hlsl.Void.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Intrinsics\Hlsl.g.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
@@ -137,8 +137,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="Intrinsics\Hlsl.Void.tt">
|
||||
<LastGenOutput>Hlsl.Void.g.cs</LastGenOutput>
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>Hlsl.Void.g.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Update="Intrinsics\Hlsl.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ partial class ID2D1ShaderGenerator
|
||||
HashSet<int> resourceTextureIndices = new(resourceTextureInfos.Where(info => info.Index.HasValue).Select(info => info.Index!.Value));
|
||||
|
||||
// All input description indices must be unique
|
||||
if (resourceTextureIndices.Count != resourceTextureInfos.Count)
|
||||
if (resourceTextureIndices.Count != resourceTextureInfos.Count(info => info.Index.HasValue))
|
||||
{
|
||||
diagnostics.Add(RepeatedD2DResourceTextureIndices, structDeclarationSymbol, structDeclarationSymbol);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,24 @@
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- T4 template generation service -->
|
||||
<ItemGroup>
|
||||
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Shaders\Interop\Effects\PixelShaderEffect.Properties.g.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>PixelShaderEffect.Properties.tt</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="Shaders\Interop\Effects\PixelShaderEffect.Properties.tt">
|
||||
<Generator>TextTemplatingFileGenerator</Generator>
|
||||
<LastGenOutput>PixelShaderEffect.Properties.g.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Enable trimming support on .NET 6 -->
|
||||
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
|
||||
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
|
||||
|
||||
@@ -34,6 +34,18 @@ internal static class ThrowHelper
|
||||
throw new ArgumentException(message, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentNullException(string? name, string? message)
|
||||
{
|
||||
throw new ArgumentNullException(name, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using static TerraFX.Interop.DirectX.D2D1_EXTEND_MODE;
|
||||
|
||||
namespace ComputeSharp.D2D1;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies how a brush paints areas outside of its normal content area.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This type exposes the available values in <see href="https://docs.microsoft.com/windows/win32/api/d2d1/ne-d2d1-d2d1_extend_mode"/>.
|
||||
/// </remarks>
|
||||
public enum D2D1ExtendMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Repeat the edge pixels of the brush's content for all regions outside the normal content area.
|
||||
/// </summary>
|
||||
Clamp = (int)D2D1_EXTEND_MODE_CLAMP,
|
||||
|
||||
/// <summary>
|
||||
/// Repeat the brush's content.
|
||||
/// </summary>
|
||||
Wrap = (int)D2D1_EXTEND_MODE_WRAP,
|
||||
|
||||
/// <summary>
|
||||
/// The same as <see cref="Wrap"/>, except that alternate tiles of the brush's
|
||||
/// content are flipped (the brush's normal content is drawn untransformed).
|
||||
/// </summary>
|
||||
Mirror = (int)D2D1_EXTEND_MODE_MIRROR
|
||||
}
|
||||
@@ -337,10 +337,16 @@ public static class D2D1PixelShader
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader to set the constant buffer for.</typeparam>
|
||||
/// <param name="shader">The input D2D1 pixel shader to set the contant buffer for.</param>
|
||||
/// <param name="d2D1DrawInfo">A pointer to the <c>ID2D1DrawInfo</c> instance to use.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1DrawInfo"/> is <see langword="null"/>.</exception>
|
||||
/// <remarks>For more info, see <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nf-d2d1effectauthor-id2d1drawinfo-setpixelshaderconstantbuffer"/>.</remarks>
|
||||
public static unsafe void SetConstantBufferForD2D1DrawInfo<T>(in T shader, void* d2D1DrawInfo)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if (d2D1DrawInfo is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1DrawInfo), "The input ID2D1DrawInfo object cannot be null.");
|
||||
}
|
||||
|
||||
D2D1DrawInfoDispatchDataLoader dataLoader = new((ID2D1DrawInfo*)d2D1DrawInfo);
|
||||
|
||||
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
using System.Text;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Buffers;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using ComputeSharp.D2D1.Shaders.Loaders;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
@@ -28,11 +26,17 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader to register.</typeparam>
|
||||
/// <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>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Factory1"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="InvalidOperationException">Thrown if an effect is registered multiple times with different properties.</exception>
|
||||
/// <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 RegisterForD2D1Factory1<T>(void* d2D1Factory1, out Guid effectId)
|
||||
public static void RegisterForD2D1Factory1<T>(void* d2D1Factory1, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if (d2D1Factory1 is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1Factory1), "The input ID2D1Factory1 object cannot be null.");
|
||||
}
|
||||
|
||||
RegisterForD2D1Factory1<T>(d2D1Factory1, null, out effectId);
|
||||
}
|
||||
|
||||
@@ -43,12 +47,18 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// <typeparam name="TMapper">The type of <see cref="ID2D1TransformMapper{T}"/> implementation to register.</typeparam>
|
||||
/// <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>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Factory1"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="InvalidOperationException">Thrown if an effect is registered multiple times with different properties.</exception>
|
||||
/// <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 RegisterForD2D1Factory1<T, TMapper>(void* d2D1Factory1, out Guid effectId)
|
||||
public static void RegisterForD2D1Factory1<T, TMapper>(void* d2D1Factory1, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
where TMapper : class, ID2D1TransformMapper<T>, new()
|
||||
{
|
||||
if (d2D1Factory1 is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1Factory1), "The input ID2D1Factory1 object cannot be null.");
|
||||
}
|
||||
|
||||
RegisterForD2D1Factory1(d2D1Factory1, static () => new TMapper(), out effectId);
|
||||
}
|
||||
|
||||
@@ -59,11 +69,17 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// <param name="d2D1Factory1">A pointer to the <c>ID2D1Factory1</c> instance to use.</param>
|
||||
/// <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>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Factory1"/> is <see langword="null"/>.</exception>
|
||||
/// <exception cref="InvalidOperationException">Thrown if an effect is registered multiple times with different properties.</exception>
|
||||
/// <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 RegisterForD2D1Factory1<T>(void* d2D1Factory1, Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
public static void RegisterForD2D1Factory1<T>(void* d2D1Factory1, Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if (d2D1Factory1 is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1Factory1), "The input ID2D1Factory1 object cannot be null.");
|
||||
}
|
||||
|
||||
effectId = default;
|
||||
|
||||
PixelShaderEffect.For<T>.Initialize(mapperFactory);
|
||||
@@ -91,30 +107,134 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
<Property name='Buffer' type='blob'>
|
||||
<Property name='DisplayName' type='string' value='Buffer'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager0' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager0'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager1' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager1'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager2' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager2'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager3' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager3'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager4' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager4'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager5' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager5'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager6' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager6'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager7' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager7'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager8' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager8'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager9' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager9'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager10' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager10'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager11' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager11'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager12' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager12'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager13' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager13'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager14' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager14'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager15' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager15'/>
|
||||
</Property>
|
||||
</Effect>";
|
||||
|
||||
fixed (char* pXml = xml)
|
||||
fixed (char* pPropertyName = "Buffer")
|
||||
fixed (char* pBufferPropertyName = "Buffer")
|
||||
fixed (char* pResourceTextureManager0PropertyName = "ResourceTextureManager0")
|
||||
fixed (char* pResourceTextureManager1PropertyName = "ResourceTextureManager1")
|
||||
fixed (char* pResourceTextureManager2PropertyName = "ResourceTextureManager2")
|
||||
fixed (char* pResourceTextureManager3PropertyName = "ResourceTextureManager3")
|
||||
fixed (char* pResourceTextureManager4PropertyName = "ResourceTextureManager4")
|
||||
fixed (char* pResourceTextureManager5PropertyName = "ResourceTextureManager5")
|
||||
fixed (char* pResourceTextureManager6PropertyName = "ResourceTextureManager6")
|
||||
fixed (char* pResourceTextureManager7PropertyName = "ResourceTextureManager7")
|
||||
fixed (char* pResourceTextureManager8PropertyName = "ResourceTextureManager8")
|
||||
fixed (char* pResourceTextureManager9PropertyName = "ResourceTextureManager9")
|
||||
fixed (char* pResourceTextureManager10PropertyName = "ResourceTextureManager10")
|
||||
fixed (char* pResourceTextureManager11PropertyName = "ResourceTextureManager11")
|
||||
fixed (char* pResourceTextureManager12PropertyName = "ResourceTextureManager12")
|
||||
fixed (char* pResourceTextureManager13PropertyName = "ResourceTextureManager13")
|
||||
fixed (char* pResourceTextureManager14PropertyName = "ResourceTextureManager14")
|
||||
fixed (char* pResourceTextureManager15PropertyName = "ResourceTextureManager15")
|
||||
{
|
||||
// Prepare the effect binding functions
|
||||
D2D1_PROPERTY_BINDING d2D1PropertyBinding;
|
||||
d2D1PropertyBinding.propertyName = (ushort*)pPropertyName;
|
||||
d2D1PropertyBinding.getFunction =
|
||||
(delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, HRESULT>)
|
||||
#if NET6_0_OR_GREATER
|
||||
(delegate* unmanaged<IUnknown*, byte*, uint, uint*, int>)
|
||||
&PixelShaderEffect.GetConstantBuffer;
|
||||
#else
|
||||
(void*)Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.GetConstantBufferWrapper);
|
||||
#endif
|
||||
d2D1PropertyBinding.setFunction =
|
||||
(delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, HRESULT>)
|
||||
#if NET6_0_OR_GREATER
|
||||
(delegate* unmanaged<IUnknown*, byte*, uint, int>)
|
||||
&PixelShaderEffect.SetConstantBuffer;
|
||||
#else
|
||||
(void*)Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.SetConstantBufferWrapper);
|
||||
#endif
|
||||
D2D1_PROPERTY_BINDING* d2D1PropertyBinding = stackalloc D2D1_PROPERTY_BINDING[17];
|
||||
|
||||
// Property names
|
||||
d2D1PropertyBinding[0].propertyName = (ushort*)pBufferPropertyName;
|
||||
d2D1PropertyBinding[1].propertyName = (ushort*)pResourceTextureManager0PropertyName;
|
||||
d2D1PropertyBinding[2].propertyName = (ushort*)pResourceTextureManager1PropertyName;
|
||||
d2D1PropertyBinding[3].propertyName = (ushort*)pResourceTextureManager2PropertyName;
|
||||
d2D1PropertyBinding[4].propertyName = (ushort*)pResourceTextureManager3PropertyName;
|
||||
d2D1PropertyBinding[5].propertyName = (ushort*)pResourceTextureManager4PropertyName;
|
||||
d2D1PropertyBinding[6].propertyName = (ushort*)pResourceTextureManager5PropertyName;
|
||||
d2D1PropertyBinding[7].propertyName = (ushort*)pResourceTextureManager6PropertyName;
|
||||
d2D1PropertyBinding[8].propertyName = (ushort*)pResourceTextureManager7PropertyName;
|
||||
d2D1PropertyBinding[9].propertyName = (ushort*)pResourceTextureManager8PropertyName;
|
||||
d2D1PropertyBinding[10].propertyName = (ushort*)pResourceTextureManager9PropertyName;
|
||||
d2D1PropertyBinding[11].propertyName = (ushort*)pResourceTextureManager10PropertyName;
|
||||
d2D1PropertyBinding[12].propertyName = (ushort*)pResourceTextureManager11PropertyName;
|
||||
d2D1PropertyBinding[13].propertyName = (ushort*)pResourceTextureManager12PropertyName;
|
||||
d2D1PropertyBinding[14].propertyName = (ushort*)pResourceTextureManager13PropertyName;
|
||||
d2D1PropertyBinding[15].propertyName = (ushort*)pResourceTextureManager14PropertyName;
|
||||
d2D1PropertyBinding[16].propertyName = (ushort*)pResourceTextureManager15PropertyName;
|
||||
|
||||
// Property getters
|
||||
d2D1PropertyBinding[0].getFunction = PixelShaderEffect.GetConstantBuffer;
|
||||
d2D1PropertyBinding[1].getFunction = PixelShaderEffect.GetResourceTextureManager0;
|
||||
d2D1PropertyBinding[2].getFunction = PixelShaderEffect.GetResourceTextureManager1;
|
||||
d2D1PropertyBinding[3].getFunction = PixelShaderEffect.GetResourceTextureManager2;
|
||||
d2D1PropertyBinding[4].getFunction = PixelShaderEffect.GetResourceTextureManager3;
|
||||
d2D1PropertyBinding[5].getFunction = PixelShaderEffect.GetResourceTextureManager4;
|
||||
d2D1PropertyBinding[6].getFunction = PixelShaderEffect.GetResourceTextureManager5;
|
||||
d2D1PropertyBinding[7].getFunction = PixelShaderEffect.GetResourceTextureManager6;
|
||||
d2D1PropertyBinding[8].getFunction = PixelShaderEffect.GetResourceTextureManager7;
|
||||
d2D1PropertyBinding[9].getFunction = PixelShaderEffect.GetResourceTextureManager8;
|
||||
d2D1PropertyBinding[10].getFunction = PixelShaderEffect.GetResourceTextureManager9;
|
||||
d2D1PropertyBinding[11].getFunction = PixelShaderEffect.GetResourceTextureManager10;
|
||||
d2D1PropertyBinding[12].getFunction = PixelShaderEffect.GetResourceTextureManager11;
|
||||
d2D1PropertyBinding[13].getFunction = PixelShaderEffect.GetResourceTextureManager12;
|
||||
d2D1PropertyBinding[14].getFunction = PixelShaderEffect.GetResourceTextureManager13;
|
||||
d2D1PropertyBinding[15].getFunction = PixelShaderEffect.GetResourceTextureManager14;
|
||||
d2D1PropertyBinding[16].getFunction = PixelShaderEffect.GetResourceTextureManager15;
|
||||
|
||||
// Property setters
|
||||
d2D1PropertyBinding[0].setFunction = PixelShaderEffect.SetConstantBuffer;
|
||||
d2D1PropertyBinding[1].setFunction = PixelShaderEffect.SetResourceTextureManager0;
|
||||
d2D1PropertyBinding[2].setFunction = PixelShaderEffect.SetResourceTextureManager1;
|
||||
d2D1PropertyBinding[3].setFunction = PixelShaderEffect.SetResourceTextureManager2;
|
||||
d2D1PropertyBinding[4].setFunction = PixelShaderEffect.SetResourceTextureManager3;
|
||||
d2D1PropertyBinding[5].setFunction = PixelShaderEffect.SetResourceTextureManager4;
|
||||
d2D1PropertyBinding[6].setFunction = PixelShaderEffect.SetResourceTextureManager5;
|
||||
d2D1PropertyBinding[7].setFunction = PixelShaderEffect.SetResourceTextureManager6;
|
||||
d2D1PropertyBinding[8].setFunction = PixelShaderEffect.SetResourceTextureManager7;
|
||||
d2D1PropertyBinding[9].setFunction = PixelShaderEffect.SetResourceTextureManager8;
|
||||
d2D1PropertyBinding[10].setFunction = PixelShaderEffect.SetResourceTextureManager9;
|
||||
d2D1PropertyBinding[11].setFunction = PixelShaderEffect.SetResourceTextureManager10;
|
||||
d2D1PropertyBinding[12].setFunction = PixelShaderEffect.SetResourceTextureManager11;
|
||||
d2D1PropertyBinding[13].setFunction = PixelShaderEffect.SetResourceTextureManager12;
|
||||
d2D1PropertyBinding[14].setFunction = PixelShaderEffect.SetResourceTextureManager13;
|
||||
d2D1PropertyBinding[15].setFunction = PixelShaderEffect.SetResourceTextureManager14;
|
||||
d2D1PropertyBinding[16].setFunction = PixelShaderEffect.SetResourceTextureManager15;
|
||||
|
||||
fixed (Guid* pGuid = &PixelShaderEffect.For<T>.Id)
|
||||
{
|
||||
@@ -122,8 +242,8 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
((ID2D1Factory1*)d2D1Factory1)->RegisterEffectFromString(
|
||||
classId: pGuid,
|
||||
propertyXml: (ushort*)pXml,
|
||||
bindings: &d2D1PropertyBinding,
|
||||
bindingsCount: 1,
|
||||
bindings: d2D1PropertyBinding,
|
||||
bindingsCount: 17,
|
||||
effectFactory: PixelShaderEffect.For<T>.Factory).Assert();
|
||||
}
|
||||
|
||||
@@ -139,7 +259,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// <returns>A blob containing serialized information that can be used to register an effect.</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown if an effect is registered multiple times with different properties.</exception>
|
||||
/// <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)
|
||||
public static ReadOnlyMemory<byte> GetRegistrationBlob<T>(out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
return GetRegistrationBlob<T>(null, out effectId);
|
||||
@@ -154,7 +274,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// <returns>A blob containing serialized information that can be used to register an effect.</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown if an effect is registered multiple times with different properties.</exception>
|
||||
/// <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)
|
||||
public static ReadOnlyMemory<byte> GetRegistrationBlob<T, TMapper>(out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
where TMapper : class, ID2D1TransformMapper<T>, new()
|
||||
{
|
||||
@@ -201,7 +321,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// 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> GetRegistrationBlob<T>(Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
public static ReadOnlyMemory<byte> GetRegistrationBlob<T>(Func<ID2D1TransformMapper<T>>? mapperFactory, out Guid effectId)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
effectId = default;
|
||||
@@ -243,26 +363,129 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
<Property name='Buffer' type='blob'>
|
||||
<Property name='DisplayName' type='string' value='Buffer'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager0' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager0'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager1' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager1'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager2' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager2'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager3' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager3'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager4' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager4'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager5' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager5'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager6' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager6'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager7' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager7'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager8' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager8'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager9' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager9'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager10' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager10'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager11' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager11'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager12' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager12'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager13' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager13'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager14' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager14'/>
|
||||
</Property>
|
||||
<Property name='ResourceTextureManager15' type='iunknown'>
|
||||
<Property name='DisplayName' type='string' value='ResourceTextureManager15'/>
|
||||
</Property>
|
||||
</Effect>");
|
||||
|
||||
// Null terminator for the text
|
||||
writer.Write((byte)'\0');
|
||||
|
||||
// Property accessors
|
||||
#if NET6_0_OR_GREATER
|
||||
nint getBufferPointer = (nint)(delegate* unmanaged<IUnknown*, byte*, uint, uint*, int>)&PixelShaderEffect.GetConstantBuffer;
|
||||
nint setBufferPointer = (nint)(delegate* unmanaged<IUnknown*, byte*, uint, int>)&PixelShaderEffect.SetConstantBuffer;
|
||||
#else
|
||||
nint getBufferPointer = Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.GetConstantBufferWrapper);
|
||||
nint setBufferPointer = Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.SetConstantBufferWrapper);
|
||||
#endif
|
||||
|
||||
// Bindings
|
||||
writer.Write(1);
|
||||
writer.Write(17);
|
||||
writer.WriteAsUtf8("Buffer");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write(getBufferPointer);
|
||||
writer.Write(setBufferPointer);
|
||||
writer.Write((nint)PixelShaderEffect.GetConstantBuffer);
|
||||
writer.Write((nint)PixelShaderEffect.SetConstantBuffer);
|
||||
writer.WriteAsUtf8("ResourceTextureManager0");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager0);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager0);
|
||||
writer.WriteAsUtf8("ResourceTextureManager1");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager1);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager1);
|
||||
writer.WriteAsUtf8("ResourceTextureManager2");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager2);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager2);
|
||||
writer.WriteAsUtf8("ResourceTextureManager3");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager3);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager3);
|
||||
writer.WriteAsUtf8("ResourceTextureManager4");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager4);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager4);
|
||||
writer.WriteAsUtf8("ResourceTextureManager5");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager5);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager5);
|
||||
writer.WriteAsUtf8("ResourceTextureManager6");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager6);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager6);
|
||||
writer.WriteAsUtf8("ResourceTextureManager7");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager7);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager7);
|
||||
writer.WriteAsUtf8("ResourceTextureManager8");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager8);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager8);
|
||||
writer.WriteAsUtf8("ResourceTextureManager9");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager9);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager9);
|
||||
writer.WriteAsUtf8("ResourceTextureManager10");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager10);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager10);
|
||||
writer.WriteAsUtf8("ResourceTextureManager11");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager11);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager11);
|
||||
writer.WriteAsUtf8("ResourceTextureManager12");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager12);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager12);
|
||||
writer.WriteAsUtf8("ResourceTextureManager13");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager13);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager13);
|
||||
writer.WriteAsUtf8("ResourceTextureManager14");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager14);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager14);
|
||||
writer.WriteAsUtf8("ResourceTextureManager15");
|
||||
writer.Write((byte)'\0');
|
||||
writer.Write((nint)PixelShaderEffect.GetResourceTextureManager15);
|
||||
writer.Write((nint)PixelShaderEffect.SetResourceTextureManager15);
|
||||
|
||||
// Effect factory
|
||||
writer.Write((nint)PixelShaderEffect.For<T>.Factory);
|
||||
@@ -278,15 +501,26 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader to create an effect for.</typeparam>
|
||||
/// <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>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1DeviceContext"/> or <paramref name="d2D1Effect"/> are <see langword="null"/>.</exception>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown if this method is called before initializing a shader effect for the shader type <typeparamref name="T"/>.
|
||||
/// To do so, make sure to call either <see cref="RegisterForD2D1Factory1{T}(void*, out Guid)"/> (or an overload), or
|
||||
/// to use <see cref="GetRegistrationBlob{T}(out Guid)"/> (or an overload), and use that blob to register an effect.
|
||||
/// </exception>
|
||||
/// <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 CreateFromD2D1DeviceContext<T>(void* d2D1DeviceContext, void** d2D1Effect)
|
||||
public static void CreateFromD2D1DeviceContext<T>(void* d2D1DeviceContext, void** d2D1Effect)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if (d2D1DeviceContext is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1DeviceContext), "The input ID2D1DeviceContext object cannot be null.");
|
||||
}
|
||||
|
||||
if (d2D1Effect is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The pointer to the target ID2D1Effect result cannot be null.");
|
||||
}
|
||||
|
||||
if (!PixelShaderEffect.For<T>.TryGetId(out Guid id))
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("The effect for the input shader type has not been initialized yet.");
|
||||
@@ -303,12 +537,76 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
/// <typeparam name="T">The type of D2D1 pixel shader to set the constant buffer for.</typeparam>
|
||||
/// <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>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Effect"/> is <see langword="null"/>.</exception>
|
||||
/// <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 void SetConstantBufferForD2D1Effect<T>(in T shader, void* d2D1Effect)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if (d2D1Effect is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1DeviceContext object cannot be null.");
|
||||
}
|
||||
|
||||
D2D1EffectDispatchDataLoader dataLoader = new((ID2D1Effect*)d2D1Effect);
|
||||
|
||||
Unsafe.AsRef(in shader).LoadDispatchData(ref dataLoader);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the resource texture manager from an input D2D1 effect, by calling <c>ID2D1Effect::SetValue</c>.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">A pointer to the <c>ID2D1Effect</c> instance to use.</param>
|
||||
/// <param name="resourceTextureManager">The input <c>ID2D1ResourceTextureManager</c> object (see <see cref="D2D1ResourceTextureManager"/>).</param>
|
||||
/// <param name="resourceTextureIndex">The index of the resource texture to assign the resource texture manager to.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Effect"/> or <paramref name="resourceTextureManager"/> are <see langword="null"/>.</exception>
|
||||
/// <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 void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, void* resourceTextureManager, int resourceTextureIndex)
|
||||
{
|
||||
if (d2D1Effect is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1Effect object cannot be null.");
|
||||
}
|
||||
|
||||
if (resourceTextureManager is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(resourceTextureManager), "The input ID2D1ResourceTextureManager object cannot be null.");
|
||||
}
|
||||
|
||||
((ID2D1Effect*)d2D1Effect)->SetValue(
|
||||
index: D2D1PixelShaderEffectProperty.ResourceTextureManager0 + (uint)resourceTextureIndex,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_IUNKNOWN,
|
||||
data: (byte*)&resourceTextureManager,
|
||||
dataSize: (uint)sizeof(void*)).Assert();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the resource texture manager from an input D2D1 effect, by calling <c>ID2D1Effect::SetValue</c>.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">A pointer to the <c>ID2D1Effect</c> instance to use.</param>
|
||||
/// <param name="resourceTextureManager">The input <see cref="D2D1ResourceTextureManager"/> instance..</param>
|
||||
/// <param name="resourceTextureIndex">The index of the resource texture to assign the resource texture manager to.</param>
|
||||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="d2D1Effect"/> or <paramref name="resourceTextureManager"/> are <see langword="null"/>.</exception>
|
||||
/// <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 void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, D2D1ResourceTextureManager resourceTextureManager, int resourceTextureIndex)
|
||||
{
|
||||
if (d2D1Effect is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(d2D1Effect), "The input ID2D1Effect object cannot be null.");
|
||||
}
|
||||
|
||||
if (resourceTextureManager is null)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentNullException(nameof(resourceTextureManager), "The input D2D1ResourceTextureManager object cannot be null.");
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager2 = default;
|
||||
|
||||
resourceTextureManager.GetD2D1ResourceTextureManager(resourceTextureManager2.GetAddressOf());
|
||||
|
||||
((ID2D1Effect*)d2D1Effect)->SetValue(
|
||||
index: D2D1PixelShaderEffectProperty.ResourceTextureManager0 + (uint)resourceTextureIndex,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_IUNKNOWN,
|
||||
data: (byte*)resourceTextureManager2.GetAddressOf(),
|
||||
dataSize: (uint)sizeof(void*)).Assert();
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
public static class D2D1PixelShaderEffectProperty
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>The index for the constant buffer property of a <see cref="D2D1PixelShaderEffect"/> object.</para>
|
||||
/// The index for the constant buffer property of a <see cref="D2D1PixelShaderEffect"/> object.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>The value to set for this property can be retrieved with <see cref="D2D1PixelShader.GetConstantBuffer{T}(in T)"/>.</para>
|
||||
@@ -16,4 +16,100 @@ public static class D2D1PixelShaderEffectProperty
|
||||
/// <para>For more info, see <see href="https://docs.microsoft.com/en-us/windows/win32/api/d2d1_1/nf-d2d1_1-id2d1properties-getvalue(u)"/>.</para>
|
||||
/// </remarks>
|
||||
public const uint ConstantBuffer = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 0.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager0 = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 1.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager1 = 2;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 2.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager2 = 3;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 3.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager3 = 4;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 4.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager4 = 5;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 5.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager5 = 6;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 6.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager6 = 7;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 7.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager7 = 8;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 8.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager8 = 9;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 9.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager9 = 10;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 10.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager10 = 11;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 11.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager11 = 12;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 12.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager12 = 13;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 13.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager13 = 14;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 14.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager14 = 15;
|
||||
|
||||
/// <summary>
|
||||
/// The index for the <c>ID2D1ResourceTextureManager</c> instance for the resource texture at index 15.
|
||||
/// </summary>
|
||||
/// <remarks>For more info, see <see cref="D2D1ResourceTextureManager"/>.</remarks>
|
||||
public const uint ResourceTextureManager15 = 16;
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
/// <summary>
|
||||
/// Provides an <c>ID2D1ResourceTextureManager</c> implementation, which can be used to manage resources in
|
||||
/// an effect created with <see cref="D2D1PixelShaderEffect"/> and share them across multiple effect instances.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The built-in <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nn-d2d1effectauthor-id2d1effectimpl"><c>ID2D1EffectImpl</c></see>
|
||||
/// implementation provided by <see cref="D2D1PixelShaderEffect"/> (which makes it possible to register and create
|
||||
/// <see href="https://docs.microsoft.com/en-us/windows/win32/api/d2d1_1/nn-d2d1_1-id2d1effect"><c>ID2D1Effect</c></see>
|
||||
/// instances that can be used to run D2D1 pixel shaders) uses resource texture manager objects to handle resource textures.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// These managers are COM objects implementing the following interface:
|
||||
/// <code>
|
||||
/// [uuid(3C4FC7E4-A419-46CA-B5F6-66EB4FF18D64)]
|
||||
/// interface ID2D1ResourceTextureManager : IUnknown
|
||||
/// {
|
||||
/// HRESULT Initialize(
|
||||
/// [in, optional] const GUID *resourceId,
|
||||
/// [in] const D2D1_RESOURCE_TEXTURE_PROPERTIES *resourceTextureProperties,
|
||||
/// [in, optional] const BYTE *data,
|
||||
/// [in, optional] const UINT32 *strides,
|
||||
/// UINT32 dataSize);
|
||||
///
|
||||
/// HRESULT Update(
|
||||
/// [in, optional] const UINT32 *minimumExtents,
|
||||
/// [in, optional] const UINT32 *maximimumExtents,
|
||||
/// [in] const UINT32 *strides,
|
||||
/// UINT32 dimensions,
|
||||
/// [in] const BYTE *data,
|
||||
/// UINT32 dataCount);
|
||||
/// };
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// These can be used to create resource textures, pass them to effects, and also share resources among different effects.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// For details of how these work, <c>Initialize</c> maps to
|
||||
/// <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nf-d2d1effectauthor-id2d1effectcontext-createresourcetexture"><c>ID2D1EffectContext::CreateResourceTexture</c></see>,
|
||||
/// whereas <c>Update</c> maps to <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nf-d2d1effectauthor-id2d1resourcetexture-update"><c>ID2D1ResourceTexture::Update</c></see>.
|
||||
/// The same behavior and parameters as those methods is used.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// This interface is implemented by ComputeSharp.D2D1, and it can be used through the APIs in <see cref="D2D1ResourceTextureManager"/>.
|
||||
/// That is, <see cref="Create"/> is first used to create an <c>ID2D1ResourceTextureManager</c> instance. Then, <see cref="Initialize"/>
|
||||
/// can be used to initialize the resource texture held by the manager. The manager can also be assigned to an effect at any time,
|
||||
/// using the available property indices from <see cref="D2D1PixelShaderEffectProperty"/>. To update texture data after its initial
|
||||
/// creation, <see cref="Update(void*, ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{byte})"/> can be used.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// An RCW (runtime callable wrapper, see <see href="https://docs.microsoft.com/dotnet/standard/native-interop/runtime-callable-wrapper"/>),
|
||||
/// is also available for all of these APIs, implemented by the same <see cref="D2D1PixelShaderEffect"/>. In this case, the constructor can
|
||||
/// be used to create and initialize an instance (equivalent to calling <see cref="Create"/> and <see cref="Initialize"/>), and then
|
||||
/// <see cref="Update(ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{uint}, ReadOnlySpan{byte})"/> is available for texture data updates.
|
||||
/// The instance implements <see cref="ICustomQueryInterface"/>, which can be used in advanced scenarios to retrieve the underlying COM object.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The <c>ID2D1ResourceTextureManager</c> contract allows callers to create a resource texture at any time even before the effect
|
||||
/// has been initialized and the manager assigned to it. In that case, the manager will buffer the data internally, and will defer
|
||||
/// the creation of the actual resource texture until it's possible for it to do so, at which point it will also free the buffer.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If implementing a custom resource manager is needed, in order for external implementations to be accepted by the effect objects
|
||||
/// created by <see cref="D2D1PixelShaderEffect"/>, the <c>ID2D1ResourceTextureManagerInternal</c> interface also needs to be implemented:
|
||||
/// <code>
|
||||
/// [uuid(5CBB1024-8EA1-4689-81BF-8AD190B5EF5D)]
|
||||
/// interface ID2D1ResourceTextureManager : IUnknown
|
||||
/// {
|
||||
/// HRESULT Initialize(
|
||||
/// [in] ID2D1EffectContext *effectContext,
|
||||
/// [in, optional] const UINT32 *dimensions);
|
||||
///
|
||||
/// HRESULT GetResourceTexture([out] ID2D1ResourceTexture **resourceTexture);
|
||||
/// };
|
||||
/// </code>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Note that due to the fact <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nn-d2d1effectauthor-id2d1effectcontext"><c>ID2D1EffectContext</c></see>
|
||||
/// and <see href="https://docs.microsoft.com/windows/win32/api/d2d1effectauthor/nn-d2d1effectauthor-id2d1resourcetexture"><c>ID2D1ResourceTexture</c></see> are not thread safe,
|
||||
/// they are only safe to use without additional synchronization when <c>Initialize</c> and <c>GetResourceTexture</c> are called. This happens from the internal
|
||||
/// <see href="https://docs.microsoft.com/windows/win32/api/d2d1_1/nn-d2d1_1-id2d1multithread"><c>ID2D1EffectImpl</c></see> object, which is invoked by D2D, which will handle
|
||||
/// taking the necessary lock before invoking these APIs. Due to the fact the context has to be stored internally, custom implementations have to make sure to retrieve the
|
||||
/// right <c>ID2D1Multithread</c> instance from the effect context and use that to synchronize all accesses to those two objects from all APIs (including those exposed by
|
||||
/// <c>ID2D1ResourceTextureManager</c>). The built-in implementation of these two interfaces provided by <see cref="D2D1ResourceTextureManager"/> takes care of all this.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The <c>dimensions</c> parameter in <c>ID2D1ResourceTextureManager::Initialize</c> is optional, and can be passed by an <c>ID2D1Effect</c>
|
||||
/// when initializing an input resurce texture manager, if the dimensions of the resource texture at the target index are known in advance.
|
||||
/// This can allow the manager to perform additional validation when the resource texture is initialized. Not providing a value is not an
|
||||
/// error, but if a resource texture with invalid size is used the effect might fail to render later on and be more difficult to troubleshoot.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed unsafe class D2D1ResourceTextureManager : ICustomQueryInterface
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1ResourceTextureManagerImpl"/> object wrapped by the current instance.
|
||||
/// </summary>
|
||||
private readonly D2D1ResourceTextureManagerImpl* d2D1ResourceManagerImpl;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes)
|
||||
: this(
|
||||
null,
|
||||
extents,
|
||||
bufferPrecision,
|
||||
channelDepth,
|
||||
filter,
|
||||
extendModes,
|
||||
ReadOnlySpan<byte>.Empty,
|
||||
ReadOnlySpan<uint>.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="resourceId">The resource id for the resource to create.</param>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
Guid resourceId,
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes)
|
||||
: this(
|
||||
&resourceId,
|
||||
extents,
|
||||
bufferPrecision,
|
||||
channelDepth,
|
||||
filter,
|
||||
extendModes,
|
||||
ReadOnlySpan<byte>.Empty,
|
||||
ReadOnlySpan<uint>.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <param name="data">The data to load in the resource to create.</param>
|
||||
/// <param name="strides">The strides for the data supplied for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes,
|
||||
ReadOnlySpan<byte> data,
|
||||
ReadOnlySpan<uint> strides)
|
||||
: this(
|
||||
null,
|
||||
extents,
|
||||
bufferPrecision,
|
||||
channelDepth,
|
||||
filter,
|
||||
extendModes,
|
||||
data,
|
||||
strides)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="resourceId">The resource id for the resource to create.</param>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <param name="data">The data to load in the resource to create.</param>
|
||||
/// <param name="strides">The strides for the data supplied for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
public D2D1ResourceTextureManager(
|
||||
Guid resourceId,
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes,
|
||||
ReadOnlySpan<byte> data,
|
||||
ReadOnlySpan<uint> strides)
|
||||
: this(
|
||||
&resourceId,
|
||||
extents,
|
||||
bufferPrecision,
|
||||
channelDepth,
|
||||
filter,
|
||||
extendModes,
|
||||
data,
|
||||
strides)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="D2D1ResourceTextureManager"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="resourceId">The resource id for the resource to create.</param>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <param name="data">The data to load in the resource to create.</param>
|
||||
/// <param name="strides">The strides for the data supplied for the resource to create.</param>
|
||||
/// <exception cref="Exception">Thrown if creating or initializing the <see cref="D2D1ResourceTextureManager"/> instance failed.</exception>
|
||||
private D2D1ResourceTextureManager(
|
||||
Guid* resourceId,
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes,
|
||||
ReadOnlySpan<byte> data,
|
||||
ReadOnlySpan<uint> strides)
|
||||
{
|
||||
// Manually validate the parameters here to ensure the native objects wouldn't try
|
||||
// to read out of bounds and potentially AV. For those cases, we just throw here.
|
||||
if (extents.Length == 0 ||
|
||||
extendModes.Length == 0 ||
|
||||
extents.Length != extendModes.Length ||
|
||||
(data.Length > 0 && strides.Length != extents.Length - 1))
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
Marshal.ThrowExceptionForHR(E.E_INVALIDARG);
|
||||
}
|
||||
|
||||
fixed (D2D1ResourceTextureManagerImpl** d2D1ResourceManagerImpl = &this.d2D1ResourceManagerImpl)
|
||||
{
|
||||
D2D1ResourceTextureManagerImpl.Factory(d2D1ResourceManagerImpl);
|
||||
}
|
||||
|
||||
fixed (uint* pExtents = extents)
|
||||
fixed (D2D1ExtendMode* pExtendModes = extendModes)
|
||||
fixed (byte* pData = data)
|
||||
fixed (uint* pStrides = strides)
|
||||
{
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES d2D1ResourceTextureProperties;
|
||||
d2D1ResourceTextureProperties.extents = pExtents;
|
||||
d2D1ResourceTextureProperties.dimensions = (uint)extents.Length;
|
||||
d2D1ResourceTextureProperties.bufferPrecision = (D2D1_BUFFER_PRECISION)bufferPrecision;
|
||||
d2D1ResourceTextureProperties.channelDepth = (D2D1_CHANNEL_DEPTH)channelDepth;
|
||||
d2D1ResourceTextureProperties.filter = (D2D1_FILTER)filter;
|
||||
d2D1ResourceTextureProperties.extendModes = (D2D1_EXTEND_MODE*)pExtendModes;
|
||||
|
||||
int hresult = D2D1ResourceTextureManagerImpl.Initialize(
|
||||
@this: this.d2D1ResourceManagerImpl,
|
||||
resourceId: resourceId,
|
||||
resourceTextureProperties: &d2D1ResourceTextureProperties,
|
||||
data: pData,
|
||||
strides: pStrides,
|
||||
dataSize: (uint)data.Length);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the underlying <c>ID2D1ResourceTextureManager</c> object.
|
||||
/// </summary>
|
||||
~D2D1ResourceTextureManager()
|
||||
{
|
||||
if (this.d2D1ResourceManagerImpl is not null)
|
||||
{
|
||||
this.d2D1ResourceManagerImpl->Release();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specific resource texture inside the specific range or box using the supplied data.
|
||||
/// </summary>
|
||||
/// <param name="minimumExtents">The "left" extent of the updates if specified. If <see langword="null"/>, the entire texture is updated.</param>
|
||||
/// <param name="maximimumExtents">The "right" extent of the updates if specified. If <see langword="null"/>, the entire texture is updated.</param>
|
||||
/// <param name="strides">The stride to advance through the input data, according to dimension.</param>
|
||||
/// <param name="data">The data to be placed into the resource texture.</param>
|
||||
public void Update(
|
||||
ReadOnlySpan<uint> minimumExtents,
|
||||
ReadOnlySpan<uint> maximimumExtents,
|
||||
ReadOnlySpan<uint> strides,
|
||||
ReadOnlySpan<byte> data)
|
||||
{
|
||||
fixed (uint* pMinimumExtents = minimumExtents)
|
||||
fixed (uint* pMaximumExtents = maximimumExtents)
|
||||
fixed (uint* pStrides = strides)
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
int dimensions = strides.Length + 1;
|
||||
|
||||
// Ensure that if the extents are not null, their length is correct. This is again to
|
||||
// avoid the native method assuming they'd be longer than they are and causing an AV.
|
||||
if (pMinimumExtents is not null &&
|
||||
pMaximumExtents is not null &&
|
||||
(minimumExtents.Length != dimensions || maximimumExtents.Length != dimensions))
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(E.E_INVALIDARG);
|
||||
}
|
||||
|
||||
int hresult = D2D1ResourceTextureManagerImpl.Update(
|
||||
@this: this.d2D1ResourceManagerImpl,
|
||||
minimumExtents: pMinimumExtents,
|
||||
maximimumExtents: pMaximumExtents,
|
||||
strides: pStrides,
|
||||
dimensions: (uint)dimensions,
|
||||
data: pData,
|
||||
dataCount: (uint)data.Length);
|
||||
|
||||
GC.KeepAlive(this);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the underlying <see cref="ID2D1ResourceTextureManager"/> object.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureManager">The underlying <see cref="ID2D1ResourceTextureManager"/> object.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void GetD2D1ResourceTextureManager(ID2D1ResourceTextureManager** resourceTextureManager)
|
||||
{
|
||||
_ = this.d2D1ResourceManagerImpl->AddRef();
|
||||
|
||||
*resourceTextureManager = (ID2D1ResourceTextureManager*)this.d2D1ResourceManagerImpl;
|
||||
|
||||
GC.KeepAlive(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
CustomQueryInterfaceResult ICustomQueryInterface.GetInterface(ref Guid iid, out IntPtr ppv)
|
||||
{
|
||||
fixed (Guid* pIid = &iid)
|
||||
fixed (IntPtr* pPpv = &ppv)
|
||||
{
|
||||
int hresult = this.d2D1ResourceManagerImpl->QueryInterface(pIid, (void**)pPpv);
|
||||
|
||||
GC.KeepAlive(this);
|
||||
|
||||
return hresult switch
|
||||
{
|
||||
S.S_OK => CustomQueryInterfaceResult.Handled,
|
||||
_ => CustomQueryInterfaceResult.Failed
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <c>ID2D1ResourceTextureManager</c> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureManager">A pointer to the resulting <c>ID2D1ResourceTextureManager</c> instance.</param>
|
||||
public static void Create(void** resourceTextureManager)
|
||||
{
|
||||
D2D1ResourceTextureManagerImpl.Factory((D2D1ResourceTextureManagerImpl**)resourceTextureManager);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a given <c>ID2D1ResourceTextureManager</c> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureManager">A pointer to the <c>ID2D1ResourceTextureManager</c> instance to use.</param>
|
||||
/// <param name="resourceId">The resource id for the resource to create.</param>
|
||||
/// <param name="extents">The extents of the resource to create.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resource to create.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resource to create.</param>
|
||||
/// <param name="filter">The filter for the resource to create.</param>
|
||||
/// <param name="extendModes">The extend modes for the resource to create.</param>
|
||||
/// <param name="data">The data to load in the resource to create.</param>
|
||||
/// <param name="strides">The strides for the data supplied for the resource to create.</param>
|
||||
/// <remarks>
|
||||
/// Depending on internal state, <paramref name="resourceTextureManager"/> might immediately create the resource
|
||||
/// texture, or it might buffer the data internally and then create the resource texture at a later time.
|
||||
/// </remarks>
|
||||
public static void Initialize(
|
||||
void* resourceTextureManager,
|
||||
Guid resourceId,
|
||||
ReadOnlySpan<uint> extents,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
D2D1Filter filter,
|
||||
ReadOnlySpan<D2D1ExtendMode> extendModes,
|
||||
ReadOnlySpan<byte> data,
|
||||
ReadOnlySpan<uint> strides)
|
||||
{
|
||||
// Validate parameters early from here too to avoid AVs in the native method
|
||||
if (extents.Length == 0 ||
|
||||
extendModes.Length == 0 ||
|
||||
extents.Length != extendModes.Length ||
|
||||
(data.Length > 0 && strides.Length != extents.Length - 1))
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(E.E_INVALIDARG);
|
||||
}
|
||||
|
||||
fixed (uint* pExtents = extents)
|
||||
fixed (D2D1ExtendMode* pExtendModes = extendModes)
|
||||
fixed (byte* pData = data)
|
||||
fixed (uint* pStrides = strides)
|
||||
{
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES d2D1ResourceTextureProperties;
|
||||
d2D1ResourceTextureProperties.extents = pExtents;
|
||||
d2D1ResourceTextureProperties.dimensions = (uint)extents.Length;
|
||||
d2D1ResourceTextureProperties.bufferPrecision = (D2D1_BUFFER_PRECISION)bufferPrecision;
|
||||
d2D1ResourceTextureProperties.channelDepth = (D2D1_CHANNEL_DEPTH)channelDepth;
|
||||
d2D1ResourceTextureProperties.filter = (D2D1_FILTER)filter;
|
||||
d2D1ResourceTextureProperties.extendModes = (D2D1_EXTEND_MODE*)pExtendModes;
|
||||
|
||||
int hresult = ((ID2D1ResourceTextureManager*)resourceTextureManager)->Initialize(
|
||||
resourceId: &resourceId,
|
||||
resourceTextureProperties: &d2D1ResourceTextureProperties,
|
||||
data: pData,
|
||||
strides: pStrides,
|
||||
dataSize: (uint)data.Length);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the data in a given <c>ID2D1ResourceTextureManager</c> instance.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureManager">A pointer to the <c>ID2D1ResourceTextureManager</c> instance to use.</param>
|
||||
/// <param name="minimumExtents">The "left" extent of the updates if specified (if empty, the entire texture is updated).</param>
|
||||
/// <param name="maximimumExtents">The "right" extent of the updates if specified (if empty, the entire texture is updated).</param>
|
||||
/// <param name="strides">The stride to advance through the input data.</param>
|
||||
/// <param name="data">The data to be placed into the resource texture.</param>
|
||||
public static void Update(
|
||||
void* resourceTextureManager,
|
||||
ReadOnlySpan<uint> minimumExtents,
|
||||
ReadOnlySpan<uint> maximimumExtents,
|
||||
ReadOnlySpan<uint> strides,
|
||||
ReadOnlySpan<byte> data)
|
||||
{
|
||||
fixed (uint* pMinimumExtents = minimumExtents)
|
||||
fixed (uint* pMaximumExtents = maximimumExtents)
|
||||
fixed (uint* pStrides = strides)
|
||||
fixed (byte* pData = data)
|
||||
{
|
||||
int dimensions = strides.Length + 1;
|
||||
|
||||
// Same validation as in the Update instance method above
|
||||
if (pMinimumExtents is not null &&
|
||||
pMaximumExtents is not null &&
|
||||
(minimumExtents.Length != dimensions || maximimumExtents.Length != dimensions))
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(E.E_INVALIDARG);
|
||||
}
|
||||
|
||||
int hresult = ((ID2D1ResourceTextureManager*)resourceTextureManager)->Update(
|
||||
minimumExtents: pMinimumExtents,
|
||||
maximimumExtents: pMaximumExtents,
|
||||
strides: pStrides,
|
||||
dimensions: (uint)dimensions,
|
||||
data: pData,
|
||||
dataCount: (uint)data.Length);
|
||||
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,10 +37,13 @@ public static class D2D1ShaderCompiler
|
||||
int sourceWrittenBytes = Encoding.ASCII.GetBytes(hlslSource, sourceBuffer);
|
||||
|
||||
// Encode the entry point to ASCII
|
||||
int maxEntryPointLength = Encoding.ASCII.GetMaxByteCount(entryPoint.Length);
|
||||
int maxEntryPointLength = Encoding.ASCII.GetMaxByteCount(entryPoint.Length) + 1;
|
||||
byte[] entryPointBuffer = ArrayPool<byte>.Shared.Rent(maxEntryPointLength);
|
||||
int entryPointWrittenBytes = Encoding.ASCII.GetBytes(entryPoint, entryPointBuffer);
|
||||
|
||||
// The entry point has to be null-terminated
|
||||
entryPointBuffer[entryPointWrittenBytes] = (byte)'\0';
|
||||
|
||||
ReadOnlySpan<byte> sourceAscii = sourceBuffer.AsSpan(0, sourceWrittenBytes);
|
||||
ReadOnlySpan<byte> entryPointAscii = entryPointBuffer.AsSpan(0, entryPointWrittenBytes);
|
||||
|
||||
@@ -56,7 +59,7 @@ public static class D2D1ShaderCompiler
|
||||
/// Compiles a new HLSL shader from the input source code.
|
||||
/// </summary>
|
||||
/// <param name="hlslSourceAscii">The HLSL source code to compile (in ASCII).</param>
|
||||
/// <param name="entryPointAscii">The entry point of the shader being compiled (in ASCII).</param>
|
||||
/// <param name="entryPointAscii">The entry point of the shader being compiled (in ASCII, null-terminated).</param>
|
||||
/// <param name="shaderProfile">The shader profile to use to compile the shader.</param>
|
||||
/// <param name="options">The compiler options to use to compile the shader.</param>
|
||||
/// <returns>The bytecode for the compiled shader.</returns>
|
||||
|
||||
@@ -44,6 +44,11 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// </remarks>
|
||||
private static Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The size of the constant buffer for the shader.
|
||||
/// </summary>
|
||||
private static int constantBufferSize;
|
||||
|
||||
/// <summary>
|
||||
/// The number of inputs for the shader.
|
||||
/// </summary>
|
||||
@@ -89,6 +94,16 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// </summary>
|
||||
private static D2D1ChannelDepth channelDepth;
|
||||
|
||||
/// <summary>
|
||||
/// The number of available resource texture descriptions.
|
||||
/// </summary>
|
||||
private static int resourceTextureDescriptionCount;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer with the available resource texture descriptions for the shader.
|
||||
/// </summary>
|
||||
private static D2D1ResourceTextureDescription* resourceTextureDescriptions;
|
||||
|
||||
/// <summary>
|
||||
/// The factory of <see cref="ID2D1TransformMapper{T}"/> instances to use for each created effect.
|
||||
/// </summary>
|
||||
@@ -119,9 +134,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
// Load all shader properties
|
||||
Guid shaderId = typeof(T).GUID;
|
||||
ReadOnlyMemory<byte> bytecodeInfo = D2D1PixelShader.LoadBytecode<T>();
|
||||
int bytecodeSize = bytecodeInfo.Length;
|
||||
byte* bytecode = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For<T>), bytecodeSize);
|
||||
int constantBufferSize = D2D1PixelShader.GetConstantBufferSize<T>();
|
||||
D2D1BufferPrecision bufferPrecision = D2D1PixelShader.GetOutputBufferPrecision<T>();
|
||||
D2D1ChannelDepth channelDepth = D2D1PixelShader.GetOutputBufferChannelDepth<T>();
|
||||
D2D1PixelOptions pixelOptions = D2D1PixelShader.GetPixelOptions<T>();
|
||||
@@ -142,11 +155,23 @@ internal unsafe partial struct PixelShaderEffect
|
||||
|
||||
inputDescriptionsInfo.Span.CopyTo(new Span<D2D1InputDescription>(inputDescriptions, inputDescriptionCount));
|
||||
|
||||
// Prepare the resource texture descriptions
|
||||
ReadOnlyMemory<D2D1ResourceTextureDescription> resourceTextureDescriptionsInfo = D2D1PixelShader.GetResourceTextureDescriptions<T>();
|
||||
int resourceTextureDescriptionCount = resourceTextureDescriptionsInfo.Length;
|
||||
D2D1ResourceTextureDescription* resourceTextureDescriptions = (D2D1ResourceTextureDescription*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For<T>), sizeof(D2D1ResourceTextureDescription) * resourceTextureDescriptionCount);
|
||||
|
||||
resourceTextureDescriptionsInfo.Span.CopyTo(new Span<D2D1ResourceTextureDescription>(resourceTextureDescriptions, resourceTextureDescriptionCount));
|
||||
|
||||
// Copy the bytecode to the target buffer
|
||||
ReadOnlyMemory<byte> bytecodeInfo = D2D1PixelShader.LoadBytecode<T>();
|
||||
int bytecodeSize = bytecodeInfo.Length;
|
||||
byte* bytecode = (byte*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For<T>), bytecodeSize);
|
||||
|
||||
bytecodeInfo.Span.CopyTo(new Span<byte>(bytecode, bytecodeSize));
|
||||
|
||||
// Set the shared state and mark the type as initialized
|
||||
For<T>.shaderId = shaderId;
|
||||
For<T>.constantBufferSize = constantBufferSize;
|
||||
For<T>.inputCount = inputCount;
|
||||
For<T>.inputTypes = inputTypes;
|
||||
For<T>.inputDescriptionCount = inputDescriptionCount;
|
||||
@@ -156,6 +181,8 @@ internal unsafe partial struct PixelShaderEffect
|
||||
For<T>.bytecodeSize = bytecodeSize;
|
||||
For<T>.bufferPrecision = bufferPrecision;
|
||||
For<T>.channelDepth = channelDepth;
|
||||
For<T>.resourceTextureDescriptionCount = resourceTextureDescriptionCount;
|
||||
For<T>.resourceTextureDescriptions = resourceTextureDescriptions;
|
||||
For<T>.d2D1DrawTransformMapperFactory = d2D1DrawTransformMapperFactory;
|
||||
|
||||
isInitialized = true;
|
||||
@@ -231,6 +258,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
|
||||
return PixelShaderEffect.Factory(
|
||||
shaderId,
|
||||
constantBufferSize,
|
||||
inputCount,
|
||||
inputTypes,
|
||||
inputDescriptionCount,
|
||||
@@ -240,6 +268,8 @@ internal unsafe partial struct PixelShaderEffect
|
||||
bytecodeSize,
|
||||
bufferPrecision,
|
||||
channelDepth,
|
||||
resourceTextureDescriptionCount,
|
||||
resourceTextureDescriptions,
|
||||
d2D1TransformMapper,
|
||||
effectImpl);
|
||||
}
|
||||
|
||||
+77
-2
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
@@ -128,11 +129,27 @@ internal unsafe partial struct PixelShaderEffect
|
||||
}
|
||||
}
|
||||
|
||||
// If loading the bytecode succeeded, set the transform node
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
hresult = transformGraph->SetSingleTransformNode((ID2D1TransformNode*)&@this->lpVtblForID2D1DrawTransform);
|
||||
}
|
||||
|
||||
// If the transform node was set, also store the effect context
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
// Free the previous ID2D1EffectContext object, if present
|
||||
if (@this->d2D1EffectContext is not null)
|
||||
{
|
||||
_ = @this->d2D1EffectContext->Release();
|
||||
}
|
||||
|
||||
// Store the new ID2D1EffectContext object
|
||||
_ = effectContext->AddRef();
|
||||
|
||||
@this->d2D1EffectContext = effectContext;
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
@@ -140,14 +157,72 @@ internal unsafe partial struct PixelShaderEffect
|
||||
[UnmanagedCallersOnly]
|
||||
public static int PrepareForRender(PixelShaderEffect* @this, D2D1_CHANGE_TYPE changeType)
|
||||
{
|
||||
int hresult = S.S_OK;
|
||||
|
||||
// Validate the constant buffer
|
||||
if (@this->constantBufferSize > 0 &&
|
||||
@this->constantBuffer is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// First, set the constant buffer, if available
|
||||
if (@this->constantBuffer is not null)
|
||||
{
|
||||
return @this->d2D1DrawInfo->SetPixelShaderConstantBuffer(
|
||||
hresult = @this->d2D1DrawInfo->SetPixelShaderConstantBuffer(
|
||||
buffer: @this->constantBuffer,
|
||||
bufferCount: (uint)@this->constantBufferSize);
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
foreach (ref readonly D2D1ResourceTextureDescription resourceTextureDescription in new ReadOnlySpan<D2D1ResourceTextureDescription>(@this->resourceTextureDescriptions, @this->resourceTextureDescriptionCount))
|
||||
{
|
||||
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = @this->resourceTextureManagerBuffer[resourceTextureDescription.Index];
|
||||
|
||||
// If the current resource texture manager is not set, we cannot render, as there's an unbound resource texture
|
||||
if (resourceTextureManager.Get() is null)
|
||||
{
|
||||
hresult = E.E_NOT_VALID_STATE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1ResourceTextureManagerInternal> resourceTextureManagerInternal = default;
|
||||
|
||||
// Get the ID2D1ResourceTextureManagerInternal object
|
||||
hresult = resourceTextureManager.CopyTo(resourceTextureManagerInternal.GetAddressOf());
|
||||
|
||||
// This cast should always succeed, as when an input resource texture managers is set it's
|
||||
// also checked for ID2D1ResourceTextureManagerInternal, but still validate for good measure.
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1ResourceTexture> d2D1ResourceTexture = default;
|
||||
|
||||
// Try to get the ID2D1ResourceTexture from the manager
|
||||
hresult = resourceTextureManagerInternal.Get()->GetResourceTexture(d2D1ResourceTexture.GetAddressOf());
|
||||
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Set the ID2D1ResourceTexture object to the current index in the ID2D1DrawInfo object in use
|
||||
hresult = @this->d2D1DrawInfo->SetResourceTexture(
|
||||
textureIndex: (uint)resourceTextureDescription.Index,
|
||||
resourceTexture: d2D1ResourceTexture.Get());
|
||||
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1EffectImpl.SetGraph"/>
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop.Effects;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
#if !NET6_0_OR_GREATER
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int PropertyGetFunctionDelegate(IUnknown* effect, byte* data, uint dataSize, uint* actualSize);
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.setFunction"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int PropertySetFunctionDelegate(IUnknown* effect, byte* data, uint dataSize);
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetConstantBufferImpl"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetConstantBufferWrapper = GetConstantBufferImpl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetConstantBufferImpl"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetConstantBufferWrapper = SetConstantBufferImpl;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the constant buffer.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetConstantBuffer
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetConstantBufferImpl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetConstantBufferWrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the constant buffer.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetConstantBuffer
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetConstantBufferImpl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetConstantBufferWrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetConstantBufferImpl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
|
||||
|
||||
// This is a call likely from ID2D1Effect::GetValueSize, to query the property size
|
||||
if (data is null &&
|
||||
dataSize == 0 &&
|
||||
actualSize is not null)
|
||||
{
|
||||
*actualSize = (uint)@this->constantBufferSize;
|
||||
|
||||
return S.S_FALSE;
|
||||
}
|
||||
|
||||
if (data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (dataSize < @this->constantBufferSize)
|
||||
{
|
||||
return E.E_NOT_SUFFICIENT_BUFFER;
|
||||
}
|
||||
|
||||
if (@this->constantBuffer is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
uint writtenBytes = 0;
|
||||
|
||||
if (@this->constantBufferSize > 0)
|
||||
{
|
||||
Buffer.MemoryCopy(@this->constantBuffer, data, dataSize, @this->constantBufferSize);
|
||||
|
||||
writtenBytes = (uint)@this->constantBufferSize;
|
||||
}
|
||||
|
||||
if (actualSize is not null)
|
||||
{
|
||||
*actualSize = writtenBytes;
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetConstantBufferImpl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
if (data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
|
||||
|
||||
if (dataSize != (uint)@this->constantBufferSize)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (@this->constantBuffer is not null)
|
||||
{
|
||||
NativeMemory.Free(@this->constantBuffer);
|
||||
}
|
||||
|
||||
void* buffer = NativeMemory.Alloc(dataSize);
|
||||
|
||||
Buffer.MemoryCopy(data, buffer, dataSize, dataSize);
|
||||
|
||||
@this->constantBuffer = (byte*)buffer;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the resource texture manager for a given index.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureIndex">The index of the resource texture to get the manager for.</param>
|
||||
/// <param name="data">A pointer to a variable that stores the data that this function retrieves on the property.</param>
|
||||
/// <param name="dataSize">The number of bytes in the property to retrieve.</param>
|
||||
/// <param name="actualSize">A optional pointer to a variable that stores the actual number of bytes retrieved on the property.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
private int GetResourceTextureManagerAtIndex(int resourceTextureIndex, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
if (!IsResourceTextureManagerIndexValid(resourceTextureIndex, out _))
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (dataSize < sizeof(void*))
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = this.resourceTextureManagerBuffer[resourceTextureIndex];
|
||||
|
||||
resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data);
|
||||
|
||||
if (actualSize is not null)
|
||||
{
|
||||
*actualSize = (uint)sizeof(void*);
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the resource texture manager for a given index.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureIndex">The index of the resource texture to set the manager for.</param>
|
||||
/// <param name="data">A pointer to the data to be set on the property.</param>
|
||||
/// <param name="dataSize">The number of bytes in the property set by the function.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
private int SetResourceTextureManagerAtIndex(int resourceTextureIndex, byte* data, uint dataSize)
|
||||
{
|
||||
if (!IsResourceTextureManagerIndexValid(resourceTextureIndex, out uint dimensions))
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
void* value = *(void**)data;
|
||||
|
||||
if (value is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (dataSize != (uint)sizeof(void*))
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
using ComPtr<IUnknown> unknown = (IUnknown*)value;
|
||||
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = default;
|
||||
|
||||
// Check that the input object implements ID2D1ResourceTextureManager
|
||||
int result = unknown.CopyTo(resourceTextureManager.GetAddressOf());
|
||||
|
||||
if (result != S.S_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
using ComPtr<ID2D1ResourceTextureManagerInternal> resourceTextureManagerInternal = default;
|
||||
|
||||
// Then, also check that it implements ID2D1ResourceTextureManagerInternal
|
||||
result = unknown.CopyTo(resourceTextureManagerInternal.GetAddressOf());
|
||||
|
||||
if (result != S.S_OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
// Initialize the resource texture manager, if an effect context is available
|
||||
if (this.d2D1EffectContext is not null)
|
||||
{
|
||||
result = resourceTextureManagerInternal.Get()->Initialize(this.d2D1EffectContext, &dimensions);
|
||||
|
||||
// ID2D1ResourceTextureManager::Initialize should generally return either S_OK for first
|
||||
// initialization, S_FALSE if an ID2D1EffectContext is already present (which is allowed, to
|
||||
// enable sharing resource texture managers across different source textures and effects), or
|
||||
// E_INVALIDARG if the manager has already been initialized through the public interface,
|
||||
// and the stored dimensions for that don't match the ones for this resource texture index.
|
||||
if (!Windows.SUCCEEDED(result))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Store the resource texture manager into the buffer
|
||||
this.resourceTextureManagerBuffer[resourceTextureIndex] = resourceTextureManager.Detach();
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether a given index for a resource texture manager is valid for the current effect.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureIndex">The index of the resource texture to validate.</param>
|
||||
/// <param name="dimensions">The number of dimensions for the resource texture at the gven index.</param>
|
||||
/// <returns>Whether or not <paramref name="resourceTextureIndex"/> is valid for the current effect.</returns>
|
||||
private bool IsResourceTextureManagerIndexValid(int resourceTextureIndex, out uint dimensions)
|
||||
{
|
||||
foreach (ref readonly D2D1ResourceTextureDescription resourceTextureDescription in new ReadOnlySpan<D2D1ResourceTextureDescription>(this.resourceTextureDescriptions, this.resourceTextureDescriptionCount))
|
||||
{
|
||||
if (resourceTextureDescription.Index == resourceTextureIndex)
|
||||
{
|
||||
dimensions = (uint)resourceTextureDescription.Dimensions;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
dimensions = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,898 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
#if !NET6_OR_GREATER
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop.Effects;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
#if !NET6_0_OR_GREATER
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager0"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager0Wrapper = GetResourceTextureManager0Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager0"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager0Wrapper = SetResourceTextureManager0Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager1"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager1Wrapper = GetResourceTextureManager1Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager1"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager1Wrapper = SetResourceTextureManager1Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager2"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager2Wrapper = GetResourceTextureManager2Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager2"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager2Wrapper = SetResourceTextureManager2Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager3"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager3Wrapper = GetResourceTextureManager3Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager3"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager3Wrapper = SetResourceTextureManager3Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager4"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager4Wrapper = GetResourceTextureManager4Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager4"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager4Wrapper = SetResourceTextureManager4Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager5"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager5Wrapper = GetResourceTextureManager5Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager5"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager5Wrapper = SetResourceTextureManager5Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager6"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager6Wrapper = GetResourceTextureManager6Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager6"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager6Wrapper = SetResourceTextureManager6Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager7"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager7Wrapper = GetResourceTextureManager7Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager7"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager7Wrapper = SetResourceTextureManager7Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager8"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager8Wrapper = GetResourceTextureManager8Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager8"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager8Wrapper = SetResourceTextureManager8Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager9"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager9Wrapper = GetResourceTextureManager9Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager9"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager9Wrapper = SetResourceTextureManager9Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager10"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager10Wrapper = GetResourceTextureManager10Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager10"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager10Wrapper = SetResourceTextureManager10Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager11"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager11Wrapper = GetResourceTextureManager11Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager11"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager11Wrapper = SetResourceTextureManager11Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager12"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager12Wrapper = GetResourceTextureManager12Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager12"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager12Wrapper = SetResourceTextureManager12Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager13"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager13Wrapper = GetResourceTextureManager13Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager13"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager13Wrapper = SetResourceTextureManager13Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager14"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager14Wrapper = GetResourceTextureManager14Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager14"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager14Wrapper = SetResourceTextureManager14Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager15"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager15Wrapper = GetResourceTextureManager15Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager15"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager15Wrapper = SetResourceTextureManager15Impl;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 0.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager0
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager0Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager0Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 0.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager0
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager0Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager0Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 1.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager1
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager1Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager1Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 1.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager1
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager1Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager1Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 2.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager2
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager2Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager2Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 2.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager2
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager2Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager2Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 3.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager3
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager3Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager3Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 3.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager3
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager3Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager3Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 4.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager4
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager4Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager4Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 4.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager4
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager4Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager4Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 5.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager5
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager5Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager5Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 5.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager5
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager5Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager5Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 6.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager6
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager6Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager6Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 6.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager6
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager6Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager6Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 7.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager7
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager7Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager7Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 7.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager7
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager7Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager7Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 8.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager8
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager8Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager8Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 8.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager8
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager8Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager8Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 9.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager9
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager9Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager9Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 9.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager9
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager9Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager9Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 10.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager10
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager10Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager10Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 10.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager10
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager10Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager10Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 11.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager11
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager11Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager11Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 11.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager11
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager11Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager11Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 12.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager12
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager12Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager12Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 12.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager12
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager12Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager12Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 13.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager13
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager13Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager13Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 13.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager13
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager13Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager13Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 14.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager14
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager14Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager14Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 14.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager14
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager14Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager14Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index 15.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager15
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager15Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager15Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index 15.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager15
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager15Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager15Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager0Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(0, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager0Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(0, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager1Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(1, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager1Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(1, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager2Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(2, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager2Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(2, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager3Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(3, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager3Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(3, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager4Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(4, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager4Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(4, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager5Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(5, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager5Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(5, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager6Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(6, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager6Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(6, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager7Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(7, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager7Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(7, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager8Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(8, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager8Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(8, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager9Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(9, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager9Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(9, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager10Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(10, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager10Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(10, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager11Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(11, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager11Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(11, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager12Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(12, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager12Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(12, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager13Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(13, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager13Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(13, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager14Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(14, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager14Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(14, data, dataSize);
|
||||
}
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager15Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(15, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager15Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(15, data, dataSize);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ output extension=".g.cs"#>
|
||||
using System.Runtime.CompilerServices;
|
||||
#if !NET6_OR_GREATER
|
||||
using System.Runtime.InteropServices;
|
||||
#endif
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop.Effects;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
#if !NET6_0_OR_GREATER
|
||||
<#
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
#>
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertyGetFunctionDelegate"/> instance wrapping <see cref="GetResourceTextureManager<#=i#>"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertyGetFunctionDelegate GetResourceTextureManager<#=i#>Wrapper = GetResourceTextureManager<#=i#>Impl;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="PropertySetFunctionDelegate"/> instance wrapping <see cref="SetResourceTextureManager<#=i#>"/>.
|
||||
/// </summary>
|
||||
private static readonly PropertySetFunctionDelegate SetResourceTextureManager<#=i#>Wrapper = SetResourceTextureManager<#=i#>Impl;
|
||||
<#
|
||||
if (i < 15) WriteLine("");
|
||||
}
|
||||
#>
|
||||
#endif
|
||||
|
||||
<#
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
#>
|
||||
/// <summary>
|
||||
/// Gets the get accessor for the resource manager at index <#=i#>.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> GetResourceTextureManager<#=i#>
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &GetResourceTextureManager<#=i#>Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int>)(void*)Marshal.GetFunctionPointerForDelegate(GetResourceTextureManager<#=i#>Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the set accessor for the resource manager at index <#=i#>.
|
||||
/// </summary>
|
||||
public static delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> SetResourceTextureManager<#=i#>
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
return &SetResourceTextureManager<#=i#>Impl;
|
||||
#else
|
||||
return (delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int>)(void*)Marshal.GetFunctionPointerForDelegate(SetResourceTextureManager<#=i#>Wrapper);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
}
|
||||
#>
|
||||
<#
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
#>
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int GetResourceTextureManager<#=i#>Impl(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->GetResourceTextureManagerAtIndex(<#=i#>, data, dataSize, actualSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })]
|
||||
private static int SetResourceTextureManager<#=i#>Impl(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
return ((PixelShaderEffect*)effect)->SetResourceTextureManagerAtIndex(<#=i#>, data, dataSize);
|
||||
}
|
||||
<#
|
||||
}
|
||||
#>
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop.Effects;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial struct PixelShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// A buffer of 16 <see cref="ID2D1ResourceTextureManager"/> objects.
|
||||
/// </summary>
|
||||
private unsafe struct ResourceTextureManagerBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 0.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager0;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 1.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager1;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 2.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager2;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 3.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager3;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 4.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager4;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 5.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager5;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 6.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager6;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 7.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager7;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 8.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager8;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 9.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager9;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 10.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager10;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 11.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager11;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 12.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager12;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 13.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager13;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 14.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager14;
|
||||
|
||||
/// <summary>
|
||||
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 15.
|
||||
/// </summary>
|
||||
public ID2D1ResourceTextureManager* ResourceTextureManager15;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see langword="ref"/> to the <see cref="ID2D1ResourceTextureManager"/> pointer at a given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the instance to retrieve.</param>
|
||||
/// <returns>A <see langword="ref"/> to the <see cref="ID2D1ResourceTextureManager"/> pointer at a given index.</returns>
|
||||
public ref ID2D1ResourceTextureManager* this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
ID2D1ResourceTextureManager** @this = (ID2D1ResourceTextureManager**)Unsafe.AsPointer(ref this);
|
||||
|
||||
return ref @this[index];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="Span{T}"/> with the <see cref="ID2D1ResourceTextureManager"/> items in the current instance.
|
||||
/// </summary>
|
||||
/// <returns>A <see cref="Span{T}"/> with the <see cref="ID2D1ResourceTextureManager"/> items in the current instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Span<ID2D1ResourceTextureManager> AsSpan()
|
||||
{
|
||||
return new((ID2D1ResourceTextureManager**)Unsafe.AsPointer(ref this), 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if NET6_0_OR_GREATER
|
||||
using RuntimeHelpers = System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
#else
|
||||
using RuntimeHelpers = ComputeSharp.D2D1.NetStandard.System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop.Effects;
|
||||
@@ -38,24 +38,6 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// <inheritdoc cref="Release"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate uint ReleaseDelegate(PixelShaderEffect* @this);
|
||||
|
||||
/// <inheritdoc cref="GetConstantBuffer"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate int GetConstantBufferDelegate(IUnknown* effect, byte* data, uint dataSize, uint* actualSize);
|
||||
|
||||
/// <inheritdoc cref="SetConstantBuffer"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate int SetConstantBufferDelegate(IUnknown* effect, byte* data, uint dataSize);
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="GetConstantBufferDelegate"/> instance wrapping <see cref="GetConstantBuffer"/>.
|
||||
/// </summary>
|
||||
public static readonly GetConstantBufferDelegate GetConstantBufferWrapper = GetConstantBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="SetConstantBufferDelegate"/> instance wrapping <see cref="SetConstantBuffer"/>.
|
||||
/// </summary>
|
||||
public static readonly SetConstantBufferDelegate SetConstantBufferWrapper = SetConstantBuffer;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@@ -132,21 +114,21 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// </summary>
|
||||
private volatile int referenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> for the shader.
|
||||
/// </summary>
|
||||
private Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The constant buffer data, if set.
|
||||
/// </summary>
|
||||
private byte* constantBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// The size of <see cref="constantBuffer"/>, if set.
|
||||
/// The size of <see cref="constantBuffer"/>.
|
||||
/// </summary>
|
||||
private int constantBufferSize;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> for the shader.
|
||||
/// </summary>
|
||||
private Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The number of inputs for the shader.
|
||||
/// </summary>
|
||||
@@ -200,6 +182,19 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// </summary>
|
||||
private D2D1ChannelDepth channelDepth;
|
||||
|
||||
/// <summary>
|
||||
/// The number of available resource texture descriptions.
|
||||
/// </summary>
|
||||
private int resourceTextureDescriptionCount;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer with the available resource texture descriptions for the shader.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This buffer is also shared among effect instances, like <see cref="inputDescriptions"/>.
|
||||
/// </remarks>
|
||||
private D2D1ResourceTextureDescription* resourceTextureDescriptions;
|
||||
|
||||
/// <summary>
|
||||
/// The handle for the <see cref="D2D1TransformMapper"/> instance in use, if any.
|
||||
/// </summary>
|
||||
@@ -210,10 +205,21 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// </summary>
|
||||
private ID2D1DrawInfo* d2D1DrawInfo;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1EffectContext"/> instance currently in use.
|
||||
/// </summary>
|
||||
private ID2D1EffectContext* d2D1EffectContext;
|
||||
|
||||
/// <summary>
|
||||
/// The resource texture managers for the current instance.
|
||||
/// </summary>
|
||||
private ResourceTextureManagerBuffer resourceTextureManagerBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// The factory method for <see cref="ID2D1Factory1.RegisterEffectFromString"/>.
|
||||
/// </summary>
|
||||
/// <param name="shaderId">The <see cref="Guid"/> for the shader.</param>
|
||||
/// <param name="constantBufferSize">The size of the constant buffer for the shader.</param>
|
||||
/// <param name="inputCount">The number of inputs for the shader.</param>
|
||||
/// <param name="inputTypes">The buffer with the types of inputs for the shader.</param>
|
||||
/// <param name="inputDescriptionCount">The number of available input descriptions.</param>
|
||||
@@ -223,11 +229,14 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// <param name="bytecodeSize">The size of <paramref name="bytecode"/>.</param>
|
||||
/// <param name="bufferPrecision">The buffer precision for the resulting output buffer.</param>
|
||||
/// <param name="channelDepth">The channel depth for the resulting output buffer.</param>
|
||||
/// <param name="resourceTextureDescriptionCount">The number of available resource texture descriptions.</param>
|
||||
/// <param name="resourceTextureDescriptions">The buffer with the available resource texture descriptions for the shader.</param>
|
||||
/// <param name="d2D1TransformMapper">The <see cref="D2D1TransformMapper"/> instance to use for the effect.</param>
|
||||
/// <param name="effectImpl">The resulting effect instance.</param>
|
||||
/// <returns>This always returns <c>0</c>.</returns>
|
||||
private static int Factory(
|
||||
Guid shaderId,
|
||||
int constantBufferSize,
|
||||
int inputCount,
|
||||
D2D1PixelShaderInputType* inputTypes,
|
||||
int inputDescriptionCount,
|
||||
@@ -237,6 +246,8 @@ internal unsafe partial struct PixelShaderEffect
|
||||
int bytecodeSize,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
int resourceTextureDescriptionCount,
|
||||
D2D1ResourceTextureDescription* resourceTextureDescriptions,
|
||||
D2D1TransformMapper? d2D1TransformMapper,
|
||||
IUnknown** effectImpl)
|
||||
{
|
||||
@@ -259,6 +270,8 @@ internal unsafe partial struct PixelShaderEffect
|
||||
@this->lpVtblForID2D1DrawTransform = VtblForID2D1DrawTransform;
|
||||
@this->referenceCount = 1;
|
||||
@this->shaderId = shaderId;
|
||||
@this->constantBuffer = null;
|
||||
@this->constantBufferSize = constantBufferSize;
|
||||
@this->inputCount = inputCount;
|
||||
@this->inputTypes = inputTypes;
|
||||
@this->inputDescriptionCount = inputDescriptionCount;
|
||||
@@ -268,56 +281,19 @@ internal unsafe partial struct PixelShaderEffect
|
||||
@this->bytecodeSize = bytecodeSize;
|
||||
@this->bufferPrecision = bufferPrecision;
|
||||
@this->channelDepth = channelDepth;
|
||||
@this->resourceTextureDescriptionCount = resourceTextureDescriptionCount;
|
||||
@this->resourceTextureDescriptions = resourceTextureDescriptions;
|
||||
@this->d2D1TransformMapperHandle = GCHandle.Alloc(d2D1TransformMapper);
|
||||
@this->d2D1DrawInfo = null;
|
||||
@this->d2D1EffectContext = null;
|
||||
|
||||
@this->resourceTextureManagerBuffer.AsSpan().Clear();
|
||||
|
||||
*effectImpl = (IUnknown*)@this;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int GetConstantBuffer(IUnknown* effect, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
|
||||
|
||||
if (@this->constantBufferSize == 0)
|
||||
{
|
||||
*actualSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int bytesToCopy = Math.Min((int)dataSize, @this->constantBufferSize);
|
||||
|
||||
Buffer.MemoryCopy(@this->constantBuffer, data, dataSize, bytesToCopy);
|
||||
|
||||
*actualSize = (uint)bytesToCopy;
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1_PROPERTY_BINDING.getFunction"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int SetConstantBuffer(IUnknown* effect, byte* data, uint dataSize)
|
||||
{
|
||||
PixelShaderEffect* @this = (PixelShaderEffect*)effect;
|
||||
|
||||
if (@this->constantBuffer is not null)
|
||||
{
|
||||
NativeMemory.Free(@this->constantBuffer);
|
||||
}
|
||||
|
||||
void* buffer = NativeMemory.Alloc(dataSize);
|
||||
|
||||
Buffer.MemoryCopy(data, buffer, dataSize, dataSize);
|
||||
|
||||
@this->constantBuffer = (byte*)buffer;
|
||||
@this->constantBufferSize = (int)dataSize;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface"/>
|
||||
private int QueryInterface(Guid* riid, void** ppvObject)
|
||||
{
|
||||
@@ -379,6 +355,23 @@ internal unsafe partial struct PixelShaderEffect
|
||||
_ = this.d2D1DrawInfo->Release();
|
||||
}
|
||||
|
||||
if (this.d2D1EffectContext is not null)
|
||||
{
|
||||
_ = this.d2D1EffectContext->Release();
|
||||
}
|
||||
|
||||
// Use the list of resource texture descriptions to see the indices that might have accepted a resource texture manager.
|
||||
// Then, retrieve all of them and release the ones that had been assigned (from one of the property bindings).
|
||||
foreach (ref readonly D2D1ResourceTextureDescription resourceTextureDescription in new ReadOnlySpan<D2D1ResourceTextureDescription>(this.resourceTextureDescriptions, this.resourceTextureDescriptionCount))
|
||||
{
|
||||
ID2D1ResourceTextureManager* resourceTextureManager = resourceTextureManagerBuffer[resourceTextureDescription.Index];
|
||||
|
||||
if (resourceTextureManager is not null)
|
||||
{
|
||||
_ = ((IUnknown*)resourceTextureManager)->Release();
|
||||
}
|
||||
}
|
||||
|
||||
NativeMemory.Free(Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
|
||||
+688
@@ -0,0 +1,688 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
|
||||
/// <inheritdoc/>
|
||||
unsafe partial struct D2D1ResourceTextureManagerImpl
|
||||
{
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Initialize"/>
|
||||
public static int Initialize(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
Guid* resourceId,
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties,
|
||||
byte* data,
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
// If the method has already been called, fail
|
||||
if (@this->d2D1ResourceTexture is not null ||
|
||||
@this->data is not null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// If the manager has been assigned to an effect and the dimensions are available, validate them.
|
||||
// Check and ignore if the input properties are null (validation for that is done afterwards).
|
||||
if (@this->expectedDimensions != 0 &&
|
||||
resourceTextureProperties is not null &&
|
||||
resourceTextureProperties->dimensions != @this->expectedDimensions)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
// If the method has already been called, just forward the call
|
||||
if (@this->d2D1EffectContext is not null)
|
||||
{
|
||||
@this->d2D1Multithread->Enter();
|
||||
|
||||
// Create the resource after taking a D2D lock
|
||||
int hresult = @this->d2D1EffectContext->CreateResourceTexture(
|
||||
resourceId: resourceId,
|
||||
resourceTextureProperties: resourceTextureProperties,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataSize,
|
||||
resourceTexture: &@this->d2D1ResourceTexture);
|
||||
|
||||
@this->d2D1Multithread->Leave();
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// Initialize into a staging buffer
|
||||
return ID2D1ResourceTextureManagerMethods.InitializeWithStagingBuffer(
|
||||
@this: @this,
|
||||
resourceId: resourceId,
|
||||
resourceTextureProperties: resourceTextureProperties,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Update"/>
|
||||
public static int Update(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
uint* minimumExtents,
|
||||
uint* maximimumExtents,
|
||||
uint* strides,
|
||||
uint dimensions,
|
||||
byte* data,
|
||||
uint dataCount)
|
||||
{
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
if (@this->d2D1ResourceTexture is null &&
|
||||
@this->data is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// If a resource texture already exists, just forward the call
|
||||
if (@this->d2D1ResourceTexture is not null)
|
||||
{
|
||||
@this->d2D1Multithread->Enter();
|
||||
|
||||
// Take a D2D lock here too to ensure thread safety
|
||||
int hresult = @this->d2D1ResourceTexture->Update(
|
||||
minimumExtents: minimumExtents,
|
||||
maximimumExtents: maximimumExtents,
|
||||
strides: strides,
|
||||
dimensions: dimensions,
|
||||
data: data,
|
||||
dataCount: dataCount);
|
||||
|
||||
@this->d2D1Multithread->Leave();
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// Otherwise update the staging buffer
|
||||
return ID2D1ResourceTextureManagerMethods.UpdateWithStagingBuffer(
|
||||
@this: @this,
|
||||
minimumExtents: minimumExtents,
|
||||
maximimumExtents: maximimumExtents,
|
||||
strides: strides,
|
||||
dimensions: dimensions,
|
||||
data: data,
|
||||
dataCount: dataCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The implementation for <c>ID2D1ResourceTextureManager</c>.
|
||||
/// </summary>
|
||||
private static class ID2D1ResourceTextureManagerMethods
|
||||
{
|
||||
#if !NET6_0_OR_GREATER
|
||||
/// <inheritdoc cref="Initialize"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate int InitializeDelegate(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
Guid* resourceId,
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties,
|
||||
byte* data,
|
||||
uint* strides,
|
||||
uint dataSize);
|
||||
|
||||
/// <inheritdoc cref="Update"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate int UpdateDelegate(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
uint* minimumExtents,
|
||||
uint* maximimumExtents,
|
||||
uint* strides,
|
||||
uint dimensions,
|
||||
byte* data,
|
||||
uint dataCount);
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="QueryInterfaceDelegate"/> instance wrapping <see cref="QueryInterface"/>.
|
||||
/// </summary>
|
||||
public static readonly QueryInterfaceDelegate QueryInterfaceWrapper = QueryInterface;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="AddRefDelegate"/> instance wrapping <see cref="AddRef"/>.
|
||||
/// </summary>
|
||||
public static readonly AddRefDelegate AddRefWrapper = AddRef;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="ReleaseDelegate"/> instance wrapping <see cref="Release"/>.
|
||||
/// </summary>
|
||||
public static readonly ReleaseDelegate ReleaseWrapper = Release;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="InitializeDelegate"/> instance wrapping <see cref="Initialize"/>.
|
||||
/// </summary>
|
||||
public static readonly InitializeDelegate InitializeWrapper = Initialize;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="UpdateDelegate"/> instance wrapping <see cref="Update"/>.
|
||||
/// </summary>
|
||||
public static readonly UpdateDelegate UpdateWrapper = Update;
|
||||
#endif
|
||||
|
||||
/// <inheritdoc cref="D2D1ResourceTextureManagerImpl.QueryInterface"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int QueryInterface(D2D1ResourceTextureManagerImpl* @this, Guid* riid, void** ppvObject)
|
||||
{
|
||||
return @this->QueryInterface(riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1ResourceTextureManagerImpl.AddRef"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint AddRef(D2D1ResourceTextureManagerImpl* @this)
|
||||
{
|
||||
return @this->AddRef();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1ResourceTextureManagerImpl.Release"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint Release(D2D1ResourceTextureManagerImpl* @this)
|
||||
{
|
||||
return @this->Release();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Initialize"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int Initialize(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
Guid* resourceId,
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties,
|
||||
byte* data,
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
return D2D1ResourceTextureManagerImpl.Initialize(
|
||||
@this,
|
||||
resourceId,
|
||||
resourceTextureProperties,
|
||||
data,
|
||||
strides,
|
||||
dataSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Update"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int Update(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
uint* minimumExtents,
|
||||
uint* maximimumExtents,
|
||||
uint* strides,
|
||||
uint dimensions,
|
||||
byte* data,
|
||||
uint dataCount)
|
||||
{
|
||||
return D2D1ResourceTextureManagerImpl.Update(
|
||||
@this,
|
||||
minimumExtents,
|
||||
maximimumExtents,
|
||||
strides,
|
||||
dimensions,
|
||||
data,
|
||||
dataCount);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Initialize"/>
|
||||
public static int InitializeWithStagingBuffer(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
Guid* resourceId,
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties,
|
||||
byte* data,
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
// Return E_POINTER if any input pointer is null. In particular, the data pointer
|
||||
// must not be null if the data size is not 0, and the strides pointer must not be
|
||||
// null if some data is supplied, and the number of dimensions is greater than 1.
|
||||
if (resourceTextureProperties is null ||
|
||||
(dataSize > 0 && data is null) ||
|
||||
resourceTextureProperties->extents is null ||
|
||||
resourceTextureProperties->extendModes is null ||
|
||||
(resourceTextureProperties->dimensions > 1 && dataSize > 0 && strides is null))
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// Textures can only have between 1 and 3 dimensions
|
||||
if (resourceTextureProperties->dimensions is 0 or > 3)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
// No extent can be 0
|
||||
foreach (uint extent in new ReadOnlySpan<uint>(resourceTextureProperties->extents, (int)resourceTextureProperties->dimensions))
|
||||
{
|
||||
if (extent == 0)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
|
||||
// The buffer precision can't be unknown, and the channel depth must be explicit
|
||||
if (resourceTextureProperties->bufferPrecision == D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_UNKNOWN ||
|
||||
resourceTextureProperties->channelDepth == D2D1_CHANNEL_DEPTH.D2D1_CHANNEL_DEPTH_DEFAULT)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
// Validate the data size
|
||||
if (dataSize > 0)
|
||||
{
|
||||
uint elementSizeInBytes = GetElementSizeInBytes(
|
||||
resourceTextureProperties->bufferPrecision,
|
||||
resourceTextureProperties->channelDepth);
|
||||
|
||||
int hresult = ValidateDataAndStrides(
|
||||
elementSizeInBytes,
|
||||
resourceTextureProperties->extents,
|
||||
resourceTextureProperties->dimensions,
|
||||
strides,
|
||||
dataSize);
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
return hresult;
|
||||
}
|
||||
}
|
||||
|
||||
// Allocate a buffer for the resource id, if there is one
|
||||
if (resourceId is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@this->resourceId = (Guid*)NativeMemory.Alloc((nuint)sizeof(Guid));
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
return E.E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
*@this->resourceId = *resourceId;
|
||||
}
|
||||
|
||||
uint* extents;
|
||||
|
||||
// Allocate a buffer for the extents (one per dimension)
|
||||
try
|
||||
{
|
||||
extents = (uint*)NativeMemory.Alloc(sizeof(uint) * resourceTextureProperties->dimensions);
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
return E.E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
D2D1_EXTEND_MODE* extendModes;
|
||||
|
||||
// Allocate a buffer for the extend modes (one per dimension)
|
||||
try
|
||||
{
|
||||
extendModes = (D2D1_EXTEND_MODE*)NativeMemory.Alloc(sizeof(D2D1_EXTEND_MODE) * resourceTextureProperties->dimensions);
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
return E.E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
// Copy the extents into the buffer
|
||||
Buffer.MemoryCopy(
|
||||
source: resourceTextureProperties->extents,
|
||||
destination: extents,
|
||||
destinationSizeInBytes: sizeof(uint) * resourceTextureProperties->dimensions,
|
||||
sourceBytesToCopy: sizeof(uint) * resourceTextureProperties->dimensions);
|
||||
|
||||
// Copy the extend modes into the buffer
|
||||
Buffer.MemoryCopy(
|
||||
source: resourceTextureProperties->extendModes,
|
||||
destination: extendModes,
|
||||
destinationSizeInBytes: sizeof(D2D1_EXTEND_MODE) * resourceTextureProperties->dimensions,
|
||||
sourceBytesToCopy: sizeof(D2D1_EXTEND_MODE) * resourceTextureProperties->dimensions);
|
||||
|
||||
// Initialize the other resource texture properties
|
||||
@this->resourceTextureProperties.extents = extents;
|
||||
@this->resourceTextureProperties.dimensions = resourceTextureProperties->dimensions;
|
||||
@this->resourceTextureProperties.bufferPrecision = resourceTextureProperties->bufferPrecision;
|
||||
@this->resourceTextureProperties.channelDepth = resourceTextureProperties->channelDepth;
|
||||
@this->resourceTextureProperties.filter = resourceTextureProperties->filter;
|
||||
@this->resourceTextureProperties.extendModes = extendModes;
|
||||
|
||||
// Initialize the staging buffer and optional strides
|
||||
return InitializeStagingBufferAndStrides(
|
||||
@this: @this,
|
||||
dimensions: resourceTextureProperties->dimensions,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataSize);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManager.Update"/>
|
||||
public static int UpdateWithStagingBuffer(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
uint* minimumExtents,
|
||||
uint* maximimumExtents,
|
||||
uint* strides,
|
||||
uint dimensions,
|
||||
byte* data,
|
||||
uint dataCount)
|
||||
{
|
||||
// Either both extents are available, or none is, and the other values must not be null
|
||||
if (minimumExtents is null && maximimumExtents is not null ||
|
||||
minimumExtents is not null && maximimumExtents is null ||
|
||||
(dimensions > 1 && strides is null) ||
|
||||
data is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// The dimensions must match the currently stored texture data
|
||||
if (dimensions != @this->resourceTextureProperties.dimensions)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
// If the update extents are specified, check that the targets are all greater than the starting extents.
|
||||
if (minimumExtents is not null)
|
||||
{
|
||||
for (int i = 0; i < (int)dimensions; i++)
|
||||
{
|
||||
if (maximimumExtents[i] <= minimumExtents[i])
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint elementSizeInBytes = GetElementSizeInBytes(
|
||||
@this->resourceTextureProperties.bufferPrecision,
|
||||
@this->resourceTextureProperties.channelDepth);
|
||||
|
||||
// Calculate the extents of the buffer, based on the delta between the input extents.
|
||||
// If no extents range is provided, it means that the entire resource texture is updated.
|
||||
uint* updateExtents = stackalloc uint[3];
|
||||
|
||||
if (minimumExtents is not null)
|
||||
{
|
||||
updateExtents[0] = maximimumExtents[0] - minimumExtents[0];
|
||||
updateExtents[1] = dimensions > 1 ? (maximimumExtents[1] - minimumExtents[1]) : 1;
|
||||
updateExtents[2] = dimensions > 2 ? (maximimumExtents[2] - minimumExtents[2]) : 1;
|
||||
|
||||
// Validate that the requested extent is not greater than the corresponding dimension
|
||||
for (int i = 0; i < (int)dimensions; i++)
|
||||
{
|
||||
if (updateExtents[i] > @this->resourceTextureProperties.extents[i])
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Buffer.MemoryCopy(
|
||||
source: @this->resourceTextureProperties.extents,
|
||||
destination: updateExtents,
|
||||
destinationSizeInBytes: dimensions * sizeof(uint),
|
||||
sourceBytesToCopy: dimensions * sizeof(uint));
|
||||
}
|
||||
|
||||
// Validate that the provided buffer is valid for the update range
|
||||
int hresult = ValidateDataAndStrides(
|
||||
elementSizeInBytes,
|
||||
updateExtents,
|
||||
dimensions,
|
||||
strides,
|
||||
dataCount);
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// If the texture hasn't been allocated yet, do that now. This is only
|
||||
// valid if the whole texture is being updated (as it's being initialized).
|
||||
if (@this->data is null)
|
||||
{
|
||||
if (minimumExtents is not null)
|
||||
{
|
||||
// If explicit extents are passed, they must match the resource texture size
|
||||
for (int i = 0; i < (int)dimensions; i++)
|
||||
{
|
||||
if (updateExtents[i] != @this->resourceTextureProperties.extents[i])
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is a full update with no existing resource, so just initialize the buffer from scratch
|
||||
return InitializeStagingBufferAndStrides(
|
||||
@this: @this,
|
||||
dimensions: dimensions,
|
||||
data: data,
|
||||
strides: strides,
|
||||
dataSize: dataCount);
|
||||
}
|
||||
|
||||
// Precalculate the byte size of each row update
|
||||
uint rowUpdateSizeInBytes = updateExtents[0] * elementSizeInBytes;
|
||||
|
||||
for (int z = 0; z < updateExtents[2]; z++)
|
||||
{
|
||||
// Calculate the starting position in the source and destination buffers.
|
||||
// - The source advances by the 2D slice stride for each iteration.
|
||||
// - The destination does the same, but it also starts at the given initial offset.
|
||||
// This pointer is aligned to the start of a row in the offset 2D plane after this.
|
||||
byte* sourceDataPlane =
|
||||
data +
|
||||
(dimensions > 2 ? z * strides[1] : 0);
|
||||
byte* destinationDataPlane =
|
||||
@this->data +
|
||||
(dimensions > 2 ? minimumExtents[2] * @this->strides[1] + z * @this->strides[1] : 0) +
|
||||
(dimensions > 1 ? minimumExtents[1] * @this->strides[0] : 0);
|
||||
|
||||
for (int y = 0; y < updateExtents[1]; y++)
|
||||
{
|
||||
// Shift the source ahead to get to the start of the current row. The destination
|
||||
// is also shifted ahead by the current row, plus the target initial element offset.
|
||||
byte* sourceDataRow = sourceDataPlane + (dimensions > 1 ? y * strides[0] : 0);
|
||||
byte* destinationDataRow =
|
||||
destinationDataPlane +
|
||||
(dimensions > 1 ? y * @this->strides[0] : 0) +
|
||||
(minimumExtents[0] * elementSizeInBytes);
|
||||
|
||||
Buffer.MemoryCopy(
|
||||
source: sourceDataRow,
|
||||
destination: destinationDataRow,
|
||||
destinationSizeInBytes: rowUpdateSizeInBytes,
|
||||
sourceBytesToCopy: rowUpdateSizeInBytes);
|
||||
}
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the element size of each item in the resource texture, in bytes.
|
||||
/// </summary>
|
||||
/// <param name="bufferPrecision">The precision of the resource texture.</param>
|
||||
/// <param name="channelDepth">The number of channels in the resource texture.</param>
|
||||
/// <returns>Tthe element size of each item in the resource texture, in bytes.</returns>
|
||||
private static uint GetElementSizeInBytes(D2D1_BUFFER_PRECISION bufferPrecision, D2D1_CHANNEL_DEPTH channelDepth)
|
||||
{
|
||||
uint channelSizeInBytes = bufferPrecision switch
|
||||
{
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM => 1,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB => 1,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_UNORM => 2,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_FLOAT => 2,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT => 4,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
return channelDepth switch
|
||||
{
|
||||
D2D1_CHANNEL_DEPTH.D2D1_CHANNEL_DEPTH_1 => channelSizeInBytes,
|
||||
D2D1_CHANNEL_DEPTH.D2D1_CHANNEL_DEPTH_4 => channelSizeInBytes * 4,
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the data and strides for a call to <see cref="Initialize"/> or <see cref="Update"/>.
|
||||
/// </summary>
|
||||
/// <param name="elementSizeInBytes">The element size in bytes.</param>
|
||||
/// <param name="extents">The extents of the resource table in each dimension.</param>
|
||||
/// <param name="dimensions">The number of dimensions in the resource texture.</param>
|
||||
/// <param name="strides">The stride to advance through the input data, according to dimension.</param>
|
||||
/// <param name="dataSize">The size of the data buffer to be used to update the resource texture.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the validation.</returns>
|
||||
private static int ValidateDataAndStrides(
|
||||
uint elementSizeInBytes,
|
||||
uint* extents,
|
||||
uint dimensions,
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
uint extent0SizeInBytes;
|
||||
|
||||
try
|
||||
{
|
||||
extent0SizeInBytes = checked(extents[0] * elementSizeInBytes);
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
// For 1D textures, the row byte size must match the data size (no strides to consider)
|
||||
if (dimensions == 1)
|
||||
{
|
||||
if (extent0SizeInBytes != dataSize)
|
||||
{
|
||||
return E.E_NOT_SUFFICIENT_BUFFER;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Validate the 0th stride is not smaller than the byte size of each row
|
||||
if (extent0SizeInBytes > strides[0])
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
uint extent01SizeInBytes;
|
||||
|
||||
try
|
||||
{
|
||||
extent01SizeInBytes = checked((extents[1] - 1) * strides[0] + extent0SizeInBytes);
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
// For 2D textures, the size must match the rows * stride, plus the byte size of the last row (no trailing padding)
|
||||
if (dimensions == 2)
|
||||
{
|
||||
if (extent01SizeInBytes != dataSize)
|
||||
{
|
||||
return E.E_NOT_SUFFICIENT_BUFFER;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Validate the 1th stride is not smaller than the byte size of a 2D slice, with padding
|
||||
if (extent01SizeInBytes > strides[1])
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
uint extent012SizeInBytes;
|
||||
|
||||
try
|
||||
{
|
||||
extent012SizeInBytes = (extents[2] - 1) * strides[1] + extent01SizeInBytes;
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
if (extent012SizeInBytes != dataSize)
|
||||
{
|
||||
return E.E_NOT_SUFFICIENT_BUFFER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the staging buffer and optional strides with pre-validated data.
|
||||
/// </summary>
|
||||
/// <param name="this">The current <see cref="D2D1ResourceTextureManagerImpl"/> object.</param>
|
||||
/// <param name="dimensions">The number of dimensions in the resource texture. This must match the number used to load the texture.</param>
|
||||
/// <param name="data">The data to be placed into the resource texture.</param>
|
||||
/// <param name="strides">The stride to advance through the input data, according to dimension.</param>
|
||||
/// <param name="dataSize">The size of the data buffer to be used to update the resource texture.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
/// <remarks>
|
||||
/// <para>This method is invoked with pre-validated data and doesn't check the input arguments.</para>
|
||||
/// <para>This method is invoked either when initializing the texture, or when doing a full update with no existing texture.</para>
|
||||
/// </remarks>
|
||||
private static int InitializeStagingBufferAndStrides(
|
||||
D2D1ResourceTextureManagerImpl* @this,
|
||||
uint dimensions,
|
||||
byte* data,
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
// Allocate the data buffer (this is the one most likely to potentially throw)
|
||||
if (dataSize > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@this->data = (byte*)NativeMemory.Alloc(dataSize);
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
return E.E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
Buffer.MemoryCopy(data, @this->data, dataSize, dataSize);
|
||||
|
||||
@this->dataSize = dataSize;
|
||||
}
|
||||
|
||||
// If there are strides (ie. the texture has dimension greater than 1), initialize them as well
|
||||
if (strides is not null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@this->strides = (uint*)NativeMemory.Alloc(sizeof(uint) * (dimensions - 1));
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
{
|
||||
return E.E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
Buffer.MemoryCopy(
|
||||
source: strides,
|
||||
destination: @this->strides,
|
||||
destinationSizeInBytes: sizeof(uint) * (dimensions - 1),
|
||||
sourceBytesToCopy: sizeof(uint) * (dimensions - 1));
|
||||
}
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
+202
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Extensions;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
|
||||
/// <inheritdoc/>
|
||||
partial struct D2D1ResourceTextureManagerImpl
|
||||
{
|
||||
/// <summary>
|
||||
/// The implementation for <c>ID2D1ResourceTextureManagerInternal</c>.
|
||||
/// </summary>
|
||||
private unsafe static class ID2D1ResourceTextureManagerInternalMethods
|
||||
{
|
||||
#if !NET6_0_OR_GREATER
|
||||
/// <inheritdoc cref="Initialize"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate int InitializeDelegate(D2D1ResourceTextureManagerImpl* @this, ID2D1EffectContext* effectContext, uint* dimensions);
|
||||
|
||||
/// <inheritdoc cref="GetResourceTexture"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
public delegate int GetResourceTextureDelegate(D2D1ResourceTextureManagerImpl* @this, ID2D1ResourceTexture** resourceTexture);
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="QueryInterfaceDelegate"/> instance wrapping <see cref="QueryInterface"/>.
|
||||
/// </summary>
|
||||
public static readonly QueryInterfaceDelegate QueryInterfaceWrapper = QueryInterface;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="AddRefDelegate"/> instance wrapping <see cref="AddRef"/>.
|
||||
/// </summary>
|
||||
public static readonly AddRefDelegate AddRefWrapper = AddRef;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="ReleaseDelegate"/> instance wrapping <see cref="Release"/>.
|
||||
/// </summary>
|
||||
public static readonly ReleaseDelegate ReleaseWrapper = Release;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="InitializeDelegate"/> instance wrapping <see cref="Initialize"/>.
|
||||
/// </summary>
|
||||
public static readonly InitializeDelegate InitializeWrapper = Initialize;
|
||||
|
||||
/// <summary>
|
||||
/// A cached <see cref="GetResourceTextureDelegate"/> instance wrapping <see cref="GetResourceTexture"/>.
|
||||
/// </summary>
|
||||
public static readonly GetResourceTextureDelegate GetResourceTextureWrapper = GetResourceTexture;
|
||||
#endif
|
||||
|
||||
/// <inheritdoc cref="D2D1ResourceTextureManagerImpl.QueryInterface"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int QueryInterface(D2D1ResourceTextureManagerImpl* @this, Guid* riid, void** ppvObject)
|
||||
{
|
||||
@this = (D2D1ResourceTextureManagerImpl*)&((void**)@this)[-1];
|
||||
|
||||
return @this->QueryInterface(riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1ResourceTextureManagerImpl.AddRef"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint AddRef(D2D1ResourceTextureManagerImpl* @this)
|
||||
{
|
||||
@this = (D2D1ResourceTextureManagerImpl*)&((void**)@this)[-1];
|
||||
|
||||
return @this->AddRef();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="D2D1ResourceTextureManagerImpl.Release"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static uint Release(D2D1ResourceTextureManagerImpl* @this)
|
||||
{
|
||||
@this = (D2D1ResourceTextureManagerImpl*)&((void**)@this)[-1];
|
||||
|
||||
return @this->Release();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManagerInternal.Initialize"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int Initialize(D2D1ResourceTextureManagerImpl* @this, ID2D1EffectContext* effectContext, uint* dimensions)
|
||||
{
|
||||
@this = (D2D1ResourceTextureManagerImpl*)&((void**)@this)[-1];
|
||||
|
||||
if (effectContext is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
// If the dimensions are available, validate them
|
||||
if (dimensions is not null)
|
||||
{
|
||||
uint expectedDimensions = *dimensions;
|
||||
|
||||
if (@this->resourceTextureProperties.extents is not null &&
|
||||
@this->resourceTextureProperties.dimensions != expectedDimensions)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
|
||||
@this->expectedDimensions = expectedDimensions;
|
||||
}
|
||||
|
||||
// If this is the first time the method is called, just store the context.
|
||||
// Before doing so, get an ID2D1Multithread instance, to ensure thread safety.
|
||||
// For additional info, see docs on ID2D1EffectFactoryExtensions.GetD2D1Multithread.
|
||||
if (@this->d2D1EffectContext is null)
|
||||
{
|
||||
using ComPtr<ID2D1Multithread> d2D1Multithread = default;
|
||||
|
||||
int hresult = effectContext->GetD2D1Multithread(d2D1Multithread.GetAddressOf());
|
||||
|
||||
// If an ID2D1Multithread object is available, we can safely store the context
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
_ = effectContext->AddRef();
|
||||
|
||||
@this->d2D1EffectContext = effectContext;
|
||||
@this->d2D1Multithread = d2D1Multithread.Detach();
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
|
||||
// Otherwise, just do nothing and return S_FALSE. This allows an existing resource texture
|
||||
// manager to be shared across effects. If the resource cannot be shared, it will just
|
||||
// return an error when effect is actually set, with ID2D1DrawInfo::SetResourceTexture.
|
||||
return S.S_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1ResourceTextureManagerInternal.GetResourceTexture"/>
|
||||
[UnmanagedCallersOnly]
|
||||
public static int GetResourceTexture(D2D1ResourceTextureManagerImpl* @this, ID2D1ResourceTexture** resourceTexture)
|
||||
{
|
||||
@this = (D2D1ResourceTextureManagerImpl*)&((void**)@this)[-1];
|
||||
|
||||
if (*resourceTexture is not null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
lock (@this->lockHandle.Target!)
|
||||
{
|
||||
// If the effect context is null, it means Initialize has not been called yet
|
||||
if (@this->d2D1EffectContext is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// If the texture has already been created, just return it
|
||||
if (@this->d2D1ResourceTexture is not null)
|
||||
{
|
||||
@this->d2D1ResourceTexture->AddRef();
|
||||
|
||||
*resourceTexture = @this->d2D1ResourceTexture;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
// If the data is null at this point, it means CreateResourceTexture has not been called yet
|
||||
if (@this->data is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
}
|
||||
|
||||
// Create the resource now, as it hasn't been created yet
|
||||
int result = @this->d2D1EffectContext->CreateResourceTexture(
|
||||
resourceId: @this->resourceId,
|
||||
resourceTextureProperties: &@this->resourceTextureProperties,
|
||||
data: @this->data,
|
||||
strides: @this->strides,
|
||||
dataSize: @this->dataSize,
|
||||
resourceTexture: resourceTexture);
|
||||
|
||||
// If creation was successful, release the buffered data. Going forwards,
|
||||
// the resource texture will be used directly for all updates requested.
|
||||
if (result == S.S_OK)
|
||||
{
|
||||
NativeMemory.Free(@this->resourceTextureProperties.extents);
|
||||
NativeMemory.Free(@this->resourceTextureProperties.extendModes);
|
||||
NativeMemory.Free(@this->data);
|
||||
NativeMemory.Free(@this->strides);
|
||||
|
||||
// Reset the stored pointers to avoid double frees from Release()
|
||||
@this->resourceTextureProperties.extents = null;
|
||||
@this->resourceTextureProperties.extendModes = null;
|
||||
@this->data = null;
|
||||
@this->strides = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+281
@@ -0,0 +1,281 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if NET6_0_OR_GREATER
|
||||
using RuntimeHelpers = System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
#else
|
||||
using RuntimeHelpers = ComputeSharp.D2D1.NetStandard.System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
|
||||
/// <summary>
|
||||
/// An implementation of the <c>ID2D1ResourceTextureManager</c> and <c>ID2D1ResourceTextureManagerInternal</c> interfaces.
|
||||
/// </summary>
|
||||
internal unsafe partial struct D2D1ResourceTextureManagerImpl
|
||||
{
|
||||
/// <inheritdoc cref="QueryInterface"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int QueryInterfaceDelegate(D2D1ResourceTextureManagerImpl* @this, Guid* riid, void** ppvObject);
|
||||
|
||||
/// <inheritdoc cref="AddRef"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate uint AddRefDelegate(D2D1ResourceTextureManagerImpl* @this);
|
||||
|
||||
/// <inheritdoc cref="Release"/>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate uint ReleaseDelegate(D2D1ResourceTextureManagerImpl* @this);
|
||||
|
||||
/// <summary>
|
||||
/// The shared vtable pointer for <see cref="D2D1ResourceTextureManagerImpl"/> instance, for <c>ID2D1ResourceTextureManager</c>.
|
||||
/// </summary>
|
||||
private static readonly void** VtblForID2D1ResourceTextureManager;
|
||||
|
||||
/// <summary>
|
||||
/// The shared vtable pointer for <see cref="D2D1ResourceTextureManagerImpl"/> instance, for <c>ID2D1ResourceTextureManagerInternal</c>.
|
||||
/// </summary>
|
||||
private static readonly void** VtblForID2D1ResourceTextureManagerInternal;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the shared state for <see cref="D2D1ResourceTextureManagerImpl"/>.
|
||||
/// </summary>
|
||||
static D2D1ResourceTextureManagerImpl()
|
||||
{
|
||||
void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(D2D1ResourceTextureManagerImpl), sizeof(void*) * 10);
|
||||
|
||||
// ID2D1ResourceTextureManager
|
||||
#if NET6_0_OR_GREATER
|
||||
lpVtbl[0] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, Guid*, void**, int>)&ID2D1ResourceTextureManagerMethods.QueryInterface;
|
||||
lpVtbl[1] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, uint>)&ID2D1ResourceTextureManagerMethods.AddRef;
|
||||
lpVtbl[2] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, uint>)&ID2D1ResourceTextureManagerMethods.Release;
|
||||
lpVtbl[3] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, Guid*, D2D1_RESOURCE_TEXTURE_PROPERTIES*, byte*, uint*, uint, int>)&ID2D1ResourceTextureManagerMethods.Initialize;
|
||||
lpVtbl[4] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, uint*, uint*, uint*, uint, byte*, uint, int>)&ID2D1ResourceTextureManagerMethods.Update;
|
||||
#else
|
||||
lpVtbl[0] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerMethods.QueryInterfaceWrapper);
|
||||
lpVtbl[1] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerMethods.AddRefWrapper);
|
||||
lpVtbl[2] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerMethods.ReleaseWrapper);
|
||||
lpVtbl[3] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerMethods.InitializeWrapper);
|
||||
lpVtbl[4] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerMethods.UpdateWrapper);
|
||||
#endif
|
||||
|
||||
// ID2D1ResourceTextureManagerInternal
|
||||
#if NET6_0_OR_GREATER
|
||||
lpVtbl[5 + 0] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, Guid*, void**, int>)&ID2D1ResourceTextureManagerInternalMethods.QueryInterface;
|
||||
lpVtbl[5 + 1] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, uint>)&ID2D1ResourceTextureManagerInternalMethods.AddRef;
|
||||
lpVtbl[5 + 2] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, uint>)&ID2D1ResourceTextureManagerInternalMethods.Release;
|
||||
lpVtbl[5 + 3] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, ID2D1EffectContext*, uint*, int>)&ID2D1ResourceTextureManagerInternalMethods.Initialize;
|
||||
lpVtbl[5 + 4] = (delegate* unmanaged<D2D1ResourceTextureManagerImpl*, ID2D1ResourceTexture**, int>)&ID2D1ResourceTextureManagerInternalMethods.GetResourceTexture;
|
||||
#else
|
||||
lpVtbl[5 + 0] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerInternalMethods.QueryInterfaceWrapper);
|
||||
lpVtbl[5 + 1] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerInternalMethods.AddRefWrapper);
|
||||
lpVtbl[5 + 2] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerInternalMethods.ReleaseWrapper);
|
||||
lpVtbl[5 + 3] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerInternalMethods.InitializeWrapper);
|
||||
lpVtbl[5 + 4] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1ResourceTextureManagerInternalMethods.GetResourceTextureWrapper);
|
||||
#endif
|
||||
|
||||
VtblForID2D1ResourceTextureManager = lpVtbl;
|
||||
VtblForID2D1ResourceTextureManagerInternal = &lpVtbl[5];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vtable pointer for the current instance, for <c>ID2D1ResourceTextureManager</c>.
|
||||
/// </summary>
|
||||
private void** lpVtblForID2D1ResourceTextureManager;
|
||||
|
||||
/// <summary>
|
||||
/// The vtable pointer for the current instance, for <c>ID2D1ResourceTextureManagerInternal</c>.
|
||||
/// </summary>
|
||||
private void** lpVtblForID2D1ResourceTextureManagerInternal;
|
||||
|
||||
/// <summary>
|
||||
/// The current reference count for the object (from <c>IUnknown</c>).
|
||||
/// </summary>
|
||||
private volatile int referenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1EffectContext"/> object currently wrapped by the current instance.
|
||||
/// </summary>
|
||||
private ID2D1EffectContext* d2D1EffectContext;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1Multithread"/> instance used to lock accesses to <see cref="d2D1EffectContext"/> and <see cref="d2D1ResourceTexture"/>.
|
||||
/// </summary>
|
||||
private ID2D1Multithread* d2D1Multithread;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ID2D1ResourceTexture"/> object, if one was created already.
|
||||
/// </summary>
|
||||
private ID2D1ResourceTexture* d2D1ResourceTexture;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> to identify the resource, if available.
|
||||
/// </summary>
|
||||
private Guid* resourceId;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="D2D1_RESOURCE_TEXTURE_PROPERTIES"/> for the resource texture.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If <see cref="D2D1_RESOURCE_TEXTURE_PROPERTIES.extents"/> is <see langword="null"/>, it has not been set.
|
||||
/// </remarks>
|
||||
private D2D1_RESOURCE_TEXTURE_PROPERTIES resourceTextureProperties;
|
||||
|
||||
/// <summary>
|
||||
/// The texture data, if available.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Once the texture has been created, this will no longer be necessary.
|
||||
/// </remarks>
|
||||
private byte* data;
|
||||
|
||||
/// <summary>
|
||||
/// An optional pointer to the stride to advance through the resource texture, according to dimension.
|
||||
/// </summary>
|
||||
private uint* strides;
|
||||
|
||||
/// <summary>
|
||||
/// The size, in bytes, of the data.
|
||||
/// </summary>
|
||||
private uint dataSize;
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="GCHandle"/> to a dummy <see langword="object"/> to use for locking.
|
||||
/// </summary>
|
||||
private GCHandle lockHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The expected dimensions for the slot the manager has been assigned to in an effect.
|
||||
/// </summary>
|
||||
/// <remarks>If <c>0</c>, it has not been set, so it can be ignored.</remarks>
|
||||
private uint expectedDimensions;
|
||||
|
||||
/// <summary>
|
||||
/// The factory method for <see cref="D2D1ResourceTextureManagerImpl"/> instances.
|
||||
/// </summary>
|
||||
/// <param name="resourceTextureManager">The resulting resource texture manager instance.</param>
|
||||
public static void Factory(D2D1ResourceTextureManagerImpl** resourceTextureManager)
|
||||
{
|
||||
D2D1ResourceTextureManagerImpl* @this = (D2D1ResourceTextureManagerImpl*)NativeMemory.Alloc((nuint)sizeof(D2D1ResourceTextureManagerImpl));
|
||||
|
||||
*@this = default;
|
||||
|
||||
@this->lpVtblForID2D1ResourceTextureManager = VtblForID2D1ResourceTextureManager;
|
||||
@this->lpVtblForID2D1ResourceTextureManagerInternal = VtblForID2D1ResourceTextureManagerInternal;
|
||||
@this->referenceCount = 1;
|
||||
@this->d2D1EffectContext = null;
|
||||
@this->d2D1Multithread = null;
|
||||
@this->d2D1ResourceTexture = null;
|
||||
@this->resourceId = null;
|
||||
@this->resourceTextureProperties = default;
|
||||
@this->data = null;
|
||||
@this->strides = null;
|
||||
@this->dataSize = 0;
|
||||
@this->lockHandle = GCHandle.Alloc(new object());
|
||||
@this->expectedDimensions = 0;
|
||||
|
||||
*resourceTextureManager = @this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface"/>
|
||||
public int QueryInterface(Guid* riid, void** ppvObject)
|
||||
{
|
||||
if (ppvObject is null)
|
||||
{
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
// ID2D1ResourceTextureManager
|
||||
if (riid->Equals(Windows.__uuidof<IUnknown>()) ||
|
||||
riid->Equals(ID2D1ResourceTextureManager.Guid))
|
||||
{
|
||||
_ = Interlocked.Increment(ref this.referenceCount);
|
||||
|
||||
*ppvObject = Unsafe.AsPointer(ref this);
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
// ID2D1ResourceTextureManagerInternal
|
||||
if (riid->Equals(ID2D1ResourceTextureManagerInternal.Guid))
|
||||
{
|
||||
_ = Interlocked.Increment(ref this.referenceCount);
|
||||
|
||||
*ppvObject = (void**)Unsafe.AsPointer(ref this) + 1;
|
||||
|
||||
return S.S_OK;
|
||||
}
|
||||
|
||||
*ppvObject = null;
|
||||
|
||||
return E.E_NOINTERFACE;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef"/>
|
||||
public uint AddRef()
|
||||
{
|
||||
return (uint)Interlocked.Increment(ref this.referenceCount);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release"/>
|
||||
public uint Release()
|
||||
{
|
||||
uint referenceCount = (uint)Interlocked.Decrement(ref this.referenceCount);
|
||||
|
||||
if (referenceCount == 0)
|
||||
{
|
||||
lock (this.lockHandle.Target!)
|
||||
{
|
||||
// Also synchronize on the ID2D1Multithread instance before touching D2D objects
|
||||
if (this.d2D1Multithread is not null)
|
||||
{
|
||||
// Enter the lock, and then free the effect context. That is guaranteed to
|
||||
// not be null here, as it is only ever set if ID2D1Multithread is retrieved.
|
||||
this.d2D1Multithread->Enter();
|
||||
this.d2D1EffectContext->Release();
|
||||
|
||||
// Release the resource too if it has been created
|
||||
if (this.d2D1ResourceTexture is not null)
|
||||
{
|
||||
this.d2D1ResourceTexture->Release();
|
||||
}
|
||||
|
||||
this.d2D1Multithread->Leave();
|
||||
}
|
||||
|
||||
if (this.resourceId is not null)
|
||||
{
|
||||
NativeMemory.Free(this.resourceId);
|
||||
}
|
||||
|
||||
if (this.resourceTextureProperties.extents is not null)
|
||||
{
|
||||
NativeMemory.Free(this.resourceTextureProperties.extents);
|
||||
}
|
||||
|
||||
if (this.resourceTextureProperties.extendModes is not null)
|
||||
{
|
||||
NativeMemory.Free(this.resourceTextureProperties.extendModes);
|
||||
}
|
||||
|
||||
if (this.data is not null)
|
||||
{
|
||||
NativeMemory.Free(this.data);
|
||||
}
|
||||
|
||||
if (this.strides is not null)
|
||||
{
|
||||
NativeMemory.Free(this.strides);
|
||||
}
|
||||
}
|
||||
|
||||
this.lockHandle.Free();
|
||||
|
||||
NativeMemory.Free(Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
return referenceCount;
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
|
||||
/// <summary>
|
||||
/// The resource texture manager type to use with built-in effects.
|
||||
/// </summary>
|
||||
[Guid("3C4FC7E4-A419-46CA-B5F6-66EB4FF18D64")]
|
||||
internal unsafe struct ID2D1ResourceTextureManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="System.Guid"/> for <c>ID2D1ResourceTextureManager</c> (<c>3C4FC7E4-A419-46CA-B5F6-66EB4FF18D64</c>).
|
||||
/// </summary>
|
||||
public static ref readonly Guid Guid
|
||||
{
|
||||
get
|
||||
{
|
||||
ReadOnlySpan<byte> data = new byte[] {
|
||||
0xE4, 0xC7, 0x4F, 0x3C,
|
||||
0x19, 0xA4,
|
||||
0xCA, 0x46,
|
||||
0xB5, 0xF6,
|
||||
0x66,
|
||||
0xEB,
|
||||
0x4F,
|
||||
0xF1,
|
||||
0x8D,
|
||||
0x64
|
||||
};
|
||||
|
||||
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vtable for the current instance.
|
||||
/// </summary>
|
||||
private readonly void** lpVtbl;
|
||||
|
||||
/// <summary>
|
||||
/// Creates or finds the given resource texture, depending on whether a resource id is specified.
|
||||
/// It also optionally initializes the texture with the specified data.
|
||||
/// </summary>
|
||||
/// <param name="resourceId">An optional pointer to the unique id that identifies the resource texture.</param>
|
||||
/// <param name="resourceTextureProperties">The properties used to create the resource texture.</param>
|
||||
/// <param name="data">The optional data to be loaded into the resource texture.</param>
|
||||
/// <param name="strides">An optional pointer to the stride to advance through the resource texture, according to dimension.</param>
|
||||
/// <param name="dataSize">The size, in bytes, of the data.</param>
|
||||
/// <returns>An <see cref="HRESULT"/> for the operation.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Initialize(
|
||||
Guid* resourceId,
|
||||
D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties,
|
||||
byte* data,
|
||||
uint* strides,
|
||||
uint dataSize)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTextureManager*, Guid*, D2D1_RESOURCE_TEXTURE_PROPERTIES*, byte*, uint*, uint, int>)this.lpVtbl[3])(
|
||||
(ID2D1ResourceTextureManager*)Unsafe.AsPointer(ref this),
|
||||
resourceId,
|
||||
resourceTextureProperties,
|
||||
data,
|
||||
strides,
|
||||
dataSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the specific resource texture inside the specific range or box using the supplied data.
|
||||
/// </summary>
|
||||
/// <param name="minimumExtents">The "left" extent of the updates if specified. If <see langword="null"/>, the entire texture is updated.</param>
|
||||
/// <param name="maximimumExtents">The "right" extent of the updates if specified. If <see langword="null"/>, the entire texture is updated.</param>
|
||||
/// <param name="strides">The stride to advance through the input data, according to dimension.</param>
|
||||
/// <param name="dimensions">The number of dimensions in the resource texture. This must match the number used to load the texture.</param>
|
||||
/// <param name="data">The data to be placed into the resource texture.</param>
|
||||
/// <param name="dataCount">The size of the data buffer to be used to update the resource texture.</param>
|
||||
/// <returns>An <see cref="HRESULT"/> for the operation.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Update(
|
||||
uint* minimumExtents,
|
||||
uint* maximimumExtents,
|
||||
uint* strides,
|
||||
uint dimensions,
|
||||
byte* data,
|
||||
uint dataCount)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTextureManager*, uint*, uint*, uint*, uint, byte*, uint, int>)this.lpVtbl[4])(
|
||||
(ID2D1ResourceTextureManager*)Unsafe.AsPointer(ref this),
|
||||
minimumExtents,
|
||||
maximimumExtents,
|
||||
strides,
|
||||
dimensions,
|
||||
data,
|
||||
dataCount);
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
|
||||
/// <summary>
|
||||
/// The internal resource texture manager type to use with built-in effects.
|
||||
/// </summary>
|
||||
[Guid("5CBB1024-8EA1-4689-81BF-8AD190B5EF5D")]
|
||||
internal unsafe struct ID2D1ResourceTextureManagerInternal
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the <see cref="System.Guid"/> for <c>ID2D1ResourceTextureManagerInternal</c> (<c>5CBB1024-8EA1-4689-81BF-8AD190B5EF5D</c>).
|
||||
/// </summary>
|
||||
public static ref readonly Guid Guid
|
||||
{
|
||||
get
|
||||
{
|
||||
ReadOnlySpan<byte> data = new byte[] {
|
||||
0x24, 0x10, 0xBB, 0x5C,
|
||||
0xA1, 0x8E,
|
||||
0x89, 0x46,
|
||||
0x81, 0xBF,
|
||||
0x8A,
|
||||
0xD1,
|
||||
0x90,
|
||||
0xB5,
|
||||
0xEF,
|
||||
0x5D
|
||||
};
|
||||
|
||||
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vtable for the current instance.
|
||||
/// </summary>
|
||||
private readonly void** lpVtbl;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="ID2D1EffectContext"/> for the current <c>ID2D1ResourceTextureManagerInternal</c> instance.
|
||||
/// </summary>
|
||||
/// <param name="effectContext">The input <see cref="ID2D1EffectContext"/> for the manager.</param>
|
||||
/// <param name="dimensions">A pointer to an optional amount of dimensions for the target resource texture, for validation.</param>
|
||||
/// <returns>An <see cref="HRESULT"/> for the operation.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Initialize(ID2D1EffectContext* effectContext, uint* dimensions)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTextureManagerInternal*, ID2D1EffectContext*, uint*, int>)this.lpVtbl[3])(
|
||||
(ID2D1ResourceTextureManagerInternal*)Unsafe.AsPointer(ref this),
|
||||
effectContext,
|
||||
dimensions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ID2D1ResourceTexture"/> instance held by the manager.
|
||||
/// </summary>
|
||||
/// <param name="resourceTexture">The resulting <see cref="ID2D1ResourceTexture"/> instance.</param>
|
||||
/// <returns>An <see cref="HRESULT"/> for the operation.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int GetResourceTexture(ID2D1ResourceTexture** resourceTexture)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTextureManagerInternal*, ID2D1ResourceTexture**, int>)this.lpVtbl[4])(
|
||||
(ID2D1ResourceTextureManagerInternal*)Unsafe.AsPointer(ref this),
|
||||
resourceTexture);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Extensions for the <see cref="ID2D1Multithread"/> type.
|
||||
/// </summary>
|
||||
internal static class ID2D1EffectContextExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets an <see cref="ID2D1Multithread"/> from an input <see cref="ID2D1EffectContext"/> object.
|
||||
/// </summary>
|
||||
/// <param name="effectContext">The input <see cref="ID2D1EffectContext"/> instance.</param>
|
||||
/// <param name="multithread">The resulting <see cref="ID2D1Multithread"/> object.</param>
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation</returns>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The <see cref="ID2D1EffectContext"/> object is not thread-safe, so it cannot be used concurrently
|
||||
/// when outside of a scenario where D2D has explicitly called into user code (eg. in the public APIs
|
||||
/// from <see cref="ID2D1EffectImpl"/>. To avoid issues, it is necessary to lock with the same lock
|
||||
/// used by D2D when using any public API on <see cref="ID2D1EffectContext"/> from other callsites.
|
||||
/// The same goes for any type out of <c>d2d1effectauthor.h</c>, such as <see cref="ID2D1ResourceTexture"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// To lock, the <see cref="ID2D1Multithread"/> object can be used. To retrieve this, a <see cref="ID2D1Factory"/>
|
||||
/// instance is needed. This cannot be retrieved directly from an <see cref="ID2D1EffectContext"/>, but this
|
||||
/// can be used to create any <see cref="ID2D1Effect"/> instance (such as a flood effect, which is fairly cheap).
|
||||
/// From that, <see cref="IUnknown.QueryInterface"/> can be used to get an <see cref="ID2D1Image"/> object.
|
||||
/// The fact <see cref="ID2D1Effect"/> implements this interface is mentioned in the <see cref="ID2D1Image"/> docs,
|
||||
/// see <see href="https://docs.microsoft.com/en-us/windows/desktop/api/d2d1_1/nf-d2d1_1-id2d1effect-getoutput"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// From the <see cref="ID2D1Image"/>, an <see cref="ID2D1Factory"/> can be retrieved. Finally, this can
|
||||
/// be cast to <see cref="ID2D1Multithread"/>, which can then be kept and used to synchronize later calls.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static unsafe int GetD2D1Multithread(this ref ID2D1EffectContext effectContext, ID2D1Multithread** multithread)
|
||||
{
|
||||
using ComPtr<ID2D1Effect> floodEffect = default;
|
||||
|
||||
int hresult = effectContext.CreateEffect(
|
||||
effectId: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_D2D1Flood)),
|
||||
effect: (void**)floodEffect.GetAddressOf());
|
||||
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
using ComPtr<ID2D1Image> d2D1Image = default;
|
||||
|
||||
hresult = floodEffect.CopyTo(d2D1Image.GetAddressOf());
|
||||
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
using ComPtr<ID2D1Factory> d2D1Factory = default;
|
||||
|
||||
d2D1Image.Get()->GetFactory(d2D1Factory.GetAddressOf());
|
||||
|
||||
hresult = d2D1Factory.CopyTo(multithread);
|
||||
}
|
||||
}
|
||||
|
||||
return hresult;
|
||||
}
|
||||
}
|
||||
+14
@@ -3,6 +3,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace ComputeSharp.NetStandard.System.Runtime.InteropServices; // This cannot be in System.Runtime.InteropServices, or Roslyn will recognize it
|
||||
|
||||
/// <summary>
|
||||
@@ -14,4 +16,16 @@ namespace ComputeSharp.NetStandard.System.Runtime.InteropServices; // This canno
|
||||
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
|
||||
internal sealed class UnmanagedCallersOnlyAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Optional. If omitted, the runtime will use the default platform calling convention.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Supplied types must be from the official "System.Runtime.CompilerServices" namespace and be of the form "CallConvXXX".
|
||||
/// </remarks>
|
||||
public Type[]? CallConvs;
|
||||
|
||||
/// <summary>
|
||||
/// Optional. If omitted, no named export is emitted during compilation.
|
||||
/// </summary>
|
||||
public string? EntryPoint;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
// Ported from um/d2d1.h in the Windows SDK for Windows 10.0.22000.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
internal enum D2D1_EXTEND_MODE : uint
|
||||
{
|
||||
D2D1_EXTEND_MODE_CLAMP = 0,
|
||||
|
||||
D2D1_EXTEND_MODE_WRAP = 1,
|
||||
|
||||
D2D1_EXTEND_MODE_MIRROR = 2,
|
||||
|
||||
D2D1_EXTEND_MODE_FORCE_DWORD = 0xffffffff,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
// Ported from um/d2d1.h in the Windows SDK for Windows 10.0.22000.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
[Guid("06152247-6F50-465A-9245-118BFD3B6007")]
|
||||
[NativeTypeName("struct ID2D1Factory : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe partial struct ID2D1Factory
|
||||
{
|
||||
public void** lpVtbl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
// Ported from um/d2d1.h in the Windows SDK for Windows 10.0.22000.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
[Guid("65019F75-8DA2-497C-B32C-DFA34E48EDE6")]
|
||||
[NativeTypeName("struct ID2D1Image : ID2D1Resource")]
|
||||
[NativeInheritance("ID2D1Resource")]
|
||||
internal unsafe partial struct ID2D1Image
|
||||
{
|
||||
public void** lpVtbl;
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(0)]
|
||||
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Image*, Guid*, void**, int>)(lpVtbl[0]))((ID2D1Image*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Image*, uint>)(lpVtbl[1]))((ID2D1Image*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Image*, uint>)(lpVtbl[2]))((ID2D1Image*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public void GetFactory(ID2D1Factory** factory)
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID2D1Image*, ID2D1Factory**, void>)(lpVtbl[3]))((ID2D1Image*)Unsafe.AsPointer(ref this), factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
internal enum D2D1_PROPERTY_TYPE : uint
|
||||
{
|
||||
D2D1_PROPERTY_TYPE_BLOB = 9
|
||||
D2D1_PROPERTY_TYPE_BLOB = 9,
|
||||
D2D1_PROPERTY_TYPE_IUNKNOWN = 10
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
// Ported from um/d2d1_1.h in the Windows SDK for Windows 10.0.22000.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
[Guid("31E6E7BC-E0FF-4D46-8C64-A0A8C41C15D3")]
|
||||
[NativeTypeName("struct ID2D1Multithread : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe partial struct ID2D1Multithread
|
||||
{
|
||||
public void** lpVtbl;
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(0)]
|
||||
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Multithread*, Guid*, void**, int>)(lpVtbl[0]))((ID2D1Multithread*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Multithread*, uint>)(lpVtbl[1]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Multithread*, uint>)(lpVtbl[2]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(4)]
|
||||
public void Enter()
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID2D1Multithread*, void>)(lpVtbl[4]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(5)]
|
||||
public void Leave()
|
||||
{
|
||||
((delegate* unmanaged[Stdcall]<ID2D1Multithread*, void>)(lpVtbl[5]))((ID2D1Multithread*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-2
@@ -5,7 +5,9 @@
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using TerraFX.Interop.Windows;
|
||||
#endif
|
||||
|
||||
namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
@@ -15,9 +17,17 @@ namespace TerraFX.Interop.DirectX
|
||||
public ushort* propertyName;
|
||||
|
||||
[NativeTypeName("PD2D1_PROPERTY_SET_FUNCTION")]
|
||||
public delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, HRESULT> setFunction;
|
||||
#if NET6_0_OR_GREATER
|
||||
public delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, int> setFunction;
|
||||
#else
|
||||
public void* setFunction;
|
||||
#endif
|
||||
|
||||
[NativeTypeName("PD2D1_PROPERTY_GET_FUNCTION")]
|
||||
public delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, HRESULT> getFunction;
|
||||
#if NET6_0_OR_GREATER
|
||||
public delegate* unmanaged[Stdcall]<IUnknown*, byte*, uint, uint*, int> getFunction;
|
||||
#else
|
||||
public void* getFunction;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
// Ported from um/d2d1effectauthor.h in the Windows SDK for Windows 10.0.22000.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
internal unsafe partial struct D2D1_RESOURCE_TEXTURE_PROPERTIES
|
||||
{
|
||||
[NativeTypeName("const UINT32 *")]
|
||||
public uint* extents;
|
||||
|
||||
[NativeTypeName("UINT32")]
|
||||
public uint dimensions;
|
||||
|
||||
public D2D1_BUFFER_PRECISION bufferPrecision;
|
||||
|
||||
public D2D1_CHANNEL_DEPTH channelDepth;
|
||||
|
||||
public D2D1_FILTER filter;
|
||||
|
||||
[NativeTypeName("const D2D1_EXTEND_MODE *")]
|
||||
public D2D1_EXTEND_MODE* extendModes;
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,13 @@ namespace TerraFX.Interop.DirectX
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfo*, byte*, uint, int>)(lpVtbl[7]))((ID2D1DrawInfo*)Unsafe.AsPointer(ref this), buffer, bufferCount);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(8)]
|
||||
public HRESULT SetResourceTexture([NativeTypeName("UINT32")] uint textureIndex, ID2D1ResourceTexture* resourceTexture)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1DrawInfo*, uint, ID2D1ResourceTexture*, int>)(lpVtbl[8]))((ID2D1DrawInfo*)Unsafe.AsPointer(ref this), textureIndex, resourceTexture);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(10)]
|
||||
public HRESULT SetPixelShader([NativeTypeName("const GUID &")] Guid* shaderId, D2D1_PIXEL_OPTIONS pixelOptions = D2D1_PIXEL_OPTIONS_NONE)
|
||||
|
||||
@@ -19,6 +19,29 @@ namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
public void** lpVtbl;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(0)]
|
||||
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<IUnknown*, Guid*, void**, int>)(lpVtbl[0]))((IUnknown*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<IUnknown*, uint>)(lpVtbl[1]))((IUnknown*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<IUnknown*, uint>)(lpVtbl[2]))((IUnknown*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(4)]
|
||||
public HRESULT CreateEffect([NativeTypeName("const IID &")] Guid* effectId, void** effect)
|
||||
@@ -40,6 +63,13 @@ namespace TerraFX.Interop.DirectX
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1EffectContext*, Guid*, int>)(lpVtbl[14]))((ID2D1EffectContext*)Unsafe.AsPointer(ref this), shaderId);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(15)]
|
||||
public HRESULT CreateResourceTexture([NativeTypeName("const GUID *")] Guid* resourceId, [NativeTypeName("const D2D1_RESOURCE_TEXTURE_PROPERTIES *")] D2D1_RESOURCE_TEXTURE_PROPERTIES* resourceTextureProperties, [NativeTypeName("const BYTE *")] byte* data, [NativeTypeName("const UINT32 *")] uint* strides, [NativeTypeName("UINT32")] uint dataSize, ID2D1ResourceTexture** resourceTexture)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1EffectContext*, Guid*, D2D1_RESOURCE_TEXTURE_PROPERTIES*, byte*, uint*, uint, ID2D1ResourceTexture**, int>)(lpVtbl[15]))((ID2D1EffectContext*)Unsafe.AsPointer(ref this), resourceId, resourceTextureProperties, data, strides, dataSize, resourceTexture);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(22)]
|
||||
public HRESULT CheckFeatureSupport(D2D1_FEATURE feature, void* featureSupportData, [NativeTypeName("UINT32")] uint featureSupportDataSize)
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
// Ported from um/d2d1effectauthor.h in the Windows SDK for Windows 10.0.22000.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace TerraFX.Interop.DirectX
|
||||
{
|
||||
[Guid("688D15C3-02B0-438D-B13A-D1B44C32C39A")]
|
||||
[NativeTypeName("struct ID2D1ResourceTexture : IUnknown")]
|
||||
[NativeInheritance("IUnknown")]
|
||||
internal unsafe partial struct ID2D1ResourceTexture
|
||||
{
|
||||
public void** lpVtbl;
|
||||
|
||||
/// <inheritdoc cref="IUnknown.QueryInterface" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(0)]
|
||||
public HRESULT QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTexture*, Guid*, void**, int>)(lpVtbl[0]))((ID2D1ResourceTexture*)Unsafe.AsPointer(ref this), riid, ppvObject);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.AddRef" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(1)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint AddRef()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTexture*, uint>)(lpVtbl[1]))((ID2D1ResourceTexture*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IUnknown.Release" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(2)]
|
||||
[return: NativeTypeName("ULONG")]
|
||||
public uint Release()
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTexture*, uint>)(lpVtbl[2]))((ID2D1ResourceTexture*)Unsafe.AsPointer(ref this));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(3)]
|
||||
public HRESULT Update([NativeTypeName("const UINT32 *")] uint* minimumExtents, [NativeTypeName("const UINT32 *")] uint* maximimumExtents, [NativeTypeName("const UINT32 *")] uint* strides, [NativeTypeName("UINT32")] uint dimensions, [NativeTypeName("const BYTE *")] byte* data, [NativeTypeName("UINT32")] uint dataCount)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1ResourceTexture*, uint*, uint*, uint*, uint, byte*, uint, int>)(lpVtbl[3]))((ID2D1ResourceTexture*)Unsafe.AsPointer(ref this), minimumExtents, maximimumExtents, strides, dimensions, data, dataCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
|
||||
|
||||
// Ported from um/d2d1effects.h in the Windows SDK for Windows 10.0.22000.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TerraFX.Interop.Windows
|
||||
{
|
||||
internal static partial class CLSID
|
||||
{
|
||||
[NativeTypeName("const GUID")]
|
||||
public static ref readonly Guid CLSID_D2D1Flood
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
ReadOnlySpan<byte> data = new byte[] {
|
||||
0x20, 0x3C, 0xC2, 0x61,
|
||||
0x69, 0xAE,
|
||||
0x8E, 0x4D,
|
||||
0x94,
|
||||
0xCF,
|
||||
0x50,
|
||||
0x07,
|
||||
0x8D,
|
||||
0xF6,
|
||||
0x38,
|
||||
0xF2
|
||||
};
|
||||
|
||||
return ref Unsafe.As<byte, Guid>(ref MemoryMarshal.GetReference(data));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
差分なしでファイル名を変更。
差分なしでファイル名を変更。
@@ -17,21 +17,28 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\D2D1_PIXEL_OPTIONS.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\D2D1_PROPERTY_BINDING.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\D2D1_INPUT_DESCRIPTION.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\D2D1_RESOURCE_TEXTURE_PROPERTIES.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1DrawTransform.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1EffectContext.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1EffectImpl.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1ResourceTexture.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1Transform.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1TransformGraph.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1TransformNode.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effects\CLSID.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\D2D1_EXTEND_MODE.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\ID2D1Factory.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1\ID2D1Image.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_CHANNEL_DEPTH.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_BUFFER_PRECISION.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_PROPERTY_TYPE.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1DeviceContext.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1Effect.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1Factory1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1Multithread.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\D3D_INCLUDE_TYPE.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\D3D_SHADER_MACRO.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11shadeer\D3D11_SHADER_DESC.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11shader\D3D11_SHADER_DESC.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcommon\ID3DInclude.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcompiler\D3DCOMPILE.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3dcompiler\D3D_BLOB_PART.cs" />
|
||||
@@ -41,7 +48,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)..\TerraFX.Interop.Windows\DirectX\um\d3dcommon\D3D_TESSELLATOR_OUTPUT_PRIMITIVE.cs" Link="DirectX\um\d3dcommon\D3D_TESSELLATOR_OUTPUT_PRIMITIVE.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)..\TerraFX.Interop.Windows\DirectX\um\d3dcommon\D3D_TESSELLATOR_PARTITIONING.cs" Link="DirectX\um\d3dcommon\D3D_TESSELLATOR_PARTITIONING.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)..\TerraFX.Interop.Windows\DirectX\um\d3dcommon\D3D_TESSELLATOR_DOMAIN.cs" Link="DirectX\um\d3dcommon\D3D_TESSELLATOR_DOMAIN.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11shadeer\ID3D11ShaderReflection.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d3d11shader\ID3D11ShaderReflection.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Windows\shared\uuids\Windows.Manual.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)..\TerraFX.Interop.Windows\ComPtr`1.cs" Link="ComPtr`1.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1effectauthor\ID2D1DrawInfo.cs" />
|
||||
|
||||
@@ -7,6 +7,12 @@ namespace TerraFX.Interop.Windows
|
||||
{
|
||||
internal static class E
|
||||
{
|
||||
[NativeTypeName("#define E_NOT_VALID_STATE HRESULT_FROM_WIN32(ERROR_INVALID_STATE)")]
|
||||
public const int E_NOT_VALID_STATE = -2147019873;
|
||||
|
||||
[NativeTypeName("#define E_NOT_SUFFICIENT_BUFFER HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER)")]
|
||||
public const int E_NOT_SUFFICIENT_BUFFER = -2147024774;
|
||||
|
||||
[NativeTypeName("#define E_NOTIMPL _HRESULT_TYPEDEF_(0x80004001L)")]
|
||||
public const int E_NOTIMPL = unchecked((int)(0x80004001));
|
||||
|
||||
|
||||
@@ -12,11 +12,5 @@ namespace TerraFX.Interop.Windows
|
||||
|
||||
[NativeTypeName("#define S_FALSE ((HRESULT)1L)")]
|
||||
public const int S_FALSE = ((int)(1));
|
||||
|
||||
[NativeTypeName("#define S_STORE_LAUNCHED_FOR_REMEDIATION _HRESULT_TYPEDEF_(0x00270258L)")]
|
||||
public const int S_STORE_LAUNCHED_FOR_REMEDIATION = ((int)(0x00270258));
|
||||
|
||||
[NativeTypeName("#define S_APPLICATION_ACTIVATION_ERROR_HANDLED_BY_DIALOG _HRESULT_TYPEDEF_(0x00270259L)")]
|
||||
public const int S_APPLICATION_ACTIVATION_ERROR_HANDLED_BY_DIALOG = ((int)(0x00270259));
|
||||
}
|
||||
}
|
||||
バイナリファイルは表示されません。
|
変更後 幅: | 高さ: | サイズ: 1.5 MiB |
@@ -38,6 +38,21 @@
|
||||
<None Update="Assets\Landscape_Pixelate.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\nature_part0.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\nature_part1.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\nature_part2.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\nature_part3.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\WallpapersStack.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="Assets\ZonePlate.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Tests.Effects;
|
||||
using ComputeSharp.D2D1.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("D2D1PixelShaderEffect")]
|
||||
public partial class D2D1PixelShaderEffectTests
|
||||
{
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void RegisterForD2D1Factory1_NullD2D1Factory1()
|
||||
{
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<InvertEffect>(null, out _);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void RegisterForD2D1Factory1_WithTransformMapper_NullD2D1Factory1()
|
||||
{
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<PixelateEffect.Shader, PixelateEffect>(null, out _);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void RegisterForD2D1Factory1_WithTransformMapperFactory_NullD2D1Factory1()
|
||||
{
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1(null, () => new PixelateEffect(), out _);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void CreateFromD2D1DeviceContext_NullD2D1DeviceContext()
|
||||
{
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<InvertEffect>(null, (void**)1);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void CreateFromD2D1DeviceContext_NullD2D1Effect()
|
||||
{
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<InvertEffect>((void*)1, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void SetConstantBufferForD2D1Effect_NullD2D1Effect()
|
||||
{
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect<InvertEffect>(default, null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void SetResourceTextureManagerForD2D1Effect_NullD2D1Effect()
|
||||
{
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(null, (void*)1, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void SetResourceTextureManagerForD2D1Effect_NullD2D1ResourceTextureManager()
|
||||
{
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect((void*)1, (void*)null, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void SetResourceTextureManagerForD2D1Effect_RCW_NullD2D1Effect()
|
||||
{
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { 64 },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinLinearMagMipPoint,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Clamp });
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(null, resourceTextureManager, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void SetResourceTextureManagerForD2D1Effect_RCW_NullD2D1ResourceTextureManager()
|
||||
{
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect((void*)1, (D2D1ResourceTextureManager)null!, 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Win32Exception))]
|
||||
public unsafe void NullConstantBuffer_DrawImageFails()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<NullConstantBufferShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<NullConstantBufferShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), 128, 128);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[AutoConstructor]
|
||||
private partial struct NullConstantBufferShader : ID2D1PixelShader
|
||||
{
|
||||
private float dummy;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
return dummy;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void GetValueSize_ConstantBuffer()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<ConstantBufferSizeTestShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<ConstantBufferSizeTestShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
uint size = d2D1Effect.Get()->GetValueSize(D2D1PixelShaderEffectProperty.ConstantBuffer);
|
||||
|
||||
Assert.AreEqual(D2D1PixelShader.GetConstantBufferSize<ConstantBufferSizeTestShader>(), (int)size);
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[AutoConstructor]
|
||||
private partial struct ConstantBufferSizeTestShader : ID2D1PixelShader
|
||||
{
|
||||
private float a;
|
||||
private float b;
|
||||
private float3 c;
|
||||
private int d;
|
||||
private int e;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
return a + b + c.X + d + e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -559,4 +559,11 @@ public partial class D2D1PixelShaderTests
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
|
||||
public unsafe void SetConstantBufferForD2D1DrawInfo_NullD2D1DrawInfo()
|
||||
{
|
||||
D2D1PixelShader.SetConstantBufferForD2D1DrawInfo<InvertEffect>(default, null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,688 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Tests.Helpers;
|
||||
using ComputeSharp.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CS0649
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests;
|
||||
|
||||
[TestClass]
|
||||
[TestCategory("D2D1ResourceTextureManager")]
|
||||
public partial class D2D1ResourceTextureManagerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public unsafe void VerifyInterfaces()
|
||||
{
|
||||
using ComPtr<IUnknown> resourceTextureManager = default;
|
||||
|
||||
D2D1ResourceTextureManager.Create((void**)resourceTextureManager.GetAddressOf());
|
||||
|
||||
Assert.IsTrue(resourceTextureManager.Get() is not null);
|
||||
|
||||
_ = resourceTextureManager.Get()->AddRef();
|
||||
|
||||
Assert.AreEqual(1u, resourceTextureManager.Get()->Release());
|
||||
|
||||
using ComPtr<IUnknown> unknown = default;
|
||||
using ComPtr<IUnknown> resourceTextureManager2 = default;
|
||||
using ComPtr<IUnknown> resourceTextureManagerInternal = default;
|
||||
|
||||
Guid uuidOfIUnknown = typeof(IUnknown).GUID;
|
||||
Guid uuidOfResourceTextureManager = new("3C4FC7E4-A419-46CA-B5F6-66EB4FF18D64");
|
||||
Guid uuidOfResourceTextureManagerInternal = new("5CBB1024-8EA1-4689-81BF-8AD190B5EF5D");
|
||||
|
||||
// The object implements IUnknown and the two resource texture manager interfaces
|
||||
Assert.AreEqual(0, (int)resourceTextureManager.AsIID(&uuidOfIUnknown, &unknown));
|
||||
Assert.AreEqual(0, (int)resourceTextureManager.AsIID(&uuidOfResourceTextureManager, &resourceTextureManager2));
|
||||
Assert.AreEqual(0, (int)resourceTextureManager.AsIID(&uuidOfResourceTextureManagerInternal, &resourceTextureManagerInternal));
|
||||
|
||||
Assert.IsTrue(unknown.Get() is not null);
|
||||
Assert.IsTrue(resourceTextureManager2.Get() is not null);
|
||||
Assert.IsTrue(resourceTextureManagerInternal.Get() is not null);
|
||||
|
||||
using ComPtr<IUnknown> garbage = default;
|
||||
|
||||
Guid uuidOfGarbage = Guid.NewGuid();
|
||||
|
||||
// Any other random QueryInterface should fail
|
||||
Assert.AreEqual(E.E_NOINTERFACE, (int)resourceTextureManager.AsIID(&uuidOfGarbage, &garbage));
|
||||
|
||||
Assert.IsTrue(garbage.Get() is null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void VerifyInterfaces_RCW()
|
||||
{
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc uint[] { 64 },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinLinearMagMipPoint,
|
||||
extendModes: stackalloc D2D1ExtendMode[] { D2D1ExtendMode.Clamp });
|
||||
|
||||
using ComPtr<IUnknown> unknown = default;
|
||||
using ComPtr<IUnknown> resourceTextureManager2 = default;
|
||||
using ComPtr<IUnknown> resourceTextureManagerInternal = default;
|
||||
|
||||
Guid uuidOfIUnknown = typeof(IUnknown).GUID;
|
||||
Guid uuidOfResourceTextureManager = new("3C4FC7E4-A419-46CA-B5F6-66EB4FF18D64");
|
||||
Guid uuidOfResourceTextureManagerInternal = new("5CBB1024-8EA1-4689-81BF-8AD190B5EF5D");
|
||||
|
||||
// The object implements IUnknown and the two resource texture manager interfaces
|
||||
Assert.AreEqual(CustomQueryInterfaceResult.Handled, ((ICustomQueryInterface)resourceTextureManager).GetInterface(ref uuidOfIUnknown, out *(IntPtr*)unknown.GetAddressOf()));
|
||||
Assert.AreEqual(CustomQueryInterfaceResult.Handled, ((ICustomQueryInterface)resourceTextureManager).GetInterface(ref uuidOfResourceTextureManager, out *(IntPtr*)resourceTextureManager2.GetAddressOf()));
|
||||
Assert.AreEqual(CustomQueryInterfaceResult.Handled, ((ICustomQueryInterface)resourceTextureManager).GetInterface(ref uuidOfResourceTextureManagerInternal, out *(IntPtr*)resourceTextureManagerInternal.GetAddressOf()));
|
||||
|
||||
Assert.IsTrue(unknown.Get() is not null);
|
||||
Assert.IsTrue(resourceTextureManager2.Get() is not null);
|
||||
Assert.IsTrue(resourceTextureManagerInternal.Get() is not null);
|
||||
|
||||
using ComPtr<IUnknown> garbage = default;
|
||||
|
||||
Guid uuidOfGarbage = Guid.NewGuid();
|
||||
|
||||
// Any other random QueryInterface should fail
|
||||
Assert.AreEqual(CustomQueryInterfaceResult.Failed, ((ICustomQueryInterface)resourceTextureManager).GetInterface(ref uuidOfGarbage, out *(IntPtr*)garbage.GetAddressOf()));
|
||||
|
||||
Assert.IsTrue(garbage.Get() is null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadPixelsFromResourceTexture2D_CreateAfterGettingEffectContext()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<IndexFrom2DResourceTextureShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(default(IndexFrom2DResourceTextureShader), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<IUnknown> resourceTextureManager = default;
|
||||
|
||||
D2D1ResourceTextureManager.Create((void**)resourceTextureManager.GetAddressOf());
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager.Get(), 0);
|
||||
|
||||
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
||||
string expectedPath = Path.Combine(assemblyPath, "Assets", "Landscape.png");
|
||||
|
||||
using Image<Rgba32> expected = Image.Load<Rgba32>(expectedPath);
|
||||
|
||||
if (!expected.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> pixels))
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) });
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
string destinationPath = Path.Combine(assemblyPath, "temp", "IndexedFromResourceTexture2D_After.png");
|
||||
|
||||
_ = Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!);
|
||||
|
||||
ImageHelper.SaveBitmapToFile(destinationPath, (uint)expected.Width, (uint)expected.Height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadPixelsFromResourceTexture2D_CreateBeforeGettingEffectContext()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<IndexFrom2DResourceTextureShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(default(IndexFrom2DResourceTextureShader), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<IUnknown> resourceTextureManager = default;
|
||||
|
||||
D2D1ResourceTextureManager.Create((void**)resourceTextureManager.GetAddressOf());
|
||||
|
||||
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
||||
string expectedPath = Path.Combine(assemblyPath, "Assets", "Landscape.png");
|
||||
|
||||
using Image<Rgba32> expected = Image.Load<Rgba32>(expectedPath);
|
||||
|
||||
if (!expected.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> pixels))
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) });
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager.Get(), 0);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
string destinationPath = Path.Combine(assemblyPath, "temp", "IndexedFromResourceTexture2D_Before.png");
|
||||
|
||||
_ = Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!);
|
||||
|
||||
ImageHelper.SaveBitmapToFile(destinationPath, (uint)expected.Width, (uint)expected.Height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadPixelsFromResourceTexture2D_CreateBeforeGettingEffectContext_RCW()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<IndexFrom2DResourceTextureShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(default(IndexFrom2DResourceTextureShader), d2D1Effect.Get());
|
||||
|
||||
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
||||
string expectedPath = Path.Combine(assemblyPath, "Assets", "Landscape.png");
|
||||
|
||||
using Image<Rgba32> expected = Image.Load<Rgba32>(expectedPath);
|
||||
|
||||
if (!expected.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> pixels))
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)expected.Height },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width) });
|
||||
|
||||
using ComPtr<IUnknown> unknown = default;
|
||||
|
||||
Guid uuidOfIUnknown = typeof(IUnknown).GUID;
|
||||
|
||||
Assert.AreEqual(CustomQueryInterfaceResult.Handled, ((ICustomQueryInterface)resourceTextureManager).GetInterface(ref uuidOfIUnknown, out *(IntPtr*)unknown.GetAddressOf()));
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), unknown.Get(), 0);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
string destinationPath = Path.Combine(assemblyPath, "temp", "IndexedFromResourceTexture2D_Before.png");
|
||||
|
||||
_ = Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!);
|
||||
|
||||
ImageHelper.SaveBitmapToFile(destinationPath, (uint)expected.Width, (uint)expected.Height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
private partial struct IndexFrom2DResourceTextureShader : ID2D1PixelShader
|
||||
{
|
||||
[D2DResourceTextureIndex(0)]
|
||||
private D2D1ResourceTexture2D<float4> source;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 xy = (int2)D2D.GetScenePosition().XY;
|
||||
|
||||
return this.source[xy];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void LoadPixelsFromResourceTexture3D()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom3DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<IndexFrom3DResourceTextureShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
|
||||
string expectedPath = Path.Combine(assemblyPath, "Assets", "WallpapersStack.png");
|
||||
|
||||
using Image<Rgba32> expected = Image.Load<Rgba32>(expectedPath);
|
||||
|
||||
if (!expected.DangerousTryGetSinglePixelMemory(out Memory<Rgba32> pixels))
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
IndexFrom3DResourceTextureShader shader = new(expected.Height / 4);
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
|
||||
|
||||
using ComPtr<IUnknown> resourceTextureManager = default;
|
||||
|
||||
D2D1ResourceTextureManager.Create((void**)resourceTextureManager.GetAddressOf());
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager.Get(), 0);
|
||||
|
||||
D2D1ResourceTextureManager.Initialize(
|
||||
resourceTextureManager: resourceTextureManager.Get(),
|
||||
resourceId: Guid.NewGuid(),
|
||||
extents: stackalloc[] { (uint)expected.Width, (uint)(expected.Height / 4), 4u },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.Four,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
data: MemoryMarshal.AsBytes(pixels.Span),
|
||||
strides: stackalloc[] { (uint)(sizeof(Rgba32) * expected.Width), (uint)(sizeof(Rgba32) * expected.Width * (expected.Height / 4)) });
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)expected.Width, (uint)expected.Height);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
string destinationPath = Path.Combine(assemblyPath, "temp", "IndexedFromResourceTexture3D.png");
|
||||
|
||||
_ = Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!);
|
||||
|
||||
ImageHelper.SaveBitmapToFile(destinationPath, (uint)expected.Width, (uint)expected.Height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[AutoConstructor]
|
||||
private partial struct IndexFrom3DResourceTextureShader : ID2D1PixelShader
|
||||
{
|
||||
private int height;
|
||||
|
||||
[D2DResourceTextureIndex(0)]
|
||||
private D2D1ResourceTexture3D<float4> source;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 xy = (int2)D2D.GetScenePosition().XY;
|
||||
|
||||
int x = xy.X;
|
||||
int y = (int)((uint)xy.Y % (uint)height);
|
||||
int z = (int)((uint)xy.Y / (uint)height);
|
||||
|
||||
return this.source[x, y, z];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(128, 0, 26)]
|
||||
[DataRow(128, 0, 67)]
|
||||
[DataRow(128, 0, 128)]
|
||||
[DataRow(128, 32, 64)]
|
||||
[DataRow(1024, 311, 489)]
|
||||
[DataRow(1024, 907, 117)]
|
||||
public unsafe void UpdateResourceTexture1D(int width, int startOffset, int updateLength)
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture1DShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<CopyFromResourceTexture1DShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
CopyFromResourceTexture1DShader shader = new(width);
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
|
||||
|
||||
byte[] texture = new byte[width];
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc[] { (uint)width },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp },
|
||||
data: texture,
|
||||
strides: null);
|
||||
|
||||
byte[] data = RandomNumberGenerator.GetBytes(updateLength);
|
||||
|
||||
resourceTextureManager.Update(
|
||||
minimumExtents: stackalloc uint[] { (uint)startOffset },
|
||||
maximimumExtents: stackalloc uint[] { (uint)(startOffset + updateLength) },
|
||||
strides: ReadOnlySpan<uint>.Empty,
|
||||
data: data);
|
||||
|
||||
data.CopyTo(texture.AsSpan(startOffset));
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager, 0);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)width, 1);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
byte[] resultingBytes = new byte[width];
|
||||
int i = 0;
|
||||
|
||||
foreach (Bgra32 pixel in new ReadOnlySpan<Bgra32>(d2D1MappedRect.bits, width))
|
||||
{
|
||||
resultingBytes[i++] = pixel.B;
|
||||
}
|
||||
|
||||
Assert.IsTrue(texture.AsSpan().SequenceEqual(resultingBytes));
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[AutoConstructor]
|
||||
private partial struct CopyFromResourceTexture1DShader : ID2D1PixelShader
|
||||
{
|
||||
private int width;
|
||||
|
||||
[D2DResourceTextureIndex(0)]
|
||||
private D2D1ResourceTexture1D<float> source;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 xy = (int2)D2D.GetScenePosition().XY;
|
||||
|
||||
return this.source[xy.X];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(64, 64, 0, 0, 64, 64)]
|
||||
[DataRow(64, 64, 32, 32, 32, 32)]
|
||||
[DataRow(64, 64, 12, 33, 43, 22)]
|
||||
[DataRow(512, 768, 245, 111, 255, 461)]
|
||||
[DataRow(1024, 2048, 11, 899, 512, 342)]
|
||||
public unsafe void UpdateResourceTexture2D(
|
||||
int width,
|
||||
int height,
|
||||
int startOffsetX,
|
||||
int startOffsetY,
|
||||
int updateLengthX,
|
||||
int updateLengthY)
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture2DShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<CopyFromResourceTexture2DShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
CopyFromResourceTexture2DShader shader = new(width, height);
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
|
||||
|
||||
byte[] texture = new byte[width * height];
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc[] { (uint)width, (uint)height },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
data: texture,
|
||||
strides: stackalloc uint[] { (uint)width });
|
||||
|
||||
byte[] data = RandomNumberGenerator.GetBytes(updateLengthX * updateLengthY);
|
||||
|
||||
resourceTextureManager.Update(
|
||||
minimumExtents: stackalloc uint[] { (uint)startOffsetX, (uint)startOffsetY },
|
||||
maximimumExtents: stackalloc uint[] { (uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY) },
|
||||
strides: stackalloc uint[] { (uint)updateLengthX },
|
||||
data: data);
|
||||
|
||||
for (int y = 0; y < updateLengthY; y++)
|
||||
{
|
||||
ReadOnlySpan<byte> source = data.AsSpan(y * updateLengthX, updateLengthX);
|
||||
Span<byte> destination = texture.AsSpan(startOffsetY * width + y * width + startOffsetX, updateLengthX);
|
||||
|
||||
source.CopyTo(destination);
|
||||
}
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager, 0);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)width, (uint)height);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
byte[] resultingBytes = new byte[width * height];
|
||||
int i = 0;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
foreach (Bgra32 pixel in new ReadOnlySpan<Bgra32>(d2D1MappedRect.bits + d2D1MappedRect.pitch * y, width))
|
||||
{
|
||||
resultingBytes[i++] = pixel.B;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.IsTrue(texture.AsSpan().SequenceEqual(resultingBytes));
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[AutoConstructor]
|
||||
private partial struct CopyFromResourceTexture2DShader : ID2D1PixelShader
|
||||
{
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
[D2DResourceTextureIndex(0)]
|
||||
private D2D1ResourceTexture2D<float> source;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 xy = (int2)D2D.GetScenePosition().XY;
|
||||
|
||||
return this.source[xy];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow(64, 64, 3, 0, 0, 0, 64, 64, 3)]
|
||||
[DataRow(64, 64, 3, 10, 22, 1, 44, 33, 1)]
|
||||
[DataRow(64, 64, 3, 10, 22, 1, 44, 33, 2)]
|
||||
[DataRow(64, 64, 3, 10, 22, 0, 44, 33, 2)]
|
||||
[DataRow(512, 512, 6, 245, 0, 2, 188, 1, 4)]
|
||||
[DataRow(512, 512, 6, 245, 0, 2, 188, 467, 3)]
|
||||
[DataRow(512, 512, 6, 245, 113, 1, 256, 322, 2)]
|
||||
public unsafe void UpdateResourceTexture3D(
|
||||
int width,
|
||||
int height,
|
||||
int depth,
|
||||
int startOffsetX,
|
||||
int startOffsetY,
|
||||
int startOffsetZ,
|
||||
int updateLengthX,
|
||||
int updateLengthY,
|
||||
int updateLengthZ)
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture3DShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<CopyFromResourceTexture3DShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
CopyFromResourceTexture3DShader shader = new(width, height, depth);
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
|
||||
|
||||
byte[] texture = new byte[width * height * depth];
|
||||
|
||||
D2D1ResourceTextureManager resourceTextureManager = new(
|
||||
extents: stackalloc[] { (uint)width, (uint)height, (uint)depth },
|
||||
bufferPrecision: D2D1BufferPrecision.UInt8Normalized,
|
||||
channelDepth: D2D1ChannelDepth.One,
|
||||
filter: D2D1Filter.MinMagMipPoint,
|
||||
extendModes: stackalloc[] { D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp, D2D1ExtendMode.Clamp },
|
||||
data: texture,
|
||||
strides: stackalloc uint[] { (uint)width, (uint)(width * height) });
|
||||
|
||||
byte[] data = RandomNumberGenerator.GetBytes(updateLengthX * updateLengthY * updateLengthZ);
|
||||
|
||||
resourceTextureManager.Update(
|
||||
minimumExtents: stackalloc uint[] { (uint)startOffsetX, (uint)startOffsetY, (uint)startOffsetZ },
|
||||
maximimumExtents: stackalloc uint[] { (uint)(startOffsetX + updateLengthX), (uint)(startOffsetY + updateLengthY), (uint)(startOffsetZ + updateLengthZ) },
|
||||
strides: stackalloc uint[] { (uint)updateLengthX, (uint)(updateLengthX * updateLengthY) },
|
||||
data: data);
|
||||
|
||||
for (int z = 0; z < updateLengthZ; z++)
|
||||
{
|
||||
for (int y = 0; y < updateLengthY; y++)
|
||||
{
|
||||
ReadOnlySpan<byte> source = data.AsSpan(z * updateLengthX * updateLengthY + y * updateLengthX, updateLengthX);
|
||||
Span<byte> destination = texture.AsSpan((startOffsetZ + z) * (width * height) + (startOffsetY + y) * width + startOffsetX, updateLengthX);
|
||||
|
||||
source.CopyTo(destination);
|
||||
}
|
||||
}
|
||||
|
||||
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager, 0);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), (uint)width, (uint)(height * depth));
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
byte[] resultingBytes = new byte[width * height * depth];
|
||||
int i = 0;
|
||||
|
||||
for (int y = 0; y < height * depth; y++)
|
||||
{
|
||||
foreach (Bgra32 pixel in new ReadOnlySpan<Bgra32>(d2D1MappedRect.bits + d2D1MappedRect.pitch * y, width))
|
||||
{
|
||||
resultingBytes[i++] = pixel.B;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.IsTrue(texture.AsSpan().SequenceEqual(resultingBytes));
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
[AutoConstructor]
|
||||
private partial struct CopyFromResourceTexture3DShader : ID2D1PixelShader
|
||||
{
|
||||
private int width;
|
||||
private int height;
|
||||
private int depth;
|
||||
|
||||
[D2DResourceTextureIndex(0)]
|
||||
private D2D1ResourceTexture3D<float> source;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
int2 xy = (int2)D2D.GetScenePosition().XY;
|
||||
|
||||
int x = xy.X;
|
||||
int y = (int)((uint)xy.Y % (uint)this.height);
|
||||
int z = (int)((uint)xy.Y / (uint)this.height);
|
||||
|
||||
return this.source[x, y, z];
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(Win32Exception))]
|
||||
public unsafe void NullResourceTexture_DrawImageFails()
|
||||
{
|
||||
using ComPtr<ID2D1Factory2> d2D1Factory2 = D2D1Helper.CreateD2D1Factory2();
|
||||
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
|
||||
|
||||
D2D1PixelShaderEffect.RegisterForD2D1Factory1<NullResourceTextureShader>(d2D1Factory2.Get(), null, out _);
|
||||
|
||||
using ComPtr<ID2D1Effect> d2D1Effect = default;
|
||||
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<NullResourceTextureShader>(d2D1DeviceContext.Get(), (void**)d2D1Effect.GetAddressOf());
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(default(NullResourceTextureShader), d2D1Effect.Get());
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), 128, 128);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
}
|
||||
|
||||
[D2DInputCount(0)]
|
||||
[D2DRequiresScenePosition]
|
||||
private partial struct NullResourceTextureShader : ID2D1PixelShader
|
||||
{
|
||||
[D2DResourceTextureIndex(0)]
|
||||
private D2D1ResourceTexture2D<float4> source;
|
||||
|
||||
public float4 Execute()
|
||||
{
|
||||
return source[0, 0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Tests.Effects;
|
||||
using ComputeSharp.D2D1.Tests.Effects;
|
||||
using ComputeSharp.D2D1.Tests.Helpers;
|
||||
using ComputeSharp.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SixLabors.ImageSharp;
|
||||
|
||||
@@ -23,19 +18,19 @@ public class EndToEndTests
|
||||
[TestMethod]
|
||||
public unsafe void Invert()
|
||||
{
|
||||
RunAndCompareShader(new InvertEffect(), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
D2D1TestRunner.RunAndCompareShader(new InvertEffect(), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void InvertWithThreshold()
|
||||
{
|
||||
RunAndCompareShader(new InvertWithThresholdEffect(1), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
D2D1TestRunner.RunAndCompareShader(new InvertWithThresholdEffect(1), null, "Landscape.png", "Landscape_Inverted.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void Pixelate()
|
||||
{
|
||||
RunAndCompareShader(
|
||||
D2D1TestRunner.RunAndCompareShader(
|
||||
new PixelateEffect.Shader(new PixelateEffect.Shader.Constants(1280, 840, 16)),
|
||||
static () => new PixelateEffect(),
|
||||
"Landscape.png",
|
||||
@@ -45,88 +40,12 @@ public class EndToEndTests
|
||||
[TestMethod]
|
||||
public unsafe void ZonePlate()
|
||||
{
|
||||
RunAndCompareShader(new ZonePlateEffect(1280, 720, 800), null, 1280, 720, "ZonePlate.png");
|
||||
D2D1TestRunner.RunAndCompareShader(new ZonePlateEffect(1280, 720, 800), null, 1280, 720, "ZonePlate.png");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public unsafe void CheckerboardClip()
|
||||
{
|
||||
RunAndCompareShader(new CheckerboardClipEffect(1280, 840, 32), null, "Landscape.png", "Landscape_CheckerboardClip.png");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="originalFileName">The name of the source image.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
private static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
string originalFileName,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string originalPath = Path.Combine(assetsPath, originalFileName);
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
D2D1TestRunner.ExecutePixelShaderAndCompareResults(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
originalPath,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="width">The resulting width.</param>
|
||||
/// <param name="height">The resulting height.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
private static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
int width,
|
||||
int height,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
D2D1TestRunner.ExecutePixelShaderAndCompareResults(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
width,
|
||||
height,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
D2D1TestRunner.RunAndCompareShader(new CheckerboardClipEffect(1280, 840, 32), null, "Landscape.png", "Landscape_CheckerboardClip.png");
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using ComputeSharp.D2D1.Tests.Extensions;
|
||||
using System;
|
||||
using ComputeSharp.D2D1.Tests.Extensions;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
@@ -100,17 +101,40 @@ internal static class D2D1Helper
|
||||
/// Creates an <see cref="ID2D1Bitmap"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="d2D1DeviceContext">The input <see cref="ID2D1DeviceContext"/> instance to use to create the bitmap source.</param>
|
||||
/// <param name="wicBitmap">The input <see cref="IWICBitmap"/> to use to create the bitmap source.</param>
|
||||
/// <param name="pixels">The loaded pixel data.</param>
|
||||
/// <param name="width">The width of the bitmap.</param>
|
||||
/// <param name="height">The height of the bitmap.</param>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> to set the source for.</param>
|
||||
/// <returns>A new <see cref="ID2D1Bitmap"/> instance.</returns>
|
||||
public static unsafe ComPtr<ID2D1Bitmap> CreateD2D1BitmapAndSetAsSource(ID2D1DeviceContext* d2D1DeviceContext, IWICBitmap* wicBitmap, ID2D1Effect* d2D1Effect)
|
||||
public static unsafe ComPtr<ID2D1Bitmap> CreateD2D1BitmapAndSetAsSource(
|
||||
ID2D1DeviceContext* d2D1DeviceContext,
|
||||
ReadOnlyMemory<byte> pixels,
|
||||
uint width,
|
||||
uint height,
|
||||
ID2D1Effect* d2D1Effect)
|
||||
{
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapSource = default;
|
||||
|
||||
// Create a source D2D1 bitmap from the WIC bitmap
|
||||
d2D1DeviceContext->CreateBitmapFromWicBitmap(
|
||||
wicBitmapSource: (IWICBitmapSource*)wicBitmap,
|
||||
bitmap: d2D1BitmapSource.GetAddressOf()).Assert();
|
||||
D2D_SIZE_U d2DSize = default;
|
||||
d2DSize.width = width;
|
||||
d2DSize.height = height;
|
||||
|
||||
D2D1_BITMAP_PROPERTIES d2DBitmapProperties = default;
|
||||
d2DBitmapProperties.pixelFormat.format = DXGI_FORMAT.DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
d2DBitmapProperties.pixelFormat.alphaMode = D2D1_ALPHA_MODE.D2D1_ALPHA_MODE_PREMULTIPLIED;
|
||||
d2DBitmapProperties.dpiX = 96;
|
||||
d2DBitmapProperties.dpiY = 96;
|
||||
|
||||
fixed (byte* p = pixels.Span)
|
||||
{
|
||||
// Create a source D2D1 bitmap from the image data
|
||||
d2D1DeviceContext->CreateBitmap(
|
||||
size: d2DSize,
|
||||
srcData: p,
|
||||
pitch: width * 4,
|
||||
bitmapProperties: &d2DBitmapProperties,
|
||||
bitmap: d2D1BitmapSource.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
d2D1Effect->SetInput(0, (ID2D1Image*)d2D1BitmapSource.Get());
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.Tests.Helpers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
@@ -10,6 +14,82 @@ namespace ComputeSharp.D2D1.Tests.Helpers;
|
||||
/// </summary>
|
||||
internal static class D2D1TestRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="originalFileName">The name of the source image.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
public static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
string originalFileName,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string originalPath = Path.Combine(assetsPath, originalFileName);
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
ExecutePixelShaderAndSaveToFile(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
originalPath,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader and compares the expected results.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="width">The resulting width.</param>
|
||||
/// <param name="height">The resulting height.</param>
|
||||
/// <param name="expectedFileName">The name of the expected result image.</param>
|
||||
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
|
||||
/// <param name="shader">The shader to run.</param>
|
||||
public static void RunAndCompareShader<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
int width,
|
||||
int height,
|
||||
string expectedFileName,
|
||||
[CallerMemberName] string destinationFileName = "")
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
string assetsPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets");
|
||||
string temporaryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "temp");
|
||||
|
||||
_ = Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
string expectedPath = Path.Combine(assetsPath, expectedFileName);
|
||||
string destinationPath = Path.Combine(temporaryPath, $"{destinationFileName}.png");
|
||||
|
||||
// Run the shader
|
||||
ExecutePixelShaderAndSaveToFile(
|
||||
in shader,
|
||||
transformMapperFactory,
|
||||
width,
|
||||
height,
|
||||
destinationPath);
|
||||
|
||||
// Compare the results
|
||||
TolerantImageComparer.AssertEqual(destinationPath, expectedPath, 0.00001f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a pixel shader to produce an image.
|
||||
/// </summary>
|
||||
@@ -18,7 +98,7 @@ internal static class D2D1TestRunner
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="sourcePath">The source path for the image to run the shader on.</param>
|
||||
/// <param name="destinationPath">The destination path for the result.</param>
|
||||
public static unsafe void ExecutePixelShaderAndCompareResults<T>(
|
||||
public static unsafe void ExecutePixelShaderAndSaveToFile<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
string sourcePath,
|
||||
@@ -37,8 +117,9 @@ internal static class D2D1TestRunner
|
||||
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(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());
|
||||
ReadOnlyMemory<byte> pixels = ImageHelper.LoadBitmapFromFile(sourcePath, out uint width, out uint height);
|
||||
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapSource = D2D1Helper.CreateD2D1BitmapAndSetAsSource(d2D1DeviceContext.Get(), pixels, width, height, d2D1Effect.Get());
|
||||
using ComPtr<ID2D1Bitmap> d2D1BitmapTarget = D2D1Helper.CreateD2D1BitmapAndSetAsTarget(d2D1DeviceContext.Get(), width, height);
|
||||
|
||||
D2D1Helper.DrawEffect(d2D1DeviceContext.Get(), d2D1Effect.Get());
|
||||
@@ -46,7 +127,7 @@ internal static class D2D1TestRunner
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
// Save the image
|
||||
WICHelper.SaveBitmapToFile(destinationPath, width, height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
ImageHelper.SaveBitmapToFile(destinationPath, width, height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,7 +139,7 @@ internal static class D2D1TestRunner
|
||||
/// <param name="height">The resulting height.</param>
|
||||
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
|
||||
/// <param name="destinationPath">The destination path for the result.</param>
|
||||
public static unsafe void ExecutePixelShaderAndCompareResults<T>(
|
||||
public static unsafe void ExecutePixelShaderAndSaveToFile<T>(
|
||||
in T shader,
|
||||
Func<ID2D1TransformMapper<T>>? transformMapperFactory,
|
||||
int width,
|
||||
@@ -85,6 +166,6 @@ internal static class D2D1TestRunner
|
||||
using ComPtr<ID2D1Bitmap1> d2D1Bitmap1Buffer = D2D1Helper.CreateD2D1Bitmap1Buffer(d2D1DeviceContext.Get(), d2D1BitmapTarget.Get(), out D2D1_MAPPED_RECT d2D1MappedRect);
|
||||
|
||||
// Save the image
|
||||
WICHelper.SaveBitmapToFile(destinationPath, (uint)width, (uint)height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
ImageHelper.SaveBitmapToFile(destinationPath, (uint)width, (uint)height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with helpers to load and save images.
|
||||
/// </summary>
|
||||
internal static class ImageHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads a <see cref="ReadOnlyMemory{T}"/> instance from a given path.
|
||||
/// </summary>
|
||||
/// <param name="filename">The path to load the image from.</param>
|
||||
/// <param name="width">The resulting image width.</param>
|
||||
/// <param name="height">The resulting image height.</param>
|
||||
/// <returns>The resulting <see cref="ReadOnlyMemory{T}"/> instance.</returns>
|
||||
public static unsafe ReadOnlyMemory<byte> LoadBitmapFromFile(string filename, out uint width, out uint height)
|
||||
{
|
||||
using Image<Bgra32> image = Image.Load<Bgra32>(filename);
|
||||
|
||||
width = (uint)image.Width;
|
||||
height = (uint)image.Height;
|
||||
|
||||
if (!image.DangerousTryGetSinglePixelMemory(out Memory<Bgra32> memory))
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
}
|
||||
|
||||
return MemoryMarshal.AsBytes(memory.Span).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a given image buffer to a target path.
|
||||
/// </summary>
|
||||
/// <param name="filename">The path to save the image to.</param>
|
||||
/// <param name="width">The image width.</param>
|
||||
/// <param name="height">The image height.</param>
|
||||
/// <param name="strideInBytes">The image stride in bytes.</param>
|
||||
/// <param name="buffer">The image pixel buffer.</param>
|
||||
public static unsafe void SaveBitmapToFile(string filename, uint width, uint height, uint strideInBytes, byte* buffer)
|
||||
{
|
||||
byte[] pixelData = ArrayPool<byte>.Shared.Rent((int)width * (int)height * sizeof(Bgra32));
|
||||
|
||||
for (int i = 0; i < (int)height; i++)
|
||||
{
|
||||
ReadOnlySpan<byte> source = new(buffer + i * (int)strideInBytes, (int)width * sizeof(Bgra32));
|
||||
|
||||
source.CopyTo(pixelData.AsSpan(i * (int)width * sizeof(Bgra32)));
|
||||
}
|
||||
|
||||
using (Image<Bgra32> image = Image.WrapMemory<Bgra32>(pixelData, (int)width, (int)height))
|
||||
{
|
||||
image.Save(filename);
|
||||
}
|
||||
|
||||
ArrayPool<byte>.Shared.Return(pixelData);
|
||||
}
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Tests.Extensions;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1.Tests.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that uses the WIC APIs to load and decode images.
|
||||
/// </summary>
|
||||
internal static class WICHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads an <see cref="IWICBitmap"/> instance from a given path.
|
||||
/// </summary>
|
||||
/// <param name="filename">The path to load the image from.</param>
|
||||
/// <param name="width">The resulting image width.</param>
|
||||
/// <param name="height">The resulting image height.</param>
|
||||
/// <returns>The resulting <see cref="IWICBitmap"/> instance.</returns>
|
||||
public static unsafe ComPtr<IWICBitmap> LoadBitmapFromFile(string filename, out uint width, out uint height)
|
||||
{
|
||||
using ComPtr<IWICImagingFactory2> wicImagingFactory2 = default;
|
||||
|
||||
// Create a Windows Imaging Component (WIC) factory
|
||||
Windows.CoCreateInstance(
|
||||
rclsid: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_WICImagingFactory2)),
|
||||
pUnkOuter: null,
|
||||
dwClsContext: (uint)CLSCTX.CLSCTX_INPROC_SERVER,
|
||||
riid: Windows.__uuidof<IWICImagingFactory2>(),
|
||||
ppv: (void**)wicImagingFactory2.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapDecoder> wicBitmapDecoder = default;
|
||||
|
||||
// Get the bitmap decoder for the target file
|
||||
fixed (char* p = filename)
|
||||
{
|
||||
wicImagingFactory2.Get()->CreateDecoderFromFilename(
|
||||
wzFilename: (ushort*)p,
|
||||
pguidVendor: null,
|
||||
dwDesiredAccess: Windows.GENERIC_READ,
|
||||
metadataOptions: WICDecodeOptions.WICDecodeMetadataCacheOnDemand,
|
||||
ppIDecoder: wicBitmapDecoder.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
using ComPtr<IWICBitmapFrameDecode> wicBitmapFrameDecode = default;
|
||||
|
||||
// Get the first frame of the loaded image (if more are present, they will be ignored)
|
||||
wicBitmapDecoder.Get()->GetFrame(0, wicBitmapFrameDecode.GetAddressOf()).Assert();
|
||||
|
||||
fixed (uint* widthPtr = &width)
|
||||
fixed (uint* heightPtr = &height)
|
||||
{
|
||||
// Extract the image size info
|
||||
wicBitmapFrameDecode.Get()->GetSize(widthPtr, heightPtr).Assert();
|
||||
}
|
||||
|
||||
Guid wicTargetPixelFormatGuid = GUID.GUID_WICPixelFormat32bppPBGRA;
|
||||
Guid wicActualPixelFormatGuid;
|
||||
|
||||
// Get the current and target pixel format info
|
||||
wicBitmapFrameDecode.Get()->GetPixelFormat(&wicActualPixelFormatGuid).Assert();
|
||||
|
||||
using ComPtr<IWICBitmap> wicBitmap = default;
|
||||
|
||||
// Create the target bitmap
|
||||
wicImagingFactory2.Get()->CreateBitmap(
|
||||
uiWidth: width,
|
||||
uiHeight: height,
|
||||
pixelFormat: &wicTargetPixelFormatGuid,
|
||||
option: WICBitmapCreateCacheOption.WICBitmapCacheOnLoad,
|
||||
ppIBitmap: wicBitmap.GetAddressOf()).Assert();
|
||||
|
||||
WICRect wicRect;
|
||||
wicRect.X = 0;
|
||||
wicRect.Y = 0;
|
||||
wicRect.Width = (int)width;
|
||||
wicRect.Height = (int)height;
|
||||
|
||||
using (ComPtr<IWICBitmapLock> wicBitmapLock = default)
|
||||
{
|
||||
// Lock the bitmap
|
||||
wicBitmap.Get()->Lock(
|
||||
prcLock: &wicRect,
|
||||
flags: (uint)WICBitmapLockFlags.WICBitmapLockWrite,
|
||||
ppILock: wicBitmapLock.GetAddressOf()).Assert();
|
||||
|
||||
uint wicBitmapStride;
|
||||
|
||||
// Get the stride
|
||||
wicBitmapLock.Get()->GetStride(&wicBitmapStride).Assert();
|
||||
|
||||
uint wicBitmapSize;
|
||||
byte* wicBitmapPointer;
|
||||
|
||||
// Get the bitmap size and pointer
|
||||
wicBitmapLock.Get()->GetDataPointer(&wicBitmapSize, &wicBitmapPointer).Assert();
|
||||
|
||||
// Check if a pixel format conversion is needed
|
||||
if (wicTargetPixelFormatGuid == wicActualPixelFormatGuid)
|
||||
{
|
||||
// No conversion is needed, just copy the pixels directly
|
||||
wicBitmapFrameDecode.Get()->CopyPixels(
|
||||
prc: &wicRect,
|
||||
cbStride: wicBitmapStride,
|
||||
cbBufferSize: wicBitmapSize,
|
||||
pbBuffer: wicBitmapPointer).Assert();
|
||||
}
|
||||
else
|
||||
{
|
||||
using ComPtr<IWICFormatConverter> wicFormatConverter = default;
|
||||
|
||||
// Create a format converter
|
||||
wicImagingFactory2.Get()->CreateFormatConverter(wicFormatConverter.GetAddressOf()).Assert();
|
||||
|
||||
// Get a format converter to decode the pixel data
|
||||
wicFormatConverter.Get()->Initialize(
|
||||
pISource: (IWICBitmapSource*)wicBitmapFrameDecode.Get(),
|
||||
dstFormat: &wicTargetPixelFormatGuid,
|
||||
dither: WICBitmapDitherType.WICBitmapDitherTypeNone,
|
||||
pIPalette: null,
|
||||
alphaThresholdPercent: 0,
|
||||
paletteTranslate: WICBitmapPaletteType.WICBitmapPaletteTypeCustom).Assert();
|
||||
|
||||
// Decode the pixel data into the upload buffer
|
||||
wicFormatConverter.Get()->CopyPixels(
|
||||
prc: &wicRect,
|
||||
cbStride: wicBitmapStride,
|
||||
cbBufferSize: wicBitmapSize,
|
||||
pbBuffer: wicBitmapPointer).Assert();
|
||||
}
|
||||
}
|
||||
|
||||
return wicBitmap.Move();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a given image buffer to a target path.
|
||||
/// </summary>
|
||||
/// <param name="filename">The path to save the image to.</param>
|
||||
/// <param name="width">The image width.</param>
|
||||
/// <param name="height">The image height.</param>
|
||||
/// <param name="strideInBytes">The image stride in bytes.</param>
|
||||
/// <param name="buffer">The image pixel buffer.</param>
|
||||
public static unsafe void SaveBitmapToFile(string filename, uint width, uint height, uint strideInBytes, byte* buffer)
|
||||
{
|
||||
using ComPtr<IWICImagingFactory2> wicImagingFactory2 = default;
|
||||
|
||||
// Create a Windows Imaging Component (WIC) factory
|
||||
Windows.CoCreateInstance(
|
||||
rclsid: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_WICImagingFactory2)),
|
||||
pUnkOuter: null,
|
||||
dwClsContext: (uint)CLSCTX.CLSCTX_INPROC_SERVER,
|
||||
riid: Windows.__uuidof<IWICImagingFactory2>(),
|
||||
ppv: (void**)wicImagingFactory2.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapEncoder> wicBitmapEncoder = default;
|
||||
|
||||
// Create the image encoder
|
||||
wicImagingFactory2.Get()->CreateEncoder(
|
||||
guidContainerFormat: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in GUID.GUID_ContainerFormatPng)),
|
||||
pguidVendor: null,
|
||||
ppIEncoder: wicBitmapEncoder.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICStream> wicStream = default;
|
||||
|
||||
// Create and initialize a stream to the target file
|
||||
wicImagingFactory2.Get()->CreateStream(wicStream.GetAddressOf()).Assert();
|
||||
|
||||
fixed (char* p = filename)
|
||||
{
|
||||
// Initialize the stream to the target file
|
||||
wicStream.Get()->InitializeFromFilename((ushort*)p, Windows.GENERIC_WRITE);
|
||||
}
|
||||
|
||||
// Initialize the encoder
|
||||
wicBitmapEncoder.Get()->Initialize(
|
||||
pIStream: (IStream*)wicStream.Get(),
|
||||
cacheOption: WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapFrameEncode> wicBitmapFrameEncode = default;
|
||||
|
||||
// Create the image frame and initialize it
|
||||
wicBitmapEncoder.Get()->CreateNewFrame(wicBitmapFrameEncode.GetAddressOf(), null).Assert();
|
||||
|
||||
Guid wicTargetPixelFormatGuid = GUID.GUID_WICPixelFormat32bppPBGRA;
|
||||
|
||||
// Set the encoding properties
|
||||
wicBitmapFrameEncode.Get()->Initialize(null).Assert();
|
||||
wicBitmapFrameEncode.Get()->SetSize(width, height).Assert();
|
||||
wicBitmapFrameEncode.Get()->SetPixelFormat(&wicTargetPixelFormatGuid).Assert();
|
||||
|
||||
// Encode the target image
|
||||
wicBitmapFrameEncode.Get()->WritePixels(
|
||||
lineCount: height,
|
||||
cbStride: strideInBytes,
|
||||
cbBufferSize: strideInBytes * height,
|
||||
pbPixels: buffer).Assert();
|
||||
|
||||
// Flush the changes
|
||||
wicBitmapFrameEncode.Get()->Commit();
|
||||
wicBitmapEncoder.Get()->Commit();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする