mirror of
https://github.com/amerkoleci/Vortice.Win32.git
synced 2026-01-14 16:16:04 +08:00
Generator: More bindings improvements and handle primitive types function/method usage.
This commit is contained in:
@@ -24,7 +24,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<!-- https://github.com/dotnet/sourcelink -->
|
<!-- https://github.com/dotnet/sourcelink -->
|
||||||
<PropertyGroup>
|
<!--<PropertyGroup>
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||||
<IncludeSymbols>false</IncludeSymbols>
|
<IncludeSymbols>false</IncludeSymbols>
|
||||||
@@ -37,6 +37,6 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>-->
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -568,7 +568,7 @@ public static class Program
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
string fullTypeName = $"{parameter.Type.Api}.{parameter.Type.Name}";
|
string fullTypeName = $"{parameter.Type.Api}.{parameter.Type.Name}";
|
||||||
if (!IsEnum(fullTypeName))
|
if (!IsPrimitive(parameter.Type) && !IsEnum(fullTypeName))
|
||||||
{
|
{
|
||||||
asPointer = true;
|
asPointer = true;
|
||||||
}
|
}
|
||||||
@@ -583,6 +583,7 @@ public static class Program
|
|||||||
parameterType = NormalizeTypeName(writer.Api, parameterType);
|
parameterType = NormalizeTypeName(writer.Api, parameterType);
|
||||||
string parameterName = parameter.Name;
|
string parameterName = parameter.Name;
|
||||||
|
|
||||||
|
|
||||||
bool isOptional = parameter.Attrs.Any(item => item is string str && str == "Optional");
|
bool isOptional = parameter.Attrs.Any(item => item is string str && str == "Optional");
|
||||||
if (parameter.Attrs.Any(item => item is string str && str == "ComOutPtr"))
|
if (parameter.Attrs.Any(item => item is string str && str == "ComOutPtr"))
|
||||||
{
|
{
|
||||||
@@ -1075,6 +1076,11 @@ public static class Program
|
|||||||
|
|
||||||
foreach (var parameter in method.Params)
|
foreach (var parameter in method.Params)
|
||||||
{
|
{
|
||||||
|
if (method.Name == "SetBreakOnSeverity")
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool asPointer = false;
|
bool asPointer = false;
|
||||||
string parameterType = default;
|
string parameterType = default;
|
||||||
if (parameter.Type.Kind == "ApiRef")
|
if (parameter.Type.Kind == "ApiRef")
|
||||||
@@ -1087,7 +1093,7 @@ public static class Program
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
string fullTypeName = $"{parameter.Type.Api}.{parameter.Type.Name}";
|
string fullTypeName = $"{parameter.Type.Api}.{parameter.Type.Name}";
|
||||||
if (!IsEnum(fullTypeName))
|
if (!IsPrimitive(parameter.Type) && !IsEnum(fullTypeName))
|
||||||
{
|
{
|
||||||
asPointer = true;
|
asPointer = true;
|
||||||
}
|
}
|
||||||
@@ -1163,7 +1169,17 @@ public static class Program
|
|||||||
|
|
||||||
writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]");
|
writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]");
|
||||||
writer.WriteLine($"[VtblIndex({vtblIndex})]");
|
writer.WriteLine($"[VtblIndex({vtblIndex})]");
|
||||||
using (writer.PushBlock($"public {returnType} {method.Name}({argumentsString})"))
|
|
||||||
|
string methodSuffix = string.Empty;
|
||||||
|
if (method.Name == "GetType")
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(argumentsString))
|
||||||
|
{
|
||||||
|
methodSuffix = "new ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using (writer.PushBlock($"public {methodSuffix}{returnType} {method.Name}({argumentsString})"))
|
||||||
{
|
{
|
||||||
writer.WriteLineUndindented("#if NET6_0_OR_GREATER");
|
writer.WriteLineUndindented("#if NET6_0_OR_GREATER");
|
||||||
if (returnType != "void")
|
if (returnType != "void")
|
||||||
@@ -1487,11 +1503,33 @@ public static class Program
|
|||||||
return GetTypeName(dataType.Name);
|
return GetTypeName(dataType.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsPrimitive(string typeName)
|
||||||
|
{
|
||||||
|
switch (typeName)
|
||||||
|
{
|
||||||
|
case "void":
|
||||||
|
case "bool":
|
||||||
|
case "int":
|
||||||
|
case "uint":
|
||||||
|
case "Bool32":
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case "nint":
|
||||||
|
case "nuint":
|
||||||
|
case "IntPtr":
|
||||||
|
case "UIntPtr":
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool IsPrimitive(ApiDataType dataType)
|
private static bool IsPrimitive(ApiDataType dataType)
|
||||||
{
|
{
|
||||||
if (dataType.Kind == "ApiRef")
|
if (dataType.Kind == "ApiRef")
|
||||||
{
|
{
|
||||||
string apiRefType = GetTypeName($"{dataType.Api}.{dataType.Name}");
|
string apiRefType = GetTypeName($"{dataType.Api}.{dataType.Name}");
|
||||||
|
return IsPrimitive(apiRefType);
|
||||||
}
|
}
|
||||||
else if (dataType.Kind == "PointerTo")
|
else if (dataType.Kind == "PointerTo")
|
||||||
{
|
{
|
||||||
@@ -1504,19 +1542,7 @@ public static class Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
string typeName = GetTypeName(dataType.Name);
|
string typeName = GetTypeName(dataType.Name);
|
||||||
switch (typeName)
|
return IsPrimitive(typeName);
|
||||||
{
|
|
||||||
case "void":
|
|
||||||
case "int":
|
|
||||||
case "uint":
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case "nint":
|
|
||||||
case "nuint":
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsEnum(string typeName)
|
private static bool IsEnum(string typeName)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,24 +1,58 @@
|
|||||||
// Copyright © Amer Koleci and Contributors.
|
// Copyright © Amer Koleci and Contributors.
|
||||||
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
|
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
|
||||||
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Win32;
|
using Win32;
|
||||||
using Win32.Graphics.Dxgi;
|
|
||||||
using Win32.Graphics.Direct3D11;
|
|
||||||
using static Win32.Apis;
|
|
||||||
using static Win32.Graphics.Dxgi.Apis;
|
|
||||||
using static Win32.Graphics.Direct3D11.Apis;
|
|
||||||
using Win32.Graphics.Direct3D;
|
using Win32.Graphics.Direct3D;
|
||||||
|
using Win32.Graphics.Direct3D11;
|
||||||
|
using Win32.Graphics.Dxgi;
|
||||||
|
using static Win32.Apis;
|
||||||
|
using static Win32.Graphics.Direct3D11.Apis;
|
||||||
|
using static Win32.Graphics.Dxgi.Apis;
|
||||||
|
using MessageId = Win32.Graphics.Direct3D11.MessageId;
|
||||||
|
using InfoQueueFilter = Win32.Graphics.Direct3D11.InfoQueueFilter;
|
||||||
|
|
||||||
namespace ClearScreen;
|
namespace ClearScreen;
|
||||||
|
|
||||||
public static unsafe class Program
|
public static unsafe class Program
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
|
static bool SdkLayersAvailable()
|
||||||
|
{
|
||||||
|
HResult hr = D3D11CreateDevice(
|
||||||
|
null,
|
||||||
|
DriverType.Null, // There is no need to create a real hardware device.
|
||||||
|
IntPtr.Zero,
|
||||||
|
CreateDeviceFlag.Debug, // Check for the SDK layers.
|
||||||
|
null, // Any feature level will do.
|
||||||
|
0,
|
||||||
|
D3D11_SDK_VERSION,
|
||||||
|
null, // No need to keep the D3D device reference.
|
||||||
|
null, // No need to know the feature level.
|
||||||
|
null // No need to keep the D3D device context reference.
|
||||||
|
);
|
||||||
|
|
||||||
|
return hr.Success;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
using ComPtr<IDXGIFactory1> factory = default;
|
using ComPtr<IDXGIFactory2> factory = default;
|
||||||
HResult hr = CreateDXGIFactory1(__uuidof<IDXGIFactory4>(), (void**)&factory);
|
uint factoryFlags = 0;
|
||||||
|
#if DEBUG
|
||||||
|
{
|
||||||
|
using ComPtr<IDXGIInfoQueue> dxgiInfoQueue = default;
|
||||||
|
if (DXGIGetDebugInterface1(0, __uuidof<IDXGIInfoQueue>(), (void**)dxgiInfoQueue.GetAddressOf()).Success)
|
||||||
|
{
|
||||||
|
factoryFlags = DXGI_CREATE_FACTORY_DEBUG;
|
||||||
|
|
||||||
|
dxgiInfoQueue.Get()->SetBreakOnSeverity(DXGI_DEBUG_ALL, InfoQueueMessageSeverity.Error, true);
|
||||||
|
dxgiInfoQueue.Get()->SetBreakOnSeverity(DXGI_DEBUG_ALL, InfoQueueMessageSeverity.Corruption, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
HResult hr = CreateDXGIFactory2(factoryFlags, __uuidof<IDXGIFactory2>(), (void**)&factory);
|
||||||
|
|
||||||
{
|
{
|
||||||
using ComPtr<IDXGIFactory5> factory5 = default;
|
using ComPtr<IDXGIFactory5> factory5 = default;
|
||||||
@@ -42,7 +76,7 @@ public static unsafe class Program
|
|||||||
adapterIndex++)
|
adapterIndex++)
|
||||||
{
|
{
|
||||||
AdapterDescription1 desc = default;
|
AdapterDescription1 desc = default;
|
||||||
adapter.Get()->GetDesc1(&desc);
|
adapter.Get()->GetDesc1(&desc).ThrowIfFailed();
|
||||||
|
|
||||||
if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
|
if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
|
||||||
continue;
|
continue;
|
||||||
@@ -59,7 +93,7 @@ public static unsafe class Program
|
|||||||
adapterIndex++)
|
adapterIndex++)
|
||||||
{
|
{
|
||||||
AdapterDescription1 desc = default;
|
AdapterDescription1 desc = default;
|
||||||
adapter.Get()->GetDesc1(&desc);
|
adapter.Get()->GetDesc1(&desc).ThrowIfFailed();
|
||||||
|
|
||||||
if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
|
if ((desc.Flags & AdapterFlags.Software) != AdapterFlags.None)
|
||||||
continue;
|
continue;
|
||||||
@@ -74,17 +108,49 @@ public static unsafe class Program
|
|||||||
FeatureLevel.Level_11_0
|
FeatureLevel.Level_11_0
|
||||||
};
|
};
|
||||||
|
|
||||||
using ComPtr<ID3D11Device> d3dDevice = default;
|
CreateDeviceFlag creationFlags = CreateDeviceFlag.BgraSupport;
|
||||||
|
#if DEBUG
|
||||||
|
if (SdkLayersAvailable())
|
||||||
|
{
|
||||||
|
// If the project is in a debug build, enable debugging via SDK Layers with this flag.
|
||||||
|
creationFlags |= CreateDeviceFlag.Debug;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using ComPtr<ID3D11Device> tempDevice = default;
|
||||||
FeatureLevel featureLevel;
|
FeatureLevel featureLevel;
|
||||||
using ComPtr<ID3D11DeviceContext> immediateContext = default;
|
using ComPtr<ID3D11DeviceContext> immediateContext = default;
|
||||||
|
|
||||||
D3D11CreateDevice(
|
D3D11CreateDevice(
|
||||||
(IDXGIAdapter*)adapter.Get(),
|
(IDXGIAdapter*)adapter.Get(),
|
||||||
DriverType.Hardware,
|
DriverType.Unknown,
|
||||||
CreateDeviceFlag.None,
|
creationFlags,
|
||||||
featureLevels,
|
featureLevels,
|
||||||
d3dDevice.GetAddressOf(),
|
tempDevice.GetAddressOf(),
|
||||||
&featureLevel,
|
&featureLevel,
|
||||||
immediateContext.GetAddressOf()).ThrowIfFailed();
|
immediateContext.GetAddressOf()).ThrowIfFailed();
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
using ComPtr<ID3D11Debug> d3dDebug = default;
|
||||||
|
if (tempDevice.CopyTo(&d3dDebug).Success)
|
||||||
|
{
|
||||||
|
using ComPtr<ID3D11InfoQueue> d3dInfoQueue = default;
|
||||||
|
if (d3dDebug.CopyTo(&d3dInfoQueue).Success)
|
||||||
|
{
|
||||||
|
d3dInfoQueue.Get()->SetBreakOnSeverity(MessageSeverity.Corruption, true);
|
||||||
|
d3dInfoQueue.Get()->SetBreakOnSeverity(MessageSeverity.Error, true);
|
||||||
|
|
||||||
|
MessageId* hide = stackalloc MessageId[1]
|
||||||
|
{
|
||||||
|
MessageId.SetprivatedataChangingparams,
|
||||||
|
};
|
||||||
|
|
||||||
|
InfoQueueFilter filter = new();
|
||||||
|
filter.DenyList.NumIDs = 1u;
|
||||||
|
filter.DenyList.pIDList = hide;
|
||||||
|
d3dInfoQueue.Get()->AddStorageFilterEntries(&filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user