layers: Validate pOffsets in vkCmdBindVertexBuffers
Change-Id: Ie618d7657af6eca555050507a623be02af2e21fe
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp
index 2ce055d..50030c9 100644
--- a/layers/core_validation.cpp
+++ b/layers/core_validation.cpp
@@ -7068,6 +7068,12 @@
return ValidateBufferMemoryIsValid(dev_data, buffer_state, "vkCmdBindVertexBuffers()");
};
cb_node->validate_functions.push_back(function);
+ if (pOffsets[i] >= buffer_state->createInfo.size) {
+ skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_BUFFER_EXT,
+ reinterpret_cast<uint64_t &>(buffer_state->buffer), __LINE__, VALIDATION_ERROR_01417, "DS",
+ "vkCmdBindVertexBuffers() offset (0x%" PRIxLEAST64 ") is beyond the end of the buffer. %s",
+ pOffsets[i], validation_error_map[VALIDATION_ERROR_01417]);
+ }
}
UpdateCmdBufferLastCmd(cb_node, CMD_BINDVERTEXBUFFER);
updateResourceTracking(cb_node, firstBinding, bindingCount, pBuffers);
diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt
index 27ad10c..a6d38f4 100644
--- a/layers/vk_validation_error_database.txt
+++ b/layers/vk_validation_error_database.txt
@@ -1362,7 +1362,7 @@
VALIDATION_ERROR_01414~^~N~^~Unknown~^~vkCmdDrawIndexedIndirectCountAMD~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'format must be a valid VkFormat value' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#VkVertexInputAttributeDescription)~^~implicit
VALIDATION_ERROR_01415~^~N~^~Unknown~^~vkCmdBindVertexBuffers~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'firstBinding must be less than VkPhysicalDeviceLimits::maxVertexInputBindings' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#vkCmdBindVertexBuffers)~^~
VALIDATION_ERROR_01416~^~N~^~Unknown~^~vkCmdBindVertexBuffers~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'The sum of firstBinding and bindingCount must be less than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#vkCmdBindVertexBuffers)~^~
-VALIDATION_ERROR_01417~^~N~^~Unknown~^~vkCmdBindVertexBuffers~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'All elements of pOffsets must be less than the size of the corresponding element in pBuffers' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#vkCmdBindVertexBuffers)~^~
+VALIDATION_ERROR_01417~^~Y~^~BadVertexBufferOffset~^~vkCmdBindVertexBuffers~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'All elements of pOffsets must be less than the size of the corresponding element in pBuffers' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#vkCmdBindVertexBuffers)~^~
VALIDATION_ERROR_01418~^~N~^~Unknown~^~vkCmdBindVertexBuffers~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'All elements of pBuffers must have been created with the VK_BUFFER_USAGE_VERTEX_BUFFER_BIT flag' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#vkCmdBindVertexBuffers)~^~
VALIDATION_ERROR_01419~^~Y~^~None~^~vkCmdBindVertexBuffers~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'commandBuffer must be a valid VkCommandBuffer handle' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#vkCmdBindVertexBuffers)~^~implicit
VALIDATION_ERROR_01420~^~Y~^~None~^~vkCmdBindVertexBuffers~^~For more information refer to Vulkan Spec Section '20.2. Vertex Input Description' which states 'pBuffers must be a pointer to an array of bindingCount valid VkBuffer handles' (https://www.khronos.org/registry/vulkan/specs/1.0-extensions/html/vkspec.html#vkCmdBindVertexBuffers)~^~implicit
diff --git a/tests/layer_validation_tests.cpp b/tests/layer_validation_tests.cpp
index 046e5ba..27c282e 100644
--- a/tests/layer_validation_tests.cpp
+++ b/tests/layer_validation_tests.cpp
@@ -12394,6 +12394,22 @@
vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
}
+TEST_F(VkLayerTest, BadVertexBufferOffset) {
+ TEST_DESCRIPTION("Submit an offset past the end of a vertex buffer");
+
+ ASSERT_NO_FATAL_FAILURE(Init());
+ ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
+ static const float vbo_data[3] = {1.f, 0.f, 1.f};
+ VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
+ VkMemoryRequirements memory_reqs;
+ vkGetBufferMemoryRequirements(m_device->device(), vbo.handle(), &memory_reqs);
+ m_commandBuffer->BeginCommandBuffer();
+ m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
+ m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01417);
+ BindVertexBuffer(&vbo, (VkDeviceSize)(memory_reqs.size + 1), 1); // Offset past the end of the buffer
+ m_errorMonitor->VerifyFound();
+}
+
// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
TEST_F(VkLayerTest, InvalidImageLayout) {
TEST_DESCRIPTION(