Skip to content

Commit 44356f1

Browse files
committed
Add manual Vk file with Create and Clone methods
1 parent ae30d31 commit 44356f1

File tree

1 file changed

+55
-0
lines changed
  • sources/Vulkan/Vulkan

1 file changed

+55
-0
lines changed

sources/Vulkan/Vulkan/Vk.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Silk.NET.Core.Loader;
2+
3+
namespace Silk.NET.Vulkan;
4+
5+
public partial class Vk
6+
{
7+
public static IVk Create()
8+
{
9+
var context = new NativeContext();
10+
var vk = new Vk(context);
11+
12+
context.Vk = vk;
13+
14+
return vk;
15+
}
16+
17+
public unsafe IVk Clone()
18+
{
19+
var context = new NativeContext();
20+
var vk = new Vk(context);
21+
22+
context.Vk = vk;
23+
24+
vk.CurrentInstance = CurrentInstance;
25+
vk.CurrentDevice = CurrentDevice;
26+
Array.Copy(_slots, vk._slots, _slots.Length);
27+
28+
return vk;
29+
}
30+
31+
private class NativeContext : INativeContext
32+
{
33+
public Vk Vk { get; set; } = null!;
34+
private IVk Ivk => Vk;
35+
36+
public unsafe void* LoadFunction(string functionName, string libraryNameHint)
37+
{
38+
if (functionName.EndsWith("ProcAddr"))
39+
{
40+
return null;
41+
}
42+
43+
void* ptr = Ivk.GetDeviceProcAddr(Vk.CurrentDevice.GetValueOrDefault(), functionName);
44+
if (ptr != null)
45+
{
46+
return ptr;
47+
}
48+
49+
ptr = Ivk.GetInstanceProcAddr(Vk.CurrentInstance.GetValueOrDefault(), functionName);
50+
return ptr;
51+
}
52+
53+
public void Dispose() {}
54+
}
55+
}

0 commit comments

Comments
 (0)