aboutsummaryrefslogtreecommitdiff
path: root/layers/core_validation.cpp
diff options
context:
space:
mode:
authorTobin Ehlis <tobine@google.com>2017-07-11 11:24:22 -0600
committerTobin Ehlis <tobine@google.com>2017-07-11 14:38:31 -0600
commit797e93c3aa9e547aeaee12db34cac3b745ad111d (patch)
tree4a3da289832cc465ed3764c41bb08c0ea429e6eb /layers/core_validation.cpp
parent66175388142af434dbcc8d0ce03e2c0bb4d399d0 (diff)
downloadusermoji-797e93c3aa9e547aeaee12db34cac3b745ad111d.tar.xz
layers:Refactor CmdUpdateBuffer to Pre/Post
Refactoring CmdUpdateBuffer function to use the Pre/Post call pattern. Updated the pre-path so that command buffer state pointer is const throughout. Pulled the state update code into the post function. Note that this slightly deviates from the previous pattern by doing object state look-up in top-level function instead of passing a ptr to a ptr to Pre* function and having it do the object state look-up. I prefer this method as it allows const* throughout the Pre* call chain and avoids the ptr derefs in Pre* function. I'm open to discussion if others prefer the alternate method however.
Diffstat (limited to 'layers/core_validation.cpp')
-rw-r--r--layers/core_validation.cpp67
1 files changed, 39 insertions, 28 deletions
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp
index f5576ac2..87fa6c7d 100644
--- a/layers/core_validation.cpp
+++ b/layers/core_validation.cpp
@@ -1555,8 +1555,8 @@ bool ValidateCmdSubpassState(const layer_data *dev_data, const GLOBAL_CB_NODE *p
return skip;
}
-bool ValidateCmdQueueFlags(layer_data *dev_data, GLOBAL_CB_NODE *cb_node, const char *caller_name, VkQueueFlags required_flags,
- UNIQUE_VALIDATION_ERROR_CODE error_code) {
+bool ValidateCmdQueueFlags(layer_data *dev_data, const GLOBAL_CB_NODE *cb_node, const char *caller_name,
+ VkQueueFlags required_flags, UNIQUE_VALIDATION_ERROR_CODE error_code) {
auto pool = GetCommandPoolNode(dev_data, cb_node->createInfo.commandPool);
if (pool) {
VkQueueFlags queue_flags = dev_data->phys_dev_properties.queue_family_properties[pool->queueFamilyIndex].queueFlags;
@@ -1587,7 +1587,7 @@ static char const * GetCauseStr(VK_OBJECT obj) {
return "destroyed";
}
-static bool ReportInvalidCommandBuffer(layer_data *dev_data, GLOBAL_CB_NODE *cb_state, const char *call_source) {
+static bool ReportInvalidCommandBuffer(layer_data *dev_data, const GLOBAL_CB_NODE *cb_state, const char *call_source) {
bool skip = false;
for (auto obj : cb_state->broken_bindings) {
const char *type_str = object_string[obj.type];
@@ -1602,7 +1602,7 @@ static bool ReportInvalidCommandBuffer(layer_data *dev_data, GLOBAL_CB_NODE *cb_
// Validate the given command being added to the specified cmd buffer, flagging errors if CB is not in the recording state or if
// there's an issue with the Cmd ordering
-bool ValidateCmd(layer_data *dev_data, GLOBAL_CB_NODE *cb_state, const CMD_TYPE cmd, const char *caller_name) {
+bool ValidateCmd(layer_data *dev_data, const GLOBAL_CB_NODE *cb_state, const CMD_TYPE cmd, const char *caller_name) {
switch (cb_state->state) {
case CB_RECORDING:
return ValidateCmdSubpassState(dev_data, cb_state, cmd);
@@ -1816,7 +1816,8 @@ static void set_cb_pso_status(GLOBAL_CB_NODE *pCB, const PIPELINE_STATE *pPipe)
// Flags validation error if the associated call is made inside a render pass. The apiName routine should ONLY be called outside a
// render pass.
-bool insideRenderPass(const layer_data *dev_data, GLOBAL_CB_NODE *pCB, const char *apiName, UNIQUE_VALIDATION_ERROR_CODE msgCode) {
+bool insideRenderPass(const layer_data *dev_data, const GLOBAL_CB_NODE *pCB, const char *apiName,
+ UNIQUE_VALIDATION_ERROR_CODE msgCode) {
bool inside = false;
if (pCB->activeRenderPass) {
inside = log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
@@ -5941,37 +5942,47 @@ VKAPI_ATTR void VKAPI_CALL CmdCopyImageToBuffer(VkCommandBuffer commandBuffer, V
}
}
+static bool PreCallCmdUpdateBuffer(layer_data *device_data, const GLOBAL_CB_NODE *cb_state, const BUFFER_STATE *dst_buffer_state) {
+ bool skip = false;
+ skip |= ValidateMemoryIsBoundToBuffer(device_data, dst_buffer_state, "vkCmdUpdateBuffer()", VALIDATION_ERROR_1e400046);
+ // Validate that DST buffer has correct usage flags set
+ skip |= ValidateBufferUsageFlags(device_data, dst_buffer_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
+ VALIDATION_ERROR_1e400044, "vkCmdUpdateBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
+ skip |= ValidateCmdQueueFlags(device_data, cb_state, "vkCmdUpdateBuffer()",
+ VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_1e402415);
+ skip |= ValidateCmd(device_data, cb_state, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
+ skip |= insideRenderPass(device_data, cb_state, "vkCmdUpdateBuffer()", VALIDATION_ERROR_1e400017);
+ return skip;
+}
+
+static void PostCallRecordCmdUpdateBuffer(layer_data *device_data, GLOBAL_CB_NODE *cb_state, BUFFER_STATE *dst_buffer_state) {
+ // Update bindings between buffer and cmd buffer
+ AddCommandBufferBindingBuffer(device_data, cb_state, dst_buffer_state);
+ std::function<bool()> function = [=]() {
+ SetBufferMemoryValid(device_data, dst_buffer_state, true);
+ return false;
+ };
+ cb_state->validate_functions.push_back(function);
+}
+
VKAPI_ATTR void VKAPI_CALL CmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,
VkDeviceSize dataSize, const uint32_t *pData) {
bool skip = false;
layer_data *dev_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
unique_lock_t lock(global_lock);
- auto cb_node = GetCBNode(dev_data, commandBuffer);
+ auto cb_state = GetCBNode(dev_data, commandBuffer);
+ assert(cb_state);
auto dst_buff_state = GetBufferState(dev_data, dstBuffer);
- if (cb_node && dst_buff_state) {
- skip |= ValidateMemoryIsBoundToBuffer(dev_data, dst_buff_state, "vkCmdUpdateBuffer()", VALIDATION_ERROR_1e400046);
- // 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 |= ValidateBufferUsageFlags(dev_data, dst_buff_state, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true,
- VALIDATION_ERROR_1e400044, "vkCmdUpdateBuffer()", "VK_BUFFER_USAGE_TRANSFER_DST_BIT");
- std::function<bool()> function = [=]() {
- SetBufferMemoryValid(dev_data, dst_buff_state, true);
- return false;
- };
- cb_node->validate_functions.push_back(function);
-
- skip |=
- ValidateCmdQueueFlags(dev_data, cb_node, "vkCmdUpdateBuffer()",
- VK_QUEUE_TRANSFER_BIT | VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT, VALIDATION_ERROR_1e402415);
- skip |= ValidateCmd(dev_data, cb_node, CMD_UPDATEBUFFER, "vkCmdUpdateBuffer()");
- skip |= insideRenderPass(dev_data, cb_node, "vkCmdUpdateBuffer()", VALIDATION_ERROR_1e400017);
- } else {
- assert(0);
- }
+ assert(dst_buff_state);
+ skip |= PreCallCmdUpdateBuffer(dev_data, cb_state, dst_buff_state);
lock.unlock();
- if (!skip) dev_data->dispatch_table.CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
+ if (!skip) {
+ dev_data->dispatch_table.CmdUpdateBuffer(commandBuffer, dstBuffer, dstOffset, dataSize, pData);
+ lock.lock();
+ PostCallRecordCmdUpdateBuffer(dev_data, cb_state, dst_buff_state);
+ lock.unlock();
+ }
}
VKAPI_ATTR void VKAPI_CALL CmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset,