From 0bef4380b315e488133bb9fecd0532d352a16230 Mon Sep 17 00:00:00 2001 From: spencer-lunarg Date: Mon, 23 Nov 2026 16:15:12 -0500 Subject: [PATCH] layers: Add missing cmd validation --- layers/core_checks/cc_buffer.cpp | 5 +- layers/core_checks/cc_cmd_buffer.cpp | 11 ++++- layers/core_checks/cc_cmd_buffer_dynamic.cpp | 8 +++ layers/core_checks/cc_copy_blit_resolve.cpp | 20 ++++++-- layers/core_checks/cc_device_memory.cpp | 2 + layers/core_checks/cc_query.cpp | 2 + layers/core_checks/core_validation.h | 4 +- tests/unit/device_address.cpp | 18 +++++++ tests/unit/device_address_commands.cpp | 52 +++++++++++++++++++- tests/unit/memory.cpp | 33 +++++++++++++ 10 files changed, 144 insertions(+), 11 deletions(-) diff --git a/layers/core_checks/cc_buffer.cpp b/layers/core_checks/cc_buffer.cpp index 2a274ef28db..62710489b51 100644 --- a/layers/core_checks/cc_buffer.cpp +++ b/layers/core_checks/cc_buffer.cpp @@ -570,12 +570,13 @@ bool CoreChecks::PreCallValidateCmdFillMemoryKHR(VkCommandBuffer commandBuffer, const ErrorObject& error_obj) const { bool skip = false; + const auto& cb_state = *GetRead(commandBuffer); + skip |= ValidateCmd(cb_state, error_obj.location); + skip |= ValidateDeviceAddressRange(pDstRange->address, pDstRange->size, false, error_obj.location.dot(Field::pDstRange), LogObjectList(commandBuffer), VK_BUFFER_USAGE_2_TRANSFER_DST_BIT, "VUID-vkCmdFillMemoryKHR-dstRange-13000"); - auto cb_state_ptr = GetRead(commandBuffer); - const vvl::CommandBuffer& cb_state = *cb_state_ptr; if (!phys_dev_props_core11.protectedNoFault) { if (cb_state.unprotected) { if ((dstFlags & VK_ADDRESS_COMMAND_PROTECTED_BIT_KHR) != 0) { diff --git a/layers/core_checks/cc_cmd_buffer.cpp b/layers/core_checks/cc_cmd_buffer.cpp index eacf02bf29f..8ea5244c67e 100644 --- a/layers/core_checks/cc_cmd_buffer.cpp +++ b/layers/core_checks/cc_cmd_buffer.cpp @@ -764,6 +764,9 @@ bool CoreChecks::PreCallValidateCmdUpdateMemoryKHR(VkCommandBuffer commandBuffer const ErrorObject& error_obj) const { bool skip = false; + const auto& cb_state = *GetRead(commandBuffer); + skip |= ValidateCmd(cb_state, error_obj.location); + skip |= ValidateDeviceAddressCommands(commandBuffer, pDstRange->address, pDstRange->size, dstFlags, error_obj.location.dot(Field::pDstRange)); @@ -772,7 +775,6 @@ bool CoreChecks::PreCallValidateCmdUpdateMemoryKHR(VkCommandBuffer commandBuffer "VUID-vkCmdUpdateMemoryKHR-dstRange-13005"); if (!phys_dev_props_core11.protectedNoFault) { - const auto& cb_state = *GetRead(commandBuffer); if (cb_state.unprotected) { if ((dstFlags & VK_ADDRESS_COMMAND_PROTECTED_BIT_KHR) != 0) { skip |= LogError("VUID-vkCmdUpdateMemoryKHR-commandBuffer-13010", commandBuffer, @@ -2557,6 +2559,8 @@ bool CoreChecks::PreCallValidateCmdBindTransformFeedbackBuffersEXT(VkCommandBuff bool skip = false; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); + if (cb_state->transform_feedback_active) { skip |= LogError("VUID-vkCmdBindTransformFeedbackBuffersEXT-None-02365", commandBuffer, error_obj.location, "transform feedback is active."); @@ -2603,6 +2607,8 @@ bool CoreChecks::PreCallValidateCmdBindTransformFeedbackBuffers2EXT(VkCommandBuf bool skip = false; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); + if (cb_state->transform_feedback_active) { skip |= LogError("VUID-vkCmdBindTransformFeedbackBuffers2EXT-None-02365", commandBuffer, error_obj.location, "transform feedback is active."); @@ -2919,6 +2925,9 @@ bool CoreChecks::PreCallValidateCmdBindVertexBuffers3KHR(VkCommandBuffer command const ErrorObject& error_obj) const { bool skip = false; + auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); + for (uint32_t i = 0; i < bindingCount; ++i) { const Location binding_info_loc = error_obj.location.dot(Field::pBindingInfos, i); const VkBindVertexBuffer3InfoKHR& info = pBindingInfos[i]; diff --git a/layers/core_checks/cc_cmd_buffer_dynamic.cpp b/layers/core_checks/cc_cmd_buffer_dynamic.cpp index 275808e82c0..30864ef0af2 100644 --- a/layers/core_checks/cc_cmd_buffer_dynamic.cpp +++ b/layers/core_checks/cc_cmd_buffer_dynamic.cpp @@ -2021,6 +2021,14 @@ bool CoreChecks::PreCallValidateCmdSetPrimitiveRestartEnable(VkCommandBuffer com return ValidateCmdSetPrimitiveRestartEnable(commandBuffer, primitiveRestartEnable, error_obj); } +bool CoreChecks::PreCallValidateCmdSetPrimitiveRestartIndexEXT(VkCommandBuffer commandBuffer, uint32_t primitiveRestartIndex, + const ErrorObject& error_obj) const { + bool skip = false; + auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); + return skip; +} + bool CoreChecks::ValidateCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode, const ErrorObject& error_obj) const { bool skip = false; diff --git a/layers/core_checks/cc_copy_blit_resolve.cpp b/layers/core_checks/cc_copy_blit_resolve.cpp index 1a00126dd9f..41a270b58f7 100644 --- a/layers/core_checks/cc_copy_blit_resolve.cpp +++ b/layers/core_checks/cc_copy_blit_resolve.cpp @@ -4164,6 +4164,7 @@ bool CoreChecks::PreCallValidateCmdCopyMemoryIndirectKHR(VkCommandBuffer command const ErrorObject& error_obj) const { bool skip = false; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); if (!enabled_features.indirectMemoryCopy) { skip |= LogError("VUID-vkCmdCopyMemoryIndirectKHR-indirectMemoryCopy-10935", commandBuffer, error_obj.location, @@ -4366,6 +4367,7 @@ bool CoreChecks::PreCallValidateCmdCopyMemoryToImageIndirectKHR( const ErrorObject& error_obj) const { bool skip = false; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); if (!enabled_features.indirectMemoryToImageCopy) { skip |= LogError("VUID-vkCmdCopyMemoryToImageIndirectKHR-indirectMemoryToImageCopy-10947", commandBuffer, @@ -4393,13 +4395,12 @@ bool CoreChecks::PreCallValidateCmdCopyMemoryToImageIndirectKHR( // vkCmdCopyMemoryToImageKHR and vkCmdCopyImageToMemoryKHR (VK_KHR_device_address_commands) // TODO - We duplciate logic to not add more complexity to the already over-complicated templated ValidateMemoryImageCopyCommon() -bool CoreChecks::ValidateCmdCopyMemoryToImage(VkCommandBuffer command_buffer, +bool CoreChecks::ValidateCmdCopyMemoryToImage(const vvl::CommandBuffer& cb_state, const VkCopyDeviceMemoryImageInfoKHR& copy_memory_info, const Location& info_loc) const { bool skip = false; - auto cb_state_ptr = GetRead(command_buffer); - const vvl::CommandBuffer& cb_state = *cb_state_ptr; + const VkCommandBuffer command_buffer = cb_state.VkHandle(); auto image_state = Get(copy_memory_info.image); ASSERT_AND_RETURN_SKIP(image_state); @@ -4580,19 +4581,28 @@ bool CoreChecks::ValidateCmdCopyMemoryToImage(VkCommandBuffer command_buffer, bool CoreChecks::PreCallValidateCmdCopyMemoryToImageKHR(VkCommandBuffer commandBuffer, const VkCopyDeviceMemoryImageInfoKHR* pCopyMemoryInfo, const ErrorObject& error_obj) const { - return ValidateCmdCopyMemoryToImage(commandBuffer, *pCopyMemoryInfo, error_obj.location.dot(Field::pCopyMemoryInfo)); + bool skip = false; + auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); + skip |= ValidateCmdCopyMemoryToImage(*cb_state, *pCopyMemoryInfo, error_obj.location.dot(Field::pCopyMemoryInfo)); + return skip; } bool CoreChecks::PreCallValidateCmdCopyImageToMemoryKHR(VkCommandBuffer commandBuffer, const VkCopyDeviceMemoryImageInfoKHR* pCopyMemoryInfo, const ErrorObject& error_obj) const { - return ValidateCmdCopyMemoryToImage(commandBuffer, *pCopyMemoryInfo, error_obj.location.dot(Field::pCopyMemoryInfo)); + bool skip = false; + auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); + skip |= ValidateCmdCopyMemoryToImage(*cb_state, *pCopyMemoryInfo, error_obj.location.dot(Field::pCopyMemoryInfo)); + return skip; } bool CoreChecks::PreCallValidateCmdCopyMemoryKHR(VkCommandBuffer commandBuffer, const VkCopyDeviceMemoryInfoKHR* pCopyMemoryInfo, const ErrorObject& error_obj) const { bool skip = false; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); const Location info_loc = error_obj.location.dot(Field::pCopyMemoryInfo); for (uint32_t i = 0; i < pCopyMemoryInfo->regionCount; ++i) { diff --git a/layers/core_checks/cc_device_memory.cpp b/layers/core_checks/cc_device_memory.cpp index bdfde375fc7..7aff91fe95a 100644 --- a/layers/core_checks/cc_device_memory.cpp +++ b/layers/core_checks/cc_device_memory.cpp @@ -3276,6 +3276,7 @@ bool CoreChecks::PreCallValidateCmdDecompressMemoryEXT(VkCommandBuffer commandBu const ErrorObject& error_obj) const { bool skip = false; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); const LogObjectList objlist(cb_state->Handle()); const Location memory_info_loc = error_obj.location.dot(Field::pDecompressMemoryInfoEXT); @@ -3327,6 +3328,7 @@ bool CoreChecks::PreCallValidateCmdDecompressMemoryIndirectCountEXT(VkCommandBuf const ErrorObject& error_obj) const { bool skip = false; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); const LogObjectList objlist(cb_state->Handle()); { diff --git a/layers/core_checks/cc_query.cpp b/layers/core_checks/cc_query.cpp index a0d07ef789d..34ccafdfcf5 100644 --- a/layers/core_checks/cc_query.cpp +++ b/layers/core_checks/cc_query.cpp @@ -1239,6 +1239,8 @@ bool CoreChecks::PreCallValidateCmdCopyQueryPoolResultsToMemoryKHR(VkCommandBuff bool skip = false; if (disabled[query_validation]) return skip; auto cb_state = GetRead(commandBuffer); + skip |= ValidateCmd(*cb_state, error_obj.location); + const auto query_pool_state = Get(queryPool); ASSERT_AND_RETURN_SKIP(query_pool_state); diff --git a/layers/core_checks/core_validation.h b/layers/core_checks/core_validation.h index 12e83c1acc5..ac6c8e7f5ce 100644 --- a/layers/core_checks/core_validation.h +++ b/layers/core_checks/core_validation.h @@ -2605,7 +2605,7 @@ class CoreChecks : public vvl::DeviceProxy { bool PreCallValidateCmdCopyMemoryToImageIndirectKHR(VkCommandBuffer commandBuffer, const VkCopyMemoryToImageIndirectInfoKHR* pCopyMemoryToImageIndirectInfo, const ErrorObject& error_obj) const override; - bool ValidateCmdCopyMemoryToImage(VkCommandBuffer commandBuffer, const VkCopyDeviceMemoryImageInfoKHR& copy_memory_info, + bool ValidateCmdCopyMemoryToImage(const vvl::CommandBuffer& cb_state, const VkCopyDeviceMemoryImageInfoKHR& copy_memory_info, const Location& info_loc) const; bool PreCallValidateCmdCopyMemoryToImageKHR(VkCommandBuffer commandBuffer, const VkCopyDeviceMemoryImageInfoKHR* pCopyMemoryInfo, @@ -2681,6 +2681,8 @@ class CoreChecks : public vvl::DeviceProxy { const ErrorObject& error_obj) const override; bool PreCallValidateCmdSetPrimitiveRestartEnable(VkCommandBuffer commandBuffer, VkBool32 primitiveRestartEnable, const ErrorObject& error_obj) const override; + bool PreCallValidateCmdSetPrimitiveRestartIndexEXT(VkCommandBuffer commandBuffer, uint32_t primitiveRestartIndex, + const ErrorObject& error_obj) const override; bool ValidateCmdSetCullMode(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode, const ErrorObject& error_obj) const; bool PreCallValidateCmdSetCullModeEXT(VkCommandBuffer commandBuffer, VkCullModeFlags cullMode, diff --git a/tests/unit/device_address.cpp b/tests/unit/device_address.cpp index fa9c16b7294..0593ac0a736 100644 --- a/tests/unit/device_address.cpp +++ b/tests/unit/device_address.cpp @@ -787,3 +787,21 @@ TEST_F(NegativeDeviceAddress, TransformFeedback) { m_default_queue->SubmitAndWait(m_command_buffer); m_errorMonitor->VerifyFound(); } + +TEST_F(NegativeDeviceAddress, CmdCopyMemoryIndirectNotRecording) { + AddRequiredExtensions(VK_KHR_COPY_MEMORY_INDIRECT_EXTENSION_NAME); + AddRequiredFeature(vkt::Feature::indirectMemoryCopy); + AddRequiredFeature(vkt::Feature::bufferDeviceAddress); + RETURN_IF_SKIP(Init()); + + const VkDeviceSize copy_size = sizeof(VkCopyMemoryIndirectCommandKHR); + vkt::Buffer indirect_buffer(*m_device, copy_size, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT, vkt::device_address); + + VkCopyMemoryIndirectInfoKHR indirect_info = vku::InitStructHelper(); + indirect_info.copyCount = 1u; + indirect_info.copyAddressRange = {indirect_buffer.Address(), copy_size, copy_size}; + + m_errorMonitor->SetDesiredError("VUID-vkCmdCopyMemoryIndirectKHR-commandBuffer-recording"); + vk::CmdCopyMemoryIndirectKHR(m_command_buffer, &indirect_info); + m_errorMonitor->VerifyFound(); +} \ No newline at end of file diff --git a/tests/unit/device_address_commands.cpp b/tests/unit/device_address_commands.cpp index 9d917e4983b..b55700f5576 100644 --- a/tests/unit/device_address_commands.cpp +++ b/tests/unit/device_address_commands.cpp @@ -235,9 +235,9 @@ TEST_F(NegativeDeviceAddressCommands, ComputeQueueDepthAspect) { RETURN_IF_SKIP(InitBasicDeviceAddressCommands()); - auto compute_queue = m_device->QueueFamily(VK_QUEUE_COMPUTE_BIT, VK_QUEUE_GRAPHICS_BIT); + auto compute_queue = m_device->QueueFamily(VK_QUEUE_COMPUTE_BIT | VK_QUEUE_TRANSFER_BIT, VK_QUEUE_GRAPHICS_BIT); if (!compute_queue.has_value()) { - GTEST_SKIP() << "Need a queue that supports compute but not graphics"; + GTEST_SKIP() << "Need a queue that supports compute and transfer but not graphics"; } vkt::CommandPool pool(*m_device, *compute_queue); vkt::CommandBuffer cb(*m_device, pool); @@ -374,6 +374,54 @@ TEST_F(NegativeDeviceAddressCommands, CmdUpdateMemoryUsage) { m_command_buffer.End(); } +TEST_F(NegativeDeviceAddressCommands, Recording) { + AddRequiredFeature(vkt::Feature::dynamicRendering); + RETURN_IF_SKIP(InitBasicDeviceAddressCommands()); + + vkt::Buffer buffer(*m_device, 256u, VK_BUFFER_USAGE_TRANSFER_DST_BIT, vkt::device_address); + const VkDeviceAddressRangeKHR range = buffer.AddressRange(); + + { + m_errorMonitor->SetDesiredError("VUID-vkCmdFillMemoryKHR-commandBuffer-recording"); + vk::CmdFillMemoryKHR(m_command_buffer, &range, 0u, 0u); + m_errorMonitor->VerifyFound(); + } + + { + vkt::Image image(*m_device, 4u, 4u, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT); + + VkDeviceMemoryImageCopyKHR region = vku::InitStructHelper(); + region.addressRange = buffer.AddressRange(); + region.imageSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1}; + region.imageLayout = VK_IMAGE_LAYOUT_GENERAL; + region.imageExtent = {4u, 4u, 1u}; + VkCopyDeviceMemoryImageInfoKHR copy_memory_info = vku::InitStructHelper(); + copy_memory_info.image = image; + copy_memory_info.regionCount = 1u; + copy_memory_info.pRegions = ®ion; + + m_errorMonitor->SetDesiredError("VUID-vkCmdCopyImageToMemoryKHR-commandBuffer-recording"); + vk::CmdCopyImageToMemoryKHR(m_command_buffer, ©_memory_info); + m_errorMonitor->VerifyFound(); + } + + { + const uint32_t data = 255; + + VkRenderingInfo suspend_info = vku::InitStructHelper(); + suspend_info.flags = VK_RENDERING_SUSPENDING_BIT; + suspend_info.layerCount = 1; + suspend_info.renderArea = {{0, 0}, {1, 1}}; + + m_command_buffer.Begin(); + m_command_buffer.BeginRendering(suspend_info); + m_command_buffer.EndRendering(); + m_errorMonitor->SetDesiredError("VUID-vkCmdUpdateMemoryKHR-suspended"); + vk::CmdUpdateMemoryKHR(m_command_buffer, &range, 0u, sizeof(data), &data); + m_errorMonitor->VerifyFound(); + } +} + TEST_F(NegativeDeviceAddressCommands, CmdUpdateMemoryAlignmentAndSize) { RETURN_IF_SKIP(InitBasicDeviceAddressCommands()); diff --git a/tests/unit/memory.cpp b/tests/unit/memory.cpp index f744ec67a1c..68ef1d0ebb5 100644 --- a/tests/unit/memory.cpp +++ b/tests/unit/memory.cpp @@ -693,6 +693,39 @@ TEST_F(NegativeMemory, MemoryDecompressionSrcAddressOutOfRange) { m_command_buffer.End(); } +TEST_F(NegativeMemory, MemoryDecompressionNotRecording) { + AddRequiredExtensions(VK_EXT_MEMORY_DECOMPRESSION_EXTENSION_NAME); + AddRequiredExtensions(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME); + AddRequiredFeature(vkt::Feature::memoryDecompression); + AddRequiredFeature(vkt::Feature::bufferDeviceAddress); + RETURN_IF_SKIP(Init()); + VkPhysicalDeviceMemoryDecompressionPropertiesEXT props = vku::InitStructHelper(); + GetPhysicalDeviceProperties2(props); + if ((props.decompressionMethods & VK_MEMORY_DECOMPRESSION_METHOD_GDEFLATE_1_0_BIT_EXT) == 0) { + GTEST_SKIP() << "GDeflate decompression method not supported"; + } + + VkBufferUsageFlags2CreateInfo usage2 = vku::InitStructHelper(); + usage2.usage = VK_BUFFER_USAGE_2_MEMORY_DECOMPRESSION_BIT_EXT; + vkt::Buffer src_buffer(*m_device, 64u, usage2, vkt::device_address); + vkt::Buffer dst_buffer(*m_device, 64u, usage2, vkt::device_address); + + VkDecompressMemoryRegionEXT region = {}; + region.srcAddress = src_buffer.Address(); + region.dstAddress = dst_buffer.Address(); + region.compressedSize = 64u; + region.decompressedSize = 64u; + + VkDecompressMemoryInfoEXT decompress_info = vku::InitStructHelper(); + decompress_info.decompressionMethod = VK_MEMORY_DECOMPRESSION_METHOD_GDEFLATE_1_0_BIT_EXT; + decompress_info.regionCount = 1; + decompress_info.pRegions = ®ion; + + m_errorMonitor->SetDesiredError("VUID-vkCmdDecompressMemoryEXT-commandBuffer-recording"); + vk::CmdDecompressMemoryEXT(m_command_buffer, &decompress_info); + m_errorMonitor->VerifyFound(); +} + TEST_F(NegativeMemory, MapMemory) { RETURN_IF_SKIP(Init());