Enable unit tests for D3D12MA support

このコミットが含まれているのは:
Sergio Pedri committed 2023-07-01 21:26:21 +02:00
1 親 00b841b33e
コミット a7c497322e
5ファイル変更
+107

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

+6
ファイルの表示
@@ -4,6 +4,11 @@
<Platforms>AnyCPU;x64;ARM64</Platforms>
</PropertyGroup>
<!-- Add a defined constant for D3D12MA, same as in the main test project -->
<PropertyGroup Condition="'$(UseD3D12MemoryAllocator)' == 'true'">
<DefineConstants>$(DefineConstants);USE_D3D12MA</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
@@ -16,6 +21,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D3D12MemoryAllocator\ComputeSharp.D3D12MemoryAllocator.csproj" Condition="'$(TargetFramework)' != 'net472'" />
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
</ItemGroup>
+12
ファイルの表示
@@ -1,4 +1,7 @@
using System;
#if USE_D3D12MA
using ComputeSharp.D3D12MemoryAllocator;
#endif
using ComputeSharp.Interop;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.DeviceLost.Helpers;
@@ -15,6 +18,15 @@ using Win32 = Win32.Apis;
[TestCategory("DeviceDisposal")]
public partial class DeviceDisposalTests
{
[AssemblyInitialize]
public static void ConfigureImageSharp(TestContext _)
{
#if USE_D3D12MA
// If requested by the test runner, configure D3D12MA
AllocationServices.ConfigureAllocatorFactory(new D3D12MemoryAllocatorFactory());
#endif
}
[TestMethod]
public void DeviceDisposal_GetDefault_ReferenceCounting()
{
+74
ファイルの表示
@@ -0,0 +1,74 @@
#if NET6_0_OR_GREATER
using System;
using System.Runtime.InteropServices;
using ComputeSharp.D3D12MemoryAllocator;
using ComputeSharp.Interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Win32;
namespace ComputeSharp.Tests;
[TestClass]
[TestCategory("AllocationServices")]
public class AllocationServicesTests
{
[TestMethod]
public unsafe void ConfigureAllocationFactory_CorrectLogic()
{
#if !USE_D3D12MA
// Ensure a device has been created already (if D3D12MA is set, this isn't needed, because
// the global assembly initializer will have always configured D3D12MA for the process).
_ = GraphicsDevice.GetDefault();
#endif
D3D12MemoryAllocatorFactory allocatorFactory = new();
Guid uuidOfID3D12MemoryAllocatorFactory = new("CC1E74A7-786D-40F4-8AE2-F8B7A255587E");
using ComPtr<IUnknown> d3D12MemoryAllocatorFactory = default;
CustomQueryInterfaceResult result = ((ICustomQueryInterface)allocatorFactory).GetInterface(
iid: ref uuidOfID3D12MemoryAllocatorFactory,
ppv: out *(IntPtr*)d3D12MemoryAllocatorFactory.GetAddressOf());
Assert.AreEqual(CustomQueryInterfaceResult.Handled, result);
Assert.IsTrue(d3D12MemoryAllocatorFactory.Get() is not null);
_ = d3D12MemoryAllocatorFactory.Get()->AddRef();
uint referenceCount = d3D12MemoryAllocatorFactory.Get()->Release();
// There's two references: one from the managed object, one from the local ComPtr<T>
Assert.AreEqual(2u, referenceCount);
try
{
// Try to configure the allocator (this should fail)
AllocationServices.ConfigureAllocatorFactory(allocatorFactory);
}
catch (InvalidOperationException)
{
// This is expected
}
catch
{
Assert.Fail();
}
_ = d3D12MemoryAllocatorFactory.Get()->AddRef();
referenceCount = d3D12MemoryAllocatorFactory.Get()->Release();
// No additional references should've been added
Assert.AreEqual(2u, referenceCount);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ConfigureAllocationFactory_ValidatesArgument()
{
AllocationServices.ConfigureAllocatorFactory(null!);
}
}
#endif
+6
ファイルの表示
@@ -4,6 +4,11 @@
<Platforms>AnyCPU;x64;ARM64</Platforms>
</PropertyGroup>
<!-- Add a defined constant to selectively enable D3D12MA in unit tests -->
<PropertyGroup Condition="'$(UseD3D12MemoryAllocator)' == 'true'">
<DefineConstants>$(DefineConstants);USE_D3D12MA</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Diagnostics" Version="8.2.0" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.2.0" />
@@ -17,6 +22,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ComputeSharp.Core\ComputeSharp.Core.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.Core.SourceGenerators\ComputeSharp.Core.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
<ProjectReference Include="..\..\src\ComputeSharp.D3D12MemoryAllocator\ComputeSharp.D3D12MemoryAllocator.csproj" Condition="'$(TargetFramework)' != 'net472'" />
<ProjectReference Include="..\..\src\ComputeSharp\ComputeSharp.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.Dynamic\ComputeSharp.Dynamic.csproj" />
<ProjectReference Include="..\..\src\ComputeSharp.SourceGenerators\ComputeSharp.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="contentfiles;build" />
+9
ファイルの表示
@@ -3,6 +3,10 @@ using System.Buffers;
using System.IO;
using System.Reflection;
using CommunityToolkit.HighPerformance.Buffers;
#if USE_D3D12MA
using ComputeSharp.D3D12MemoryAllocator;
using ComputeSharp.Interop;
#endif
using ComputeSharp.Resources;
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
@@ -23,6 +27,11 @@ public class ImagingTests
public static void ConfigureImageSharp(TestContext _)
{
Configuration.Default.PreferContiguousImageBuffers = true;
#if USE_D3D12MA
// If requested by the test runner, configure D3D12MA
AllocationServices.ConfigureAllocatorFactory(new D3D12MemoryAllocatorFactory());
#endif
}
[CombinatorialTestMethod]