Fixed cancellation of Gpu.Default.Dispose
このコミットが含まれているのは:
1 親
c2345bef99
コミット
d131707cd1
10ファイル変更
+51
-17
検索条件に一致するファイルはありません
@@ -149,7 +149,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.d3D12Resource.Dispose();
|
||||
|
||||
@@ -157,6 +157,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
{
|
||||
GraphicsDevice.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, D3D12GpuDescriptorHandle);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -253,7 +253,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.d3D12Resource.Dispose();
|
||||
|
||||
@@ -261,6 +261,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
{
|
||||
GraphicsDevice.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, D3D12GpuDescriptorHandle);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -276,7 +276,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.d3D12Resource.Dispose();
|
||||
|
||||
@@ -284,6 +284,8 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
|
||||
{
|
||||
GraphicsDevice.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, D3D12GpuDescriptorHandle);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -41,10 +41,12 @@ namespace ComputeSharp.Graphics.Commands
|
||||
public ID3D12PipelineState* D3D12PipelineState => this.d3D12PipelineState;
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.d3D12RootSignature.Dispose();
|
||||
this.d3D12PipelineState.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,9 +210,12 @@ namespace ComputeSharp.Graphics
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
if (DeviceHelper.GetDefaultDeviceLuid() == Luid) return;
|
||||
if (DeviceHelper.GetDefaultDeviceLuid() == Luid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
DeviceHelper.NotifyDisposedDevice(this);
|
||||
|
||||
@@ -224,6 +227,8 @@ namespace ComputeSharp.Graphics
|
||||
this.computeCommandAllocatorPool.Dispose();
|
||||
this.copyCommandAllocatorPool.Dispose();
|
||||
this.shaderResourceViewDescriptorAllocator.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -155,9 +155,11 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.dxgiFactory4.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace ComputeSharp.Graphics.Interop
|
||||
/// </summary>
|
||||
~NativeObject()
|
||||
{
|
||||
CheckAndDispose();
|
||||
_ = CheckAndDispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -26,28 +26,33 @@ namespace ComputeSharp.Graphics.Interop
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
|
||||
CheckAndDispose();
|
||||
if (CheckAndDispose())
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
private void CheckAndDispose()
|
||||
private bool CheckAndDispose()
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
IsDisposed = true;
|
||||
|
||||
OnDispose();
|
||||
return IsDisposed = OnDispose();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and (optionally) managed resources.
|
||||
/// </summary>
|
||||
protected abstract void OnDispose();
|
||||
/// <returns>
|
||||
/// Whether or not the dispose has actually been executed. This is done in order to allow derived types to
|
||||
/// optionally cancel a dispose operation, by not releasing resources and returning <see langword="false"/>.
|
||||
/// </returns>
|
||||
protected abstract bool OnDispose();
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ObjectDisposedException"/> if the current instance has been disposed.
|
||||
|
||||
@@ -28,9 +28,11 @@ namespace ComputeSharp.Shaders.Translation.Interop
|
||||
public D3D12_SHADER_BYTECODE D3D12ShaderBytecode => new((ID3DBlob*)this.dxcBlob.Get());
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnDispose()
|
||||
protected override bool OnDispose()
|
||||
{
|
||||
this.dxcBlob.Dispose();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ namespace ComputeSharp
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default <see cref="GraphicsDevice"/> instance for the current machine.
|
||||
/// This instance cannot be manually disposed - attempting to do so is safe and it will
|
||||
/// not cause an exception, but it will simply do nothing and not dispose the device.
|
||||
/// </summary>
|
||||
/// <exception cref="NotSupportedException">Thrown when a default device is not available.</exception>
|
||||
/// <remarks>Make sure to check <see cref="IsSupported"/> before accessing this property.</remarks>
|
||||
|
||||
@@ -25,6 +25,16 @@ namespace ComputeSharp.Tests
|
||||
Assert.IsTrue(Gpu.Default.WavefrontSize != 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DisposeDefault()
|
||||
{
|
||||
using var before = Gpu.Default.AllocateReadOnlyBuffer<float>(128);
|
||||
|
||||
Gpu.Default.Dispose();
|
||||
|
||||
using var after = Gpu.Default.AllocateReadOnlyBuffer<float>(128);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EnumerateDevices()
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする