Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Silk.NET.Windowing.Common", "src\Windowing\Silk.NET.Windowing.Common\Silk.NET.Windowing.Common.csproj", "{956F722C-DFD3-435E-9D2E-A0549C4D8BC0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{E1F91563-7277-4E9B-A3B7-8D5FD9802A4A}"
ProjectSection(SolutionItems) = preProject
examples\Directory.Build.props = examples\Directory.Build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenAL", "OpenAL", "{081E7761-B200-4DBF-8950-941464DECACE}"
EndProject
Expand Down
1 change: 1 addition & 0 deletions examples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>
<PropertyGroup>
<AssemblyName>Tutorial</AssemblyName>
<LangVersion>9</LangVersion>
</PropertyGroup>
</Project>
11 changes: 10 additions & 1 deletion generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,16 @@
"mode": "Default",
"path": "src/OpenXR",
"licenseFile": "build/LICENSE_HEADER.txt",
"props": "build/props/bindings.props"
"props": "build/props/bindings.props",
"inject": [
{
"functions": [
"xrCreateInstance"
],
"stage": "end",
"code": "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(instance)$%; }"
}
]
},
"namespace": "Silk.NET.OpenXR",
"extensionsNamespace": "Silk.NET.OpenXR.Extensions",
Expand Down
39 changes: 22 additions & 17 deletions src/Core/Silk.NET.SilkTouch/Middlewares/InjectMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,29 @@ public static void InjectMiddleware(ref IMarshalContext ctx, Action next)
var code = (string)injectData.ConstructorArguments[1].Value!;
ctx.AddSideEffectToStage(injectPoint, ctx =>
{
if (ctx.ResultVariable.HasValue)
if (injectPoint == SilkTouchStage.End)
{
code = code.Replace
(
"%$RESULT$%",
ParenthesizedExpression(ctx.ResolveVariable(ctx.ResultVariable.Value).Value).NormalizeWhitespace().ToFullString()
);
}

for (var i = 0; i < ctx.ParameterVariables.Length; i++)
{
code = code.Replace
(
$"%$PARAM({ctx.MethodSymbol.Parameters[i].Name})$%",
ParenthesizedExpression(ctx.ResolveVariable(ctx.ParameterVariables[i]).Value)
.NormalizeWhitespace()
.ToFullString()
);
if (ctx.ResultVariable.HasValue)
{
code = code.Replace
(
"%$RESULT$%",
ParenthesizedExpression(ctx.ResolveVariable(ctx.ResultVariable.Value).Value)
.NormalizeWhitespace()
.ToFullString()
);
}

for (var i = 0; i < ctx.ParameterVariables.Length; i++)
{
code = code.Replace
(
$"%$PARAM({ctx.MethodSymbol.Parameters[i].Name})$%",
ParenthesizedExpression(ctx.ResolveVariable(ctx.ParameterVariables[i]).Value)
.NormalizeWhitespace()
.ToFullString()
);
}
}

return ParseStatement(code);
Expand Down
25 changes: 20 additions & 5 deletions src/OpenXR/Silk.NET.OpenXR/XR.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand All @@ -14,7 +15,13 @@ namespace Silk.NET.OpenXR
{
public partial class XR
{
public Instance? CurrentInstance { get; set; }
private Instance? _currentInstance;
private ConcurrentDictionary<Instance?, IVTable> _vTables = new();
public Instance? CurrentInstance
{
get => _currentInstance;
set => SwapVTable(_vTables.GetOrAdd(_currentInstance = value, _ => XrCreateVTable()));
}
public static XR GetApi()
{
return new XR(CreateDefaultContext(new OpenXRLibraryNameContainer().GetLibraryName()));
Expand Down Expand Up @@ -64,8 +71,8 @@ public unsafe bool IsInstanceExtensionPresent(string layer, string extension)
{
// For a detailed explanation of the logic see Silk.Net.Vulkan.Vk.IsDeviceExtensionPresent
layer ??= string.Empty;
var layer_sep = layer + '\0';
var fullKey = layer_sep + extension;
var layerSep = layer + '\0';
var fullKey = layerSep + extension;
var result = false;

_cachedInstanceExtensionsLock.EnterUpgradeableReadLock();
Expand All @@ -88,7 +95,6 @@ public unsafe bool IsInstanceExtensionPresent(string layer, string extension)
mem = GlobalMemory.Allocate((int) extensionCount * sizeof(ExtensionProperties));
var exts = (ExtensionProperties*) Unsafe.AsPointer(ref mem.GetPinnableReference());

// TODO Is this necessary?
for (int i = 0; i < extensionCount; i++)
{
exts[i] = new ExtensionProperties(StructureType.TypeExtensionProperties);
Expand All @@ -97,7 +103,7 @@ public unsafe bool IsInstanceExtensionPresent(string layer, string extension)
EnumerateInstanceExtensionProperties((byte*) layerName, extensionCount, &extensionCount, exts);
for (var i = 0; i < extensionCount; i++)
{
var newKey = layer_sep + Marshal.PtrToStringAnsi((nint) exts[i].ExtensionName);
var newKey = layerSep + Marshal.PtrToStringAnsi((nint) exts[i].ExtensionName);
_cachedInstanceExtensions.Add(newKey);
if (!result && string.Equals(newKey, fullKey))
{
Expand All @@ -116,6 +122,15 @@ public unsafe bool IsInstanceExtensionPresent(string layer, string extension)
_cachedInstanceExtensionsLock.ExitUpgradeableReadLock();
return result;
}

private IVTable XrCreateVTable()
{
var ret = CreateVTable();
ret.Initialize(Context, CoreGetSlotCount());
return ret;
}

protected override void PostInit() => _vTables.TryAdd(null, CurrentVTable);
}
}

4 changes: 4 additions & 0 deletions src/OpenXR/Silk.NET.OpenXR/XR.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,22 @@ public unsafe partial class XR : NativeAPI
public partial Result CreateActionSpace([Count(Count = 0)] Session session, [Count(Count = 0), Flow(FlowDirection.In)] in ActionSpaceCreateInfo createInfo, [Count(Count = 0)] ref Space space);

/// <summary>To be documented.</summary>
[Inject((SilkTouchStage) 6, "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(instance)$%; }")]
[NativeApi(EntryPoint = "xrCreateInstance")]
public unsafe partial Result CreateInstance([Count(Count = 0), Flow(FlowDirection.In)] InstanceCreateInfo* createInfo, [Count(Count = 0)] Instance* instance);

/// <summary>To be documented.</summary>
[Inject((SilkTouchStage) 6, "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(instance)$%; }")]
[NativeApi(EntryPoint = "xrCreateInstance")]
public unsafe partial Result CreateInstance([Count(Count = 0), Flow(FlowDirection.In)] InstanceCreateInfo* createInfo, [Count(Count = 0)] ref Instance instance);

/// <summary>To be documented.</summary>
[Inject((SilkTouchStage) 6, "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(instance)$%; }")]
[NativeApi(EntryPoint = "xrCreateInstance")]
public unsafe partial Result CreateInstance([Count(Count = 0), Flow(FlowDirection.In)] in InstanceCreateInfo createInfo, [Count(Count = 0)] Instance* instance);

/// <summary>To be documented.</summary>
[Inject((SilkTouchStage) 6, "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(instance)$%; }")]
[NativeApi(EntryPoint = "xrCreateInstance")]
public partial Result CreateInstance([Count(Count = 0), Flow(FlowDirection.In)] in InstanceCreateInfo createInfo, [Count(Count = 0)] ref Instance instance);

Expand Down
3 changes: 3 additions & 0 deletions src/OpenXR/Silk.NET.OpenXR/XROverloads.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,23 @@ public static unsafe Result CreateActionSpace(this XR thisApi, [Count(Count = 0)
}

/// <summary>To be documented.</summary>
[Inject((SilkTouchStage) 6, "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(pInstance)$%; }")]
public static unsafe Result CreateInstance(this XR thisApi, [Count(Count = 0), Flow(FlowDirection.In)] InstanceCreateInfo* createInfo, [Count(Count = 0)] Span<Instance> instance)
{
// SpanOverloader
return thisApi.CreateInstance(createInfo, ref instance.GetPinnableReference());
}

/// <summary>To be documented.</summary>
[Inject((SilkTouchStage) 6, "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(pInstance)$%; }")]
public static unsafe Result CreateInstance(this XR thisApi, [Count(Count = 0), Flow(FlowDirection.In)] ReadOnlySpan<InstanceCreateInfo> createInfo, [Count(Count = 0)] Instance* instance)
{
// SpanOverloader
return thisApi.CreateInstance(in createInfo.GetPinnableReference(), instance);
}

/// <summary>To be documented.</summary>
[Inject((SilkTouchStage) 6, "if (%$RESULT$% == Result.Success) { CurrentInstance = *%$PARAM(pInstance)$%; }")]
public static unsafe Result CreateInstance(this XR thisApi, [Count(Count = 0), Flow(FlowDirection.In)] ReadOnlySpan<InstanceCreateInfo> createInfo, [Count(Count = 0)] Span<Instance> instance)
{
// SpanOverloader
Expand Down
22 changes: 1 addition & 21 deletions src/Windowing/Silk.NET.SDL/Sdl.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,7 @@
namespace Silk.NET.SDL
{
public unsafe partial class Sdl : NativeAPI
{
/* Function prototypes */
/**
* \brief This function allows access to driver-dependent window information.
*
* \param window The window about which information is being requested
* \param info This structure must be initialized with the SDL version, and is
* then filled in with information about the given window.
*
* \return SDL_TRUE if the function is implemented and the version member of
* the \c info struct is valid, SDL_FALSE otherwise.
*
* You typically use this function like this:
* \code
* SDL_SysWMinfo info;
* SDL_VERSION(&info.version);
* if ( SDL_GetWindowWMInfo(window, &info) ) { ... }
* \endcode
*/
[NativeApi(EntryPoint = "SDL_GetWindowWMInfo")]
public unsafe partial bool GetWindowWMInfo(Window* window, SysWMInfo* info);
{

/// <summary>To be documented.</summary>
[NativeName("Src", "Line 188, Column 38 in build/submodules/SDL-mirror/include/SDL_platform.h")]
Expand Down
7 changes: 3 additions & 4 deletions src/Windowing/iOS/Silk.NET.Windowing.Sdl.iOS/Class1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using ObjCRuntime;
Expand Down Expand Up @@ -46,7 +45,7 @@ public static unsafe void RunApp(int numArgs, byte** args, MainFunction callback
EndRun();
}

public static unsafe void RunApp(int numArgs, byte** args, Action<string[]> callback)
public static unsafe void RunApp(int numArgs, byte** args, System.Action<string[]> callback)
{
BeginRun();
CurrentMain = (inNumArgs, argsPtr) => callback(SilkMarshal.PtrToStringArray((nint)argsPtr, inNumArgs));
Expand All @@ -66,7 +65,7 @@ public static unsafe void RunApp(IReadOnlyList<string> args, MainFunction callba
EndRun();
}

public static unsafe void RunApp(IReadOnlyList<string> args, Action<string[]> callback)
public static unsafe void RunApp(IReadOnlyList<string> args, System.Action<string[]> callback)
{
BeginRun();
var argsPtr = SilkMarshal.StringArrayToPtr(args);
Expand All @@ -87,7 +86,7 @@ private static void BeginRun()
{
if (_running)
{
throw new InvalidOperationException("App already running.");
throw new System.InvalidOperationException("App already running.");
}

SdlWindowing.RegisterPlatform();
Expand Down