public void EnableDebugCallback(VkDebugReportFlagsEXT flags = VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.ErrorEXT)
        {
            _debugCallbackFunc = DebugCallback;
            IntPtr debugFunctionPtr = Marshal.GetFunctionPointerForDelegate(_debugCallbackFunc);
            VkDebugReportCallbackCreateInfoEXT debugCallbackCI = VkDebugReportCallbackCreateInfoEXT.New();

            debugCallbackCI.flags       = flags;
            debugCallbackCI.pfnCallback = debugFunctionPtr;
            FixedUtf8String debugExtFnName = "vkCreateDebugReportCallbackEXT";
            IntPtr          createFnPtr    = vkGetInstanceProcAddr(_instance, debugExtFnName);
            vkCreateDebugReportCallbackEXT_d createDelegate = Marshal.GetDelegateForFunctionPointer <vkCreateDebugReportCallbackEXT_d>(createFnPtr);

            createDelegate(_instance, &debugCallbackCI, IntPtr.Zero, out _debugCallbackHandle);
        }
Exemple #2
0
        public void EnableDebugCallback(VkDebugReportFlagsEXT flags = VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.ErrorEXT)
        {
            Debug.WriteLine("Enabling Vulkan Debug callbacks.");
            _debugCallbackFunc = DebugCallback;
            IntPtr debugFunctionPtr = Marshal.GetFunctionPointerForDelegate(_debugCallbackFunc);
            VkDebugReportCallbackCreateInfoEXT debugCallbackCI = VkDebugReportCallbackCreateInfoEXT.New();

            debugCallbackCI.flags       = flags;
            debugCallbackCI.pfnCallback = debugFunctionPtr;
            IntPtr createFnPtr;

            using (FixedUtf8String debugExtFnName = "vkCreateDebugReportCallbackEXT")
            {
                createFnPtr = vkGetInstanceProcAddr(_instance, debugExtFnName);
            }
            vkCreateDebugReportCallbackEXT_d createDelegate = Marshal.GetDelegateForFunctionPointer <vkCreateDebugReportCallbackEXT_d>(createFnPtr);
            VkResult result = createDelegate(_instance, &debugCallbackCI, IntPtr.Zero, out _debugCallbackHandle);

            CheckResult(result);
        }
Exemple #3
0
        private VkInstance CreateInstance()
        {
            List <GCHandle> handles = new List <GCHandle>();

            bool debug = false;

            string[] debugOnlyLayers = new string[] {
                //"VK_LAYER_GOOGLE_threading",
                //"VK_LAYER_LUNARG_parameter_validation",
                //"VK_LAYER_LUNARG_device_limits", Not Present?
                //"VK_LAYER_LUNARG_object_tracker",
                //"VK_LAYER_LUNARG_image", Not Present?
                "VK_LAYER_LUNARG_core_validation",
                //"VK_LAYER_LUNARG_swapchain",
                //"VK_LAYER_GOOGLE_unique_objects",
            };
            List <string> layerList = new List <string>();

            if (debug)
            {
                layerList.AddRange(debugOnlyLayers);
            }

            string[] layers       = layerList.ToArray();
            byte[][] pDebugLayers = new byte[layers.Length][];


            byte *[] ppDebugLayerArray = new byte *[pDebugLayers.Length];
            if (!debug)
            {
                ppDebugLayerArray = new byte *[1];//this is to give a null ptr to use later
            }
            for (int i = 0; i < pDebugLayers.Length; i++)
            {
                pDebugLayers[i] = Encoding.UTF8.GetBytes(layers[i] + char.MinValue);
                GCHandle handle = GCHandle.Alloc(pDebugLayers[i]);
                handles.Add(handle);
                fixed(byte *p = &(((byte[])handle.Target)[0]))
                {
                    ppDebugLayerArray[i] = p;
                }
            }

            List <string> requiredExtensions = new List <string>();

            requiredExtensions.Add("VK_EXT_debug_report");
            requiredExtensions.AddRange(GLFW.Vulkan.GetRequiredInstanceExtensions());

            string[] extensionNames = requiredExtensions.ToArray();



            byte[][] pExtensionNames = new byte[extensionNames.Length][];

            byte *[] ppExtensionNamesArray = new byte *[extensionNames.Length];

            for (int i = 0; i < pExtensionNames.Length; i++)
            {
                pExtensionNames[i] = Encoding.UTF8.GetBytes(extensionNames[i] + char.MinValue);
                GCHandle handle = GCHandle.Alloc(pExtensionNames[i]);
                handles.Add(handle);
                fixed(byte *p = &(((byte[])handle.Target)[0]))
                {
                    ppExtensionNamesArray[i] = p;
                }
            }
            VkInstance instance = new VkInstance();

            fixed(byte **layersptr = &ppDebugLayerArray[0])
            {
                fixed(byte **extensions = &ppExtensionNamesArray[0])
                {
                    VkInstanceCreateInfo pCreateInfo = VkInstanceCreateInfo.New();

                    pCreateInfo.ppEnabledLayerNames     = layersptr;
                    pCreateInfo.ppEnabledExtensionNames = extensions;
                    pCreateInfo.enabledLayerCount       = (uint)pDebugLayers.Length;
                    pCreateInfo.enabledExtensionCount   = (uint)extensionNames.Length;

                    Assert(vkCreateInstance(&pCreateInfo, null, &instance));
                }
            }

            foreach (var handle in handles)
            {
                handle.Free();
            }

            DebugDelegate debugDelegate = new DebugDelegate(DebugCallback);

            //PFN_vkDebugReportCallbackEXT _debugCallbackFunc =(PFN_vkDebugReportCallbackEXT) debugDelegate;



            IntPtr debugFunctionPtr = Marshal.GetFunctionPointerForDelegate(debugDelegate);

            debugDelegateHandle = GCHandle.Alloc(debugDelegate);

            VkDebugReportCallbackCreateInfoEXT createInfoEXT = VkDebugReportCallbackCreateInfoEXT.New();

            createInfoEXT.pfnCallback = debugFunctionPtr;
            createInfoEXT.flags       = //VkDebugReportFlagsEXT.DebugEXT | VkDebugReportFlagsEXT.ErrorEXT | VkDebugReportFlagsEXT.WarningEXT |
                                        (VkDebugReportFlagsEXT)int.MaxValue;

            byte[] debugExtFnName = Encoding.UTF8.GetBytes("vkCreateDebugReportCallbackEXT" + char.MinValue);



            IntPtr createFnPtr;

            fixed(byte *namePtr = &(debugExtFnName[0]))
            {
                createFnPtr = vkGetInstanceProcAddr(instance, namePtr);
            }

            vkCreateDebugReportCallbackEXT_d createDelegate = Marshal.GetDelegateForFunctionPointer <vkCreateDebugReportCallbackEXT_d>(createFnPtr);



            VkDebugReportCallbackCreateInfoEXT *createInfoPtr = (&createInfoEXT);

            fixed(ulong *ptr = &(debugReport.Handle))
            {
                Assert(createDelegate(instance, createInfoPtr, IntPtr.Zero, out debugReport));
            }

            return(instance);
        }