Use [InlineArray] in ResourceTextureManagerBuffer

このコミットが含まれているのは:
Sergio Pedri committed 2023-11-21 02:10:34 +01:00
1 親 341c40fd2a
コミット 56f07203dc
4ファイル変更
+13 -108

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

@@ -108,7 +108,7 @@ internal unsafe partial struct PixelShaderEffect
for (int i = 0; i < resourceTextureDescriptions.Length; i++)
{
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = new(@this->resourceTextureManagerBuffer[i]);
ref readonly ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = ref @this->resourceTextureManagerBuffer[i];
// If the current resource texture manager is not set, we cannot render, as there's an unbound resource texture
if (resourceTextureManager.Get() is null)
+2 -9
ファイルの表示
@@ -180,9 +180,7 @@ unsafe partial struct PixelShaderEffect
default(ArgumentOutOfRangeException).ThrowIfLessThan((int)dataSize, sizeof(void*), nameof(dataSize));
default(ArgumentOutOfRangeException).ThrowIfGreaterThanOrEqual(index, GetGlobals().ResourceTextureCount);
using ComPtr<ID2D1ResourceTextureManager> resourceTextureManager = new(this.resourceTextureManagerBuffer[index]);
resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data).Assert();
this.resourceTextureManagerBuffer[index].CopyTo((ID2D1ResourceTextureManager**)data).Assert();
if (actualSize is not null)
{
@@ -240,13 +238,8 @@ unsafe partial struct PixelShaderEffect
resourceTextureManagerInternal.Get()->Initialize(this.d2D1EffectContext, &dimensions).Assert();
}
ref ID2D1ResourceTextureManager* currentResourceTextureManager = ref this.resourceTextureManagerBuffer[index];
// If there's already an existing manager at this index, release it
ComPtr.Dispose(currentResourceTextureManager);
// Store the resource texture manager into the buffer
currentResourceTextureManager = resourceTextureManager.Detach();
this.resourceTextureManagerBuffer[index].Attach(resourceTextureManager.Detach());
return S.S_OK;
}
@@ -1,7 +1,8 @@
using System.Runtime.CompilerServices;
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
using ComputeSharp.Win32;
#pragma warning disable CS0649
#pragma warning disable IDE0051
namespace ComputeSharp.D2D1.Interop.Effects;
@@ -11,102 +12,12 @@ partial struct PixelShaderEffect
/// <summary>
/// A buffer of 16 <see cref="ID2D1ResourceTextureManager"/> objects.
/// </summary>
[InlineArray(16)]
private unsafe struct ResourceTextureManagerBuffer
{
/// <summary>
/// The pointer to the <see cref="ID2D1ResourceTextureManager"/> instance at index 0.
/// 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];
}
}
private ComPtr<ID2D1ResourceTextureManager> resourceTextureManager0;
}
}
+5 -4
ファイルの表示
@@ -2,6 +2,7 @@ using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
using ComputeSharp.Win32;
@@ -201,11 +202,11 @@ internal unsafe partial struct PixelShaderEffect
ComPtr.Dispose(this.d2D1EffectContext);
// Retrieve all possible resource texture managers in use and release the ones that had been
// assigned (from one of the property bindings). We just hardcode 16 here and dont access
// the globals, as technically invoking APIs on it might throw an exception.
for (int i = 0; i < 16; i++)
// assigned (from one of the property bindings). We just try to dispose all of them here and
// don't access the globals, as technically invoking APIs on it might throw an exception.
foreach (ref ComPtr<ID2D1ResourceTextureManager> resourceTextureManager in (Span<ComPtr<ID2D1ResourceTextureManager>>)this.resourceTextureManagerBuffer)
{
ComPtr.Dispose(this.resourceTextureManagerBuffer[i]);
resourceTextureManager.Dispose();
}
NativeMemory.Free(Unsafe.AsPointer(ref this));