Implement PixelShaderEffect<T>.Value property
このコミットが含まれているのは:
1 親
b6f739ca9d
コミット
c58695cb5f
5ファイル変更
+104
-20
検索条件に一致するファイルはありません
@@ -1,5 +1,11 @@
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
|
||||
@@ -8,6 +14,34 @@ namespace ComputeSharp.D2D1.Uwp.Extensions;
|
||||
/// </summary>
|
||||
internal static unsafe class ID2D1EffectExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the constant buffer of type <typeparamref name="T"/> from a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
|
||||
/// <returns>The constant buffer of type <typeparamref name="T"/> for <paramref name="d2D1Effect"/>.</returns>
|
||||
public static T GetConstantBuffer<T>(this ref ID2D1Effect d2D1Effect)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
int constantBufferSize = D2D1PixelShader.GetConstantBufferSize<T>();
|
||||
byte[] buffer = ArrayPool<byte>.Shared.Rent(constantBufferSize);
|
||||
|
||||
fixed (byte* p = buffer)
|
||||
{
|
||||
// Get the raw constant buffer from the effect
|
||||
d2D1Effect.GetValue(
|
||||
index: D2D1PixelShaderEffectProperty.ConstantBuffer,
|
||||
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_BLOB,
|
||||
data: p,
|
||||
dataSize: (uint)constantBufferSize).Assert();
|
||||
}
|
||||
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
shader.InitializeFromDispatchData(buffer.AsSpan(0, constantBufferSize));
|
||||
|
||||
return shader;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D2D1_PROPERTY.D2D1_PROPERTY_CACHED"/> property for a given <see cref="ID2D1Effect"/> object.
|
||||
/// </summary>
|
||||
|
||||
@@ -166,7 +166,8 @@ unsafe partial class PixelShaderEffect<T>
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache the last update value of the cache and precision properties
|
||||
// Cache the last update values for the constant buffer, cache output and buffer precision properties
|
||||
this.value = this.d2D1Effect.Get()->GetConstantBuffer<T>();
|
||||
this.cacheOutput = this.d2D1Effect.Get()->GetCachedProperty();
|
||||
this.d2D1BufferPrecision = this.d2D1Effect.Get()->GetPrecisionProperty();
|
||||
|
||||
@@ -231,7 +232,8 @@ unsafe partial class PixelShaderEffect<T>
|
||||
hresult.Assert();
|
||||
}
|
||||
|
||||
// TODO: transfer properties (eg. D2D1ResourceTextureManager-s)
|
||||
// Set the constant buffer for the effect
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(this.value, this.d2D1Effect.Get());
|
||||
|
||||
// If cache input has been set, forward that to the new effect
|
||||
if (this.cacheOutput)
|
||||
@@ -247,8 +249,7 @@ unsafe partial class PixelShaderEffect<T>
|
||||
|
||||
// TODO: port base CanvasEffect::Realize logic
|
||||
|
||||
// Also set the current constants for the effect
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(Value, this.d2D1Effect.Get());
|
||||
// TODO: transfer properties (eg. D2D1ResourceTextureManager-s)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -259,8 +260,6 @@ unsafe partial class PixelShaderEffect<T>
|
||||
/// <param name="deviceContext">The <see cref="ID2D1DeviceContext"/> instance in use.</param>
|
||||
private void RefreshInputs(CanvasImageGetD2DImageFlags flags, float targetDpi, ID2D1DeviceContext* deviceContext)
|
||||
{
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(Value, this.d2D1Effect.Get());
|
||||
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
using Microsoft.Graphics.Canvas;
|
||||
@@ -8,6 +9,47 @@ namespace ComputeSharp.D2D1.Uwp;
|
||||
/// <inheritdoc/>
|
||||
unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
/// <returns>The marshalled value for <see cref="CacheOutput"/>.</returns>
|
||||
private T GetConstantBuffer()
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
return this.d2D1Effect.Get() switch
|
||||
{
|
||||
not null => this.d2D1Effect.Get()->GetConstantBuffer<T>(),
|
||||
_ => this.value
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the marshalled value for <see cref="Value"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to set for <see cref="Value"/>.</param>
|
||||
private void SetConstantBuffer(in T value)
|
||||
{
|
||||
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// If the effect is realized, set the property on the underlying ID2D1Effect object
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in value, this.d2D1Effect.Get());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, just store the value locally
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the marshalled value for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
@@ -18,13 +60,11 @@ unsafe partial class PixelShaderEffect<T>
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
// If the effect is realized, get the latest value from it
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
return this.d2D1Effect.Get() switch
|
||||
{
|
||||
this.cacheOutput = this.d2D1Effect.Get()->GetCachedProperty();
|
||||
}
|
||||
|
||||
return this.cacheOutput;
|
||||
not null => this.d2D1Effect.Get()->GetCachedProperty(),
|
||||
_ => this.cacheOutput
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,13 +78,15 @@ unsafe partial class PixelShaderEffect<T>
|
||||
|
||||
lock (this.lockObject)
|
||||
{
|
||||
this.cacheOutput = value;
|
||||
|
||||
// If the effect is realized, set the property on the underlying ID2D1Effect object too
|
||||
// If the effect is realized, set the property on the underlying ID2D1Effect object
|
||||
if (this.d2D1Effect.Get() is not null)
|
||||
{
|
||||
this.d2D1Effect.Get()->SetCachedProperty(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cacheOutput = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +100,11 @@ unsafe partial class PixelShaderEffect<T>
|
||||
|
||||
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() switch
|
||||
{
|
||||
this.d2D1BufferPrecision = this.d2D1Effect.Get()->GetPrecisionProperty();
|
||||
}
|
||||
not null => this.d2D1Effect.Get()->GetPrecisionProperty(),
|
||||
_ => this.d2D1BufferPrecision
|
||||
};
|
||||
|
||||
// Map from D2D1_BUFFER_PRECISION to CanvasBufferPrecision, and return null for D2D1_BUFFER_PRECISION_UNKNOWN
|
||||
return this.d2D1BufferPrecision switch
|
||||
|
||||
@@ -25,7 +25,11 @@ partial class PixelShaderEffect<T>
|
||||
/// <summary>
|
||||
/// Gets or sets the current <typeparamref name="T"/> value in use.
|
||||
/// </summary>
|
||||
public T Value { get; set; }
|
||||
public T Value
|
||||
{
|
||||
get => GetConstantBuffer();
|
||||
set => SetConstantBuffer(in value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="SourceCollection"/> object associated with the current instance.
|
||||
|
||||
@@ -43,6 +43,11 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
|
||||
/// </summary>
|
||||
private ComPtr<ID2D1Effect> d2D1Effect;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="Value"/>.
|
||||
/// </summary>
|
||||
private T value;
|
||||
|
||||
/// <summary>
|
||||
/// The backing field for <see cref="CacheOutput"/>.
|
||||
/// </summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする