Kale
Loading...
Searching...
No Matches
CoreValidation.cpp
Go to the documentation of this file.
1/*
2 Copyright 2022 Rishi Challa
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifdef KALE_VULKAN
18
19#include "Core.hpp"
20
21using namespace Kale;
22using namespace Kale::Vulkan;
23
24#ifdef KALE_DEBUG
25
33static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,
34 VkDebugUtilsMessageTypeFlagsEXT type, const VkDebugUtilsMessengerCallbackDataEXT* callbackData,
35 void* userData) {
36
37 switch (vk::DebugUtilsMessageSeverityFlagBitsEXT(severity)) {
38 #ifdef KALE_VERBOSE
39 case vk::DebugUtilsMessageSeverityFlagBitsEXT::eVerbose:
40 console.log(callbackData->pMessage);
41 return VK_FALSE;
42 #endif
43 case vk::DebugUtilsMessageSeverityFlagBitsEXT::eInfo:
44 console.info(callbackData->pMessage);
45 return VK_FALSE;
46 case vk::DebugUtilsMessageSeverityFlagBitsEXT::eWarning:
47 console.warn(callbackData->pMessage);
48 return VK_FALSE;
49 case vk::DebugUtilsMessageSeverityFlagBitsEXT::eError:
50 console.error(callbackData->pMessage);
51 return VK_FALSE;
52 default:
53 return VK_FALSE;
54 }
55}
56
60void Core::setupDebugMessageCallback() {
61 using MessageSeverity = vk::DebugUtilsMessageSeverityFlagBitsEXT;
62 using MessageType = vk::DebugUtilsMessageTypeFlagBitsEXT;
63
64 vk::DebugUtilsMessengerCreateInfoEXT createInfo;
65 #ifdef KALE_VERBOSE
66 createInfo.messageSeverity = MessageSeverity::eError | MessageSeverity::eWarning |
67 MessageSeverity::eInfo | MessageSeverity::eVerbose;
68 #else
69 createInfo.messageSeverity = MessageSeverity::eError | MessageSeverity::eWarning;
70 #endif
71 createInfo.messageType = MessageType::eGeneral | MessageType::ePerformance | MessageType::eValidation;
72 createInfo.pfnUserCallback = debugCallback;
73 createInfo.pUserData = nullptr;
74
75 auto func = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance.get(),
76 "vkCreateDebugUtilsMessengerEXT"));
77
78 if (func == nullptr) {
79 console.error("Unable to load Debug Utils Extension");
80 return;
81 }
82
83 const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo = &createInfo.operator const VkDebugUtilsMessengerCreateInfoEXT&();
84 if (func(instance.get(), pCreateInfo, nullptr, &debugMessenger) != VK_SUCCESS) {
85 console.error("Failed to setup Debug Messenger");
86 return;
87 }
88}
89
93void Core::destroyDebugMessageCallback() {
94 auto func = reinterpret_cast<PFN_vkDestroyDebugUtilsMessengerEXT>(vkGetInstanceProcAddr(instance.get(),
95 "vkDestroyDebugUtilsMessengerEXT"));
96
97 if (func == nullptr) {
98 console.error("Failed to load Debug Utils Deletion Extension");
99 return;
100 }
101
102 func(instance.get(), debugMessenger, nullptr);
103}
104
105#endif
106
107#endif
void warn(T msg)
Definition Logger.hpp:182
void log(T msg)
Definition Logger.hpp:150
void error(T msg)
Definition Logger.hpp:198
void info(T msg)
Definition Logger.hpp:166
static vk::UniqueInstance instance
Definition Core.hpp:89
Logger console
Definition Logger.hpp:317