From bf6bcad21e911637db8f3769bdfd7dd7ceb61701 Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Wed, 20 Jan 2016 10:25:29 -0700 Subject: [PATCH] layers: MR149, Cleanup CMD_NODE use in draw_state Move pCmds vector to be cmds vector instead. This simplifies cleanup of the data structure as we don't have to manage the ptr new/delete lifecycle. --- layers/draw_state.cpp | 39 ++++++++++----------------------------- layers/draw_state.h | 2 +- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/layers/draw_state.cpp b/layers/draw_state.cpp index fd975ee..8954a89 100644 --- a/layers/draw_state.cpp +++ b/layers/draw_state.cpp @@ -2497,12 +2497,6 @@ static void deleteCommandBuffers(layer_data* my_data) return; } for (auto ii=my_data->commandBufferMap.begin(); ii!=my_data->commandBufferMap.end(); ++ii) { - vector cmd_node_list = (*ii).second->pCmds; - while (!cmd_node_list.empty()) { - CMD_NODE* cmd_node = cmd_node_list.back(); - delete cmd_node; - cmd_node_list.pop_back(); - } delete (*ii).second; } my_data->commandBufferMap.clear(); @@ -2536,18 +2530,11 @@ static VkBool32 addCmd(const layer_data* my_data, GLOBAL_CB_NODE* pCB, const CMD if (pCB->state != CB_RECORDING) { skipCall |= report_error_no_cb_begin(my_data, pCB->commandBuffer, caller_name); skipCall |= validateCmdsInCmdBuffer(my_data, pCB, cmd); - CMD_NODE* pCmd = new CMD_NODE; - if (pCmd) { - // init cmd node and append to end of cmd LL - memset(pCmd, 0, sizeof(CMD_NODE)); - pCmd->cmdNumber = ++pCB->numCmds; - pCmd->type = cmd; - pCB->pCmds.push_back(pCmd); - } else { - // TODO : How to pass cb as srcObj here? - skipCall |= log_msg(my_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_OUT_OF_MEMORY, "DS", - "Out of memory while attempting to allocate new CMD_NODE for commandBuffer %#" PRIxLEAST64, reinterpret_cast(pCB->commandBuffer)); - } + CMD_NODE cmdNode = {}; + // init cmd node and append to end of cmd LL + cmdNode.cmdNumber = ++pCB->numCmds; + cmdNode.type = cmd; + pCB->cmds.push_back(cmdNode); } return skipCall; } @@ -2557,12 +2544,7 @@ static void resetCB(layer_data* my_data, const VkCommandBuffer cb) { GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb); if (pCB) { - vector cmd_list = pCB->pCmds; - while (!cmd_list.empty()) { - delete cmd_list.back(); - cmd_list.pop_back(); - } - pCB->pCmds.clear(); + pCB->cmds.clear(); // Reset CB state (note that createInfo is not cleared) pCB->commandBuffer = cb; memset(&pCB->beginInfo, 0, sizeof(VkCommandBufferBeginInfo)); @@ -2573,7 +2555,6 @@ static void resetCB(layer_data* my_data, const VkCommandBuffer cb) pCB->state = CB_NEW; pCB->submitCount = 0; pCB->status = 0; - pCB->pCmds.clear(); pCB->lastBoundPipeline = 0; pCB->viewports.clear(); pCB->scissors.clear(); @@ -2731,14 +2712,14 @@ static VkBool32 printDSConfig(layer_data* my_data, const VkCommandBuffer cb) static void printCB(layer_data* my_data, const VkCommandBuffer cb) { GLOBAL_CB_NODE* pCB = getCBNode(my_data, cb); - if (pCB && pCB->pCmds.size() > 0) { + if (pCB && pCB->cmds.size() > 0) { log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, (VkDebugReportObjectTypeEXT) 0, 0, __LINE__, DRAWSTATE_NONE, "DS", "Cmds in CB %p", (void*)cb); - vector pCmds = pCB->pCmds; - for (auto ii=pCmds.begin(); ii!=pCmds.end(); ++ii) { + vector cmds = pCB->cmds; + for (auto ii=cmds.begin(); ii!=cmds.end(); ++ii) { // TODO : Need to pass cb as srcObj here log_msg(my_data->report_data, VK_DEBUG_REPORT_INFO_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0, __LINE__, DRAWSTATE_NONE, "DS", - " CMD#%" PRIu64 ": %s", (*ii)->cmdNumber, cmdTypeToString((*ii)->type).c_str()); + " CMD#%" PRIu64 ": %s", (*ii).cmdNumber, cmdTypeToString((*ii).type).c_str()); } } else { // Nothing to print diff --git a/layers/draw_state.h b/layers/draw_state.h index e2e8aeb..cbd9a08 100755 --- a/layers/draw_state.h +++ b/layers/draw_state.h @@ -485,7 +485,7 @@ typedef struct _GLOBAL_CB_NODE { CB_STATE state; // Track cmd buffer update state uint64_t submitCount; // Number of times CB has been submitted CBStatusFlags status; // Track status of various bindings on cmd buffer - vector pCmds; + vector cmds; // vector of commands bound to this command buffer // Currently storing "lastBound" objects on per-CB basis // long-term may want to create caches of "lastBound" states and could have // each individual CMD_NODE referencing its own "lastBound" state -- 2.7.4