aboutsummaryrefslogtreecommitdiffstatsci
path: root/vulkan/LoadingUtils.cs
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-12-07 20:18:00 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2021-12-07 20:18:00 +0100
commitfe6cb8a976b328b87ec66357c97614f67865e1d7 (patch)
tree9c45081e91c552f96558ea2a8b13af23cf48181e /vulkan/LoadingUtils.cs
parent35323bd205c9680ad1fdb5dcc072872746747f6f (diff)
move sample.Utils to main lib and Vulkan.Utils
Diffstat (limited to 'vulkan/LoadingUtils.cs')
-rw-r--r--vulkan/LoadingUtils.cs32
1 files changed, 32 insertions, 0 deletions
diff --git a/vulkan/LoadingUtils.cs b/vulkan/LoadingUtils.cs
new file mode 100644
index 0000000..b91a47b
--- /dev/null
+++ b/vulkan/LoadingUtils.cs
@@ -0,0 +1,32 @@
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
+using System.Runtime.InteropServices;
+
+namespace Vulkan {
+ internal static class LoadingUtils {
+ public static IntPtr GetDelegate (VkInstance inst, string name) {
+ byte[] n = System.Text.Encoding.UTF8.GetBytes (name + '\0');
+ GCHandle hnd = GCHandle.Alloc (n, GCHandleType.Pinned);
+ IntPtr del = Vk.vkGetInstanceProcAddr (inst, hnd.AddrOfPinnedObject ());
+ if (del == IntPtr.Zero)
+ System.Diagnostics.Debug.WriteLine ("instance function pointer not found for " + name);
+ hnd.Free ();
+ return del;
+ }
+ /// <summary>
+ /// try to get device function handle if available
+ /// </summary>
+ public static void GetDelegate (VkDevice dev, string name, ref IntPtr ptr) {
+ byte[] n = System.Text.Encoding.UTF8.GetBytes (name + '\0');
+ GCHandle hnd = GCHandle.Alloc (n, GCHandleType.Pinned);
+ IntPtr del = Vk.vkGetDeviceProcAddr (dev, hnd.AddrOfPinnedObject ());
+ if (del == IntPtr.Zero)
+ System.Diagnostics.Debug.WriteLine ("device function pointer not found for " + name);
+ else
+ ptr = del;
+ hnd.Free ();
+ }
+ }
+}