Add PixelShaderEffect<T>.TransformMapper property

このコミットが含まれているのは:
Sergio Pedri committed 2022-12-22 10:56:03 -08:00
1 親 e57caf94b2
コミット 68bf5fe9b3
7ファイル変更
+123 -3

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

+1
ファイルの表示
@@ -11,6 +11,7 @@
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)System\Buffers\BitOperations.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics.CodeAnalysis\DoesNotReturnAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics.CodeAnalysis\DisallowNullAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics.CodeAnalysis\NotNullAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Math.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" />
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Diagnostics.CodeAnalysis;
/// <summary>
/// Specifies that null is disallowed as an input even if the corresponding type allows it.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.Property, Inherited = false)]
internal sealed class DisallowNullAttribute : Attribute
{
}
+42
ファイルの表示
@@ -4,6 +4,9 @@ using System;
using ComputeSharp.D2D1.Extensions;
using TerraFX.Interop.DirectX;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
using TerraFX.Interop.Windows;
using System.Runtime.InteropServices;
#pragma warning disable CS0618
@@ -17,6 +20,7 @@ internal static unsafe class ID2D1EffectExtensions
/// <summary>
/// Gets the constant buffer of type <typeparamref name="T"/> from a given <see cref="ID2D1Effect"/> object.
/// </summary>
/// <typeparam name="T">The type of shader being used.</typeparam>
/// <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)
@@ -42,6 +46,44 @@ internal static unsafe class ID2D1EffectExtensions
return shader;
}
/// <summary>
/// Gets the <see cref="D2D1TransformMapper{T}"/> instance from a given <see cref="ID2D1Effect"/> object.
/// </summary>
/// <typeparam name="T">The type of shader being used.</typeparam>
/// <param name="d2D1Effect">The input <see cref="ID2D1Effect"/> instance.</param>
/// <returns>The <see cref="D2D1TransformMapper{T}"/> instance for <paramref name="d2D1Effect"/>.</returns>
public static D2D1TransformMapper<T>? GetTransformMapper<T>(this ref ID2D1Effect d2D1Effect)
where T : unmanaged, ID2D1PixelShader
{
using ComPtr<ID2D1TransformMapper> d2D1TransformMapper = default;
// Get the ID2D1TransformMapper object from the effect
d2D1Effect.GetValue(
index: D2D1PixelShaderEffectProperty.TransformMapper,
type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_IUNKNOWN,
data: (byte*)d2D1TransformMapper.GetAddressOf(),
dataSize: (uint)sizeof(void*)).Assert();
// If there is no transform, just return null (this is the default state)
if (d2D1TransformMapper.Get() is null)
{
return null;
}
// Otherwise, check if it's an internal CCW and retrieve the managed wrapper
using ComPtr<ID2D1TransformMapperInternal> d2D1TransformMapperInternal = default;
d2D1TransformMapper.CopyTo(d2D1TransformMapperInternal.GetAddressOf()).Assert();
IntPtr handlePtr;
// Get the underlying GCHandle value
d2D1TransformMapperInternal.Get()->GetManagedWrapperHandle((void**)&handlePtr).Assert();
// Retrieve the managed wrapper from the GCHandle
return (D2D1TransformMapper<T>)GCHandle.FromIntPtr(handlePtr).Target!;
}
/// <summary>
/// Gets the <see cref="D2D1_PROPERTY.D2D1_PROPERTY_CACHED"/> property for a given <see cref="ID2D1Effect"/> object.
/// </summary>
+7
ファイルの表示
@@ -168,6 +168,7 @@ unsafe partial class PixelShaderEffect<T>
// Cache the last update values for the constant buffer, cache output and buffer precision properties
this.value = this.d2D1Effect.Get()->GetConstantBuffer<T>();
this.transformMapper = this.d2D1Effect.Get()->GetTransformMapper<T>();
this.cacheOutput = this.d2D1Effect.Get()->GetCachedProperty();
this.d2D1BufferPrecision = this.d2D1Effect.Get()->GetPrecisionProperty();
@@ -221,6 +222,12 @@ unsafe partial class PixelShaderEffect<T>
// Set the constant buffer for the effect
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(this.value, this.d2D1Effect.Get());
// If there is a transform mapper, set it in the effect
if (this.transformMapper is not null)
{
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(this.d2D1Effect.Get(), this.transformMapper);
}
// If cache input has been set, forward that to the new effect
if (this.cacheOutput)
{
+39 -1
ファイルの表示
@@ -50,6 +50,45 @@ unsafe partial class PixelShaderEffect<T>
}
}
/// <summary>
/// Gets the marshalled value for <see cref="TransformMapper"/>.
/// </summary>
/// <returns>The marshalled value for <see cref="TransformMapper"/>.</returns>
private D2D1TransformMapper<T>? GetTransformMapper()
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
return this.d2D1Effect.Get() switch
{
not null => this.d2D1Effect.Get()->GetTransformMapper<T>(),
_ => this.transformMapper
};
}
}
/// <summary>
/// Sets the marshalled value for <see cref="TransformMapper"/>.
/// </summary>
/// <param name="value">The value to set for <see cref="TransformMapper"/>.</param>
private void SetTransformMapper(D2D1TransformMapper<T> value)
{
using ReferenceTracker.Lease _0 = GetReferenceTracker().GetLease();
lock (this.lockObject)
{
if (this.d2D1Effect.Get() is not null)
{
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(this.d2D1Effect.Get(), value);
}
else
{
this.transformMapper = value;
}
}
}
/// <summary>
/// Gets the marshalled value for <see cref="CacheOutput"/>.
/// </summary>
@@ -78,7 +117,6 @@ unsafe partial class PixelShaderEffect<T>
lock (this.lockObject)
{
// 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);
+15 -2
ファイルの表示
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics.CodeAnalysis;
using ComputeSharp.D2D1.Interop;
using Microsoft.Graphics.Canvas;
using Windows.Graphics.Effects;
@@ -17,9 +19,15 @@ partial class PixelShaderEffect<T>
}
/// <summary>
/// Gets the <see cref="SourceCollection"/> object associated with the current instance.
/// Gets or sets the <see cref="D2D1TransformMapper{T}"/> instance to use for the effect, if any.
/// </summary>
public SourceCollection Sources { get; } = new();
/// <exception cref="ArgumentNullException">Thrown if the value is set to <see langword="null"/>.</exception>
[DisallowNull]
public D2D1TransformMapper<T>? TransformMapper
{
get => GetTransformMapper();
set => SetTransformMapper(value);
}
/// <summary>
/// Gets or sets a value indicating whether to enable caching the output from drawing this effect.
@@ -40,6 +48,11 @@ partial class PixelShaderEffect<T>
set => SetBufferPrecision(value);
}
/// <summary>
/// Gets the <see cref="SourceCollection"/> object associated with the current instance.
/// </summary>
public SourceCollection Sources { get; } = new();
/// <summary>
/// Represents the collection of <see cref="IGraphicsEffectSource"/> sources in a <see cref="PixelShaderEffect{T}"/> instance.
/// </summary>
+6
ファイルの表示
@@ -1,4 +1,5 @@
using ABI.Microsoft.Graphics.Canvas;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.Interop;
using Microsoft.Graphics.Canvas;
using TerraFX.Interop.DirectX;
@@ -48,6 +49,11 @@ public sealed partial class PixelShaderEffect<T> : IReferenceTrackedObject, ICan
/// </summary>
private T value;
/// <summary>
/// The backing field for <see cref="TransformMapper"/>.
/// </summary>
private D2D1TransformMapper<T>? transformMapper;
/// <summary>
/// The backing field for <see cref="CacheOutput"/>.
/// </summary>