Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public static unsafe void DestroyDebugReportCallback(Instance instance, DebugReportCallbackEXT debugReportCallbackEXT)
        {
            if (debugReportCallbackEXT.NativePointer != 0)
            {
                var name      = "vkDestroyDebugReportCallbackEXT";
                var fnPointer = Vk.GetInstanceProcAddr(instance, name);
                if (fnPointer == IntPtr.Zero)
                {
                    throw new NullReferenceException($"Didn't find InstanceProcAddr {name}");
                }

                var destroyDebugReportCallback = (DestroyDebugReportCallbackDelegate)Marshal.GetDelegateForFunctionPointer(fnPointer, typeof(DestroyDebugReportCallbackDelegate));
                destroyDebugReportCallback(instance.NativePointer, debugReportCallbackEXT.NativePointer, null);
            }
        }
Ejemplo n.º 3
0
        /// <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();
        }
Ejemplo n.º 4
0
        public static unsafe DebugReportCallbackEXT CreateDebugReportCallback(Instance instance, DebugReportCallbackDelegate callback)
        {
            var name      = "vkCreateDebugReportCallbackEXT";
            var nameBytes = Encoding.ASCII.GetBytes(name);
            var procAddr  = Vk.GetInstanceProcAddr(instance, name);

            if (procAddr == IntPtr.Zero)
            {
                throw new NullReferenceException($"Didn't find InstanceProcAddr {nameBytes}");
            }

            debugDelegate = callback;
            GC.KeepAlive(debugDelegate);

            callbackHolder = Marshal.GetFunctionPointerForDelegate(callback);
            GC.KeepAlive(callbackHolder);

            var createDelegate = (CreateDebugReportCallbackEXT_Delegate)Marshal.GetDelegateForFunctionPointer(procAddr, typeof(CreateDebugReportCallbackEXT_Delegate));
            var createInfo     = new DebugReportCallbackCreateInfoEXT
            {
                Flags    = (DebugReportFlagsEXT)0x1F,//DebugReportFlagsEXT.Error | DebugReportFlagsEXT.Warning | DebugReportFlagsEXT.PerformanceWarning,
                Callback = callbackHolder,
            };

            var debugReportCallbackEXT = new DebugReportCallbackEXT();

            fixed(UInt64 *ptr = &debugReportCallbackEXT.NativePointer)
            {
                var result = createDelegate(instance.NativePointer, createInfo.NativePointer, null, ptr);

                if (result != Result.Success)
                {
                    throw new VulkanResultException("vkCreateDebugReportCallbackEXT", result);
                }
            }

            createInfo.Dispose();
            return(debugReportCallbackEXT);
        }
Ejemplo n.º 5
0
 static Vk()
 {
     s_nativeLib = LoadNativeLibrary();
     Vk.LoadFunctionPointers();
 }