Skip to content

Commit

Permalink
layers: Move sync related methods to CMD_BUFFER_STATE
Browse files Browse the repository at this point in the history
Convert sync related ValidationStateTracker methods to be
CMD_BUFFER_STATE methods. This change also adds RecordCmd()
calls to them.
  • Loading branch information
jeremyg-lunarg committed Aug 18, 2021
1 parent 29110d2 commit cefa7fd
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 82 deletions.
107 changes: 52 additions & 55 deletions layers/cmd_buffer_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,104 +1055,101 @@ static bool SetEventStageMask(VkEvent event, VkPipelineStageFlags2KHR stageMask,
return false;
}

void ValidationStateTracker::RecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask) {
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
if (!disabled[command_buffer_state]) {
auto event_state = GetEventState(event);
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) {
cb_state->AddChild(event_state);
AddChild(event_state);
}
}
cb_state->events.push_back(event);
if (!cb_state->waitedEvents.count(event)) {
cb_state->writeEventsBeforeWait.push_back(event);
events.push_back(event);
if (!waitedEvents.count(event)) {
writeEventsBeforeWait.push_back(event);
}
cb_state->eventUpdates.emplace_back(
eventUpdates.emplace_back(
[event, stageMask](const ValidationStateTracker *device_data, bool do_validate, EventToStageMap *localEventToStageMap) {
return SetEventStageMask(event, stageMask, localEventToStageMap);
});
}

void ValidationStateTracker::RecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask) {
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
if (!disabled[command_buffer_state]) {
auto event_state = GetEventState(event);
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) {
cb_state->AddChild(event_state);
AddChild(event_state);
}
}
cb_state->events.push_back(event);
if (!cb_state->waitedEvents.count(event)) {
cb_state->writeEventsBeforeWait.push_back(event);
events.push_back(event);
if (!waitedEvents.count(event)) {
writeEventsBeforeWait.push_back(event);
}

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

void ValidationStateTracker::RecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents) {
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
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 (!disabled[command_buffer_state]) {
auto event_state = GetEventState(pEvents[i]);
if (!dev_data->disabled[command_buffer_state]) {
auto event_state = dev_data->GetEventState(pEvents[i]);
if (event_state) {
cb_state->AddChild(event_state);
AddChild(event_state);
}
}
cb_state->waitedEvents.insert(pEvents[i]);
cb_state->events.push_back(pEvents[i]);
waitedEvents.insert(pEvents[i]);
events.push_back(pEvents[i]);
}
}

void ValidationStateTracker::RecordBarriers(VkCommandBuffer commandBuffer, uint32_t memoryBarrierCount,
const VkMemoryBarrier *pMemoryBarriers, uint32_t bufferMemoryBarrierCount,
const VkBufferMemoryBarrier *pBufferMemoryBarriers, uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *pImageMemoryBarriers) {
if (disabled[command_buffer_state]) return;
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;

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

void ValidationStateTracker::RecordBarriers(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR *pDependencyInfo) {
if (disabled[command_buffer_state]) return;
void CMD_BUFFER_STATE::RecordBarriers(const VkDependencyInfoKHR &dep_info) {
if (dev_data->disabled[command_buffer_state]) return;

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

void ValidationStateTracker::RecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR pipelineStage,
VkQueryPool queryPool, uint32_t slot) {
if (disabled[query_validation]) return;
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
if (!disabled[command_buffer_state]) {
auto pool_state = GetQueryPoolState(queryPool);
cb_state->AddChild(pool_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};
cb_state->EndQuery(query);
EndQuery(query);
}
9 changes: 9 additions & 0 deletions layers/cmd_buffer_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ class CMD_BUFFER_STATE : public REFCOUNTED_NODE {
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
43 changes: 27 additions & 16 deletions layers/state_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3140,26 +3140,29 @@ void ValidationStateTracker::PostCallRecordCmdUpdateBuffer(VkCommandBuffer comma

void ValidationStateTracker::PreCallRecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event,
VkPipelineStageFlags stageMask) {
RecordCmdSetEvent(commandBuffer, event, stageMask);
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordSetEvent(CMD_SETEVENT, event, stageMask);
}

void ValidationStateTracker::PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
const VkDependencyInfoKHR *pDependencyInfo) {
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
auto stage_masks = sync_utils::GetGlobalStageMasks(*pDependencyInfo);

RecordCmdSetEvent(commandBuffer, event, stage_masks.src);

RecordBarriers(commandBuffer, pDependencyInfo);
cb_state->RecordSetEvent(CMD_SETEVENT2KHR, event, stage_masks.src);
cb_state->RecordBarriers(*pDependencyInfo);
}

void ValidationStateTracker::PreCallRecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event,
VkPipelineStageFlags stageMask) {
RecordCmdResetEvent(commandBuffer, event, stageMask);
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordResetEvent(CMD_RESETEVENT, event, stageMask);
}

void ValidationStateTracker::PreCallRecordCmdResetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
VkPipelineStageFlags2KHR stageMask) {
RecordCmdResetEvent(commandBuffer, event, stageMask);
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordResetEvent(CMD_RESETEVENT2KHR, event, stageMask);
}

void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
Expand All @@ -3169,16 +3172,18 @@ void ValidationStateTracker::PreCallRecordCmdWaitEvents(VkCommandBuffer commandB
const VkBufferMemoryBarrier *pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *pImageMemoryBarriers) {
RecordCmdWaitEvents(commandBuffer, eventCount, pEvents);
RecordBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
imageMemoryBarrierCount, pImageMemoryBarriers);
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWaitEvents(CMD_WAITEVENTS, eventCount, pEvents);
cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
imageMemoryBarrierCount, pImageMemoryBarriers);
}

