void InitializeFunctions() { vkCreateDebugReportCallbackEXT = (NativeMethods.vkCreateDebugReportCallbackEXT)GetMethod("vkCreateDebugReportCallbackEXT", typeof(NativeMethods.vkCreateDebugReportCallbackEXT)); vkDestroyDebugReportCallbackEXT = (NativeMethods.vkDestroyDebugReportCallbackEXT)GetMethod("vkDestroyDebugReportCallbackEXT", typeof(NativeMethods.vkDestroyDebugReportCallbackEXT)); vkDebugReportMessageEXT = (NativeMethods.vkDebugReportMessageEXT)GetMethod("vkDebugReportMessageEXT", typeof(NativeMethods.vkDebugReportMessageEXT)); }
public unsafe VulkanInstance(string ApplicationName, IntPtr SDLWindowHandle, AllocationCallbacks Allocator = null) { this.SDLWindowHandle = SDLWindowHandle; uint Count; IntPtr myPtr; List <String> myStrings = new List <string>(); SDL2.SDL.SDL_Vulkan_GetInstanceExtensions(SDLWindowHandle, &Count, null); if (Count == 0) { throw new VULKAN_NO_HARDWARE_SUPPORTED_DEVICES(); } SDL2.SDL.SDL_Vulkan_GetInstanceExtensions(SDLWindowHandle, &Count, out myPtr); for (int i = 0; i < Count; i++) { void * Test = myPtr.ToPointer(); string aString = Marshal.PtrToStringAnsi(myPtr); myStrings.Add(aString); myPtr = IntPtr.Add(myPtr, myStrings[i].Length + 1); } #if DEBUG myStrings.Add("VK_EXT_debug_report"); //myStrings.Add("VK_EXT_debug_utils"); #endif List <Interop.LayerProperties> Layers = new List <Interop.LayerProperties>(); unsafe { String myValues; uint myCount; Interop.LayerProperties *myProperties; Interop.NativeMethods.vkEnumerateInstanceLayerProperties(&myCount, null); int SizeofBuffer = Marshal.SizeOf(typeof(Interop.LayerProperties)); IntPtr myStartingBlock = Marshal.AllocHGlobal((int)myCount * SizeofBuffer); IntPtr Memory = myStartingBlock; Interop.NativeMethods.vkEnumerateInstanceLayerProperties(&myCount, (Interop.LayerProperties *)Memory.ToPointer()); int *Positions = ((int *)myStartingBlock.ToPointer()); int Last = 0; for (int i = 0; i < myCount; i++) { Interop.LayerProperties myProperties2 = new Interop.LayerProperties(); int *PropertiesToCopy = (int *)&myProperties2; int q = 0; for (q = Last; q < Last + (SizeofBuffer / Marshal.SizeOf(typeof(int))); q++) { PropertiesToCopy[q - Last] = Positions[q]; } Last = q; Layers.Add(myProperties2); } Marshal.FreeHGlobal(myStartingBlock); } #if DEBUG List <String> LayerNames = new List <string>(); foreach (Interop.LayerProperties a in Layers) { byte * AName = a.LayerName; string A = Marshal.PtrToStringAnsi(new IntPtr(AName)); Debug.WriteLine(A); #if RENDERDOCENABLED if (A.Contains("RENDERDOC") || A.Contains("VK_LAYER_LUNARG_standard_validation")) { LayerNames.Add(A); } #else if (A.Contains("VK_LAYER_LUNARG_standard_validation") || A.Contains("VK_LAYER_KHRONOS_validation")) { LayerNames.Add(A); } #endif } #endif myInfoCreatedWith = new InstanceCreateInfo() { #if DEBUG EnabledLayerCount = (uint)LayerNames.Count, EnabledLayerNames = LayerNames.ToArray(), #endif EnabledExtensionNames = myStrings.ToArray(), ApplicationInfo = new ApplicationInfo() { ApiVersion = Vulkan.Version.Make(1, 0, 0), ApplicationName = ApplicationName, ApplicationVersion = Vulkan.Version.Make(0, 0, 1) } };; Result result; unsafe { fixed(IntPtr *ptrInstance = &m) { result = Interop.NativeMethods.vkCreateInstance(myInfoCreatedWith.m, Allocator != null ? Allocator.m : null, ptrInstance); } } if (result != Result.Success) { throw new ResultException(result); } vkCreateDebugUtilsCallbackExt = (NativeMethods.vkCreateDebugUtilsCallbackExt)GetMethod("vkCreateDebugUtilsMessengerEXT", typeof(NativeMethods.vkCreateDebugUtilsCallbackExt)); //TODO:vkDestroyDebugUtilsCallbackExt = (NativeMethods.DebugUtilsMessengerCallback)GetMethod("vkDestroyDebugUtilsMessengerEXT", typeof(NativeMethods.DebugUtilsMessengerCallback)); vkCreateDebugReportCallbackEXT = (NativeMethods.vkCreateDebugReportCallbackEXT)GetMethod("vkCreateDebugReportCallbackEXT", typeof(NativeMethods.vkCreateDebugReportCallbackEXT)); vkDestroyDebugReportCallbackEXT = (NativeMethods.vkDestroyDebugReportCallbackEXT)GetMethod("vkDestroyDebugReportCallbackEXT", typeof(NativeMethods.vkDestroyDebugReportCallbackEXT)); vkDebugReportMessageEXT = (NativeMethods.vkDebugReportMessageEXT)GetMethod("vkDebugReportMessageEXT", typeof(NativeMethods.vkDebugReportMessageEXT)); vkDebugUtilsMessage = (NativeMethods.DebugUtilsMessengerCallback)GetMethod("vkDebugUtilsMessengerEXT", typeof(NativeMethods.vkCreateDebugUtilsCallbackExt)); #if DEBUG EnableDebug(DebugCallback); //EnableValidation(ValidationCallback); #endif }