-
Notifications
You must be signed in to change notification settings - Fork 524
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46a6728
commit 6cf79ea
Showing
10 changed files
with
341 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using Vortice.Direct3D12; | ||
using Vortice.DXGI; | ||
|
||
namespace SkiaSharp.Tests | ||
{ | ||
public class Direct3DContext : IDisposable | ||
{ | ||
public virtual IDXGIAdapter1 Adapter { get; protected set; } | ||
|
||
public virtual ID3D12Device Device { get; protected set; } | ||
|
||
public virtual ID3D12CommandQueue Queue { get; protected set; } | ||
|
||
public virtual void Dispose() | ||
{ | ||
Queue.Dispose(); | ||
Device.Dispose(); | ||
Adapter.Dispose(); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Direct3DTests/Direct3DContexts/Win32/Win32Direct3DContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Vortice.Direct3D; | ||
using Vortice.Direct3D12; | ||
using Vortice.DXGI; | ||
|
||
namespace SkiaSharp.Tests; | ||
|
||
public class Win32Direct3DContext : Direct3DContext | ||
{ | ||
public Win32Direct3DContext() | ||
{ | ||
// Create the device | ||
var factory = DXGI.CreateDXGIFactory1<IDXGIFactory4>(); | ||
Adapter = GetHardwareAdapter(factory); | ||
Device = D3D12.D3D12CreateDevice<ID3D12Device>(Adapter, FeatureLevel.Level_11_0); | ||
|
||
// Create the command queue | ||
var queueDesc = new CommandQueueDescription(CommandListType.Direct); | ||
Queue = Device.CreateCommandQueue(queueDesc); | ||
} | ||
|
||
private static IDXGIAdapter1 GetHardwareAdapter(IDXGIFactory4 pFactory) | ||
{ | ||
for (var adapterIndex = 0; ; adapterIndex++) | ||
{ | ||
// No more adapters to enumerate. | ||
if (pFactory.EnumAdapters1(adapterIndex, out var pAdapter).Failure) | ||
break; | ||
|
||
// Check to see if the adapter supports Direct3D 12. | ||
if (D3D12.IsSupported(pAdapter, FeatureLevel.Level_11_0)) | ||
return pAdapter; | ||
|
||
pAdapter.Release(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using SkiaSharp.Tests; | ||
using Xunit; | ||
|
||
namespace SkiaSharp.Direct3D.Tests | ||
{ | ||
public class Direct3DTest : SKTest | ||
{ | ||
protected Direct3DContext CreateDirect3DContext() | ||
{ | ||
try | ||
{ | ||
if (!IsWindows) | ||
throw new PlatformNotSupportedException(); | ||
|
||
return new Win32Direct3DContext(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new SkipException($"Unable to create Direct3D context: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using Xunit; | ||
using SkiaSharp.Tests; | ||
|
||
namespace SkiaSharp.Direct3D.Tests; | ||
|
||
public class GRContextTest : Direct3DTest | ||
{ | ||
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)] | ||
[SkippableFact] | ||
public void CreateD3DContextIsValid() | ||
{ | ||
using var ctx = CreateDirect3DContext(); | ||
|
||
using var grD3DBackendContext = new GRDirect3DBackendContext | ||
{ | ||
Adapter = ctx.Adapter, | ||
Device = ctx.Device, | ||
Queue = ctx.Queue, | ||
ProtectedContext = false | ||
}; | ||
|
||
Assert.NotNull(grD3DBackendContext); | ||
|
||
using var grContext = GRContext.CreateDirect3D(grD3DBackendContext); | ||
|
||
Assert.NotNull(grContext); | ||
} | ||
|
||
[Trait(Traits.Category.Key, Traits.Category.Values.Gpu)] | ||
[SkippableFact] | ||
public void CreateVkContextWithOptionsIsValid() | ||
{ | ||
using var ctx = CreateDirect3DContext(); | ||
|
||
using var grD3DBackendContext = new GRDirect3DBackendContext | ||
{ | ||
Adapter = ctx.Adapter, | ||
Device = ctx.Device, | ||
Queue = ctx.Queue, | ||
ProtectedContext = false | ||
}; | ||
|
||
Assert.NotNull(grD3DBackendContext); | ||
|
||
var options = new GRContextOptions(); | ||
|
||
using var grContext = GRContext.CreateDirect3D(grD3DBackendContext, options); | ||
|
||
Assert.NotNull(grContext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// using Xunit; | ||
// using SkiaSharp.Tests; | ||
|
||
// namespace SkiaSharp.Direct3D.Tests | ||
// { | ||
// public class SharpVkBackendContextTest : Direct3DTest | ||
// { | ||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)] | ||
// [SkippableFact] | ||
// public void VkGpuSurfaceIsCreatedSharpVkTypes() | ||
// { | ||
// using var ctx = CreateVkContext(); | ||
// using var grVkBackendContext = new GRSharpVkBackendContext | ||
// { | ||
// VkInstance = ctx.Instance, | ||
// VkPhysicalDevice = ctx.PhysicalDevice, | ||
// VkDevice = ctx.Device, | ||
// VkQueue = ctx.GraphicsQueue, | ||
// GraphicsQueueIndex = ctx.GraphicsFamily, | ||
// GetProcedureAddress = ctx.SharpVkGetProc, | ||
// VkPhysicalDeviceFeatures = ctx.PhysicalDevice.GetFeatures(), | ||
// }; | ||
// Assert.NotNull(grVkBackendContext); | ||
|
||
// var baseType = grVkBackendContext as GRVkBackendContext; | ||
// Assert.NotNull(baseType); | ||
|
||
// Assert.Equal(ctx.Instance.RawHandle.ToUInt64(), (ulong)baseType.VkInstance); | ||
// Assert.Equal(ctx.PhysicalDevice.RawHandle.ToUInt64(), (ulong)baseType.VkPhysicalDevice); | ||
// Assert.Equal(ctx.Device.RawHandle.ToUInt64(), (ulong)baseType.VkDevice); | ||
// Assert.Equal(ctx.GraphicsQueue.RawHandle.ToUInt64(), (ulong)baseType.VkQueue); | ||
// Assert.NotEqual(0, (long)baseType.VkPhysicalDeviceFeatures); | ||
// } | ||
|
||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)] | ||
// [SkippableFact] | ||
// public void PropertyIsSetAndUnset() | ||
// { | ||
// using var grVkBackendContext = new GRSharpVkBackendContext(); | ||
// var baseType = grVkBackendContext as GRVkBackendContext; | ||
|
||
// Assert.Equal(0, (long)baseType.VkPhysicalDeviceFeatures); | ||
|
||
// grVkBackendContext.VkPhysicalDeviceFeatures = new global::SharpVk.PhysicalDeviceFeatures(); | ||
// Assert.NotEqual(0, (long)baseType.VkPhysicalDeviceFeatures); | ||
|
||
// grVkBackendContext.VkPhysicalDeviceFeatures = null; | ||
// Assert.Equal(0, (long)baseType.VkPhysicalDeviceFeatures); | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// using System; | ||
// using Xunit; | ||
// using SkiaSharp.Tests; | ||
|
||
// namespace SkiaSharp.Direct3D.Tests | ||
// { | ||
// public class SKSurfaceTest : Direct3DTest | ||
// { | ||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)] | ||
// [SkippableFact] | ||
// public void VkGpuSurfaceIsCreated() | ||
// { | ||
// using var ctx = CreateVkContext(); | ||
|
||
// using var grVkBackendContext = new GRVkBackendContext | ||
// { | ||
// VkInstance = (IntPtr)ctx.Instance.RawHandle.ToUInt64(), | ||
// VkPhysicalDevice = (IntPtr)ctx.PhysicalDevice.RawHandle.ToUInt64(), | ||
// VkDevice = (IntPtr)ctx.Device.RawHandle.ToUInt64(), | ||
// VkQueue = (IntPtr)ctx.GraphicsQueue.RawHandle.ToUInt64(), | ||
// GraphicsQueueIndex = ctx.GraphicsFamily, | ||
// GetProcedureAddress = ctx.GetProc | ||
// }; | ||
|
||
// Assert.NotNull(grVkBackendContext); | ||
|
||
// using var grContext = GRContext.CreateVulkan(grVkBackendContext); | ||
|
||
// using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100)); | ||
|
||
// Assert.NotNull(surface); | ||
|
||
// var canvas = surface.Canvas; | ||
// Assert.NotNull(canvas); | ||
|
||
// canvas.Clear(SKColors.Transparent); | ||
|
||
// canvas.Flush(); | ||
// } | ||
|
||
// [Trait(Traits.Category.Key, Traits.Category.Values.Gpu)] | ||
// [SkippableFact] | ||
// public void VkGpuSurfaceIsCreatedSharpVkTypes() | ||
// { | ||
// using var ctx = CreateVkContext(); | ||
|
||
// using var grVkBackendContext = new GRSharpVkBackendContext | ||
// { | ||
// VkInstance = ctx.Instance, | ||
// VkPhysicalDevice = ctx.PhysicalDevice, | ||
// VkDevice = ctx.Device, | ||
// VkQueue = ctx.GraphicsQueue, | ||
// GraphicsQueueIndex = ctx.GraphicsFamily, | ||
// GetProcedureAddress = ctx.SharpVkGetProc | ||
// }; | ||
|
||
// Assert.NotNull(grVkBackendContext); | ||
|
||
// using var grContext = GRContext.CreateVulkan(grVkBackendContext); | ||
|
||
// using var surface = SKSurface.Create(grContext, true, new SKImageInfo(100, 100)); | ||
|
||
// Assert.NotNull(surface); | ||
|
||
// var canvas = surface.Canvas; | ||
// Assert.NotNull(canvas); | ||
|
||
// canvas.Clear(SKColors.Transparent); | ||
|
||
// canvas.Flush(); | ||
// } | ||
// } | ||
// } |
44 changes: 44 additions & 0 deletions
44
tests/SkiaSharp.Direct3D.Tests.Console/SkiaSharp.Direct3D.Tests.Console.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net7.0</TargetFrameworks> | ||
<RootNamespace>SkiaSharp.Direct3D.Tests</RootNamespace> | ||
<AssemblyName>SkiaSharp.Direct3D.Tests</AssemblyName> | ||
<SignAssembly>false</SignAssembly> | ||
<SkipGenerateAssemblyVersionInfo>true</SkipGenerateAssemblyVersionInfo> | ||
<SkipMDocGenerateDocs>true</SkipMDocGenerateDocs> | ||
<Platforms>AnyCPU;x64;x86</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" /> | ||
<PackageReference Include="XunitXml.TestLogger" Version="3.0.78" /> | ||
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" /> | ||
<PackageReference Include="Vortice.Direct3D12" Version="3.5.0" /> | ||
<PackageReference Include="coverlet.msbuild" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\binding\HarfBuzzSharp\HarfBuzzSharp.csproj" /> | ||
<ProjectReference Include="..\..\binding\SkiaSharp\SkiaSharp.csproj" /> | ||
<ProjectReference Include="..\..\binding\SkiaSharp.SceneGraph\SkiaSharp.SceneGraph.csproj" /> | ||
<ProjectReference Include="..\..\binding\SkiaSharp.Skottie\SkiaSharp.Skottie.csproj" /> | ||
<ProjectReference Include="..\..\source\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz\SkiaSharp.HarfBuzz.csproj" /> | ||
<ProjectReference Include="..\..\source\SkiaSharp.Direct3D\SkiaSharp.Direct3D.Vortice\SkiaSharp.Direct3D.Vortice.csproj" /> | ||
<ProjectReference Include="..\SkiaSharp.Tests.Console\SkiaSharp.Tests.Console.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="..\Direct3DTests\**\*.cs" Link="%(RecursiveDir)%(FileName)%(Extension)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="..\Content\**\*" Link="%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="Always" /> | ||
</ItemGroup> | ||
|
||
<Import Project="..\..\binding\IncludeNativeAssets.SkiaSharp.targets" /> | ||
<Import Project="..\..\binding\IncludeNativeAssets.HarfBuzzSharp.targets" /> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters