Add CacheOutput and BufferPrecision properties
このコミットが含まれているのは:
1 親
139ad8ed62
コミット
e7273d23c6
5ファイル変更
+212
-1
検索条件に一致するファイルはありません
@@ -51,11 +51,142 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
|
||||
/// </summary>
|
||||
private ComPtr<ID2D1Effect> d2D1Effect;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
private int cacheOutput;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="BufferPrecision"/>.
|
||||
/// </summary>
|
||||
private D2D1_BUFFER_PRECISION d2D1BufferPrecision;
|
||||
|
||||
/// <summary>
|
||||
/// The current <typeparamref name="T"/> value in use.
|
||||
/// </summary>
|
||||
public T Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to enable caching the output from drawing this effect.
|
||||
/// </summary>
|
||||
public unsafe bool CacheOutput
|
||||
{
|
||||
get
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// If the effect is realized, get the latest value from it
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
int cacheOutput;
|
||||
|
||||
this.d2D1Effect.Get()->GetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL,
|
||||
data: (byte*)&cacheOutput,
|
||||
dataSize: sizeof(int)).Assert();
|
||||
|
||||
this.cacheOutput = cacheOutput;
|
||||
}
|
||||
|
||||
return this.cacheOutput != 0;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
this.cacheOutput = value ? 1 : 0;
|
||||
|
||||
// If the effect is realized, set the property on the underlying ID2D1Effect object too
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
int cacheOutput = this.cacheOutput;
|
||||
|
||||
this.d2D1Effect.Get()->SetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL,
|
||||
data: (byte*)&cacheOutput,
|
||||
dataSize: sizeof(int)).Assert();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the precision to use for intermediate buffers when drawing this effect.
|
||||
/// </summary>
|
||||
/// <remarks>If <see langword="null"/>, the default precision for effects will be used.</remarks>
|
||||
public unsafe CanvasBufferPrecision? BufferPrecision
|
||||
{
|
||||
get
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// If the effect is realized, get the latest value from it
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
D2D1_BUFFER_PRECISION d2D1BufferPrecision;
|
||||
|
||||
this.d2D1Effect.Get()->GetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2D1BufferPrecision,
|
||||
dataSize: sizeof(D2D1_BUFFER_PRECISION)).Assert();
|
||||
|
||||
this.d2D1BufferPrecision = d2D1BufferPrecision;
|
||||
}
|
||||
|
||||
// Map from D2D1_BUFFER_PRECISION to CanvasBufferPrecision, and return null for D2D1_BUFFER_PRECISION_UNKNOWN
|
||||
return this.d2D1BufferPrecision switch
|
||||
{
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM => CanvasBufferPrecision.Precision8UIntNormalized,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB => CanvasBufferPrecision.Precision8UIntNormalizedSrgb,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_UNORM => CanvasBufferPrecision.Precision16UIntNormalized,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_FLOAT => CanvasBufferPrecision.Precision16Float,
|
||||
D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT => CanvasBufferPrecision.Precision32Float,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// Map back from CanvasBufferPrecision? to D2D1_BUFFER_PRECISION (null results in D2D1_BUFFER_PRECISION_UNKNOWN)
|
||||
this.d2D1BufferPrecision = value switch
|
||||
{
|
||||
CanvasBufferPrecision.Precision8UIntNormalized => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM,
|
||||
CanvasBufferPrecision.Precision8UIntNormalizedSrgb => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB,
|
||||
CanvasBufferPrecision.Precision16UIntNormalized => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_UNORM,
|
||||
CanvasBufferPrecision.Precision16Float => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_16BPC_FLOAT,
|
||||
CanvasBufferPrecision.Precision32Float => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_32BPC_FLOAT,
|
||||
_ => D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_UNKNOWN
|
||||
};
|
||||
|
||||
// If the effect is realized, set the property on the underlying ID2D1Effect object too
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
D2D1_BUFFER_PRECISION d2D1BufferPrecision = this.d2D1BufferPrecision;
|
||||
|
||||
this.d2D1Effect.Get()->SetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2D1BufferPrecision,
|
||||
dataSize: sizeof(D2D1_BUFFER_PRECISION)).Assert();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
Rect ICanvasImage.GetBounds(ICanvasResourceCreator resourceCreator)
|
||||
{
|
||||
@@ -219,7 +350,32 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// Cache the last update value of the cache property
|
||||
int cacheOutput;
|
||||
|
||||
this.d2D1Effect.Get()->GetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL,
|
||||
data: (byte*)&cacheOutput,
|
||||
dataSize: sizeof(int)).Assert();
|
||||
|
||||
this.cacheOutput = cacheOutput;
|
||||
|
||||
// Do the same for the buffer precision
|
||||
D2D1_BUFFER_PRECISION d2D1BufferPrecision;
|
||||
|
||||
this.d2D1Effect.Get()->GetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2D1BufferPrecision,
|
||||
dataSize: sizeof(D2D1_BUFFER_PRECISION)).Assert();
|
||||
|
||||
this.d2D1BufferPrecision = d2D1BufferPrecision;
|
||||
|
||||
// TODO: read back D2D sources from the effect
|
||||
|
||||
// Finally release the effect as well
|
||||
this.d2D1Effect.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -249,6 +405,30 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
|
||||
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<T>(deviceContext, (void**)d2D1Effect);
|
||||
}
|
||||
|
||||
// If cache input has been set, forward that to the new effect
|
||||
if (this.cacheOutput != 0)
|
||||
{
|
||||
int cacheOutput = this.cacheOutput;
|
||||
|
||||
this.d2D1Effect.Get()->GetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_CACHED,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BOOL,
|
||||
data: (byte*)&cacheOutput,
|
||||
dataSize: sizeof(int)).Assert();
|
||||
}
|
||||
|
||||
// If the buffer precision isn't unknown, forward that as well
|
||||
if (this.d2D1BufferPrecision != D2D1_BUFFER_PRECISION.D2D1_BUFFER_PRECISION_UNKNOWN)
|
||||
{
|
||||
D2D1_BUFFER_PRECISION d2D1BufferPrecision = this.d2D1BufferPrecision;
|
||||
|
||||
this.d2D1Effect.Get()->SetValue(
|
||||
index: (uint)D2D1_PROPERTY.D2D1_PROPERTY_PRECISION,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_UNKNOWN,
|
||||
data: (byte*)&d2D1BufferPrecision,
|
||||
dataSize: sizeof(D2D1_BUFFER_PRECISION)).Assert();
|
||||
}
|
||||
|
||||
// TODO: port base CanvasEffect::Realize logic
|
||||
|
||||
// Also set the current constants for the effect
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// 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.22621.0
|
||||
// Original source is Copyright © Microsoft. All rights reserved.
|
||||
|
||||
namespace TerraFX.Interop.DirectX;
|
||||
|
||||
internal enum D2D1_PROPERTY : uint
|
||||
{
|
||||
D2D1_PROPERTY_CLSID = 0x80000000,
|
||||
D2D1_PROPERTY_DISPLAYNAME = 0x80000001,
|
||||
D2D1_PROPERTY_AUTHOR = 0x80000002,
|
||||
D2D1_PROPERTY_CATEGORY = 0x80000003,
|
||||
D2D1_PROPERTY_DESCRIPTION = 0x80000004,
|
||||
D2D1_PROPERTY_INPUTS = 0x80000005,
|
||||
D2D1_PROPERTY_CACHED = 0x80000006,
|
||||
D2D1_PROPERTY_PRECISION = 0x80000007,
|
||||
D2D1_PROPERTY_MIN_INPUTS = 0x80000008,
|
||||
D2D1_PROPERTY_MAX_INPUTS = 0x80000009,
|
||||
D2D1_PROPERTY_FORCE_DWORD = 0xffffffff
|
||||
}
|
||||
@@ -7,6 +7,8 @@ namespace TerraFX.Interop.DirectX;
|
||||
|
||||
internal enum D2D1_PROPERTY_TYPE : uint
|
||||
{
|
||||
D2D1_PROPERTY_TYPE_UNKNOWN = 0,
|
||||
D2D1_PROPERTY_TYPE_BOOL = 2,
|
||||
D2D1_PROPERTY_TYPE_BLOB = 9,
|
||||
D2D1_PROPERTY_TYPE_IUNKNOWN = 10
|
||||
}
|
||||
@@ -25,4 +25,11 @@ internal unsafe partial struct ID2D1Effect
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Effect*, uint, D2D1_PROPERTY_TYPE, byte*, uint, int>)(lpVtbl[9]))((ID2D1Effect*)Unsafe.AsPointer(ref this), index, type, data, dataSize);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
[VtblIndex(11)]
|
||||
public HRESULT GetValue([NativeTypeName("UINT32")] uint index, D2D1_PROPERTY_TYPE type, byte* data, [NativeTypeName("UINT32")] uint dataSize)
|
||||
{
|
||||
return ((delegate* unmanaged[Stdcall]<ID2D1Effect*, uint, D2D1_PROPERTY_TYPE, byte*, uint, int>)(lpVtbl[11]))((ID2D1Effect*)Unsafe.AsPointer(ref this), index, type, data, dataSize);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@
|
||||
<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.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\D2D1_PROPERTY_TYPE.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1CommandList.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)DirectX\um\d2d1_1\ID2D1DeviceContext.cs" />
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする