Refactor shared state for built-in pixel shader effect
このコミットが含まれているのは:
1 親
3b5eb66d74
コミット
73c492ba2b
8ファイル変更
+213
-380
検索条件に一致するファイルはありません
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.D2D1.Uwp.Helpers;
|
||||
@@ -74,7 +74,7 @@ unsafe partial class PixelShaderEffect<T>
|
||||
if (!this.isEffectFactoryRegistered)
|
||||
{
|
||||
ResourceManager.RegisterEffectFactory(
|
||||
effectId: PixelShaderEffect.For<T>.Instance.Id,
|
||||
effectId: D2D1PixelShaderEffect.GetEffectId<T>(),
|
||||
factory: new EffectFactory());
|
||||
|
||||
this.isEffectFactoryRegistered = true;
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Threading;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
#if WINDOWS_UWP
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.D2D1.Uwp.Helpers;
|
||||
@@ -262,7 +261,7 @@ unsafe partial class PixelShaderEffect<T>
|
||||
{
|
||||
fixed (ID2D1Effect** d2D1Effect = this.d2D1Effect)
|
||||
{
|
||||
Guid effectId = PixelShaderEffect.For<T>.Instance.Id;
|
||||
Guid effectId = D2D1PixelShaderEffect.GetEffectId<T>();
|
||||
|
||||
using ComPtr<ID2D1DeviceContext> d2D1DeviceContextEffective = default;
|
||||
using ComPtr<ID2D1DeviceContextLease> d2D1DeviceContextLease = default;
|
||||
|
||||
@@ -188,7 +188,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager14].setFunction = PixelShaderEffect.SetResourceTextureManager14;
|
||||
d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager15].setFunction = PixelShaderEffect.SetResourceTextureManager15;
|
||||
|
||||
fixed (Guid* pGuid = &PixelShaderEffect.For<T>.Instance.Id)
|
||||
fixed (Guid* pGuid = &GetEffectId<T>())
|
||||
{
|
||||
// Register the effect
|
||||
((ID2D1Factory1*)d2D1Factory1)->RegisterEffectFromString(
|
||||
@@ -196,10 +196,10 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
propertyXml: (ushort*)pXml,
|
||||
bindings: d2D1PropertyBinding,
|
||||
bindingsCount: (uint)(D2D1PixelShaderEffectProperty.NumberOfAlwaysAvailableProperties + D2D1PixelShader.GetResourceTextureCount<T>()),
|
||||
effectFactory: PixelShaderEffect.For<T>.Instance.Factory).Assert();
|
||||
effectFactory: PixelShaderEffect.Globals<T>.Instance.Factory).Assert();
|
||||
}
|
||||
|
||||
effectId = PixelShaderEffect.For<T>.Instance.Id;
|
||||
effectId = GetEffectId<T>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,8 +250,8 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
writer.Write(D2D1EffectRegistrationData.V1.BlobId);
|
||||
|
||||
// Effect id and number of inputs
|
||||
writer.Write(PixelShaderEffect.For<T>.Instance.Id);
|
||||
writer.Write(PixelShaderEffect.For<T>.Instance.InputCount);
|
||||
writer.Write(GetEffectId<T>());
|
||||
writer.Write(D2D1PixelShader.GetInputCount<T>());
|
||||
|
||||
// Retrieve the effect XML and include it into the registration blob
|
||||
using (D2D1EffectXmlFactory.EffectXml effectXml = D2D1EffectXmlFactory.GetXmlBuffer<T>())
|
||||
@@ -388,14 +388,14 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
}
|
||||
|
||||
// Effect factory
|
||||
writer.Write((nint)PixelShaderEffect.For<T>.Instance.Factory);
|
||||
writer.Write((nint)PixelShaderEffect.Globals<T>.Instance.Factory);
|
||||
|
||||
byte[] registrationBlob = writer.WrittenSpan.ToArray();
|
||||
|
||||
writer.Dispose();
|
||||
|
||||
// Extract the effect id (the same that was encoded in the registration blob)
|
||||
effectId = PixelShaderEffect.For<T>.Instance.Id;
|
||||
effectId = GetEffectId<T>();
|
||||
|
||||
return registrationBlob;
|
||||
}
|
||||
@@ -419,7 +419,7 @@ public static unsafe class D2D1PixelShaderEffect
|
||||
default(ArgumentNullException).ThrowIfNull(d2D1DeviceContext);
|
||||
default(ArgumentNullException).ThrowIfNull(d2D1Effect);
|
||||
|
||||
fixed (Guid* pGuid = &PixelShaderEffect.For<T>.Instance.Id)
|
||||
fixed (Guid* pGuid = &GetEffectId<T>())
|
||||
{
|
||||
((ID2D1DeviceContext*)d2D1DeviceContext)->CreateEffect(
|
||||
effectId: pGuid,
|
||||
|
||||
@@ -4,9 +4,6 @@ using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Descriptors;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
#if !NET6_0_OR_GREATER
|
||||
using RuntimeHelpers = ComputeSharp.NetStandard.RuntimeHelpers;
|
||||
#endif
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop.Effects;
|
||||
|
||||
@@ -21,210 +18,59 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// <param name="effectImpl">The resulting effect factory.</param>
|
||||
/// <returns>The <c>HRESULT</c> for the operation.</returns>
|
||||
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||||
private delegate int FactoryDelegate(IUnknown** effectImpl);
|
||||
public delegate int FactoryDelegate(IUnknown** effectImpl);
|
||||
|
||||
/// <summary>
|
||||
/// A generic pixel shader implementation.
|
||||
/// A base type with global values for pixel shader effects.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader.</typeparam>
|
||||
public sealed class For<T>
|
||||
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
|
||||
public abstract class Globals
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="FactoryDelegate"/> wrapper for the shader factory.
|
||||
/// Gets the <see cref="FactoryDelegate"/> wrapper for the shader factory.
|
||||
/// </summary>
|
||||
private readonly FactoryDelegate effectFactory;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> for the shader.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This field could have used <see cref="FixedAddressValueTypeAttribute"/> to reduce some verbosity where it is
|
||||
/// being used to pass its address to a native API, but the attribute is incompatible with collectible assemblies.
|
||||
/// Because of that, it can't be used, as this project is explicitly meant to support plugin-like scenarios.
|
||||
/// </remarks>
|
||||
private readonly Guid shaderId;
|
||||
|
||||
/// <summary>
|
||||
/// The size of the constant buffer for the shader.
|
||||
/// </summary>
|
||||
private readonly int constantBufferSize;
|
||||
|
||||
/// <summary>
|
||||
/// The number of inputs for the shader.
|
||||
/// </summary>
|
||||
private readonly int inputCount;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer with the types of inputs for the shader.
|
||||
/// </summary>
|
||||
private readonly D2D1PixelShaderInputType* inputTypes;
|
||||
|
||||
/// <summary>
|
||||
/// The number of available input descriptions.
|
||||
/// </summary>
|
||||
private readonly int inputDescriptionCount;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer with the available input descriptions for the shader.
|
||||
/// </summary>
|
||||
private readonly D2D1InputDescription* inputDescriptions;
|
||||
|
||||
/// <summary>
|
||||
/// The pixel options for the shader.
|
||||
/// </summary>
|
||||
private readonly D2D1PixelOptions pixelOptions;
|
||||
|
||||
/// <summary>
|
||||
/// The shader bytecode.
|
||||
/// </summary>
|
||||
private readonly byte* bytecode;
|
||||
|
||||
/// <summary>
|
||||
/// The size of <see cref="bytecode"/>.
|
||||
/// </summary>
|
||||
private readonly int bytecodeSize;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer precision for the resulting output buffer.
|
||||
/// </summary>
|
||||
private readonly D2D1BufferPrecision bufferPrecision;
|
||||
|
||||
/// <summary>
|
||||
/// The channel depth for the resulting output buffer.
|
||||
/// </summary>
|
||||
private readonly D2D1ChannelDepth channelDepth;
|
||||
|
||||
/// <summary>
|
||||
/// The number of available resource texture descriptions.
|
||||
/// </summary>
|
||||
private readonly int resourceTextureDescriptionCount;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer with the available resource texture descriptions for the shader.
|
||||
/// </summary>
|
||||
private readonly D2D1ResourceTextureDescription* resourceTextureDescriptions;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="For{T}"/> instance with the specified parameters.
|
||||
/// Creates a new <see cref="Globals"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="effectFactory">The <see cref="FactoryDelegate"/> wrapper for the shader factory.</param>
|
||||
/// <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>
|
||||
/// <param name="inputDescriptions">The buffer with the available input descriptions for the shader.</param>
|
||||
/// <param name="pixelOptions">The pixel options for the shader.</param>
|
||||
/// <param name="bytecode">The shader bytecode.</param>
|
||||
/// <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>
|
||||
private For(
|
||||
FactoryDelegate effectFactory,
|
||||
Guid shaderId,
|
||||
int constantBufferSize,
|
||||
int inputCount,
|
||||
D2D1PixelShaderInputType* inputTypes,
|
||||
int inputDescriptionCount,
|
||||
D2D1InputDescription* inputDescriptions,
|
||||
D2D1PixelOptions pixelOptions,
|
||||
byte* bytecode,
|
||||
int bytecodeSize,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
int resourceTextureDescriptionCount,
|
||||
D2D1ResourceTextureDescription* resourceTextureDescriptions)
|
||||
protected Globals(FactoryDelegate effectFactory)
|
||||
{
|
||||
this.effectFactory = effectFactory;
|
||||
this.shaderId = shaderId;
|
||||
this.constantBufferSize = constantBufferSize;
|
||||
this.inputCount = inputCount;
|
||||
this.inputTypes = inputTypes;
|
||||
this.inputDescriptionCount = inputDescriptionCount;
|
||||
this.inputDescriptions = inputDescriptions;
|
||||
this.pixelOptions = pixelOptions;
|
||||
this.bytecode = bytecode;
|
||||
this.bytecodeSize = bytecodeSize;
|
||||
this.bufferPrecision = bufferPrecision;
|
||||
this.channelDepth = channelDepth;
|
||||
this.resourceTextureDescriptionCount = resourceTextureDescriptionCount;
|
||||
this.resourceTextureDescriptions = resourceTextureDescriptions;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the shared <see cref="For{T}"/> instance.
|
||||
/// </summary>
|
||||
public static For<T> Instance { get; } = CreateInstance();
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.EffectId"/>
|
||||
public abstract ref readonly Guid EffectId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="For{T}"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>The initialized <see cref="For{T}"/> instance.</returns>
|
||||
private static For<T> CreateInstance()
|
||||
{
|
||||
// Load all shader properties
|
||||
Guid shaderId = D2D1PixelShaderEffect.GetEffectId<T>();
|
||||
int constantBufferSize = D2D1PixelShader.GetConstantBufferSize<T>();
|
||||
D2D1BufferPrecision bufferPrecision = D2D1PixelShader.GetOutputBufferPrecision<T>();
|
||||
D2D1ChannelDepth channelDepth = D2D1PixelShader.GetOutputBufferChannelDepth<T>();
|
||||
D2D1PixelOptions pixelOptions = D2D1PixelShader.GetPixelOptions<T>();
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.ConstantBufferSize"/>
|
||||
public abstract int ConstantBufferSize { get; }
|
||||
|
||||
// Prepare the inputs info
|
||||
int inputCount = D2D1PixelShader.GetInputCount<T>();
|
||||
D2D1PixelShaderInputType* inputTypes = (D2D1PixelShaderInputType*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For<T>), sizeof(D2D1PixelShaderInputType) * inputCount);
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.InputCount"/>
|
||||
public abstract int InputCount { get; }
|
||||
|
||||
D2D1PixelShader.GetInputTypes<T>().Span.CopyTo(new Span<D2D1PixelShaderInputType>(inputTypes, inputCount));
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.ResourceTextureCount"/>
|
||||
public abstract int ResourceTextureCount { get; }
|
||||
|
||||
// Prepare the input descriptions
|
||||
ReadOnlyMemory<D2D1InputDescription> inputDescriptionsInfo = D2D1PixelShader.GetInputDescriptions<T>();
|
||||
int inputDescriptionCount = inputDescriptionsInfo.Length;
|
||||
D2D1InputDescription* inputDescriptions = (D2D1InputDescription*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(For<T>), sizeof(D2D1InputDescription) * inputDescriptionCount);
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.InputTypes"/>
|
||||
public abstract ReadOnlyMemory<D2D1PixelShaderInputType> InputTypes { get; }
|
||||
|
||||
inputDescriptionsInfo.Span.CopyTo(new Span<D2D1InputDescription>(inputDescriptions, inputDescriptionCount));
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.InputDescriptions"/>
|
||||
public abstract ReadOnlyMemory<D2D1InputDescription> InputDescriptions { get; }
|
||||
|
||||
// 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);
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.ResourceTextureDescriptions"/>
|
||||
public abstract ReadOnlyMemory<D2D1ResourceTextureDescription> ResourceTextureDescriptions { get; }
|
||||
|
||||
resourceTextureDescriptionsInfo.Span.CopyTo(new Span<D2D1ResourceTextureDescription>(resourceTextureDescriptions, resourceTextureDescriptionCount));
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.PixelOptions"/>
|
||||
public abstract D2D1PixelOptions PixelOptions { get; }
|
||||
|
||||
// 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);
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.BufferPrecision"/>
|
||||
public abstract D2D1BufferPrecision BufferPrecision { get; }
|
||||
|
||||
bytecodeInfo.Span.CopyTo(new Span<byte>(bytecode, bytecodeSize));
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.ChannelDepth"/>
|
||||
public abstract D2D1ChannelDepth ChannelDepth { get; }
|
||||
|
||||
// Initialize the shared instance with the computed state
|
||||
return new(
|
||||
CreateEffect,
|
||||
shaderId,
|
||||
constantBufferSize,
|
||||
inputCount,
|
||||
inputTypes,
|
||||
inputDescriptionCount,
|
||||
inputDescriptions,
|
||||
pixelOptions,
|
||||
bytecode,
|
||||
bytecodeSize,
|
||||
bufferPrecision,
|
||||
channelDepth,
|
||||
resourceTextureDescriptionCount,
|
||||
resourceTextureDescriptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a reference to the id of the effect.
|
||||
/// </summary>
|
||||
public ref readonly Guid Id
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref this.shaderId;
|
||||
}
|
||||
/// <inheritdoc cref="ID2D1PixelShaderDescriptor{T}.HlslBytecode"/>
|
||||
public abstract ReadOnlyMemory<byte> HlslBytecode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the factory for the current effect.
|
||||
@@ -242,32 +88,83 @@ internal unsafe partial struct PixelShaderEffect
|
||||
get => (void*)Marshal.GetFunctionPointerForDelegate(this.effectFactory);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A generic pixel shader implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of shader.</typeparam>
|
||||
public sealed class Globals<T> : Globals
|
||||
where T : unmanaged, ID2D1PixelShader, ID2D1PixelShaderDescriptor<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The HLSL bytecode (either precompiled, or the currently available one after compilation).
|
||||
/// </summary>
|
||||
private ReadOnlyMemory<byte> hlslBytecode;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of inputs for the effect.
|
||||
/// Creates a new <see cref="Globals"/> instance for shaders of type <typeparamref name="T"/>.
|
||||
/// </summary>
|
||||
public int InputCount => this.inputCount;
|
||||
private Globals()
|
||||
: base(CreateEffect)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the shared <see cref="Globals{T}"/> instance to use.
|
||||
/// </summary>
|
||||
public static Globals<T> Instance { get; } = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ref readonly Guid EffectId => ref D2D1PixelShaderEffect.GetEffectId<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int ConstantBufferSize => D2D1PixelShader.GetConstantBufferSize<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int InputCount => D2D1PixelShader.GetInputCount<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override int ResourceTextureCount => D2D1PixelShader.GetResourceTextureCount<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ReadOnlyMemory<D2D1PixelShaderInputType> InputTypes => D2D1PixelShader.GetInputTypes<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ReadOnlyMemory<D2D1InputDescription> InputDescriptions => D2D1PixelShader.GetInputDescriptions<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ReadOnlyMemory<D2D1ResourceTextureDescription> ResourceTextureDescriptions => D2D1PixelShader.GetResourceTextureDescriptions<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override D2D1PixelOptions PixelOptions => D2D1PixelShader.GetPixelOptions<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override D2D1BufferPrecision BufferPrecision => D2D1PixelShader.GetOutputBufferPrecision<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override D2D1ChannelDepth ChannelDepth => D2D1PixelShader.GetOutputBufferChannelDepth<T>();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override ReadOnlyMemory<byte> HlslBytecode
|
||||
{
|
||||
get
|
||||
{
|
||||
// Fast path if we already have some bytecode (either precompiled, or already compiled)
|
||||
if (this.hlslBytecode is ReadOnlyMemory<byte> { Length: > 0 } hlslBytecode)
|
||||
{
|
||||
return hlslBytecode;
|
||||
}
|
||||
|
||||
// If not, lazily compile the bytecode when requested
|
||||
return this.hlslBytecode = D2D1PixelShader.LoadBytecode<T>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="FactoryDelegate"/>
|
||||
private static int CreateEffect(IUnknown** effectImpl)
|
||||
{
|
||||
For<T> instance = Instance;
|
||||
|
||||
return PixelShaderEffect.Factory(
|
||||
instance.shaderId,
|
||||
instance.constantBufferSize,
|
||||
instance.inputCount,
|
||||
instance.inputTypes,
|
||||
instance.inputDescriptionCount,
|
||||
instance.inputDescriptions,
|
||||
instance.pixelOptions,
|
||||
instance.bytecode,
|
||||
instance.bytecodeSize,
|
||||
instance.bufferPrecision,
|
||||
instance.channelDepth,
|
||||
instance.resourceTextureDescriptionCount,
|
||||
instance.resourceTextureDescriptions,
|
||||
effectImpl);
|
||||
return PixelShaderEffect.Factory(Instance, effectImpl);
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
-27
@@ -110,7 +110,7 @@ partial struct PixelShaderEffect
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
return (uint)@this->inputCount;
|
||||
return (uint)@this->GetGlobals().InputCount;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ID2D1DrawTransform.MapOutputRectToInputRects"/>
|
||||
@@ -119,7 +119,7 @@ partial struct PixelShaderEffect
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
if (inputRectsCount != @this->inputCount)
|
||||
if (inputRectsCount != @this->GetGlobals().InputCount)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
@@ -136,6 +136,8 @@ partial struct PixelShaderEffect
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadOnlySpan<D2D1PixelShaderInputType> inputTypes = @this->GetGlobals().InputTypes.Span;
|
||||
|
||||
// If no custom transform is used, apply the default mapping. In this case, the loop will
|
||||
// automatically handle cases where no inputs are defined. If inputs are present instead,
|
||||
// the default mapping will set the input rect for a simple input to be the same as the
|
||||
@@ -143,7 +145,7 @@ partial struct PixelShaderEffect
|
||||
// will handle clipping the inputs to the actual output rect area, if needed.
|
||||
for (uint i = 0; i < inputRectsCount; i++)
|
||||
{
|
||||
switch (@this->inputTypes[i])
|
||||
switch (inputTypes[(int)i])
|
||||
{
|
||||
case D2D1PixelShaderInputType.Simple:
|
||||
inputRects[i] = *outputRect;
|
||||
@@ -166,7 +168,7 @@ partial struct PixelShaderEffect
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
if (inputRectCount != @this->inputCount)
|
||||
if (inputRectCount != @this->GetGlobals().InputCount)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
@@ -179,7 +181,7 @@ partial struct PixelShaderEffect
|
||||
HRESULT hresult = D2D1DrawInfoUpdateContextImpl.Factory(
|
||||
drawInfoUpdateContext: d2D1DrawInfoUpdateContext.GetAddressOf(),
|
||||
constantBuffer: @this->constantBuffer,
|
||||
constantBufferSize: @this->constantBufferSize,
|
||||
constantBufferSize: @this->GetGlobals().ConstantBufferSize,
|
||||
d2D1DrawInfo: @this->d2D1DrawInfo);
|
||||
|
||||
if (!Windows.SUCCEEDED(hresult))
|
||||
@@ -215,6 +217,8 @@ partial struct PixelShaderEffect
|
||||
}
|
||||
else
|
||||
{
|
||||
ReadOnlySpan<D2D1PixelShaderInputType> inputTypes = @this->GetGlobals().InputTypes.Span;
|
||||
|
||||
// If at least one input is present and no custom mapper is available, apply the default
|
||||
// mapping. In this case, the output rect should be the union of the input rects for all
|
||||
// the simple shader inputs, or infinite if there are no simple inputs. The input rects
|
||||
@@ -224,7 +228,7 @@ partial struct PixelShaderEffect
|
||||
|
||||
for (uint i = 0; i < inputRectCount; i++)
|
||||
{
|
||||
if (@this->inputTypes[i] == D2D1PixelShaderInputType.Simple)
|
||||
if (inputTypes[(int)i] == D2D1PixelShaderInputType.Simple)
|
||||
{
|
||||
if (isUnionOfSimpleRectsEmpty)
|
||||
{
|
||||
@@ -259,7 +263,7 @@ partial struct PixelShaderEffect
|
||||
{
|
||||
@this = (PixelShaderEffect*)&((void**)@this)[-1];
|
||||
|
||||
if (inputIndex >= (uint)@this->inputCount)
|
||||
if (inputIndex >= (uint)@this->GetGlobals().InputCount)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
@@ -278,7 +282,7 @@ partial struct PixelShaderEffect
|
||||
{
|
||||
// The default mapping in this scenario just needs to set the invalid output rect for simple inputs to
|
||||
// be the invalid input rect, and to set the invalid output rect for complex inputs to an infinite rect.
|
||||
switch (@this->inputTypes[inputIndex])
|
||||
switch (@this->GetGlobals().InputTypes.Span[(int)inputIndex])
|
||||
{
|
||||
case D2D1PixelShaderInputType.Simple:
|
||||
*invalidOutputRect = invalidInputRect;
|
||||
@@ -311,8 +315,11 @@ partial struct PixelShaderEffect
|
||||
|
||||
@this->d2D1DrawInfo = drawInfo;
|
||||
|
||||
Guid shaderId = @this->GetGlobals().EffectId;
|
||||
D2D1PixelOptions pixelOptions = @this->GetGlobals().PixelOptions;
|
||||
|
||||
// Set the pixel shader for the effect
|
||||
HRESULT hresult = drawInfo->SetPixelShader(&@this->shaderId, (D2D1_PIXEL_OPTIONS)@this->pixelOptions);
|
||||
HRESULT hresult = drawInfo->SetPixelShader(&shaderId, (D2D1_PIXEL_OPTIONS)pixelOptions);
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
@@ -320,32 +327,30 @@ partial struct PixelShaderEffect
|
||||
}
|
||||
|
||||
// If any input descriptions are present, set them
|
||||
if (@this->inputDescriptionCount > 0)
|
||||
foreach (ref readonly D2D1InputDescription inputDescription in @this->GetGlobals().InputDescriptions.Span)
|
||||
{
|
||||
for (int i = 0; i < @this->inputDescriptionCount; i++)
|
||||
D2D1_INPUT_DESCRIPTION d2D1InputDescription;
|
||||
d2D1InputDescription.filter = (D2D1_FILTER)inputDescription.Filter;
|
||||
d2D1InputDescription.levelOfDetailCount = (uint)inputDescription.LevelOfDetailCount;
|
||||
|
||||
hresult = drawInfo->SetInputDescription((uint)inputDescription.Index, d2D1InputDescription);
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
ref D2D1InputDescription inputDescription = ref @this->inputDescriptions[i];
|
||||
|
||||
D2D1_INPUT_DESCRIPTION d2D1InputDescription;
|
||||
d2D1InputDescription.filter = (D2D1_FILTER)inputDescription.Filter;
|
||||
d2D1InputDescription.levelOfDetailCount = (uint)inputDescription.LevelOfDetailCount;
|
||||
|
||||
hresult = drawInfo->SetInputDescription((uint)inputDescription.Index, d2D1InputDescription);
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
return hresult;
|
||||
}
|
||||
return hresult;
|
||||
}
|
||||
}
|
||||
|
||||
D2D1BufferPrecision bufferPrecision = @this->GetGlobals().BufferPrecision;
|
||||
D2D1ChannelDepth channelDepth = @this->GetGlobals().ChannelDepth;
|
||||
|
||||
// If a custom buffer precision or channel depth is requested, set it
|
||||
if (@this->bufferPrecision != D2D1BufferPrecision.Unknown ||
|
||||
@this->channelDepth != D2D1ChannelDepth.Default)
|
||||
if (bufferPrecision != D2D1BufferPrecision.Unknown ||
|
||||
channelDepth != D2D1ChannelDepth.Default)
|
||||
{
|
||||
hresult = drawInfo->SetOutputBuffer(
|
||||
(D2D1_BUFFER_PRECISION)@this->bufferPrecision,
|
||||
(D2D1_CHANNEL_DEPTH)@this->channelDepth);
|
||||
(D2D1_BUFFER_PRECISION)bufferPrecision,
|
||||
(D2D1_CHANNEL_DEPTH)channelDepth);
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
|
||||
+22
-13
@@ -86,17 +86,24 @@ internal unsafe partial struct PixelShaderEffect
|
||||
[UnmanagedCallersOnly]
|
||||
public static int Initialize(PixelShaderEffect* @this, ID2D1EffectContext* effectContext, ID2D1TransformGraph* transformGraph)
|
||||
{
|
||||
int hresult = effectContext->LoadPixelShader(
|
||||
shaderId: &@this->shaderId,
|
||||
shaderBuffer: @this->bytecode,
|
||||
shaderBufferCount: (uint)@this->bytecodeSize);
|
||||
ReadOnlySpan<byte> bytecode = @this->GetGlobals().HlslBytecode.Span;
|
||||
int hresult;
|
||||
|
||||
// If E_INVALIDARG was returned, try to check whether double precision support was requested when not available. This
|
||||
// is only done to provide a more helpful error message to callers. If no error was returned, the behavior is the same.
|
||||
// If any error is detected while trying to check for shader support, ignore the value and propagate the current HRESULT.
|
||||
if (hresult == E.E_INVALIDARG && effectContext->IsShaderSupported(@this->bytecode, @this->bytecodeSize) == S.S_FALSE)
|
||||
fixed (Guid* pShaderId = &@this->GetGlobals().EffectId)
|
||||
fixed (byte* pBytecode = bytecode)
|
||||
{
|
||||
hresult = D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES;
|
||||
hresult = effectContext->LoadPixelShader(
|
||||
shaderId: pShaderId,
|
||||
shaderBuffer: pBytecode,
|
||||
shaderBufferCount: (uint)bytecode.Length);
|
||||
|
||||
// If E_INVALIDARG was returned, try to check whether double precision support was requested when not available. This
|
||||
// is only done to provide a more helpful error message to callers. If no error was returned, the behavior is the same.
|
||||
// If any error is detected while trying to check for shader support, ignore the value and propagate the current HRESULT.
|
||||
if (hresult == E.E_INVALIDARG && effectContext->IsShaderSupported(pBytecode, bytecode.Length) == S.S_FALSE)
|
||||
{
|
||||
hresult = D2DERR.D2DERR_INSUFFICIENT_DEVICE_CAPABILITIES;
|
||||
}
|
||||
}
|
||||
|
||||
// If loading the bytecode succeeded, set the transform node
|
||||
@@ -130,7 +137,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
int hresult = S.S_OK;
|
||||
|
||||
// Validate the constant buffer
|
||||
if (@this->constantBufferSize > 0 &&
|
||||
if (@this->GetGlobals().ConstantBufferSize > 0 &&
|
||||
@this->constantBuffer is null)
|
||||
{
|
||||
return E.E_NOT_VALID_STATE;
|
||||
@@ -141,12 +148,14 @@ internal unsafe partial struct PixelShaderEffect
|
||||
{
|
||||
hresult = @this->d2D1DrawInfo->SetPixelShaderConstantBuffer(
|
||||
buffer: @this->constantBuffer,
|
||||
bufferCount: (uint)@this->constantBufferSize);
|
||||
bufferCount: (uint)@this->GetGlobals().ConstantBufferSize);
|
||||
}
|
||||
|
||||
if (Windows.SUCCEEDED(hresult))
|
||||
{
|
||||
for (int i = 0; i < @this->resourceTextureDescriptionCount; i++)
|
||||
ReadOnlySpan<D2D1ResourceTextureDescription> resourceTextureDescriptions = @this->GetGlobals().ResourceTextureDescriptions.Span;
|
||||
|
||||
for (int i = 0; i < resourceTextureDescriptions.Length; i++)
|
||||
{
|
||||
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = @this->resourceTextureManagerBuffer[i];
|
||||
|
||||
@@ -180,7 +189,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
break;
|
||||
}
|
||||
|
||||
ref readonly D2D1ResourceTextureDescription resourceTextureDescription = ref @this->resourceTextureDescriptions[i];
|
||||
ref readonly D2D1ResourceTextureDescription resourceTextureDescription = ref resourceTextureDescriptions[i];
|
||||
|
||||
// Set the ID2D1ResourceTexture object to the current index in the ID2D1DrawInfo object in use
|
||||
hresult = @this->d2D1DrawInfo->SetResourceTexture(
|
||||
|
||||
@@ -120,7 +120,7 @@ unsafe partial struct PixelShaderEffect
|
||||
dataSize == 0 &&
|
||||
actualSize is not null)
|
||||
{
|
||||
*actualSize = (uint)@this->constantBufferSize;
|
||||
*actualSize = (uint)@this->GetGlobals().ConstantBufferSize;
|
||||
|
||||
return S.S_FALSE;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ unsafe partial struct PixelShaderEffect
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (dataSize < @this->constantBufferSize)
|
||||
if (dataSize < @this->GetGlobals().ConstantBufferSize)
|
||||
{
|
||||
return E.E_NOT_SUFFICIENT_BUFFER;
|
||||
}
|
||||
@@ -142,11 +142,11 @@ unsafe partial struct PixelShaderEffect
|
||||
|
||||
uint writtenBytes = 0;
|
||||
|
||||
if (@this->constantBufferSize > 0)
|
||||
if (@this->GetGlobals().ConstantBufferSize > 0)
|
||||
{
|
||||
Buffer.MemoryCopy(@this->constantBuffer, data, dataSize, @this->constantBufferSize);
|
||||
Buffer.MemoryCopy(@this->constantBuffer, data, dataSize, @this->GetGlobals().ConstantBufferSize);
|
||||
|
||||
writtenBytes = (uint)@this->constantBufferSize;
|
||||
writtenBytes = (uint)@this->GetGlobals().ConstantBufferSize;
|
||||
}
|
||||
|
||||
if (actualSize is not null)
|
||||
@@ -168,7 +168,7 @@ unsafe partial struct PixelShaderEffect
|
||||
return E.E_POINTER;
|
||||
}
|
||||
|
||||
if (dataSize != (uint)@this->constantBufferSize)
|
||||
if (dataSize != (uint)@this->GetGlobals().ConstantBufferSize)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
@@ -284,7 +284,7 @@ unsafe partial struct PixelShaderEffect
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
private int GetResourceTextureManagerAtIndex(int index, byte* data, uint dataSize, uint* actualSize)
|
||||
{
|
||||
if (index >= this.resourceTextureDescriptionCount)
|
||||
if (index >= GetGlobals().ResourceTextureCount)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ unsafe partial struct PixelShaderEffect
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
private int SetResourceTextureManagerAtIndex(int index, byte* data, uint dataSize)
|
||||
{
|
||||
if (index >= this.resourceTextureDescriptionCount)
|
||||
if (index >= GetGlobals().ResourceTextureCount)
|
||||
{
|
||||
return E.E_INVALIDARG;
|
||||
}
|
||||
@@ -371,7 +371,7 @@ unsafe partial struct PixelShaderEffect
|
||||
// Initialize the resource texture manager, if an effect context is available
|
||||
if (this.d2D1EffectContext is not null)
|
||||
{
|
||||
uint dimensions = (uint)this.resourceTextureDescriptions[index].Dimensions;
|
||||
uint dimensions = (uint)GetGlobals().ResourceTextureDescriptions.Span[index].Dimensions;
|
||||
|
||||
result = resourceTextureManagerInternal.Get()->Initialize(this.d2D1EffectContext, &dimensions);
|
||||
|
||||
|
||||
@@ -106,86 +106,15 @@ internal unsafe partial struct PixelShaderEffect
|
||||
private volatile int referenceCount;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Guid"/> for the shader.
|
||||
/// The <see cref="GCHandle"/> for the <see cref="Globals"/> instance in use.
|
||||
/// </summary>
|
||||
private Guid shaderId;
|
||||
private GCHandle globalsHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The constant buffer data, if set.
|
||||
/// </summary>
|
||||
private byte* constantBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// The size of <see cref="constantBuffer"/>.
|
||||
/// </summary>
|
||||
private int constantBufferSize;
|
||||
|
||||
/// <summary>
|
||||
/// The number of inputs for the shader.
|
||||
/// </summary>
|
||||
private int inputCount;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer with the types of inputs for the shader.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This buffer is shared among effect instances, so it should not be released. It is
|
||||
/// owned by <see cref="For{T}"/>, which will release it when the target type is unloaded.
|
||||
/// </remarks>
|
||||
private D2D1PixelShaderInputType* inputTypes;
|
||||
|
||||
/// <summary>
|
||||
/// The number of available input descriptions.
|
||||
/// </summary>
|
||||
private int inputDescriptionCount;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer with the available input descriptions for the shader.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This buffer is also shared among effect instances, so it should not be released. It is
|
||||
/// owned by <see cref="For{T}"/>, which will release it when the target type is unloaded.
|
||||
/// </remarks>
|
||||
private D2D1InputDescription* inputDescriptions;
|
||||
|
||||
/// <summary>
|
||||
/// The pixel options for the shader.
|
||||
/// </summary>
|
||||
private D2D1PixelOptions pixelOptions;
|
||||
|
||||
/// <summary>
|
||||
/// The shader bytecode.
|
||||
/// </summary>
|
||||
private byte* bytecode;
|
||||
|
||||
/// <summary>
|
||||
/// The size of <see cref="bytecode"/>.
|
||||
/// </summary>
|
||||
private int bytecodeSize;
|
||||
|
||||
/// <summary>
|
||||
/// The buffer precision for the resulting output buffer.
|
||||
/// </summary>
|
||||
private D2D1BufferPrecision bufferPrecision;
|
||||
|
||||
/// <summary>
|
||||
/// The channel depth for the resulting output buffer.
|
||||
/// </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 <see cref="ID2D1TransformMapper"/> instance to use, if any.
|
||||
/// </summary>
|
||||
@@ -209,45 +138,33 @@ internal unsafe partial struct PixelShaderEffect
|
||||
/// <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>
|
||||
/// <param name="inputDescriptions">The buffer with the available input descriptions for the shader.</param>
|
||||
/// <param name="pixelOptions">The pixel options for the shader.</param>
|
||||
/// <param name="bytecode">The shader bytecode.</param>
|
||||
/// <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="globals">The <see cref="Globals"/> instance to use.</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,
|
||||
D2D1InputDescription* inputDescriptions,
|
||||
D2D1PixelOptions pixelOptions,
|
||||
byte* bytecode,
|
||||
int bytecodeSize,
|
||||
D2D1BufferPrecision bufferPrecision,
|
||||
D2D1ChannelDepth channelDepth,
|
||||
int resourceTextureDescriptionCount,
|
||||
D2D1ResourceTextureDescription* resourceTextureDescriptions,
|
||||
IUnknown** effectImpl)
|
||||
/// <returns>The <see cref="HRESULT"/> for the operation.</returns>
|
||||
private static int Factory(Globals globals, IUnknown** effectImpl)
|
||||
{
|
||||
PixelShaderEffect* @this;
|
||||
PixelShaderEffect* @this = null;
|
||||
GCHandle globalsHandle = default;
|
||||
|
||||
try
|
||||
{
|
||||
@this = (PixelShaderEffect*)NativeMemory.Alloc((nuint)sizeof(PixelShaderEffect));
|
||||
globalsHandle = GCHandle.Alloc(globals);
|
||||
}
|
||||
catch (OutOfMemoryException)
|
||||
catch (Exception)
|
||||
{
|
||||
// Free the effect, if we have one
|
||||
if (@this is not null)
|
||||
{
|
||||
NativeMemory.Free(@this);
|
||||
}
|
||||
|
||||
// Free the handle, if we have one
|
||||
if (globalsHandle.IsAllocated)
|
||||
{
|
||||
globalsHandle.Free();
|
||||
}
|
||||
|
||||
*effectImpl = null;
|
||||
|
||||
return E.E_OUTOFMEMORY;
|
||||
@@ -258,20 +175,8 @@ internal unsafe partial struct PixelShaderEffect
|
||||
@this->lpVtblForID2D1EffectImpl = VtblForID2D1EffectImpl;
|
||||
@this->lpVtblForID2D1DrawTransform = VtblForID2D1DrawTransform;
|
||||
@this->referenceCount = 1;
|
||||
@this->shaderId = shaderId;
|
||||
@this->globalsHandle = globalsHandle;
|
||||
@this->constantBuffer = null;
|
||||
@this->constantBufferSize = constantBufferSize;
|
||||
@this->inputCount = inputCount;
|
||||
@this->inputTypes = inputTypes;
|
||||
@this->inputDescriptionCount = inputDescriptionCount;
|
||||
@this->inputDescriptions = inputDescriptions;
|
||||
@this->pixelOptions = pixelOptions;
|
||||
@this->bytecode = bytecode;
|
||||
@this->bytecodeSize = bytecodeSize;
|
||||
@this->bufferPrecision = bufferPrecision;
|
||||
@this->channelDepth = channelDepth;
|
||||
@this->resourceTextureDescriptionCount = resourceTextureDescriptionCount;
|
||||
@this->resourceTextureDescriptions = resourceTextureDescriptions;
|
||||
@this->d2D1TransformMapper = null;
|
||||
@this->d2D1DrawInfo = null;
|
||||
@this->d2D1EffectContext = null;
|
||||
@@ -331,6 +236,14 @@ internal unsafe partial struct PixelShaderEffect
|
||||
|
||||
if (referenceCount == 0)
|
||||
{
|
||||
// Retrieve the number of resource textures before freeing the globals handle
|
||||
int resourceTextureDescriptionCount = GetGlobals().ResourceTextureCount;
|
||||
|
||||
if (this.globalsHandle.IsAllocated)
|
||||
{
|
||||
this.globalsHandle.Free();
|
||||
}
|
||||
|
||||
if (this.constantBuffer is not null)
|
||||
{
|
||||
NativeMemory.Free(this.constantBuffer);
|
||||
@@ -352,7 +265,7 @@ internal unsafe partial struct PixelShaderEffect
|
||||
}
|
||||
|
||||
// Retrieve all possible resource texture managers in use and release the ones that had been assigned (from one of the property bindings)
|
||||
for (int i = 0; i < this.resourceTextureDescriptionCount; i++)
|
||||
for (int i = 0; i < resourceTextureDescriptionCount; i++)
|
||||
{
|
||||
ID2D1ResourceTextureManager* resourceTextureManager = this.resourceTextureManagerBuffer[i];
|
||||
|
||||
@@ -367,4 +280,14 @@ internal unsafe partial struct PixelShaderEffect
|
||||
|
||||
return referenceCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Globals"/> instance for the current effect.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Globals"/> instance for the current effect.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private Globals GetGlobals()
|
||||
{
|
||||
return Unsafe.As<Globals>(this.globalsHandle.Target!);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする