@@ -299,6 +299,8 @@ void EndSingleTimeCommands()
299299{
300300 ERR_GUARD_VULKAN ( vkEndCommandBuffer (g_hTemporaryCommandBuffer) );
301301
302+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_COMMAND_BUFFER, reinterpret_cast <std::uint64_t >(g_hTemporaryCommandBuffer), " g_hTemporaryCommandBuffer" );
303+
302304 VkSubmitInfo submitInfo = { VK_STRUCTURE_TYPE_SUBMIT_INFO };
303305 submitInfo.commandBufferCount = 1 ;
304306 submitInfo.pCommandBuffers = &g_hTemporaryCommandBuffer;
@@ -715,6 +717,7 @@ static void CreateMesh()
715717 vbInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
716718 vbAllocCreateInfo.flags = 0 ;
717719 ERR_GUARD_VULKAN ( vmaCreateBuffer (g_hAllocator, &vbInfo, &vbAllocCreateInfo, &g_hVertexBuffer, &g_hVertexBufferAlloc, nullptr ) );
720+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_BUFFER, reinterpret_cast <std::uint64_t >(g_hVertexBuffer), " g_hVertexBuffer" );
718721
719722 // Create index buffer
720723
@@ -739,6 +742,7 @@ static void CreateMesh()
739742 ibInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
740743 ibAllocCreateInfo.flags = 0 ;
741744 ERR_GUARD_VULKAN ( vmaCreateBuffer (g_hAllocator, &ibInfo, &ibAllocCreateInfo, &g_hIndexBuffer, &g_hIndexBufferAlloc, nullptr ) );
745+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_BUFFER, reinterpret_cast <std::uint64_t >(g_hIndexBuffer), " g_hIndexBuffer" );
742746
743747 // Copy buffers
744748
@@ -820,7 +824,11 @@ static void CreateTexture(uint32_t sizeX, uint32_t sizeY)
820824 VmaAllocationCreateInfo imageAllocCreateInfo = {};
821825 imageAllocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
822826
823- ERR_GUARD_VULKAN ( vmaCreateImage (g_hAllocator, &imageInfo, &imageAllocCreateInfo, &g_hTextureImage, &g_hTextureImageAlloc, nullptr ) );
827+ VmaAllocationInfo textureImageAllocInfo = {};
828+
829+ ERR_GUARD_VULKAN ( vmaCreateImage (g_hAllocator, &imageInfo, &imageAllocCreateInfo, &g_hTextureImage, &g_hTextureImageAlloc, &textureImageAllocInfo) );
830+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_IMAGE, reinterpret_cast <std::uint64_t >(g_hTextureImage), " g_hTextureImage" );
831+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_DEVICE_MEMORY, reinterpret_cast <std::uint64_t >(textureImageAllocInfo.deviceMemory ), " textureImageAllocInfo.deviceMemory" );
824832
825833 // Transition image layouts, copy image.
826834
@@ -889,6 +897,7 @@ static void CreateTexture(uint32_t sizeX, uint32_t sizeY)
889897 textureImageViewInfo.subresourceRange .baseArrayLayer = 0 ;
890898 textureImageViewInfo.subresourceRange .layerCount = 1 ;
891899 ERR_GUARD_VULKAN ( vkCreateImageView (g_hDevice, &textureImageViewInfo, g_Allocs, &g_hTextureImageView) );
900+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_IMAGE_VIEW, reinterpret_cast <std::uint64_t >(g_hTextureImageView), " g_hTextureImageView" );
892901}
893902
894903struct UniformBufferObject
@@ -994,13 +1003,20 @@ static void CreateSwapchain()
9941003 vkDestroySwapchainKHR (g_hDevice, g_hSwapchain, g_Allocs);
9951004 g_hSwapchain = hNewSwapchain;
9961005
1006+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_SWAPCHAIN_KHR, reinterpret_cast <std::uint64_t >(g_hSwapchain), " g_hSwapchain" );
1007+
9971008 // Retrieve swapchain images.
9981009
9991010 uint32_t swapchainImageCount = 0 ;
10001011 ERR_GUARD_VULKAN ( vkGetSwapchainImagesKHR (g_hDevice, g_hSwapchain, &swapchainImageCount, nullptr ) );
10011012 g_SwapchainImages.resize (swapchainImageCount);
10021013 ERR_GUARD_VULKAN ( vkGetSwapchainImagesKHR (g_hDevice, g_hSwapchain, &swapchainImageCount, g_SwapchainImages.data ()) );
10031014
1015+ for (size_t i = 0 ; i < swapchainImageCount; i++) {
1016+ std::string swapchainImgName = " g_SwapchainImages[" + std::to_string (i) + " ]" ;
1017+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_IMAGE, reinterpret_cast <std::uint64_t >(g_SwapchainImages[i]), swapchainImgName);
1018+ }
1019+
10041020 // Create swapchain image views.
10051021
10061022 for (size_t i = g_SwapchainImageViews.size (); i--; )
@@ -1024,6 +1040,8 @@ static void CreateSwapchain()
10241040 swapchainImageViewInfo.subresourceRange .baseArrayLayer = 0 ;
10251041 swapchainImageViewInfo.subresourceRange .layerCount = 1 ;
10261042 ERR_GUARD_VULKAN ( vkCreateImageView (g_hDevice, &swapchainImageViewInfo, g_Allocs, &g_SwapchainImageViews[i]) );
1043+ std::string imgViewName = " g_SwapchainImageViews[" + std::to_string (i) + " ]" ;
1044+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_IMAGE_VIEW, reinterpret_cast <std::uint64_t >(g_SwapchainImageViews[i]), imgViewName);
10271045 }
10281046
10291047 // Create depth buffer
@@ -1049,7 +1067,11 @@ static void CreateSwapchain()
10491067 VmaAllocationCreateInfo depthImageAllocCreateInfo = {};
10501068 depthImageAllocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO;
10511069
1052- ERR_GUARD_VULKAN ( vmaCreateImage (g_hAllocator, &depthImageInfo, &depthImageAllocCreateInfo, &g_hDepthImage, &g_hDepthImageAlloc, nullptr ) );
1070+ VmaAllocationInfo depthImageAllocInfo = {};
1071+
1072+ ERR_GUARD_VULKAN ( vmaCreateImage (g_hAllocator, &depthImageInfo, &depthImageAllocCreateInfo, &g_hDepthImage, &g_hDepthImageAlloc, &depthImageAllocInfo) );
1073+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_IMAGE, reinterpret_cast <std::uint64_t >(g_hDepthImage), " g_hDepthImage" );
1074+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_DEVICE_MEMORY, reinterpret_cast <std::uint64_t >(depthImageAllocInfo.deviceMemory ), " depthImageAllocInfo.deviceMemory" );
10531075
10541076 VkImageViewCreateInfo depthImageViewInfo = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO };
10551077 depthImageViewInfo.image = g_hDepthImage;
@@ -1062,6 +1084,7 @@ static void CreateSwapchain()
10621084 depthImageViewInfo.subresourceRange .layerCount = 1 ;
10631085
10641086 ERR_GUARD_VULKAN ( vkCreateImageView (g_hDevice, &depthImageViewInfo, g_Allocs, &g_hDepthImageView) );
1087+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_IMAGE_VIEW, reinterpret_cast <std::uint64_t >(g_hDepthImageView), " g_hDepthImageView" );
10651088
10661089 // Create pipeline layout
10671090 {
@@ -1084,6 +1107,7 @@ static void CreateSwapchain()
10841107 pipelineLayoutInfo.pushConstantRangeCount = 1 ;
10851108 pipelineLayoutInfo.pPushConstantRanges = pushConstantRanges;
10861109 ERR_GUARD_VULKAN ( vkCreatePipelineLayout (g_hDevice, &pipelineLayoutInfo, g_Allocs, &g_hPipelineLayout) );
1110+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_PIPELINE_LAYOUT, reinterpret_cast <std::uint64_t >(g_hPipelineLayout), " g_hPipelineLayout" );
10871111 }
10881112
10891113 // Create render pass
@@ -1136,6 +1160,7 @@ static void CreateSwapchain()
11361160 renderPassInfo.pSubpasses = &subpassDesc;
11371161 renderPassInfo.dependencyCount = 0 ;
11381162 ERR_GUARD_VULKAN ( vkCreateRenderPass (g_hDevice, &renderPassInfo, g_Allocs, &g_hRenderPass) );
1163+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_RENDER_PASS, reinterpret_cast <std::uint64_t >(g_hRenderPass), " g_hRenderPass" );
11391164 }
11401165
11411166 // Create pipeline
@@ -1147,13 +1172,15 @@ static void CreateSwapchain()
11471172 shaderModuleInfo.pCode = (const uint32_t *)vertShaderCode.data ();
11481173 VkShaderModule hVertShaderModule = VK_NULL_HANDLE;
11491174 ERR_GUARD_VULKAN ( vkCreateShaderModule (g_hDevice, &shaderModuleInfo, g_Allocs, &hVertShaderModule) );
1175+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_SHADER_MODULE, reinterpret_cast <std::uint64_t >(hVertShaderModule), " hVertShaderModule" );
11501176
11511177 std::vector<char > hFragShaderCode;
11521178 LoadShader (hFragShaderCode, " Shader.frag.spv" );
11531179 shaderModuleInfo.codeSize = hFragShaderCode.size ();
11541180 shaderModuleInfo.pCode = (const uint32_t *)hFragShaderCode.data ();
11551181 VkShaderModule fragShaderModule = VK_NULL_HANDLE;
11561182 ERR_GUARD_VULKAN ( vkCreateShaderModule (g_hDevice, &shaderModuleInfo, g_Allocs, &fragShaderModule) );
1183+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_SHADER_MODULE, reinterpret_cast <std::uint64_t >(fragShaderModule), " fragShaderModule" );
11571184
11581185 VkPipelineShaderStageCreateInfo vertPipelineShaderStageInfo = { VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO };
11591186 vertPipelineShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT;
@@ -1293,6 +1320,8 @@ static void CreateSwapchain()
12931320 g_Allocs,
12941321 &g_hPipeline) );
12951322
1323+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_PIPELINE, reinterpret_cast <std::uint64_t >(g_hPipeline), " g_hPipeline" );
1324+
12961325 vkDestroyShaderModule (g_hDevice, fragShaderModule, g_Allocs);
12971326 vkDestroyShaderModule (g_hDevice, hVertShaderModule, g_Allocs);
12981327 }
@@ -1316,6 +1345,8 @@ static void CreateSwapchain()
13161345 framebufferInfo.height = g_Extent.height ;
13171346 framebufferInfo.layers = 1 ;
13181347 ERR_GUARD_VULKAN ( vkCreateFramebuffer (g_hDevice, &framebufferInfo, g_Allocs, &g_Framebuffers[i]) );
1348+ std::string framebufName = " g_Framebuffers[" + std::to_string (i) + " ]" ;
1349+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_FRAMEBUFFER, reinterpret_cast <std::uint64_t >(g_Framebuffers[i]), framebufName);
13191350 }
13201351
13211352 // Destroy the old semaphores and create new ones
@@ -1342,7 +1373,12 @@ static void CreateSwapchain()
13421373
13431374 for (std::size_t swapchain_img_index = 0 ; swapchain_img_index < g_SwapchainImageCount; swapchain_img_index++) {
13441375 ERR_GUARD_VULKAN (vkCreateSemaphore (g_hDevice, &semaphoreInfo, g_Allocs, &g_hImageAvailableSemaphores[swapchain_img_index]));
1376+ std::string semaphoreName = " g_hImageAvailableSemaphores[" + std::to_string (swapchain_img_index) + " ]" ;
1377+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_SEMAPHORE, reinterpret_cast <std::uint64_t >(g_hImageAvailableSemaphores[swapchain_img_index]), semaphoreName);
1378+
13451379 ERR_GUARD_VULKAN (vkCreateSemaphore (g_hDevice, &semaphoreInfo, g_Allocs, &g_hRenderFinishedSemaphores[swapchain_img_index]));
1380+ semaphoreName = " g_hRenderFinishedSemaphores[" + std::to_string (swapchain_img_index) + " ]" ;
1381+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_SEMAPHORE, reinterpret_cast <std::uint64_t >(g_hRenderFinishedSemaphores[swapchain_img_index]), semaphoreName);
13461382 }
13471383}
13481384
@@ -2045,6 +2081,10 @@ static void InitializeApplication()
20452081 deviceCreateInfo.pQueueCreateInfos = queueCreateInfo;
20462082
20472083 ERR_GUARD_VULKAN ( vkCreateDevice (g_hPhysicalDevice, &deviceCreateInfo, g_Allocs, &g_hDevice) );
2084+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_DEVICE, reinterpret_cast <std::uint64_t >(g_hDevice), " g_hDevice" );
2085+ // Only now that SetDebugUtilsObjectName is loaded, we can assign a name to g_hVulkanInstance as well
2086+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_INSTANCE, reinterpret_cast <std::uint64_t >(g_hVulkanInstance), " g_hVulkanInstance" );
2087+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_PHYSICAL_DEVICE, reinterpret_cast <std::uint64_t >(g_hPhysicalDevice), " g_hPhysicalDevice" );
20482088
20492089 // Fetch pointers to extension functions
20502090 if (VK_KHR_buffer_device_address_enabled)
@@ -2079,6 +2119,8 @@ static void InitializeApplication()
20792119 vkGetDeviceQueue (g_hDevice, g_PresentQueueFamilyIndex, 0 , &g_hPresentQueue);
20802120 assert (g_hGraphicsQueue);
20812121 assert (g_hPresentQueue);
2122+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_QUEUE, reinterpret_cast <std::uint64_t >(g_hGraphicsQueue), " g_hGraphicsQueue" );
2123+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_QUEUE, reinterpret_cast <std::uint64_t >(g_hPresentQueue), " g_hPresentQueue" );
20822124
20832125 if (g_SparseBindingEnabled)
20842126 {
@@ -2092,24 +2134,33 @@ static void InitializeApplication()
20922134 commandPoolInfo.queueFamilyIndex = g_GraphicsQueueFamilyIndex;
20932135 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20942136 ERR_GUARD_VULKAN ( vkCreateCommandPool (g_hDevice, &commandPoolInfo, g_Allocs, &g_hCommandPool) );
2137+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_COMMAND_POOL, reinterpret_cast <std::uint64_t >(g_hCommandPool), " g_hCommandPool" );
20952138
20962139 VkCommandBufferAllocateInfo commandBufferInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO };
20972140 commandBufferInfo.commandPool = g_hCommandPool;
20982141 commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20992142 commandBufferInfo.commandBufferCount = COMMAND_BUFFER_COUNT;
21002143 ERR_GUARD_VULKAN ( vkAllocateCommandBuffers (g_hDevice, &commandBufferInfo, g_MainCommandBuffers) );
2144+ for (size_t i = 0 ; i < COMMAND_BUFFER_COUNT; i++) {
2145+ std::string cmdBufName = " g_MainCommandBuffers[" + std::to_string (i) + " ]" ;
2146+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_COMMAND_BUFFER, reinterpret_cast <std::uint64_t >(g_MainCommandBuffers[i]), cmdBufName);
2147+ }
21012148
21022149 VkFenceCreateInfo fenceInfo = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO };
21032150 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
21042151 for (size_t i = 0 ; i < COMMAND_BUFFER_COUNT; ++i)
21052152 {
21062153 ERR_GUARD_VULKAN ( vkCreateFence (g_hDevice, &fenceInfo, g_Allocs, &g_MainCommandBufferExecutedFences[i]) );
2154+ std::string fenceName = " g_MainCommandBufferExecutedFences[" + std::to_string (i) + " ]" ;
2155+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_FENCE, reinterpret_cast <std::uint64_t >(g_MainCommandBufferExecutedFences[i]), fenceName);
21072156 }
21082157
21092158 ERR_GUARD_VULKAN ( vkCreateFence (g_hDevice, &fenceInfo, g_Allocs, &g_ImmediateFence) );
2159+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_FENCE, reinterpret_cast <std::uint64_t >(g_ImmediateFence), " g_ImmediateFence" );
21102160
21112161 commandBufferInfo.commandBufferCount = 1 ;
21122162 ERR_GUARD_VULKAN ( vkAllocateCommandBuffers (g_hDevice, &commandBufferInfo, &g_hTemporaryCommandBuffer) );
2163+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_COMMAND_BUFFER, reinterpret_cast <std::uint64_t >(g_hTemporaryCommandBuffer), " g_hTemporaryCommandBuffer" );
21132164
21142165 // Create texture sampler
21152166
@@ -2130,6 +2181,7 @@ static void InitializeApplication()
21302181 samplerInfo.minLod = 0 .f ;
21312182 samplerInfo.maxLod = FLT_MAX;
21322183 ERR_GUARD_VULKAN ( vkCreateSampler (g_hDevice, &samplerInfo, g_Allocs, &g_hSampler) );
2184+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_SAMPLER, reinterpret_cast <std::uint64_t >(g_hSampler), " g_hSampler" );
21332185
21342186 CreateTexture (128 , 128 );
21352187 CreateMesh ();
@@ -2144,6 +2196,7 @@ static void InitializeApplication()
21442196 descriptorSetLayoutInfo.bindingCount = 1 ;
21452197 descriptorSetLayoutInfo.pBindings = &samplerLayoutBinding;
21462198 ERR_GUARD_VULKAN ( vkCreateDescriptorSetLayout (g_hDevice, &descriptorSetLayoutInfo, g_Allocs, &g_hDescriptorSetLayout) );
2199+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT, reinterpret_cast <std::uint64_t >(g_hDescriptorSetLayout), " g_hDescriptorSetLayout" );
21472200
21482201 // Create descriptor pool
21492202
@@ -2159,6 +2212,7 @@ static void InitializeApplication()
21592212 descriptorPoolInfo.pPoolSizes = descriptorPoolSizes;
21602213 descriptorPoolInfo.maxSets = 1 ;
21612214 ERR_GUARD_VULKAN ( vkCreateDescriptorPool (g_hDevice, &descriptorPoolInfo, g_Allocs, &g_hDescriptorPool) );
2215+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_DESCRIPTOR_POOL, reinterpret_cast <std::uint64_t >(g_hDescriptorPool), " g_hDescriptorPool" );
21622216
21632217 // Create descriptor set layout
21642218
@@ -2168,6 +2222,7 @@ static void InitializeApplication()
21682222 descriptorSetInfo.descriptorSetCount = 1 ;
21692223 descriptorSetInfo.pSetLayouts = descriptorSetLayouts;
21702224 ERR_GUARD_VULKAN ( vkAllocateDescriptorSets (g_hDevice, &descriptorSetInfo, &g_hDescriptorSet) );
2225+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_DESCRIPTOR_SET, reinterpret_cast <std::uint64_t >(g_hDescriptorSet), " g_hDescriptorSet" );
21712226
21722227 VkDescriptorImageInfo descriptorImageInfo = {};
21732228 descriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
@@ -2313,6 +2368,7 @@ static void DrawFrame()
23132368 VkCommandBufferBeginInfo commandBufferBeginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
23142369 commandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
23152370 ERR_GUARD_VULKAN ( vkBeginCommandBuffer (hCommandBuffer, &commandBufferBeginInfo) );
2371+ SetDebugUtilsObjectName (VK_OBJECT_TYPE_COMMAND_BUFFER, reinterpret_cast <std::uint64_t >(hCommandBuffer), " hCommandBuffer" );
23162372
23172373 // Acquire swapchain image
23182374 uint32_t imageIndex = 0 ;
0 commit comments