Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layers: Add 01912, 01913 #5277

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions layers/core_checks/cmd_buffer_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,3 +1677,28 @@ bool CoreChecks::PreCallValidateCmdBindShadingRateImageNV(VkCommandBuffer comman

return skip;
}

void CoreChecks::PostCallRecordCmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer, const VkDebugUtilsLabelEXT *pLabelInfo) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);
assert(cb_state);
cb_state->BeginLabel();
}

bool CoreChecks::PreCallValidateCmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer) const {
auto cb_state = GetRead<CMD_BUFFER_STATE>(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<CMD_BUFFER_STATE>(commandBuffer);
assert(cb_state);
cb_state->EndLabel();
}
6 changes: 6 additions & 0 deletions layers/core_checks/core_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,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
Expand Down
8 changes: 8 additions & 0 deletions layers/state_tracker/cmd_buffer_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,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);
Expand Down
45 changes: 45 additions & 0 deletions tests/vklayertests_others.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10794,3 +10794,48 @@ TEST_F(VkLayerTest, InvalidExtEnum) {
vk_testing::Sampler sampler(*m_device, sampler_ci);
m_errorMonitor->VerifyFound();
}

TEST_F(VkLayerTest, EndDebugLabelWithNoBegin) {
TEST_DESCRIPTION("Call vkCmdEndDebugUtilsLabelEXT without matching vkCmdBeginDebugUtilsLabelEXT");

AddRequiredExtensions(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
ASSERT_NO_FATAL_FAILURE(InitFramework());
if (!AreRequiredExtensionsEnabled()) {
GTEST_SKIP() << RequiredExtensionsNotSupported() << " not supported";
}
ASSERT_NO_FATAL_FAILURE(InitState());

auto vkCmdBeginDebugUtilsLabelEXT = reinterpret_cast<PFN_vkCmdBeginDebugUtilsLabelEXT>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we use the templated version? As a bonus it will also check for null result.

    auto vkCmdBeginDebugUtilsLabelEXT = GetDeviceProcAddr<PFN_vkCmdBeginDebugUtilsLabelEXT>("vkCmdBeginDebugUtilsLabelEXT");
    auto vkCmdEndDebugUtilsLabelEXT = GetDeviceProcAddr<PFN_vkCmdEndDebugUtilsLabelEXT>("vkCmdEndDebugUtilsLabelEXT");

vk::GetDeviceProcAddr(m_device->device(), "vkCmdBeginDebugUtilsLabelEXT"));
ASSERT_NE(vkCmdBeginDebugUtilsLabelEXT, nullptr);
auto vkCmdEndDebugUtilsLabelEXT =
reinterpret_cast<PFN_vkCmdEndDebugUtilsLabelEXT>(vk::GetDeviceProcAddr(m_device->device(), "vkCmdEndDebugUtilsLabelEXT"));
ASSERT_NE(vkCmdEndDebugUtilsLabelEXT, nullptr);

m_commandBuffer->begin();
// First verify there is no error in the valid case
auto label = LvlInitStruct<VkDebugUtilsLabelEXT>(nullptr, "Test");
vkCmdBeginDebugUtilsLabelEXT(*m_commandBuffer, &label);
vkCmdEndDebugUtilsLabelEXT(*m_commandBuffer);

// Now call vkCmdEndDebugUtilsLabelEXT without a corresponding begin
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01912");
vkCmdEndDebugUtilsLabelEXT(*m_commandBuffer);
m_errorMonitor->VerifyFound();

m_commandBuffer->end();

// Now test the same scenario for secondary buffers
auto cb_info =
LvlInitStruct<VkCommandBufferAllocateInfo>(nullptr, m_commandPool->handle(), VK_COMMAND_BUFFER_LEVEL_SECONDARY, 1u);
vk_testing::CommandBuffer cb(*m_device, cb_info);
cb.begin();
vkCmdBeginDebugUtilsLabelEXT(cb, &label);
vkCmdEndDebugUtilsLabelEXT(cb);

m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdEndDebugUtilsLabelEXT-commandBuffer-01913");
vkCmdEndDebugUtilsLabelEXT(cb);
m_errorMonitor->VerifyFound();

cb.end();
}
3 changes: 3 additions & 0 deletions tests/vktestbinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class Handle {
const T &handle() const noexcept { return handle_; }
bool initialized() const noexcept { return (handle_ != T{}); }

operator T() const noexcept { return handle(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

operator bool() const noexcept { return initialized(); }

protected:
typedef T handle_type;

Expand Down