Fixed resource disposing after owning device
このコミットが含まれているのは:
1 親
c7f7eac265
コミット
df970a5e40
12ファイル変更
+190
-12
検索条件に一致するファイルはありません
@@ -80,6 +80,7 @@ namespace ComputeSharp.Resources
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, (ulong)SizeInBytes);
|
||||
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
|
||||
switch (resourceType)
|
||||
@@ -172,6 +173,8 @@ namespace ComputeSharp.Resources
|
||||
this.d3D12Resource.Dispose();
|
||||
this.allocation.Dispose();
|
||||
|
||||
GraphicsDevice.UnregisterAllocatedResource();
|
||||
|
||||
if (GraphicsDevice?.IsDisposed == false)
|
||||
{
|
||||
GraphicsDevice.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, D3D12GpuDescriptorHandle);
|
||||
|
||||
@@ -107,6 +107,7 @@ namespace ComputeSharp.Resources
|
||||
out _,
|
||||
out _);
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
|
||||
switch (resourceType)
|
||||
@@ -436,6 +437,8 @@ namespace ComputeSharp.Resources
|
||||
this.d3D12Resource.Dispose();
|
||||
this.allocation.Dispose();
|
||||
|
||||
GraphicsDevice.UnregisterAllocatedResource();
|
||||
|
||||
if (GraphicsDevice?.IsDisposed == false)
|
||||
{
|
||||
GraphicsDevice.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, D3D12GpuDescriptorHandle);
|
||||
|
||||
@@ -111,6 +111,7 @@ namespace ComputeSharp.Resources
|
||||
out _,
|
||||
out _);
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle);
|
||||
|
||||
switch (resourceType)
|
||||
@@ -479,6 +480,8 @@ namespace ComputeSharp.Resources
|
||||
this.d3D12Resource.Dispose();
|
||||
this.allocation.Dispose();
|
||||
|
||||
GraphicsDevice.UnregisterAllocatedResource();
|
||||
|
||||
if (GraphicsDevice?.IsDisposed == false)
|
||||
{
|
||||
GraphicsDevice.ReturnShaderResourceViewDescriptorHandles(D3D12CpuDescriptorHandle, D3D12GpuDescriptorHandle);
|
||||
|
||||
@@ -54,6 +54,8 @@ namespace ComputeSharp.Resources
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, sizeInBytes);
|
||||
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
|
||||
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
|
||||
|
||||
this.d3D12Resource.Get()->SetName(this);
|
||||
@@ -109,6 +111,8 @@ namespace ComputeSharp.Resources
|
||||
this.d3D12Resource.Dispose();
|
||||
this.allocation.Dispose();
|
||||
|
||||
GraphicsDevice.UnregisterAllocatedResource();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,6 +71,8 @@ namespace ComputeSharp.Resources
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
|
||||
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
|
||||
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
|
||||
|
||||
this.d3D12Resource.Get()->SetName(this);
|
||||
@@ -119,6 +121,8 @@ namespace ComputeSharp.Resources
|
||||
this.d3D12Resource.Dispose();
|
||||
this.allocation.Dispose();
|
||||
|
||||
GraphicsDevice.UnregisterAllocatedResource();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,8 @@ namespace ComputeSharp.Resources
|
||||
this.allocation = device.Allocator->CreateResource(device.Pool, resourceType, allocationMode, totalSizeInBytes);
|
||||
this.d3D12Resource = new ComPtr<ID3D12Resource>(this.allocation.Get()->GetResource());
|
||||
|
||||
device.RegisterAllocatedResource();
|
||||
|
||||
this.mappedData = (T*)this.d3D12Resource.Get()->Map().Pointer;
|
||||
|
||||
this.d3D12Resource.Get()->SetName(this);
|
||||
@@ -126,6 +128,8 @@ namespace ComputeSharp.Resources
|
||||
this.d3D12Resource.Dispose();
|
||||
this.allocation.Dispose();
|
||||
|
||||
GraphicsDevice.UnregisterAllocatedResource();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,33 @@ namespace ComputeSharp.Tests
|
||||
_ = buffer.ToArray();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
[Resource(typeof(ReadOnlyBuffer<>))]
|
||||
[Resource(typeof(ReadWriteBuffer<>))]
|
||||
public void DisposeAfterDevice(Device device, Type bufferType)
|
||||
{
|
||||
GraphicsDevice? gpu = device switch
|
||||
{
|
||||
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
|
||||
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
|
||||
_ => throw new ArgumentException(nameof(device))
|
||||
};
|
||||
|
||||
if (gpu is null)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Buffer<float> buffer = gpu.AllocateBuffer<float>(bufferType, 128);
|
||||
|
||||
gpu.Dispose();
|
||||
buffer.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ConstantBuffer<>))]
|
||||
|
||||
@@ -86,6 +86,32 @@ namespace ComputeSharp.Tests
|
||||
_ = texture.ToArray();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<>))]
|
||||
public void DisposeAfterDevice(Device device, Type textureType)
|
||||
{
|
||||
GraphicsDevice? gpu = device switch
|
||||
{
|
||||
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
|
||||
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
|
||||
_ => throw new ArgumentException(nameof(device))
|
||||
};
|
||||
|
||||
if (gpu is null)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Texture2D<float> texture = gpu.AllocateTexture2D<float>(textureType, 10, 10);
|
||||
|
||||
gpu.Dispose();
|
||||
texture.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<>))]
|
||||
|
||||
@@ -105,6 +105,32 @@ namespace ComputeSharp.Tests
|
||||
_ = texture.ToArray();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
[Resource(typeof(ReadWriteTexture3D<>))]
|
||||
public void DisposeAfterDevice(Device device, Type textureType)
|
||||
{
|
||||
GraphicsDevice? gpu = device switch
|
||||
{
|
||||
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
|
||||
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
|
||||
_ => throw new ArgumentException(nameof(device))
|
||||
};
|
||||
|
||||
if (gpu is null)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Texture3D<float> texture = gpu.AllocateTexture3D<float>(textureType, 10, 10, 4);
|
||||
|
||||
gpu.Dispose();
|
||||
texture.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture3D<>))]
|
||||
|
||||
@@ -66,6 +66,32 @@ namespace ComputeSharp.Tests
|
||||
_ = buffer.Span;
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadBuffer<>))]
|
||||
[Resource(typeof(ReadBackBuffer<>))]
|
||||
public void DisposeAfterDevice(Device device, Type bufferType)
|
||||
{
|
||||
GraphicsDevice? gpu = device switch
|
||||
{
|
||||
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
|
||||
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
|
||||
_ => throw new ArgumentException(nameof(device))
|
||||
};
|
||||
|
||||
if (gpu is null)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TransferBuffer<float> buffer = gpu.AllocateTransferBuffer<float>(bufferType, 128);
|
||||
|
||||
gpu.Dispose();
|
||||
buffer.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadBuffer_Copy_Full(Device device)
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace ComputeSharp.Tests
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
[Data(AllocationMode.Default)]
|
||||
[Data(AllocationMode.Clear)]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType, AllocationMode allocationMode)
|
||||
public unsafe void Allocate_Uninitialized_Ok(Device device, Type textureType, AllocationMode allocationMode)
|
||||
{
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(bufferType, 128, 256, allocationMode);
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(textureType, 128, 256, allocationMode);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
@@ -50,9 +50,9 @@ namespace ComputeSharp.Tests
|
||||
[Data(0, -4314)]
|
||||
[Data(-14, -53)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int width, int height)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type textureType, int width, int height)
|
||||
{
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(bufferType, width, height);
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(textureType, width, height);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
@@ -60,15 +60,41 @@ namespace ComputeSharp.Tests
|
||||
[Resource(typeof(UploadTexture2D<>))]
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Device device, Type bufferType)
|
||||
public void UsageAfterDispose(Device device, Type textureType)
|
||||
{
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(bufferType, 32, 32);
|
||||
using TransferTexture2D<float> texture = device.Get().AllocateTransferTexture2D<float>(textureType, 32, 32);
|
||||
|
||||
texture.Dispose();
|
||||
|
||||
_ = texture.View;
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture2D<>))]
|
||||
[Resource(typeof(ReadBackTexture2D<>))]
|
||||
public void DisposeAfterDevice(Device device, Type textureType)
|
||||
{
|
||||
GraphicsDevice? gpu = device switch
|
||||
{
|
||||
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
|
||||
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
|
||||
_ => throw new ArgumentException(nameof(device))
|
||||
};
|
||||
|
||||
if (gpu is null)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TransferTexture2D<float> texture = gpu.AllocateTransferTexture2D<float>(textureType, 32, 32);
|
||||
|
||||
gpu.Dispose();
|
||||
texture.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadTexture2D_Copy_Full(Device device)
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace ComputeSharp.Tests
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
[Data(AllocationMode.Default)]
|
||||
[Data(AllocationMode.Clear)]
|
||||
public unsafe void Allocate_Uninitialized_Ok(Device device, Type bufferType, AllocationMode allocationMode)
|
||||
public unsafe void Allocate_Uninitialized_Ok(Device device, Type textureType, AllocationMode allocationMode)
|
||||
{
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(bufferType, 128, 256, 32, allocationMode);
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(textureType, 128, 256, 32, allocationMode);
|
||||
|
||||
Assert.IsNotNull(texture);
|
||||
Assert.AreEqual(texture.Width, 128);
|
||||
@@ -57,9 +57,9 @@ namespace ComputeSharp.Tests
|
||||
[Data(12, 12, -1)]
|
||||
[Data(2, 4, ushort.MaxValue + 1)]
|
||||
[ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type bufferType, int width, int height, int depth)
|
||||
public void Allocate_Uninitialized_Fail(Device device, Type textureType, int width, int height, int depth)
|
||||
{
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(bufferType, width, height, depth);
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(textureType, width, height, depth);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
@@ -67,15 +67,41 @@ namespace ComputeSharp.Tests
|
||||
[Resource(typeof(UploadTexture3D<>))]
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
[ExpectedException(typeof(ObjectDisposedException))]
|
||||
public void UsageAfterDispose(Device device, Type bufferType)
|
||||
public void UsageAfterDispose(Device device, Type textureType)
|
||||
{
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(bufferType, 32, 32, 16);
|
||||
using TransferTexture3D<float> texture = device.Get().AllocateTransferTexture3D<float>(textureType, 32, 32, 16);
|
||||
|
||||
texture.Dispose();
|
||||
|
||||
_ = texture.View;
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(UploadTexture3D<>))]
|
||||
[Resource(typeof(ReadBackTexture3D<>))]
|
||||
public void DisposeAfterDevice(Device device, Type textureType)
|
||||
{
|
||||
GraphicsDevice? gpu = device switch
|
||||
{
|
||||
Device.Discrete => Gpu.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(),
|
||||
Device.Warp => Gpu.QueryDevices(info => !info.IsHardwareAccelerated).First(),
|
||||
_ => throw new ArgumentException(nameof(device))
|
||||
};
|
||||
|
||||
if (gpu is null)
|
||||
{
|
||||
Assert.Inconclusive();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TransferTexture3D<float> texture = gpu.AllocateTransferTexture3D<float>(textureType, 32, 32, 16);
|
||||
|
||||
gpu.Dispose();
|
||||
texture.Dispose();
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
public void Allocate_UploadTexture3D_Copy_Full(Device device)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする