From 99a86825c8b22db7d9727678befffe8ab94a251c Mon Sep 17 00:00:00 2001 From: Mark Lobodzinski Date: Fri, 10 Feb 2017 14:01:27 -0700 Subject: [PATCH] layers: Refactor CmdFillBuffer Separated validation from state updates, refactored for pre/post and moved these functions out of core_validation. Also updated for coding style. Change-Id: I9b24bc8c951fd1df99a65db5fa8f1d0412488192 --- layers/buffer_validation.cpp | 22 ++++++++++++++++++++++ layers/buffer_validation.h | 4 ++++ layers/core_validation.cpp | 33 +++++++++++---------------------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/layers/buffer_validation.cpp b/layers/buffer_validation.cpp index 695290d..bd65e47 100644 --- a/layers/buffer_validation.cpp +++ b/layers/buffer_validation.cpp @@ -2384,3 +2384,25 @@ void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffe invalidateCommandBuffers(device_data, buffer_view_state->cb_bindings, obj_struct); GetBufferViewMap(device_data)->erase(buffer_view); } + +bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { + bool skip = false; + skip |= ValidateMemoryIsBoundToBuffer(device_data, buffer_state, "vkCmdFillBuffer()", VALIDATION_ERROR_02529); + skip |= ValidateCmd(device_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()"); + // Validate that DST buffer has correct usage flags set + skip |= ValidateBufferUsageFlags(device_data, buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, VALIDATION_ERROR_01137, + "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); + skip |= insideRenderPass(device_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_01142); + return skip; +} + +void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state) { + std::function function = [=]() { + SetBufferMemoryValid(device_data, buffer_state, true); + return false; + }; + cb_node->validate_functions.push_back(function); + // Update bindings between buffer and cmd buffer + AddCommandBufferBindingBuffer(device_data, cb_node, buffer_state); + core_validation::UpdateCmdBufferLastCmd(cb_node, CMD_FILLBUFFER); +} diff --git a/layers/buffer_validation.h b/layers/buffer_validation.h index 32dd5dd..59617b3 100644 --- a/layers/buffer_validation.h +++ b/layers/buffer_validation.h @@ -193,4 +193,8 @@ bool PreCallValidateDestroyBufferView(layer_data *device_data, VkBufferView buff void PostCallRecordDestroyBufferView(layer_data *device_data, VkBufferView buffer_view, BUFFER_VIEW_STATE *buffer_view_state, VK_OBJECT obj_struct); +bool PreCallValidateCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state); + +void PreCallRecordCmdFillBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_node, BUFFER_STATE *buffer_state); + #endif // CORE_VALIDATION_BUFFER_VALIDATION_H_ diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index ce60fa7..8dbfbe3 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -7706,33 +7706,22 @@ VKAPI_ATTR void VKAPI_CALL CmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuff VKAPI_ATTR void VKAPI_CALL CmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size, uint32_t data) { - bool skip_call = false; - layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map); + layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map); std::unique_lock lock(global_lock); + auto cb_node = GetCBNode(device_data, commandBuffer); + auto buffer_state = GetBufferState(device_data, dstBuffer); - auto cb_node = GetCBNode(dev_data, commandBuffer); - auto dst_buff_state = GetBufferState(dev_data, dstBuffer); - if (cb_node && dst_buff_state) { - skip_call |= ValidateMemoryIsBoundToBuffer(dev_data, dst_buff_state, "vkCmdFillBuffer()", VALIDATION_ERROR_02529); - // Update bindings between buffer and cmd buffer - AddCommandBufferBindingBuffer(dev_data, cb_node, dst_buff_state); - // Validate that DST buffer has correct usage flags set - skip_call |= ValidateBufferUsageFlags(dev_data, dst_buff_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true, - VALIDATION_ERROR_01137, "vkCmdFillBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT"); - std::function function = [=]() { - SetBufferMemoryValid(dev_data, dst_buff_state, true); - return false; - }; - cb_node->validate_functions.push_back(function); - - skip_call |= ValidateCmd(dev_data, cb_node, CMD_FILLBUFFER, "vkCmdFillBuffer()"); - UpdateCmdBufferLastCmd(cb_node, CMD_FILLBUFFER); - skip_call |= insideRenderPass(dev_data, cb_node, "vkCmdFillBuffer()", VALIDATION_ERROR_01142); + if (cb_node && buffer_state) { + bool skip = PreCallValidateCmdFillBuffer(device_data, cb_node, buffer_state); + if (!skip) { + PreCallRecordCmdFillBuffer(device_data, cb_node, buffer_state); + lock.unlock(); + device_data->dispatch_table.CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); + } } else { + lock.unlock(); assert(0); } - lock.unlock(); - if (!skip_call) dev_data->dispatch_table.CmdFillBuffer(commandBuffer, dstBuffer, dstOffset, size, data); } VKAPI_ATTR void VKAPI_CALL CmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount, -- 2.7.4