aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Forbes <chrisforbes@google.com>2017-09-14 11:13:34 -0700
committerChris Forbes <chrisf@ijw.co.nz>2017-09-15 13:43:08 -0700
commitfabaad9a6dae4865ecf8d424fe8543a3d5a5ba08 (patch)
tree54fb9268e1e3f5c396077541ccae15bf9a311610
parent497f2d0131c6fc682e455e24a555dbab4facaef5 (diff)
downloadusermoji-fabaad9a6dae4865ecf8d424fe8543a3d5a5ba08.tar.xz
layers: Implement VU check for BUFFER_USAGE_INDEX_BUFFER_BIT
-rw-r--r--layers/core_validation.cpp70
-rw-r--r--layers/vk_validation_error_database.txt2
2 files changed, 39 insertions, 33 deletions
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp
index a3095bb7..65375234 100644
--- a/layers/core_validation.cpp
+++ b/layers/core_validation.cpp
@@ -5654,48 +5654,54 @@ VKAPI_ATTR void VKAPI_CALL CmdPushDescriptorSetKHR(VkCommandBuffer commandBuffer
pDescriptorWrites);
}
+static VkDeviceSize GetIndexAlignment(VkIndexType indexType) {
+ switch (indexType) {
+ case VK_INDEX_TYPE_UINT16:
+ return 2;
+ case VK_INDEX_TYPE_UINT32:
+ return 4;
+ default:
+ // Not a real index type. Express no alignment requirement here; we expect upper layer
+ // to have already picked up on the enum being nonsense.
+ return 1;
+ }
+}
+
VKAPI_ATTR void VKAPI_CALL CmdBindIndexBuffer(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset,
VkIndexType indexType) {
bool skip = false;
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
- // TODO : Somewhere need to verify that IBs have correct usage state flagged
unique_lock_t lock(global_lock);
auto buffer_state = GetBufferState(dev_data, buffer);
auto cb_node = GetCBNode(dev_data, commandBuffer);
- if (cb_node && buffer_state) {
- skip |=
- ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdBindIndexBuffer()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_17e02415);
- skip |= ValidateCmd(dev_data, cb_node, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
- skip |= ValidateMemoryIsBoundToBuffer(dev_data, buffer_state, "vkCmdBindIndexBuffer()", VALIDATION_ERROR_17e00364);
- std::function<bool()> function = [=]() {
- return ValidateBufferMemoryIsValid(dev_data, buffer_state, "vkCmdBindIndexBuffer()");
- };
- cb_node->queue_submit_functions.push_back(function);
- VkDeviceSize offset_align = 0;
- switch (indexType) {
- case VK_INDEX_TYPE_UINT16:
- offset_align = 2;
- break;
- case VK_INDEX_TYPE_UINT32:
- offset_align = 4;
- break;
- default:
- // ParamChecker should catch bad enum, we'll also throw alignment error below if offset_align stays 0
- break;
- }
- if (!offset_align || (offset % offset_align)) {
- skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
- HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
- "vkCmdBindIndexBuffer() offset (0x%" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset,
- string_VkIndexType(indexType));
- }
- cb_node->status |= CBSTATUS_INDEX_BUFFER_BOUND;
- } else {
- assert(0);
+ assert(cb_node);
+ assert(buffer_state);
+
+ skip |= ValidateBufferUsageFlags(dev_data, buffer_state, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, true,
+ VALIDATION_ERROR_17e00362, "vkCmdBindIndexBuffer()", "VK_BUFFER_USAGE_INDEX_BUFFER_BIT");
+ skip |= ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdBindIndexBuffer()", VK_QUEUE_GRAPHICS_BIT, VALIDATION_ERROR_17e02415);
+ skip |= ValidateCmd(dev_data, cb_node, CMD_BINDINDEXBUFFER, "vkCmdBindIndexBuffer()");
+ skip |= ValidateMemoryIsBoundToBuffer(dev_data, buffer_state, "vkCmdBindIndexBuffer()", VALIDATION_ERROR_17e00364);
+ auto offset_align = GetIndexAlignment(indexType);
+ if (offset % offset_align) {
+ skip |= log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
+ HandleToUint64(commandBuffer), __LINE__, DRAWSTATE_VTX_INDEX_ALIGNMENT_ERROR, "DS",
+ "vkCmdBindIndexBuffer() offset (0x%" PRIxLEAST64 ") does not fall on alignment (%s) boundary.", offset,
+ string_VkIndexType(indexType));
}
+
+ if (skip)
+ return;
+
+ std::function<bool()> function = [=]() {
+ return ValidateBufferMemoryIsValid(dev_data, buffer_state, "vkCmdBindIndexBuffer()");
+ };
+ cb_node->queue_submit_functions.push_back(function);
+ cb_node->status |= CBSTATUS_INDEX_BUFFER_BOUND;
+
lock.unlock();
- if (!skip) dev_data->dispatch_table.CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
+ dev_data->dispatch_table.CmdBindIndexBuffer(commandBuffer, buffer, offset, indexType);
}
void updateResourceTracking(GLOBAL_CB_NODE *pCB, uint32_t firstBinding, uint32_t bindingCount, const VkBuffer *pBuffers) {
diff --git a/layers/vk_validation_error_database.txt b/layers/vk_validation_error_database.txt
index a91e958d..17208fba 100644
--- a/layers/vk_validation_error_database.txt
+++ b/layers/vk_validation_error_database.txt
@@ -1602,7 +1602,7 @@ VALIDATION_ERROR_17c27e01~^~Y~^~Unknown~^~vkCmdBindDescriptorSets~^~VUID-vkCmdBi
VALIDATION_ERROR_17e00009~^~Y~^~Unknown~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-commonparent~^~core~^~The spec valid usage text states 'Both of buffer, and commandBuffer must have been created, allocated, or retrieved from the same VkDevice' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-commonparent)~^~implicit
VALIDATION_ERROR_17e0035e~^~N~^~Unknown~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-offset-00431~^~core~^~The spec valid usage text states 'offset must be less than the size of buffer' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-offset-00431)~^~
VALIDATION_ERROR_17e00360~^~N~^~Unknown~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-offset-00432~^~core~^~The spec valid usage text states 'The sum of offset and the address of the range of VkDeviceMemory object that is backing buffer, must be a multiple of the type indicated by indexType' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-offset-00432)~^~
-VALIDATION_ERROR_17e00362~^~N~^~Unknown~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-buffer-00433~^~core~^~The spec valid usage text states 'buffer must have been created with the VK_BUFFER_USAGE_INDEX_BUFFER_BIT flag' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-buffer-00433)~^~
+VALIDATION_ERROR_17e00362~^~Y~^~Unknown~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-buffer-00433~^~core~^~The spec valid usage text states 'buffer must have been created with the VK_BUFFER_USAGE_INDEX_BUFFER_BIT flag' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-buffer-00433)~^~
VALIDATION_ERROR_17e00364~^~Y~^~Unknown~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-buffer-00434~^~core~^~The spec valid usage text states 'If buffer is non-sparse then it must be bound completely and contiguously to a single VkDeviceMemory object' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-buffer-00434)~^~
VALIDATION_ERROR_17e01a01~^~Y~^~None~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-buffer-parameter~^~core~^~The spec valid usage text states 'buffer must be a valid VkBuffer handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-buffer-parameter)~^~implicit
VALIDATION_ERROR_17e02401~^~Y~^~None~^~vkCmdBindIndexBuffer~^~VUID-vkCmdBindIndexBuffer-commandBuffer-parameter~^~core~^~The spec valid usage text states 'commandBuffer must be a valid VkCommandBuffer handle' (https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#VUID-vkCmdBindIndexBuffer-commandBuffer-parameter)~^~implicit