void ValidationStateTracker::PreCallRecordCmdWaitEvents2KHR(VkCommandBuffer commandBuffer, uint32_t eventCount,
const VkEvent *pEvents, const VkDependencyInfoKHR *pDependencyInfos) {
RecordCmdWaitEvents(commandBuffer, eventCount, pEvents);
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWaitEvents(CMD_WAITEVENTS2KHR, eventCount, pEvents);
for (uint32_t i = 0; i < eventCount; i++) {
RecordBarriers(commandBuffer, &pDependencyInfos[i]);
cb_state->RecordBarriers(pDependencyInfos[i]);
}
}

Expand All @@ -3189,13 +3194,17 @@ void ValidationStateTracker::PostCallRecordCmdPipelineBarrier(VkCommandBuffer co
const VkBufferMemoryBarrier *pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier *pImageMemoryBarriers) {
RecordBarriers(commandBuffer, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
imageMemoryBarrierCount, pImageMemoryBarriers);
auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_PIPELINEBARRIER);
cb_state->RecordBarriers(memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers,
imageMemoryBarrierCount, pImageMemoryBarriers);
}

void ValidationStateTracker::PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer,
const VkDependencyInfoKHR *pDependencyInfo) {
RecordBarriers(commandBuffer, pDependencyInfo);
auto cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordCmd(CMD_PIPELINEBARRIER2KHR);
cb_state->RecordBarriers(*pDependencyInfo);
}

QueryState ValidationStateTracker::GetQueryState(const QueryMap *localQueryToStateMap, VkQueryPool queryPool, uint32_t queryIndex,
Expand Down Expand Up @@ -3268,13 +3277,15 @@ void ValidationStateTracker::PostCallRecordCmdCopyQueryPoolResults(VkCommandBuff

void ValidationStateTracker::PostCallRecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlagBits pipelineStage,
VkQueryPool queryPool, uint32_t slot) {
RecordCmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP, pipelineStage, queryPool, slot);
}

void ValidationStateTracker::PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer,
VkPipelineStageFlags2KHR pipelineStage, VkQueryPool queryPool,
uint32_t slot) {
RecordCmdWriteTimestamp(commandBuffer, pipelineStage, queryPool, slot);
CMD_BUFFER_STATE *cb_state = Get<CMD_BUFFER_STATE>(commandBuffer);
cb_state->RecordWriteTimestamp(CMD_WRITETIMESTAMP2KHR, pipelineStage, queryPool, slot);
}

void ValidationStateTracker::PostCallRecordCmdWriteAccelerationStructuresPropertiesKHR(
Expand Down
11 changes: 0 additions & 11 deletions layers/state_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -1221,22 +1221,13 @@ class ValidationStateTracker : public ValidationObject {
void PreCallRecordCmdSetDepthBiasEnableEXT(VkCommandBuffer commandBuffer, VkBool32 depthBiasEnable) override;
void PreCallRecordCmdSetPrimitiveRestartEnableEXT(VkCommandBuffer commandBuffer, VkBool32 primitiveRestartEnable) override;

void RecordCmdSetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask);
void RecordCmdWaitEvents(VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent* pEvents);
void RecordCmdResetEvent(VkCommandBuffer commandBuffer, VkEvent event, VkPipelineStageFlags2KHR stageMask);

void PostCallRecordCmdPipelineBarrier(VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask,
VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags,
uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount,
const VkImageMemoryBarrier* pImageMemoryBarriers) override;

void RecordBarriers(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR* pDependencyInfo);
void RecordBarriers(VkCommandBuffer commandBuffer, uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers,
uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers,
uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers);

void PreCallRecordCmdPipelineBarrier2KHR(VkCommandBuffer commandBuffer, const VkDependencyInfoKHR* pDependencyInfo) override;

void PreCallRecordCmdSetEvent2KHR(VkCommandBuffer commandBuffer, VkEvent event,
Expand All @@ -1246,8 +1237,6 @@ class ValidationStateTracker : public ValidationObject {
const VkDependencyInfoKHR* pDependencyInfos) override;
void PostCallRecordCmdWriteTimestamp2KHR(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR stage, VkQueryPool queryPool,
uint32_t query) override;
void RecordCmdWriteTimestamp(VkCommandBuffer commandBuffer, VkPipelineStageFlags2KHR stage, VkQueryPool queryPool,
uint32_t query);
void PostCallRecordQueueSubmit2KHR(VkQueue queue, uint32_t submitCount, const VkSubmitInfo2KHR* pSubmits, VkFence fence,
VkResult result) override;

Expand Down

0 comments on commit cefa7fd

Please sign in to comment.