From c2722caf8277258b9dfa2a7393f16d20fdf70245 Mon Sep 17 00:00:00 2001 From: Nathaniel Cesario Date: Mon, 13 Feb 2023 16:17:39 -0700 Subject: [PATCH] layers: Add 01912, 01913 Check to see that each "EndLabel" has a corresponding "BeginLabel." Closes #5230. --- layers/core_checks/cmd_buffer_validation.cpp | 25 ++++++++++++++++++++ layers/core_checks/core_validation.h | 6 +++++ layers/state_tracker/cmd_buffer_state.h | 8 +++++++ 3 files changed, 39 insertions(+) diff --git a/layers/core_checks/cmd_buffer_validation.cpp b/layers/core_checks/cmd_buffer_validation.cpp index b509f52125e..f2531d49515 100644 --- a/layers/core_checks/cmd_buffer_validation.cpp +++ b/layers/core_checks/cmd_buffer_validation.cpp @@ -1677,3 +1677,28 @@ bool CoreChecks::PreCallValidateCmdBindShadingRateImageNV(VkCommandBuffer comman return skip; } + +void CoreChecks::PostCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) { + auto cb_state = GetWrite(commandBuffer); + assert(cb_state); + cb_state->BeginLabel(); +} + +bool CoreChecks::PreCallValidateCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) const { + auto cb_state = GetRead(commandBuffer); + assert(cb_state); + bool skip = false; + if (cb_state->LabelStackDepth() < 1) { + const auto vuid = cb_state->IsPrimary() ? "VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01912" + : "VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01913"; + skip |= LogError(commandBuffer, vuid, + "vkCmdEndDebugUtilsLabelEXT() called without a corresponding vkCmdBeginDebugUtilsLabelEXT first"); + } + return skip; +} + +void CoreChecks::PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) { + auto cb_state = GetWrite(commandBuffer); + assert(cb_state); + cb_state->EndLabel(); +} diff --git a/layers/core_checks/core_validation.h b/layers/core_checks/core_validation.h index daa67746312..e84d69c1c87 100644 --- a/layers/core_checks/core_validation.h +++ b/layers/core_checks/core_validation.h @@ -2226,6 +2226,12 @@ class CoreChecks : public ValidationStateTracker { bool ValidateDescriptorAddressInfoEXT(VkDevice device, const VkDescriptorAddressInfoEXT* address_info) const; bool PreCallValidateGetDescriptorEXT(VkDevice device, const VkDescriptorGetInfoEXT* pDescriptorInfo, size_t dataSize, void* pDescriptor) const override; + + // Debug label APIs + void PostCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT* pLabelInfo) override; + bool PreCallValidateCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) const override; + void PostCallRecordCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) override; + #ifdef VK_USE_PLATFORM_METAL_EXT bool PreCallValidateExportMetalObjectsEXT(VkDevice device, VkExportMetalObjectsInfoEXT* pMetalObjectsInfo) const override; #endif // VK_USE_PLATFORM_METAL_EXT diff --git a/layers/state_tracker/cmd_buffer_state.h b/layers/state_tracker/cmd_buffer_state.h index baa4c889cf7..df8600d4efe 100644 --- a/layers/state_tracker/cmd_buffer_state.h +++ b/layers/state_tracker/cmd_buffer_state.h @@ -582,9 +582,17 @@ class CMD_BUFFER_STATE : public REFCOUNTED_NODE { pipeline_bound = true; } + bool IsPrimary() const { return createInfo.level == VK_COMMAND_BUFFER_LEVEL_PRIMARY; } + void BeginLabel() { ++label_stack_depth_; } + void EndLabel() { --label_stack_depth_; } + int LabelStackDepth() const { return label_stack_depth_; } + private: void ResetCBState(); + // Keep track of how many CmdBeginDebugUtilsLabelEXT calls have been made without a matching CmdEndDebugUtilsLabelEXT + int label_stack_depth_ = 0; + protected: void NotifyInvalidate(const BASE_NODE::NodeList &invalid_nodes, bool unlink) override; void UpdateAttachmentsView(const VkRenderPassBeginInfo *pRenderPassBegin);