Exemplo n.º 1
0
        private void EnableDebugCallback(VkDebugReportFlagBitsEXT flags = VkDebugReportFlagBitsEXT.VK_DEBUG_REPORT_ERROR_BIT_EXT | VkDebugReportFlagBitsEXT.VK_DEBUG_REPORT_WARNING_BIT_EXT | VkDebugReportFlagBitsEXT.VK_DEBUG_REPORT_DEBUG_BIT_EXT)
        {
            Debug.WriteLine("Enabling Vulkan Debug callbacks.");

            this.debugCallbackFunc = this.DebugCallback;
            IntPtr debugFunctionPtr = Marshal.GetFunctionPointerForDelegate(this.debugCallbackFunc);

            VkDebugReportCallbackCreateInfoEXT debugCallbackCI = new VkDebugReportCallbackCreateInfoEXT();

            debugCallbackCI.sType       = VkStructureType.VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT;
            debugCallbackCI.flags       = flags;
            debugCallbackCI.pfnCallback = debugFunctionPtr;

            var createFnPtr = VulkanNative.vkGetInstanceProcAddr(this.vkInstance, "vkCreateDebugReportCallbackEXT".ToPointer());

            if (createFnPtr == IntPtr.Zero)
            {
                return;
            }

            vkCreateDebugReportCallbackEXT_d createDelegate = Marshal.GetDelegateForFunctionPointer <vkCreateDebugReportCallbackEXT_d>(createFnPtr);
            VkResult result = createDelegate(this.vkInstance, &debugCallbackCI, IntPtr.Zero, out this.debugCallbackHandle);

            Helpers.CheckErrors(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Application-defined debug report callback function.
        /// </summary>
        /// <param name="flags">flags specifies the VkDebugReportFlagBitsEXT that triggered
        /// this callback</param>
        /// <param name="objectType">objectType is a VkDebugReportObjectTypeEXT value specifying
        /// the type of object being used or created at the time the event was
        /// triggered</param>
        /// <param name="objectHandle">object is the object where the issue was detected.
        /// If objectType is VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT,
        /// object is undefined</param>
        /// <param name="location">location is a component (layer, driver, loader) defined value that
        /// specifies the location of the trigger.
        /// This is an optional value</param>
        /// <param name="messageCode">summary>messageCode is a layer-defined value indicating what test
        /// triggered this callback</param>
        /// <param name="layerPrefix">pLayerPrefix is a null-terminated string that is an abbreviation
        /// of the name of the component making the callback.
        /// pLayerPrefix is only valid for the duration of the callback</param>
        /// <param name="message">pMessage is a null-terminated string detailing the trigger
        /// conditions.
        /// pMessage is only valid for the duration of the callback</param>
        /// <param name="userData">pUserData is the user data given when the
        /// VkDebugReportCallbackEXT was created</param>
        /// <returns></returns>
        private VkBool32 DebugCallback(VkDebugReportFlagBitsEXT flags,
                                       VkDebugReportObjectTypeEXT objectType,
                                       UInt64 objectHandle, Int32 location, Int32 messageCode,
                                       IntPtr layerPrefix, IntPtr message, IntPtr userData)
        {
            string text = $"{flags}: {Marshal.PtrToStringAnsi(message)}";

            Debug.WriteLine(text);
            using (var sw = new StreamWriter(debugFilename, true)) {
                sw.WriteLine(text);
            }
            return(true);
        }
Exemplo n.º 3
0
        public bool DebugReportMessage(VkDebugReportFlagBitsEXT flags, VkDebugReportObjectTypeEXT objectType, object obj, int location, int messageCode, string pLayerPrefix, string pMessage)
        {
            bool abort = false;

            foreach (var callback in m_ReportCallbacks)
            {
                if ((callback.m_pCreateInfo.flags & flags) > 0)
                {
                    abort |= callback.m_pCreateInfo.pfnCallback(flags, objectType, obj, location, messageCode, pLayerPrefix, pMessage, callback.m_pCreateInfo.pUserData);
                }
            }
            return(abort);
        }
Exemplo n.º 4
0
        private VkBool32 DebugCallback(uint flags, VkDebugReportObjectTypeEXT objectType, ulong @object, UIntPtr location, int messageCode, byte *pLayerPrefix, byte *pMessage, void *pUserData)
        {
            string message = Marshal.PtrToStringAnsi((IntPtr)pMessage);
            VkDebugReportFlagBitsEXT debugReportFlags = (VkDebugReportFlagBitsEXT)flags;

            string fullMessage = $"[{debugReportFlags}] ({objectType}) {message}";

            if (debugReportFlags == VkDebugReportFlagBitsEXT.VK_DEBUG_REPORT_ERROR_BIT_EXT)
            {
                throw new InvalidOperationException(fullMessage);
            }

            return(false);
        }
Exemplo n.º 5
0
        public static void vkDebugReportMessageEXT(
            VkInstance instance,
            VkDebugReportFlagBitsEXT flags,
            VkDebugReportObjectTypeEXT objectType,
            object obj,
            int location,
            int messageCode,
            string pLayerPrefix,
            string pMessage)
        {
            VkPreconditions.CheckNull(instance, nameof(instance));
            VkPreconditions.CheckString(pMessage, nameof(pMessage));

            GetInstance(instance).DebugReportMessage(flags, objectType, obj, location, messageCode, pLayerPrefix, pMessage);
        }
Exemplo n.º 6
0
 private static bool debugCallback(VkDebugReportFlagBitsEXT flags, VkDebugReportObjectTypeEXT objType, object obj, int location, int messageCode, string pLayerPrefix, string msg, object userData)
 {
     Debug.WriteLine(string.Format("ERROR: validation layer: {0}", msg));
     return(false);
 }
Exemplo n.º 7
0
 public void DebugReportMessage(VkDebugReportFlagBitsEXT flags, string message)
 {
     m_device.DebugReportMessage(flags, VkDebugReportObjectTypeEXT.VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, this, 0, 0, "", message);
 }