Fix disposing resources after device on .NET 6

このコミットが含まれているのは:
Sergio Pedri committed 2022-07-31 23:26:14 +02:00
1 親 f1306a4621
コミット 42c862c148
3ファイル変更
+11 -24

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

+2 -17
ファイルの表示
@@ -8,6 +8,7 @@ namespace ComputeSharp.Core.Extensions;
/// </summary>
internal static class ComPtrExtensions
{
#if NET6_0_OR_GREATER
/// <summary>
/// Invokes <see cref="IUnknown.AddRef"/> on the wrapped object for an input <see cref="ComPtr{T}"/> value.
/// </summary>
@@ -16,20 +17,11 @@ internal static class ComPtrExtensions
/// <returns>A <see cref="ComPtr{T}"/> instance of type <see cref="IUnknown"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe uint AddRef<T>(this ComPtr<T> ptr)
#if NET6_0_OR_GREATER
where T : unmanaged, IUnknown.Interface
#else
where T : unmanaged
#endif
{
if (ptr.Get() is not null)
{
#if NET6_0_OR_GREATER
return ptr.Get()->AddRef();
#else
return ((IUnknown*)ptr.Get())->AddRef();
#endif
}
return 0;
@@ -44,19 +36,11 @@ internal static class ComPtrExtensions
/// <returns>A <see cref="ComPtr{T}"/> instance of type <see cref="IUnknown"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe uint Release<T>(this ref ComPtr<T> ptr)
#if NET6_0_OR_GREATER
where T : unmanaged, IUnknown.Interface
#else
where T : unmanaged
#endif
{
if (ptr.Get() is not null)
{
#if NET6_0_OR_GREATER
uint count = ptr.Get()->Release();
#else
uint count = ((IUnknown*)ptr.Get())->Release();
#endif
if (count == 0)
{
@@ -68,6 +52,7 @@ internal static class ComPtrExtensions
return 0;
}
#endif
/// <summary>
/// Reinterprets the current <see cref="ComPtr{T}"/> instance as one of type <see cref="IUnknown"/>.
+9 -2
ファイルの表示
@@ -444,9 +444,16 @@ public sealed unsafe partial class GraphicsDevice : NativeObject
this.computeCommandListPool.Dispose();
this.copyCommandListPool.Dispose();
this.shaderResourceViewDescriptorAllocator.Dispose();
// On .NET 6, D3D12MA is used. In this case, the pool and allocator must be kept alive
// until all associated resources are returned and destroyed. Because of this, when the
// device is disposed (since there might be outstanding resources that are still alive),
// the pool and allocator are only released, but not disposed. This allows reosurces to
// also release them when disposed (since each resource keeps a reference back to the
// parent device). When the last one is disposed, the pool and allocator will be deleted.
#if NET6_0_OR_GREATER
this.pool.Dispose();
this.allocator.Dispose();
this.pool.Release();
this.allocator.Release();
#endif
UnregisterDeviceLostCallback(this);
-5
ファイルの表示
@@ -82,11 +82,6 @@ public partial class DeviceDisposalTests
[AllDevices]
public void DeviceDisposal_DisposedResourcesAfterDevice_ReferenceCounting(Device device)
{
#if NET6_0_OR_GREATER
// TODO: investigate ref count with resources disposed after device when using D3D12MA
Assert.Inconclusive();
#endif
using ComPtr<ID3D12Device> d3D12Device = default;
ConstantBuffer<float> r1;