@@ -206,6 +206,43 @@ bool VulkanInstance::QueryGlobals() {
206206 return true ;
207207}
208208
209+ VkBool32 VKAPI_PTR DebugMessageCallback (VkDebugReportFlagsEXT flags,
210+ VkDebugReportObjectTypeEXT objectType,
211+ uint64_t object, size_t location,
212+ int32_t messageCode,
213+ const char * pLayerPrefix,
214+ const char * pMessage, void * pUserData) {
215+ if (strcmp (pLayerPrefix, " Validation" ) == 0 ) {
216+ const char * blacklist[] = {
217+ " bound but it was never updated. You may want to either update it or "
218+ " not bind it." ,
219+ " is being used in draw but has not been updated." ,
220+ };
221+ for (uint32_t i = 0 ; i < xe::countof (blacklist); ++i) {
222+ if (strstr (pMessage, blacklist[i]) != nullptr ) {
223+ return false ;
224+ }
225+ }
226+ }
227+
228+ auto instance = reinterpret_cast <VulkanInstance*>(pUserData);
229+ const char * message_type = " UNKNOWN" ;
230+ if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
231+ message_type = " ERROR" ;
232+ } else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
233+ message_type = " WARN" ;
234+ } else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
235+ message_type = " PERF WARN" ;
236+ } else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
237+ message_type = " INFO" ;
238+ } else if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
239+ message_type = " DEBUG" ;
240+ }
241+
242+ XELOGVK (" [%s/%s:%d] %s" , pLayerPrefix, message_type, messageCode, pMessage);
243+ return false ;
244+ }
245+
209246bool VulkanInstance::CreateInstance () {
210247 XELOGVK (" Verifying layers and extensions..." );
211248
@@ -227,10 +264,21 @@ bool VulkanInstance::CreateInstance() {
227264
228265 XELOGVK (" Initializing application instance..." );
229266
267+ VkDebugReportCallbackCreateInfoEXT debug_info;
268+ debug_info.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
269+ debug_info.pNext = nullptr ;
270+ // TODO(benvanik): flags to set these.
271+ debug_info.flags =
272+ VK_DEBUG_REPORT_INFORMATION_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT |
273+ VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT |
274+ VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_DEBUG_BIT_EXT;
275+ debug_info.pfnCallback = &DebugMessageCallback;
276+ debug_info.pUserData = this ;
277+
230278 // TODO(benvanik): use GetEntryInfo?
231279 VkApplicationInfo application_info;
232280 application_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
233- application_info.pNext = nullptr ;
281+ application_info.pNext = &debug_info ;
234282 application_info.pApplicationName = " xenia" ;
235283 application_info.applicationVersion = 1 ;
236284 application_info.pEngineName = " xenia" ;
@@ -294,43 +342,6 @@ void VulkanInstance::DestroyInstance() {
294342 handle = nullptr ;
295343}
296344
297- VkBool32 VKAPI_PTR DebugMessageCallback (VkDebugReportFlagsEXT flags,
298- VkDebugReportObjectTypeEXT objectType,
299- uint64_t object, size_t location,
300- int32_t messageCode,
301- const char * pLayerPrefix,
302- const char * pMessage, void * pUserData) {
303- if (strcmp (pLayerPrefix, " Validation" ) == 0 ) {
304- const char * blacklist[] = {
305- " bound but it was never updated. You may want to either update it or "
306- " not bind it." ,
307- " is being used in draw but has not been updated." ,
308- };
309- for (uint32_t i = 0 ; i < xe::countof (blacklist); ++i) {
310- if (strstr (pMessage, blacklist[i]) != nullptr ) {
311- return false ;
312- }
313- }
314- }
315-
316- auto instance = reinterpret_cast <VulkanInstance*>(pUserData);
317- const char * message_type = " UNKNOWN" ;
318- if (flags & VK_DEBUG_REPORT_ERROR_BIT_EXT) {
319- message_type = " ERROR" ;
320- } else if (flags & VK_DEBUG_REPORT_WARNING_BIT_EXT) {
321- message_type = " WARN" ;
322- } else if (flags & VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT) {
323- message_type = " PERF WARN" ;
324- } else if (flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT) {
325- message_type = " INFO" ;
326- } else if (flags & VK_DEBUG_REPORT_DEBUG_BIT_EXT) {
327- message_type = " DEBUG" ;
328- }
329-
330- XELOGVK (" [%s/%s:%d] %s" , pLayerPrefix, message_type, messageCode, pMessage);
331- return false ;
332- }
333-
334345void VulkanInstance::EnableDebugValidation () {
335346 if (dbg_report_callback_) {
336347 DisableDebugValidation ();
0 commit comments