Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layers: Move command counting to CMD_BUFFER_STATE::RecordCmd() #3184

Merged
merged 3 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 132 additions & 3 deletions layers/cmd_buffer_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,9 @@ void CMD_BUFFER_STATE::UpdateAttachmentsView(const VkRenderPassBeginInfo *pRende
}
}

void CMD_BUFFER_STATE::BeginRenderPass(const VkRenderPassBeginInfo *pRenderPassBegin, const VkSubpassContents contents) {
void CMD_BUFFER_STATE::BeginRenderPass(CMD_TYPE cmd_type, const VkRenderPassBeginInfo *pRenderPassBegin,
const VkSubpassContents contents) {
RecordCmd(cmd_type);
activeFramebuffer = dev_data->GetShared<FRAMEBUFFER_STATE>(pRenderPassBegin->framebuffer);
activeRenderPass = dev_data->GetShared<RENDER_PASS_STATE>(pRenderPassBegin->renderPass);
activeRenderPassBeginInfo = safe_VkRenderPassBeginInfo(pRenderPassBegin);
Expand Down Expand Up @@ -600,7 +602,8 @@ void CMD_BUFFER_STATE::BeginRenderPass(const VkRenderPassBeginInfo *pRenderPassB
}
}

void CMD_BUFFER_STATE::NextSubpass(VkSubpassContents contents) {
void CMD_BUFFER_STATE::NextSubpass(CMD_TYPE cmd_type, VkSubpassContents contents) {
RecordCmd(cmd_type);
activeSubpass++;
activeSubpassContents = contents;

Expand All @@ -614,7 +617,8 @@ void CMD_BUFFER_STATE::NextSubpass(VkSubpassContents contents) {
}
}

void CMD_BUFFER_STATE::EndRenderPass() {
void CMD_BUFFER_STATE::EndRenderPass(CMD_TYPE cmd_type) {
RecordCmd(cmd_type);
activeRenderPass = nullptr;
active_attachments = nullptr;
active_subpasses = nullptr;
Expand Down Expand Up @@ -695,6 +699,7 @@ void CMD_BUFFER_STATE::End(VkResult result) {
}

void CMD_BUFFER_STATE::ExecuteCommands(uint32_t commandBuffersCount, const VkCommandBuffer *pCommandBuffers) {
RecordCmd(CMD_EXECUTECOMMANDS);
CMD_BUFFER_STATE *sub_cb_state = NULL;
for (uint32_t i = 0; i < commandBuffersCount; i++) {
sub_cb_state = dev_data->Get<CMD_BUFFER_STATE>(pCommandBuffers[i]);
Expand Down Expand Up @@ -787,6 +792,8 @@ void CMD_BUFFER_STATE::UpdateStateCmdDrawType(CMD_TYPE cmd_type, VkPipelineBindP
}

void CMD_BUFFER_STATE::UpdateDrawState(CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point, const char *function) {
RecordCmd(cmd_type);

const auto lv_bind_point = ConvertToLvlBindPoint(bind_point);
auto &state = lastBound[lv_bind_point];
PIPELINE_STATE *pipe = state.pipeline_state;
Expand Down Expand Up @@ -1024,3 +1031,125 @@ void CMD_BUFFER_STATE::SetImageViewLayout(const IMAGE_VIEW_STATE &view_state, Vk
SetImageLayout(*image_state, sub_range, layout);
}
}

void CMD_BUFFER_STATE::RecordCmd(CMD_TYPE cmd_type) { commandCount++; }

void CMD_BUFFER_STATE::RecordStateCmd(CMD_TYPE cmd_type, CBStatusFlags state_bits) {
RecordCmd(cmd_type);
status |= state_bits;
static_status &= ~state_bits;
}

void CMD_BUFFER_STATE::RecordTransferCmd(CMD_TYPE cmd_type, BINDABLE *buf1, BINDABLE *buf2) {
RecordCmd(cmd_type);
if (buf1) {
AddChild(buf1);
}
if (buf2) {
AddChild(buf2);
}
}

static bool SetEventStageMask(VkEvent event, VkPipelineStageFlags2KHR stageMask, EventToStageMap *localEventToStageMap) {
(*localEventToStageMap)[event] = stageMask;
return false;
}

void CMD_BUFFER_STATE::RecordSetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask) {
RecordCmd(cmd_type);
if (!dev_data->disabled[command_buffer_state]) {
auto event_state = dev_data->GetEventState(event);
if (event_state) {
AddChild(event_state);
}
}
events.push_back(event);
if (!waitedEvents.count(event)) {
writeEventsBeforeWait.push_back(event);
}
eventUpdates.emplace_back(
[event, stageMask](const ValidationStateTracker *device_data, bool do_validate, EventToStageMap *localEventToStageMap) {
return SetEventStageMask(event, stageMask, localEventToStageMap);
});
}

void CMD_BUFFER_STATE::RecordResetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask) {
RecordCmd(cmd_type);
if (!dev_data->disabled[command_buffer_state]) {
auto event_state = dev_data->GetEventState(event);
if (event_state) {
AddChild(event_state);
}
}
events.push_back(event);
if (!waitedEvents.count(event)) {
writeEventsBeforeWait.push_back(event);
}

eventUpdates.emplace_back([event](const ValidationStateTracker *, bool do_validate, EventToStageMap *localEventToStageMap) {
return SetEventStageMask(event, VkPipelineStageFlags2KHR(0), localEventToStageMap);
});
}

void CMD_BUFFER_STATE::RecordWaitEvents(CMD_TYPE cmd_type, uint32_t eventCount, const VkEvent *pEvents) {
RecordCmd(cmd_type);
for (uint32_t i = 0; i < eventCount; ++i) {
if (!dev_data->disabled[command_buffer_state]) {
auto event_state = dev_data->GetEventState(pEvents[i]);
if (event_state) {
AddChild(event_state);
}
}
waitedEvents.insert(pEvents[i]);
events.push_back(pEvents[i]);
}
}

void CMD_BUFFER_STATE::RecordBarriers(uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier *pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier *pImageMemoryBarriers) {
if (dev_data->disabled[command_buffer_state]) return;

for (uint32_t i = 0; i < bufferMemoryBarrierCount; i++) {
auto buffer_state = dev_data->GetBufferState(pBufferMemoryBarriers[i].buffer);
if (buffer_state) {
AddChild(buffer_state);
}
}
for (uint32_t i = 0; i < imageMemoryBarrierCount; i++) {
auto image_state = dev_data->GetImageState(pImageMemoryBarriers[i].image);
if (image_state) {
AddChild(image_state);
}
}
}

void CMD_BUFFER_STATE::RecordBarriers(const VkDependencyInfoKHR &dep_info) {
if (dev_data->disabled[command_buffer_state]) return;

for (uint32_t i = 0; i < dep_info.bufferMemoryBarrierCount; i++) {
auto buffer_state = dev_data->GetBufferState(dep_info.pBufferMemoryBarriers[i].buffer);
if (buffer_state) {
AddChild(buffer_state);
}
}
for (uint32_t i = 0; i < dep_info.imageMemoryBarrierCount; i++) {
auto image_state = dev_data->GetImageState(dep_info.pImageMemoryBarriers[i].image);
if (image_state) {
AddChild(image_state);
}
}
}

void CMD_BUFFER_STATE::RecordWriteTimestamp(CMD_TYPE cmd_type, VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
uint32_t slot) {
RecordCmd(cmd_type);
if (dev_data->disabled[query_validation]) return;

if (!dev_data->disabled[command_buffer_state]) {
auto pool_state = dev_data->GetQueryPoolState(queryPool);
AddChild(pool_state);
}
QueryObject query = {queryPool, slot};
EndQuery(query);
}
19 changes: 16 additions & 3 deletions layers/cmd_buffer_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ class CMD_BUFFER_STATE : public REFCOUNTED_NODE {
void EndQueries(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount);
void ResetQueryPool(VkQueryPool queryPool, uint32_t firstQuery, uint32_t queryCount);

void BeginRenderPass(const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents);
void NextSubpass(VkSubpassContents contents);
void EndRenderPass();
void BeginRenderPass(CMD_TYPE cmd_type, const VkRenderPassBeginInfo *pRenderPassBegin, VkSubpassContents contents);
void NextSubpass(CMD_TYPE cmd_type, VkSubpassContents contents);
void EndRenderPass(CMD_TYPE cmd_type);

void ExecuteCommands(uint32_t commandBuffersCount, const VkCommandBuffer *pCommandBuffers);

Expand All @@ -417,6 +417,19 @@ class CMD_BUFFER_STATE : public REFCOUNTED_NODE {
void UpdateStateCmdDrawType(CMD_TYPE cmd_type, VkPipelineBindPoint bind_point, const char *function);
void UpdateDrawState(CMD_TYPE cmd_type, const VkPipelineBindPoint bind_point, const char *function);

virtual void RecordCmd(CMD_TYPE cmd_type);
void RecordStateCmd(CMD_TYPE cmd_type, CBStatusFlags state_bits);
void RecordTransferCmd(CMD_TYPE cmd_type, BINDABLE *buf1, BINDABLE *buf2 = nullptr);
void RecordSetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask);
void RecordResetEvent(CMD_TYPE cmd_type, VkEvent event, VkPipelineStageFlags2KHR stageMask);
void RecordWaitEvents(CMD_TYPE cmd_type, uint32_t eventCount, const VkEvent *pEvents);
void RecordWriteTimestamp(CMD_TYPE cmd_type, VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool, uint32_t slot);

void RecordBarriers(uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *pImageMemoryBarriers);
void RecordBarriers(const VkDependencyInfoKHR &dep_info);

void SetImageViewLayout(const IMAGE_VIEW_STATE &view_state, VkImageLayout layout, VkImageLayout layoutStencil);
void SetImageViewInitialLayout(const IMAGE_VIEW_STATE &view_state, VkImageLayout layout);

Expand Down
7 changes: 0 additions & 7 deletions layers/generated/command_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,6 @@ static const std::array<const char *, CMD_RANGE_SIZE> kGeneratedBufferLevelList
bool CoreChecks::ValidateCmd(const CMD_BUFFER_STATE *cb_state, const CMD_TYPE cmd, const char *caller_name) const {
bool skip = false;

// Tracks the number of commands recorded in a command buffer
// This const_cast is not ideal, but easier to maintain incrementing here as this is a single location
// all vkCmd* calls are funneled into. The other option is to append another function pointer for each call
// in the ValidationObject object_dispatch. This is also making assumption this function is locked and this
// write is not going to race without another copy of the CMD_BUFFER_STATE instance.
const_cast<CMD_BUFFER_STATE *>(cb_state)->commandCount++;

// 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
switch (cb_state->state) {
Expand Down
Loading