-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile Skia with Direct3D on Windows platform #2823
Open
Kation
wants to merge
17
commits into
mono:main
Choose a base branch
from
Kation:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ecf95b9
Compile Direct3D on Windows platform
Kation 026b206
Add Direct3D backend api
Kation 7dd993f
Merge branch 'main' into main
Kation 87b79bb
Fix sln
Kation 2ebd251
optimize
Kation a90e507
commit missing files
Kation c64cf23
ToNative
Kation 0b288cf
fix wrapper
Kation a9bec2a
vortice warpper
Kation bc15a0a
Merge branch 'main' into main
Kation 46a6728
Merge branch 'main' into main
Kation 84ed398
Merge branch 'main' into main
Kation 3c5a560
Add Direct3D test
Kation 46d36cb
Merge branch 'main' of https://github.com/Kation/SkiaSharp
Kation 938a3eb
Merge branch 'main' into main
Kation aba0b43
Merge branch 'main' into pr/2823
mattleibow ace9824
update externals
mattleibow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
#region Namespaces | ||
|
@@ -8,6 +8,12 @@ | |
|
||
#region Class declarations | ||
|
||
using d3d_alloc_t = System.IntPtr; | ||
using d3d_d12_command_queue_t = System.IntPtr; | ||
using d3d_d12_device_t = System.IntPtr; | ||
using d3d_d12_resource_t = System.IntPtr; | ||
using d3d_dxgi_adapter_t = System.IntPtr; | ||
using d3d_memory_allocator_t = System.IntPtr; | ||
using gr_backendrendertarget_t = System.IntPtr; | ||
using gr_backendtexture_t = System.IntPtr; | ||
using gr_direct_context_t = System.IntPtr; | ||
|
@@ -222,6 +228,20 @@ internal static bool gr_backendrendertarget_is_valid (gr_backendrendertarget_t r | |
(gr_backendrendertarget_is_valid_delegate ??= GetSymbol<Delegates.gr_backendrendertarget_is_valid> ("gr_backendrendertarget_is_valid")).Invoke (rendertarget); | ||
#endif | ||
|
||
// gr_backendrendertarget_t* gr_backendrendertarget_new_direct3d(int width, int height, const gr_d3d_textureinfo_t* d3dInfo) | ||
#if !USE_DELEGATES | ||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] | ||
internal static extern gr_backendrendertarget_t gr_backendrendertarget_new_direct3d (Int32 width, Int32 height, GRD3dTextureinfo* d3dInfo); | ||
#else | ||
private partial class Delegates { | ||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)] | ||
internal delegate gr_backendrendertarget_t gr_backendrendertarget_new_direct3d (Int32 width, Int32 height, GRD3dTextureinfo* d3dInfo); | ||
} | ||
private static Delegates.gr_backendrendertarget_new_direct3d gr_backendrendertarget_new_direct3d_delegate; | ||
internal static gr_backendrendertarget_t gr_backendrendertarget_new_direct3d (Int32 width, Int32 height, GRD3dTextureinfo* d3dInfo) => | ||
(gr_backendrendertarget_new_direct3d_delegate ??= GetSymbol<Delegates.gr_backendrendertarget_new_direct3d> ("gr_backendrendertarget_new_direct3d")).Invoke (width, height, d3dInfo); | ||
#endif | ||
|
||
// gr_backendrendertarget_t* gr_backendrendertarget_new_gl(int width, int height, int samples, int stencils, const gr_gl_framebufferinfo_t* glInfo) | ||
#if !USE_DELEGATES | ||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] | ||
|
@@ -368,6 +388,20 @@ internal static bool gr_backendtexture_is_valid (gr_backendtexture_t texture) => | |
(gr_backendtexture_is_valid_delegate ??= GetSymbol<Delegates.gr_backendtexture_is_valid> ("gr_backendtexture_is_valid")).Invoke (texture); | ||
#endif | ||
|
||
// gr_backendtexture_t* gr_backendtexture_new_direct3d(int width, int height, const gr_d3d_textureinfo_t* d3dInfo) | ||
#if !USE_DELEGATES | ||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] | ||
internal static extern gr_backendtexture_t gr_backendtexture_new_direct3d (Int32 width, Int32 height, GRD3dTextureinfo* d3dInfo); | ||
#else | ||
private partial class Delegates { | ||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)] | ||
internal delegate gr_backendtexture_t gr_backendtexture_new_direct3d (Int32 width, Int32 height, GRD3dTextureinfo* d3dInfo); | ||
} | ||
private static Delegates.gr_backendtexture_new_direct3d gr_backendtexture_new_direct3d_delegate; | ||
internal static gr_backendtexture_t gr_backendtexture_new_direct3d (Int32 width, Int32 height, GRD3dTextureinfo* d3dInfo) => | ||
(gr_backendtexture_new_direct3d_delegate ??= GetSymbol<Delegates.gr_backendtexture_new_direct3d> ("gr_backendtexture_new_direct3d")).Invoke (width, height, d3dInfo); | ||
#endif | ||
|
||
// gr_backendtexture_t* gr_backendtexture_new_gl(int width, int height, bool mipmapped, const gr_gl_textureinfo_t* glInfo) | ||
#if !USE_DELEGATES | ||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] | ||
|
@@ -524,6 +558,34 @@ internal static bool gr_direct_context_is_abandoned (gr_direct_context_t context | |
(gr_direct_context_is_abandoned_delegate ??= GetSymbol<Delegates.gr_direct_context_is_abandoned> ("gr_direct_context_is_abandoned")).Invoke (context); | ||
#endif | ||
|
||
// gr_direct_context_t* gr_direct_context_make_direct3d(const gr_d3d_backendcontext_t d3dBackendContext) | ||
#if !USE_DELEGATES | ||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] | ||
internal static extern gr_direct_context_t gr_direct_context_make_direct3d (GRD3dBackendcontext d3dBackendContext); | ||
#else | ||
private partial class Delegates { | ||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)] | ||
internal delegate gr_direct_context_t gr_direct_context_make_direct3d (GRD3dBackendcontext d3dBackendContext); | ||
} | ||
private static Delegates.gr_direct_context_make_direct3d gr_direct_context_make_direct3d_delegate; | ||
internal static gr_direct_context_t gr_direct_context_make_direct3d (GRD3dBackendcontext d3dBackendContext) => | ||
(gr_direct_context_make_direct3d_delegate ??= GetSymbol<Delegates.gr_direct_context_make_direct3d> ("gr_direct_context_make_direct3d")).Invoke (d3dBackendContext); | ||
#endif | ||
|
||
// gr_direct_context_t* gr_direct_context_make_direct3d_with_options(const gr_d3d_backendcontext_t d3dBackendContext, const gr_context_options_t* options) | ||
#if !USE_DELEGATES | ||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] | ||
internal static extern gr_direct_context_t gr_direct_context_make_direct3d_with_options (GRD3dBackendcontext d3dBackendContext, GRContextOptionsNative* options); | ||
#else | ||
private partial class Delegates { | ||
[UnmanagedFunctionPointer (CallingConvention.Cdecl)] | ||
internal delegate gr_direct_context_t gr_direct_context_make_direct3d_with_options (GRD3dBackendcontext d3dBackendContext, GRContextOptionsNative* options); | ||
} | ||
private static Delegates.gr_direct_context_make_direct3d_with_options gr_direct_context_make_direct3d_with_options_delegate; | ||
internal static gr_direct_context_t gr_direct_context_make_direct3d_with_options (GRD3dBackendcontext d3dBackendContext, GRContextOptionsNative* options) => | ||
(gr_direct_context_make_direct3d_with_options_delegate ??= GetSymbol<Delegates.gr_direct_context_make_direct3d_with_options> ("gr_direct_context_make_direct3d_with_options")).Invoke (d3dBackendContext, options); | ||
#endif | ||
|
||
// gr_direct_context_t* gr_direct_context_make_gl(const gr_glinterface_t* glInterface) | ||
#if !USE_DELEGATES | ||
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] | ||
|
@@ -12638,6 +12700,156 @@ public readonly override int GetHashCode () | |
|
||
} | ||
|
||
// gr_d3d_backendcontext_t | ||
[StructLayout (LayoutKind.Sequential)] | ||
public unsafe partial struct GRD3dBackendcontext : IEquatable<GRD3dBackendcontext> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note about the names of the 2 new types - the info and context need to start with an uppercase letter. I added a comment on how to do this in the json mapper file here: mono/skia#121 (review) |
||
// public d3d_dxgi_adapter_t* fAdapter | ||
private d3d_dxgi_adapter_t fAdapter; | ||
public d3d_dxgi_adapter_t Adapter { | ||
readonly get => fAdapter; | ||
set => fAdapter = value; | ||
} | ||
|
||
// public d3d_d12_device_t* fDevice | ||
private d3d_d12_device_t fDevice; | ||
public d3d_d12_device_t Device { | ||
readonly get => fDevice; | ||
set => fDevice = value; | ||
} | ||
|
||
// public d3d_d12_command_queue_t* fQueue | ||
private d3d_d12_command_queue_t fQueue; | ||
public d3d_d12_command_queue_t Queue { | ||
readonly get => fQueue; | ||
set => fQueue = value; | ||
} | ||
|
||
// public d3d_memory_allocator_t* fMemoryAllocator | ||
private d3d_memory_allocator_t fMemoryAllocator; | ||
public d3d_memory_allocator_t MemoryAllocator { | ||
readonly get => fMemoryAllocator; | ||
set => fMemoryAllocator = value; | ||
} | ||
|
||
// public bool fProtectedContext | ||
private Byte fProtectedContext; | ||
public bool ProtectedContext { | ||
readonly get => fProtectedContext > 0; | ||
set => fProtectedContext = value ? (byte)1 : (byte)0; | ||
} | ||
|
||
public readonly bool Equals (GRD3dBackendcontext obj) => | ||
fAdapter == obj.fAdapter && fDevice == obj.fDevice && fQueue == obj.fQueue && fMemoryAllocator == obj.fMemoryAllocator && fProtectedContext == obj.fProtectedContext; | ||
|
||
public readonly override bool Equals (object obj) => | ||
obj is GRD3dBackendcontext f && Equals (f); | ||
|
||
public static bool operator == (GRD3dBackendcontext left, GRD3dBackendcontext right) => | ||
left.Equals (right); | ||
|
||
public static bool operator != (GRD3dBackendcontext left, GRD3dBackendcontext right) => | ||
!left.Equals (right); | ||
|
||
public readonly override int GetHashCode () | ||
{ | ||
var hash = new HashCode (); | ||
hash.Add (fAdapter); | ||
hash.Add (fDevice); | ||
hash.Add (fQueue); | ||
hash.Add (fMemoryAllocator); | ||
hash.Add (fProtectedContext); | ||
return hash.ToHashCode (); | ||
} | ||
|
||
} | ||
|
||
// gr_d3d_textureinfo_t | ||
[StructLayout (LayoutKind.Sequential)] | ||
public unsafe partial struct GRD3dTextureinfo : IEquatable<GRD3dTextureinfo> { | ||
// public d3d_d12_resource_t* fResource | ||
private d3d_d12_resource_t fResource; | ||
public d3d_d12_resource_t Resource { | ||
readonly get => fResource; | ||
set => fResource = value; | ||
} | ||
|
||
// public d3d_alloc_t* fAlloc | ||
private d3d_alloc_t fAlloc; | ||
public d3d_alloc_t Alloc { | ||
readonly get => fAlloc; | ||
set => fAlloc = value; | ||
} | ||
|
||
// public uint32_t fResourceState | ||
private UInt32 fResourceState; | ||
public UInt32 ResourceState { | ||
readonly get => fResourceState; | ||
set => fResourceState = value; | ||
} | ||
|
||
// public uint32_t fFormat | ||
private UInt32 fFormat; | ||
public UInt32 Format { | ||
readonly get => fFormat; | ||
set => fFormat = value; | ||
} | ||
|
||
// public uint32_t fSampleCount | ||
private UInt32 fSampleCount; | ||
public UInt32 SampleCount { | ||
readonly get => fSampleCount; | ||
set => fSampleCount = value; | ||
} | ||
|
||
// public uint32_t fLevelCount | ||
private UInt32 fLevelCount; | ||
public UInt32 LevelCount { | ||
readonly get => fLevelCount; | ||
set => fLevelCount = value; | ||
} | ||
|
||
// public unsigned int fSampleQualityPattern | ||
private UInt32 fSampleQualityPattern; | ||
public UInt32 SampleQualityPattern { | ||
readonly get => fSampleQualityPattern; | ||
set => fSampleQualityPattern = value; | ||
} | ||
|
||
// public bool fProtected | ||
private Byte fProtected; | ||
public bool Protected { | ||
readonly get => fProtected > 0; | ||
set => fProtected = value ? (byte)1 : (byte)0; | ||
} | ||
|
||
public readonly bool Equals (GRD3dTextureinfo obj) => | ||
fResource == obj.fResource && fAlloc == obj.fAlloc && fResourceState == obj.fResourceState && fFormat == obj.fFormat && fSampleCount == obj.fSampleCount && fLevelCount == obj.fLevelCount && fSampleQualityPattern == obj.fSampleQualityPattern && fProtected == obj.fProtected; | ||
|
||
public readonly override bool Equals (object obj) => | ||
obj is GRD3dTextureinfo f && Equals (f); | ||
|
||
public static bool operator == (GRD3dTextureinfo left, GRD3dTextureinfo right) => | ||
left.Equals (right); | ||
|
||
public static bool operator != (GRD3dTextureinfo left, GRD3dTextureinfo right) => | ||
!left.Equals (right); | ||
|
||
public readonly override int GetHashCode () | ||
{ | ||
var hash = new HashCode (); | ||
hash.Add (fResource); | ||
hash.Add (fAlloc); | ||
hash.Add (fResourceState); | ||
hash.Add (fFormat); | ||
hash.Add (fSampleCount); | ||
hash.Add (fLevelCount); | ||
hash.Add (fSampleQualityPattern); | ||
hash.Add (fProtected); | ||
return hash.ToHashCode (); | ||
} | ||
|
||
} | ||
|
||
// gr_gl_framebufferinfo_t | ||
[StructLayout (LayoutKind.Sequential)] | ||
public unsafe partial struct GRGlFramebufferInfo : IEquatable<GRGlFramebufferInfo> { | ||
|
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
32 changes: 32 additions & 0 deletions
32
source/SkiaSharp.Direct3D/SkiaSharp.Direct3D.Vortice/GRDirect3DBackendContext.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,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Vortice.Direct3D12; | ||
using Vortice.DXGI; | ||
|
||
namespace SkiaSharp | ||
{ | ||
public class GRDirect3DBackendContext | ||
{ | ||
public IDXGIAdapter1 Adapter { get; set; } | ||
|
||
public ID3D12Device2 Device { get; set; } | ||
|
||
public ID3D12CommandQueue Queue { get; set; } | ||
|
||
public bool ProtectedContext { get; set; } | ||
|
||
public static implicit operator GRD3dBackendcontext(GRDirect3DBackendContext context) | ||
{ | ||
return new GRD3dBackendcontext | ||
{ | ||
Adapter = context.Adapter.NativePointer, | ||
Device = context.Device.NativePointer, | ||
Queue = context.Queue.NativePointer, | ||
ProtectedContext = context.ProtectedContext | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hate myself so much... But this may need to be 3d with a lowercase d for consistency. So yuck to look at and I have no idea what I was thinking at the time. Sorry universe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw that every Direct3D library use uppercase
D
, so I'm doing same with that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but sadly if you look at my
OpenGl
members I must have lost my mind. Everywhere it is uppercase-G-lowercase-l 😭