Skip to content

Commit

Permalink
layers: Add DrawCmd perf warning to Best Practices
Browse files Browse the repository at this point in the history
Change-Id: I7b4530393df8ff7b93f2ceb484ff49a1fb6e92c8
  • Loading branch information
camden-lunarg committed Nov 8, 2019
1 parent 2a8bc25 commit f4206ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions layers/best_practices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,25 @@ void BestPractices::PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindIn
}
}
}

bool BestPractices::PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects) {
bool skip = false;
const CMD_BUFFER_STATE* cb_node = GetCBState(commandBuffer);
if (!cb_node) return skip;

// Warn if this is issued prior to Draw Cmd and clearing the entire attachment
if (!cb_node->hasDrawCmd && (cb_node->activeRenderPassBeginInfo.renderArea.extent.width == pRects[0].rect.extent.width) &&
(cb_node->activeRenderPassBeginInfo.renderArea.extent.height == pRects[0].rect.extent.height)) {
// There are times where app needs to use ClearAttachments (generally when reusing a buffer inside of a render pass)
// This warning should be made more specific. It'd be best to avoid triggering this test if it's a use that must call
// CmdClearAttachments.
skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
HandleToUint64(commandBuffer), kVUID_Core_DrawState_ClearCmdBeforeDraw,
"vkCmdClearAttachments() issued on %s prior to any Draw Cmds. It is recommended you "
"use RenderPass LOAD_OP_CLEAR on Attachments prior to any Draw.",
report_data->FormatHandle(commandBuffer).c_str());
}

return skip;
}
2 changes: 2 additions & 0 deletions layers/best_practices.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class BestPractices : public ValidationStateTracker {
VkFence fence) const;
void PostCallRecordQueueBindSparse(VkQueue queue, uint32_t bindInfoCount, const VkBindSparseInfo* pBindInfo, VkFence fence,
VkResult result);
bool PreCallValidateCmdClearAttachments(VkCommandBuffer commandBuffer, uint32_t attachmentCount,
const VkClearAttachment* pAttachments, uint32_t rectCount, const VkClearRect* pRects);

private:
uint32_t instance_api_version;
Expand Down

0 comments on commit f4206ce

Please sign in to comment.