From 37823f366c836614c6e5d69826d8a619817f06de Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 29 Jul 2022 01:35:17 +0200 Subject: [PATCH] Move GPU disposal tests to DeviceLost test project --- .../DeviceDisposalTests.cs | 4 ++ .../GetDefaultDeviceTests.cs | 43 +++++++++++++++++++ tests/ComputeSharp.Tests/BufferTests.cs | 27 ------------ .../ComputeSharp.Tests/InitializationTests.cs | 10 ----- tests/ComputeSharp.Tests/Texture2DTests.cs | 26 ----------- tests/ComputeSharp.Tests/Texture3DTests.cs | 26 ----------- .../ComputeSharp.Tests/TransferBufferTests.cs | 26 ----------- .../TransferTexture2DTests.cs | 26 ----------- .../TransferTexture3DTests.cs | 26 ----------- 9 files changed, 47 insertions(+), 167 deletions(-) diff --git a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs index 174b7b0d..6c6b9070 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs +++ b/tests/ComputeSharp.Tests.DeviceLost/DeviceDisposalTests.cs @@ -86,6 +86,10 @@ public partial class DeviceDisposalTests using var r3 = graphicsDevice.AllocateReadWriteBuffer(128); using var r4 = graphicsDevice.AllocateReadOnlyTexture2D(128, 128); using var r5 = graphicsDevice.AllocateReadWriteTexture2D(128, 128); + using var r6 = graphicsDevice.AllocateUploadBuffer(128); + using var r7 = graphicsDevice.AllocateReadBackBuffer(128); + using var r8 = graphicsDevice.AllocateUploadTexture2D(128, 128); + using var r9 = graphicsDevice.AllocateReadBackTexture2D(128, 128); InteropServices.GetID3D12Device(graphicsDevice, Windows.__uuidof(), (void**)d3D12Device.GetAddressOf()); } diff --git a/tests/ComputeSharp.Tests.DeviceLost/GetDefaultDeviceTests.cs b/tests/ComputeSharp.Tests.DeviceLost/GetDefaultDeviceTests.cs index b5ae5c3f..be8c93b5 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/GetDefaultDeviceTests.cs +++ b/tests/ComputeSharp.Tests.DeviceLost/GetDefaultDeviceTests.cs @@ -73,4 +73,47 @@ public class GetDefaultDeviceTests GetDefault_VerifyContract_Part2(); } + + [TestMethod] + public unsafe void GetDefault_DisposeAndUseNewInstance() + { + using (ComPtr d3D12Device = default) + { + GraphicsDevice device = GraphicsDevice.GetDefault(); + + using (device.AllocateReadOnlyBuffer(128)) + { + } + + InteropServices.GetID3D12Device(device, Windows.__uuidof(), (void**)d3D12Device.GetAddressOf()); + + device.Dispose(); + + _ = d3D12Device.Get()->AddRef(); + + uint refCount = d3D12Device.Get()->Release(); + + Assert.AreEqual(refCount, 1u); + } + + // Just same test but twice, just for good measure + using (ComPtr d3D12Device = default) + { + GraphicsDevice device = GraphicsDevice.GetDefault(); + + using (device.AllocateReadOnlyBuffer(128)) + { + } + + InteropServices.GetID3D12Device(device, Windows.__uuidof(), (void**)d3D12Device.GetAddressOf()); + + device.Dispose(); + + _ = d3D12Device.Get()->AddRef(); + + uint refCount = d3D12Device.Get()->Release(); + + Assert.AreEqual(refCount, 1u); + } + } } diff --git a/tests/ComputeSharp.Tests/BufferTests.cs b/tests/ComputeSharp.Tests/BufferTests.cs index 39370cfc..4e468e16 100644 --- a/tests/ComputeSharp.Tests/BufferTests.cs +++ b/tests/ComputeSharp.Tests/BufferTests.cs @@ -124,33 +124,6 @@ public partial class BufferTests _ = 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 => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(), - Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(), - _ => throw new ArgumentException(nameof(device)) - }; - - if (gpu is null) - { - Assert.Inconclusive(); - - return; - } - - Buffer buffer = gpu.AllocateBuffer(bufferType, 128); - - gpu.Dispose(); - buffer.Dispose(); - } - [CombinatorialTestMethod] [AllDevices] [Resource(typeof(ConstantBuffer<>))] diff --git a/tests/ComputeSharp.Tests/InitializationTests.cs b/tests/ComputeSharp.Tests/InitializationTests.cs index 0b5f1496..3609519c 100644 --- a/tests/ComputeSharp.Tests/InitializationTests.cs +++ b/tests/ComputeSharp.Tests/InitializationTests.cs @@ -28,16 +28,6 @@ public partial class InitializationTests Assert.IsTrue(gpu.WavefrontSize != 0); } - [TestMethod] - public void DisposeDefault() - { - using var before = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(128); - - GraphicsDevice.GetDefault().Dispose(); - - using var after = GraphicsDevice.GetDefault().AllocateReadOnlyBuffer(128); - } - [TestMethod] public void EnumerateDevices() { diff --git a/tests/ComputeSharp.Tests/Texture2DTests.cs b/tests/ComputeSharp.Tests/Texture2DTests.cs index 32d782f7..a72642a4 100644 --- a/tests/ComputeSharp.Tests/Texture2DTests.cs +++ b/tests/ComputeSharp.Tests/Texture2DTests.cs @@ -86,32 +86,6 @@ public partial class Texture2DTests _ = texture.ToArray(); } - [CombinatorialTestMethod] - [AllDevices] - [Resource(typeof(ReadOnlyTexture2D<>))] - [Resource(typeof(ReadWriteTexture2D<>))] - public void DisposeAfterDevice(Device device, Type textureType) - { - GraphicsDevice? gpu = device switch - { - Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(), - Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(), - _ => throw new ArgumentException(nameof(device)) - }; - - if (gpu is null) - { - Assert.Inconclusive(); - - return; - } - - Texture2D texture = gpu.AllocateTexture2D(textureType, 10, 10); - - gpu.Dispose(); - texture.Dispose(); - } - [CombinatorialTestMethod] [AllDevices] [Resource(typeof(ReadOnlyTexture2D<>))] diff --git a/tests/ComputeSharp.Tests/Texture3DTests.cs b/tests/ComputeSharp.Tests/Texture3DTests.cs index c05252bc..80dbcdbe 100644 --- a/tests/ComputeSharp.Tests/Texture3DTests.cs +++ b/tests/ComputeSharp.Tests/Texture3DTests.cs @@ -105,32 +105,6 @@ public partial class Texture3DTests _ = texture.ToArray(); } - [CombinatorialTestMethod] - [AllDevices] - [Resource(typeof(ReadOnlyTexture3D<>))] - [Resource(typeof(ReadWriteTexture3D<>))] - public void DisposeAfterDevice(Device device, Type textureType) - { - GraphicsDevice? gpu = device switch - { - Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(), - Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(), - _ => throw new ArgumentException(nameof(device)) - }; - - if (gpu is null) - { - Assert.Inconclusive(); - - return; - } - - Texture3D texture = gpu.AllocateTexture3D(textureType, 10, 10, 4); - - gpu.Dispose(); - texture.Dispose(); - } - [CombinatorialTestMethod] [AllDevices] [Resource(typeof(ReadOnlyTexture3D<>))] diff --git a/tests/ComputeSharp.Tests/TransferBufferTests.cs b/tests/ComputeSharp.Tests/TransferBufferTests.cs index 9d454bb4..62900553 100644 --- a/tests/ComputeSharp.Tests/TransferBufferTests.cs +++ b/tests/ComputeSharp.Tests/TransferBufferTests.cs @@ -66,32 +66,6 @@ public partial class TransferBufferTests _ = buffer.Span; } - [CombinatorialTestMethod] - [AllDevices] - [Resource(typeof(UploadBuffer<>))] - [Resource(typeof(ReadBackBuffer<>))] - public void DisposeAfterDevice(Device device, Type bufferType) - { - GraphicsDevice? gpu = device switch - { - Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(), - Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(), - _ => throw new ArgumentException(nameof(device)) - }; - - if (gpu is null) - { - Assert.Inconclusive(); - - return; - } - - TransferBuffer buffer = gpu.AllocateTransferBuffer(bufferType, 128); - - gpu.Dispose(); - buffer.Dispose(); - } - [CombinatorialTestMethod] [AllDevices] public void Allocate_UploadBuffer_CopyTo_Full(Device device) diff --git a/tests/ComputeSharp.Tests/TransferTexture2DTests.cs b/tests/ComputeSharp.Tests/TransferTexture2DTests.cs index 9b4de975..82fe3d4d 100644 --- a/tests/ComputeSharp.Tests/TransferTexture2DTests.cs +++ b/tests/ComputeSharp.Tests/TransferTexture2DTests.cs @@ -70,32 +70,6 @@ public partial class TransferTexture2DTests _ = texture.View; } - [CombinatorialTestMethod] - [AllDevices] - [Resource(typeof(UploadTexture2D<>))] - [Resource(typeof(ReadBackTexture2D<>))] - public void DisposeAfterDevice(Device device, Type textureType) - { - GraphicsDevice? gpu = device switch - { - Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(), - Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(), - _ => throw new ArgumentException(nameof(device)) - }; - - if (gpu is null) - { - Assert.Inconclusive(); - - return; - } - - TransferTexture2D texture = gpu.AllocateTransferTexture2D(textureType, 32, 32); - - gpu.Dispose(); - texture.Dispose(); - } - [CombinatorialTestMethod] [AllDevices] public unsafe void Allocate_UploadTexture2D_Copy_Full(Device device) diff --git a/tests/ComputeSharp.Tests/TransferTexture3DTests.cs b/tests/ComputeSharp.Tests/TransferTexture3DTests.cs index ca13f03b..54c0fa53 100644 --- a/tests/ComputeSharp.Tests/TransferTexture3DTests.cs +++ b/tests/ComputeSharp.Tests/TransferTexture3DTests.cs @@ -77,32 +77,6 @@ public partial class TransferTexture3DTests _ = texture.View; } - [CombinatorialTestMethod] - [AllDevices] - [Resource(typeof(UploadTexture3D<>))] - [Resource(typeof(ReadBackTexture3D<>))] - public void DisposeAfterDevice(Device device, Type textureType) - { - GraphicsDevice? gpu = device switch - { - Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(), - Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(), - _ => throw new ArgumentException(nameof(device)) - }; - - if (gpu is null) - { - Assert.Inconclusive(); - - return; - } - - TransferTexture3D texture = gpu.AllocateTransferTexture3D(textureType, 32, 32, 16); - - gpu.Dispose(); - texture.Dispose(); - } - [CombinatorialTestMethod] [AllDevices] public unsafe void Allocate_UploadTexture3D_Copy_Full(Device device)