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); } }
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); }