Skip to content

Commit

Permalink
Switch InteropServicesTests to Vortice.Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jan 14, 2023
1 parent 6037fd9 commit c3dfecf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
11 changes: 1 addition & 10 deletions tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="Vortice.Win32.Graphics.Direct3D12" Version="1.9.13" />
</ItemGroup>

<ItemGroup>
Expand All @@ -28,18 +29,8 @@
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<!-- When the .NET Standard 2.0 version of ComputeSharp is resolved, the TerraFX APIs are internal, as they
are referenced from the shared project. The same reference is needed here to make all tests build fine. -->
<Import Condition="'$(TargetFramework)' != 'net6.0' AND '$(TargetFramework)' != 'net7.0'" Project="..\..\src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems" />
<Import Condition="'$(TargetFramework)' != 'net6.0' AND '$(TargetFramework)' != 'net7.0'" Project="..\..\src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems" />

<Import Project="..\..\samples\ComputeSharp.SwapChain.Shaders.Shared\ComputeSharp.SwapChain.Shaders.Shared.projitems" Label="Shared" />

<!-- Only when the local TerraFX is referenced, ignore warnings from there -->
<PropertyGroup Condition="'$(TargetFramework)' != 'net6.0' AND '$(TargetFramework)' != 'net7.0'">
<NoWarn>$(NoWarn);CS0649</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Primitives\Complex64.cs" Link="Imaging\Primitives\Complex64.cs" />
<Compile Include="..\..\samples\ComputeSharp.ImageProcessing\Primitives\ComplexVector4.cs" Link="Imaging\Primitives\ComplexVector4.cs" />
Expand Down
78 changes: 42 additions & 36 deletions tests/ComputeSharp.Tests/InteropServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
using ComputeSharp.Tests.Attributes;
using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
using static TerraFX.Interop.DirectX.D3D12_RESOURCE_DIMENSION;
using Win32;
using Win32.Graphics.Direct3D12;

#pragma warning disable IDE0065

namespace ComputeSharp.Tests;

using D3D12_RESOURCE_DIMENSION = Win32.Graphics.Direct3D12.ResourceDimension;
using HRESULT = Win32.HResult;
using LUID = Win32.Luid;
using Win32 = Win32.Apis;

[TestClass]
[TestCategory("InteropServices")]
public unsafe partial class InteropServicesTests
Expand All @@ -20,7 +26,7 @@ public void GetDevice(Device device)
{
using ComPtr<ID3D12Device> d3D12Device = default;

InteropServices.GetID3D12Device(device.Get(), Windows.__uuidof<ID3D12Device>(), (void**)d3D12Device.GetAddressOf());
InteropServices.GetID3D12Device(device.Get(), Win32.__uuidof<ID3D12Device>(), (void**)d3D12Device.GetAddressOf());

Assert.IsTrue(d3D12Device.Get() != null);

Expand All @@ -30,9 +36,9 @@ public void GetDevice(Device device)

d3D12Device.Dispose();

int hResult = InteropServices.TryGetID3D12Device(device.Get(), Windows.__uuidof<ID3D12Device>(), (void**)d3D12Device.GetAddressOf());
int hResult = InteropServices.TryGetID3D12Device(device.Get(), Win32.__uuidof<ID3D12Device>(), (void**)d3D12Device.GetAddressOf());

Assert.AreEqual(hResult, S.S_OK);
Assert.AreEqual(hResult, (int)HRESULT.Ok);
Assert.IsTrue(d3D12Device.Get() != null);

luid = d3D12Device.Get()->GetAdapterLuid();
Expand All @@ -51,18 +57,18 @@ public void ResourceFromBuffer(Device device, Type bufferType)

using ComPtr<ID3D12Resource> d3D12Resource = default;

InteropServices.GetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
InteropServices.GetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);

d3D12Resource.Dispose();

int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
int hResult = InteropServices.TryGetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.AreEqual(hResult, S.S_OK);
Assert.AreEqual(hResult, (int)HRESULT.Ok);
Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);
}

[CombinatorialTestMethod]
Expand All @@ -75,18 +81,18 @@ public void ResourceFromTexture2D(Device device, Type bufferType)

using ComPtr<ID3D12Resource> d3D12Resource = default;

InteropServices.GetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
InteropServices.GetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE2D);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Texture2D);

d3D12Resource.Dispose();

int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
int hResult = InteropServices.TryGetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.AreEqual(hResult, S.S_OK);
Assert.AreEqual(hResult, (int)HRESULT.Ok);
Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE2D);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Texture2D);
}

[CombinatorialTestMethod]
Expand All @@ -99,18 +105,18 @@ public void ResourceFromTexture3D(Device device, Type bufferType)

using ComPtr<ID3D12Resource> d3D12Resource = default;

InteropServices.GetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
InteropServices.GetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE3D);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Texture3D);

d3D12Resource.Dispose();

int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
int hResult = InteropServices.TryGetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.AreEqual(hResult, S.S_OK);
Assert.AreEqual(hResult, (int)HRESULT.Ok);
Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_TEXTURE3D);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Texture3D);
}

[CombinatorialTestMethod]
Expand All @@ -123,18 +129,18 @@ public void ResourceFromTransferBuffer(Device device, Type bufferType)

using ComPtr<ID3D12Resource> d3D12Resource = default;

InteropServices.GetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
InteropServices.GetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);

d3D12Resource.Dispose();

int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
int hResult = InteropServices.TryGetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.AreEqual(hResult, S.S_OK);
Assert.AreEqual(hResult, (int)HRESULT.Ok);
Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);
}

[CombinatorialTestMethod]
Expand All @@ -147,18 +153,18 @@ public void ResourceFromTransferTexture2D(Device device, Type bufferType)

using ComPtr<ID3D12Resource> d3D12Resource = default;

InteropServices.GetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
InteropServices.GetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);

d3D12Resource.Dispose();

int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
int hResult = InteropServices.TryGetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.AreEqual(hResult, S.S_OK);
Assert.AreEqual(hResult, (int)HRESULT.Ok);
Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);
}

[CombinatorialTestMethod]
Expand All @@ -171,17 +177,17 @@ public void ResourceFromTransferTexture3D(Device device, Type bufferType)

using ComPtr<ID3D12Resource> d3D12Resource = default;

InteropServices.GetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
InteropServices.GetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);

d3D12Resource.Dispose();

int hResult = InteropServices.TryGetID3D12Resource(buffer, Windows.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());
int hResult = InteropServices.TryGetID3D12Resource(buffer, Win32.__uuidof<ID3D12Resource>(), (void**)d3D12Resource.GetAddressOf());

Assert.AreEqual(hResult, S.S_OK);
Assert.AreEqual(hResult, (int)HRESULT.Ok);
Assert.IsTrue(d3D12Resource.Get() != null);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION_BUFFER);
Assert.AreEqual(d3D12Resource.Get()->GetDesc().Dimension, D3D12_RESOURCE_DIMENSION.Buffer);
}
}

0 comments on commit c3dfecf

Please sign in to comment.