add VK_EXT_debug_utils labels

This extension allows adding labels to vulkan objects and insert string
labels into command buffers. This is visible in tools like RenderDoc and
helps with debugging a lot.

When running with -vkdebug:
- mark all texture VkImages and VkImageViews with corresponding names
- label brush model draw calls accordingly
This commit is contained in:
Ivan Avdeev 2021-01-31 16:50:27 -08:00
parent 12c8f00885
commit e848e312d3
4 changed files with 42 additions and 5 deletions

View File

@ -27,10 +27,6 @@
X(vkEnumerateInstanceVersion) \
X(vkCreateInstance) \
#define INSTANCE_DEBUG_FUNCS(X) \
X(vkCreateDebugUtilsMessengerEXT) \
X(vkDestroyDebugUtilsMessengerEXT) \
static PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr;
#define X(f) PFN_##f f = NULL;

View File

@ -121,6 +121,14 @@ const char *resultName(VkResult result);
X(vkDestroyDevice) \
X(vkDestroySurfaceKHR) \
#define INSTANCE_DEBUG_FUNCS(X) \
X(vkCreateDebugUtilsMessengerEXT) \
X(vkDestroyDebugUtilsMessengerEXT) \
X(vkCmdBeginDebugUtilsLabelEXT) \
X(vkCmdEndDebugUtilsLabelEXT) \
X(vkCmdInsertDebugUtilsLabelEXT) \
X(vkSetDebugUtilsObjectNameEXT) \
#define DEVICE_FUNCS(X) \
X(vkGetDeviceQueue) \
X(vkCreateSwapchainKHR) \
@ -191,4 +199,5 @@ const char *resultName(VkResult result);
#define X(f) extern PFN_##f f;
DEVICE_FUNCS(X)
INSTANCE_FUNCS(X)
INSTANCE_DEBUG_FUNCS(X)
#undef X

View File

@ -313,8 +313,18 @@ static void drawBrushModel( const model_t *mod )
int index_count = 0;
int index_offset = -1;
if (!bmodel) // TODO complain
if (!bmodel) {
gEngine.Con_Printf( S_ERROR "Model %s wasn't loaded\n", mod->name);
return;
}
if (vk_core.debug) {
VkDebugUtilsLabelEXT label = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT,
.pLabelName = mod->name,
};
vkCmdBeginDebugUtilsLabelEXT(vk_core.cb, &label);
}
for (int i = 0; i < bmodel->num_surfaces; ++i) {
const vk_brush_model_surface_t *bsurf = bmodel->surfaces + i;
@ -343,6 +353,9 @@ static void drawBrushModel( const model_t *mod )
if (index_count)
vkCmdDrawIndexed(vk_core.cb, index_count, 1, index_offset, bmodel->vertex_offset, 0);
if (vk_core.debug)
vkCmdEndDebugUtilsLabelEXT(vk_core.cb);
}
void R_RotateForEntity( matrix4x4 out, const cl_entity_t *e )

View File

@ -329,6 +329,16 @@ static qboolean VK_UploadTexture(vk_texture_t *tex, rgbdata_t *pic)
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
};
XVK_CHECK(vkCreateImage(vk_core.device, &image_create_info, NULL, &tex->vk.image));
if (vk_core.debug) {
VkDebugUtilsObjectNameInfoEXT debug_name = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.objectHandle = (uint64_t)tex->vk.image,
.objectType = VK_OBJECT_TYPE_IMAGE,
.pObjectName = tex->name,
};
XVK_CHECK(vkSetDebugUtilsObjectNameEXT(vk_core.device, &debug_name));
}
}
// 2. Alloc mem for VkImage and bind it (DEV_LOCAL)
@ -434,6 +444,15 @@ static qboolean VK_UploadTexture(vk_texture_t *tex, rgbdata_t *pic)
ivci.components = (VkComponentMapping){0, 0, 0, (pic->flags & IMAGE_HAS_ALPHA) ? 0 : VK_COMPONENT_SWIZZLE_ONE};
XVK_CHECK(vkCreateImageView(vk_core.device, &ivci, NULL, &tex->vk.image_view));
}
if (vk_core.debug) {
VkDebugUtilsObjectNameInfoEXT debug_name = {
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
.objectHandle = (uint64_t)tex->vk.image_view,
.objectType = VK_OBJECT_TYPE_IMAGE_VIEW,
.pObjectName = tex->name,
};
XVK_CHECK(vkSetDebugUtilsObjectNameEXT(vk_core.device, &debug_name));
}
// TODO how should we approach this:
// - per-texture desc sets can be inconvenient if texture is used in different incompatible contexts