Skip to content

Commit

Permalink
Add *SOME* WinRT support (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
Perksey authored Oct 10, 2023
1 parent 9014e3b commit dff1a4d
Show file tree
Hide file tree
Showing 32 changed files with 3,394 additions and 28 deletions.
Binary file modified build/cache/core.json.gz
Binary file not shown.
Binary file modified build/cache/d3d11.json.gz
Binary file not shown.
Binary file modified build/cache/dxgi.json.gz
Binary file not shown.
4 changes: 4 additions & 0 deletions build/csharp_typemap.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@
"VisualID": "nint",
"RROutput": "nint",
"HINSTANCE": "nint",
"HSTRING": "WinString",
"HSTRING__*": "WinString",
"HSTRING__**": "WinString*",
"HWND": "nint",
"HWND__*": "nint",
"HDC__*": "nint",
Expand Down Expand Up @@ -139,6 +142,7 @@
"_LARGE_INTEGER": "long",
"_ULARGE_INTEGER": "ulong",
"IUnknown": "Silk.NET.Core.Native.IUnknown",
"IInspectable": "Silk.NET.Core.Native.IInspectable",
"tagRECT": "Silk.NET.Maths.Box2D<int>",
"tagPOINT": "Silk.NET.Maths.Vector2D<int>",
"tagSIZE": "Silk.NET.Maths.Vector2D<int>",
Expand Down
48 changes: 37 additions & 11 deletions generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@
{
"profileName": "Core",
"sources": [
"$windowsSdkDir/Include/$windowsSdkVersion/um/d3dcommon.h"
"$windowsSdkDir/Include/$windowsSdkVersion/um/d3dcommon.h",
"$windowsSdkDir/Include/$windowsSdkVersion/winrt/inspectable.h"
],
"mode": "Clang",
"cacheDir": "build/cache",
Expand Down Expand Up @@ -954,18 +955,31 @@
],
"traverse": [],
"classes": {
"d3dcommon.h": "[Core]D3DCommon"
"d3dcommon.h": "[Core]D3DCommon",
"inspectable.h": "[Core]WinRT"
}
},
"exclude": [],
"exclude": [
"HSTRING_UserSize",
"HSTRING_UserMarshal",
"HSTRING_UserUnmarshal",
"HSTRING_UserFree",
"HSTRING_UserSize64",
"HSTRING_UserMarshal64",
"HSTRING_UserUnmarshal64",
"HSTRING_UserFree64",
"__REQUIRED_RPCNDR_H_VERSION__",
"__REQUIRED_RPCSAL_H_VERSION__"
],
"rename": {
"_D3D_CBUFFER_TYPE": "D3DCBufferType",
"_D3D_SHADER_CBUFFER_FLAGS": "D3DShaderCBufferFlags"
},
"bakery": {
"profileNames": [
"d3dcommon",
"silk.net.core.native.dcommon"
"silk.net.core.native.dcommon",
"inspectable"
]
},
"output": {
Expand Down Expand Up @@ -1140,7 +1154,8 @@
"$windowsSdkDir/Include/$windowsSdkVersion/shared/dxgi1_5.h",
"$windowsSdkDir/Include/$windowsSdkVersion/shared/dxgi1_6.h",
"$windowsSdkDir/Include/$windowsSdkVersion/um/dxgidebug.h",
"$windowsSdkDir/Include/$windowsSdkVersion/shared/dxgiformat.h"
"$windowsSdkDir/Include/$windowsSdkVersion/shared/dxgiformat.h",
"$windowsSdkDir/Include/$windowsSdkVersion/winrt/windows.graphics.directx.h"
],
"mode": "Clang",
"cacheDir": "build/cache",
Expand Down Expand Up @@ -1176,7 +1191,8 @@
"dxgi1_5.h": "[Core]DXGI",
"dxgi1_6.h": "[Core]DXGI",
"dxgidebug.h": "[Core]DXGI",
"dxgiformat.h": "[Core]DXGI"
"dxgiformat.h": "[Core]DXGI",
"windows.graphics.directx.h": "[Core]DXGI"
},
"comRefs": [
"Silk.NET.Core.Native.ID3D10Blob",
Expand All @@ -1195,7 +1211,8 @@
"dxgi1_5",
"dxgi1_6",
"dxgidebug",
"dxgiformat"
"dxgiformat",
"windows.graphics.directx"
]
},
"output": {
Expand Down Expand Up @@ -1698,7 +1715,9 @@
"$windowsSdkDir/Include/$windowsSdkVersion/um/d3d11shader.h",
"$windowsSdkDir/Include/$windowsSdkVersion/um/d3d11shadertracing.h",
"$windowsSdkDir/Include/$windowsSdkVersion/um/d3d11sdklayers.h",
"$windowsSdkDir/Include/$windowsSdkVersion/um/d3d11on12.h"
"$windowsSdkDir/Include/$windowsSdkVersion/um/d3d11on12.h",
"$windowsSdkDir/Include/$windowsSdkVersion/um/windows.graphics.directx.direct3d11.interop.h",
"$windowsSdkDir/Include/$windowsSdkVersion/winrt/windows.graphics.directx.direct3d11.h"
],
"mode": "Clang",
"cacheDir": "build/cache",
Expand Down Expand Up @@ -1732,7 +1751,9 @@
"d3d11shader.h": "[Core]D3D11",
"d3d11shadertracing.h": "[Core]D3D11",
"d3d11sdklayers.h": "[Core]D3D11",
"d3d11on12.h": "[D3D11On12:D3D11]D3D11On12"
"d3d11on12.h": "[D3D11On12:D3D11]D3D11On12",
"windows.graphics.directx.direct3d11.interop.h": "[Core]D3D11",
"windows.graphics.directx.direct3d11.h": "[Core]D3D11"
},
"comRefs": [
"Silk.NET.DXGI.IDXGIAdapter",
Expand All @@ -1758,7 +1779,9 @@
"d3d11shader",
"d3d11shadertracing",
"d3d11sdklayers",
"d3d11on12"
"d3d11on12",
"windows.graphics.directx.direct3d11.interop",
"windows.graphics.directx.direct3d11"
]
},
"output": {
Expand All @@ -1784,7 +1807,10 @@
"ID3D10Blob": "Silk.NET.Core.Native.ID3D10Blob",
"D3D12_RESOURCE_STATES": "Silk.NET.Direct3D12.ResourceStates",
"ID3D12Fence": "Silk.NET.Direct3D12.ID3D12Fence",
"ID3D12CommandQueue": "Silk.NET.Direct3D12.ID3D12CommandQueue"
"ID3D12CommandQueue": "Silk.NET.Direct3D12.ID3D12CommandQueue",
"ABI::Windows::Graphics::DirectX::Direct3D11::Direct3DSurfaceDescription": "Direct3DSurfaceDescription",
"ABI::Windows::Graphics::DirectX::DirectXPixelFormat": "Silk.NET.DXGI.DirectXPixelFormat",
"ABI::Windows::Graphics::DirectX::Direct3D11::Direct3DMultisampleDescription": "Direct3DMultisampleDescription"
},
{
"$include.dxTypemap": "build/dx_typemap.json",
Expand Down
6 changes: 0 additions & 6 deletions src/Core/Silk.NET.Core/Native/D3DCommon.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ namespace Silk.NET.Core.Native
{
public unsafe partial class D3DCommon
{
[NativeName("Type", "int")]
[NativeName("Name", "__REQUIRED_RPCNDR_H_VERSION__")]
public const int RequiredRpcndrHVersion = unchecked((int) 0x1F5);
[NativeName("Type", "int")]
[NativeName("Name", "__REQUIRED_RPCSAL_H_VERSION__")]
public const int RequiredRpcsalHVersion = unchecked((int) 0x64);
[NativeName("Type", "int")]
[NativeName("Name", "D3D_FL9_1_REQ_TEXTURE1D_U_DIMENSION")]
public const int D3DFL91ReqTexture1DUDimension = unchecked((int) 0x800);
Expand Down
22 changes: 22 additions & 0 deletions src/Core/Silk.NET.Core/Native/Enums/TrustLevel.gen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.


using System;
using Silk.NET.Core.Attributes;

#pragma warning disable 1591

namespace Silk.NET.Core.Native
{
[NativeName("Name", "TrustLevel")]
public enum TrustLevel : int
{
[NativeName("Name", "BaseTrust")]
BaseTrust = 0x0,
[NativeName("Name", "PartialTrust")]
PartialTrust = 0x1,
[NativeName("Name", "FullTrust")]
FullTrust = 0x2,
}
}
3 changes: 2 additions & 1 deletion src/Core/Silk.NET.Core/Native/NativeStringEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ public enum NativeStringEncoding
LPTStr = UnmanagedType.LPTStr,
LPUTF8Str = UnmanagedType.LPUTF8Str,
LPWStr = UnmanagedType.LPWStr,
WinString = UnmanagedType.WinString,
Ansi = LPStr,
Auto = LPTStr,
Uni = LPWStr,
UTF8 = LPUTF8Str
UTF8 = LPUTF8Str,
}
}
11 changes: 8 additions & 3 deletions src/Core/Silk.NET.Core/Native/SilkMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,20 @@ public static void FreeString(nint ptr, NativeStringEncoding encoding = NativeSt
/// <param name="input">The string to marshal.</param>
/// <param name="encoding">The target native string encoding.</param>
/// <returns>A pointer to the memory containing the marshalled string array.</returns>
public static nint StringToPtr(string? input, NativeStringEncoding encoding = NativeStringEncoding.Ansi)
=> input is null ? 0 : RegisterMemory(StringToMemory(input, encoding));
public static unsafe nint StringToPtr(string? input, NativeStringEncoding encoding = NativeStringEncoding.Ansi)
=> input is null ? 0 : encoding switch
{
NativeStringEncoding.WinString => (nint)new WinString(input).HString,
_ => RegisterMemory(StringToMemory(input, encoding))
};

/// <summary>
/// Reads a null-terminated string from unmanaged memory, with the given native encoding.
/// </summary>
/// <param name="input">A pointer to memory containing a null-terminated string.</param>
/// <param name="encoding">The encoding of the string in memory.</param>
/// <returns>The string read from memory.</returns>
public static string? PtrToString(nint input, NativeStringEncoding encoding = NativeStringEncoding.Ansi)
public static unsafe string? PtrToString(nint input, NativeStringEncoding encoding = NativeStringEncoding.Ansi)
{
if (input == 0)
{
Expand All @@ -299,6 +303,7 @@ public static nint StringToPtr(string? input, NativeStringEncoding encoding = Na
NativeStringEncoding.LPTStr => Utf8PtrToString(input),
NativeStringEncoding.LPUTF8Str => Utf8PtrToString(input),
NativeStringEncoding.LPWStr => WideToString(input),
NativeStringEncoding.WinString => (*(WinString*)&input).ToString(),
_ => ThrowInvalidEncoding<string>()
};

Expand Down
Loading

0 comments on commit dff1a4d

Please sign in to comment.