Skip to content

Commit

Permalink
layers: Move index buffer out of CBStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg authored and jeremyg-lunarg committed Oct 19, 2022
1 parent 1d21d51 commit 87449a7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion layers/cmd_buffer_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ struct BufferBinding {
virtual ~BufferBinding() {}

virtual void reset() { *this = BufferBinding(); }
bool bound() const { return buffer_state && !buffer_state->Destroyed(); }
};

struct IndexBufferBinding : BufferBinding {
Expand Down Expand Up @@ -371,7 +372,6 @@ class CMD_BUFFER_STATE : public REFCOUNTED_NODE {
queryUpdates;
layer_data::unordered_map<const cvdescriptorset::DescriptorSet *, cvdescriptorset::DescriptorSet::CachedValidation>
descriptorset_cache;
// Contents valid only after an index buffer is bound (CBSTATUS_INDEX_BUFFER_BOUND set)
IndexBufferBinding index_buffer_binding;
bool performance_lock_acquired = false;
bool performance_lock_released = false;
Expand Down
16 changes: 8 additions & 8 deletions layers/core_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ bool CoreChecks::IsDynamic(const PIPELINE_STATE *pPipeline, const VkDynamicState
}

// Validate state stored as flags at time of draw call
bool CoreChecks::ValidateDrawStateFlags(const CMD_BUFFER_STATE *pCB, const PIPELINE_STATE *pPipe, bool indexed,
const char *msg_code) const {
bool CoreChecks::ValidateDrawStateFlags(const CMD_BUFFER_STATE *pCB, const PIPELINE_STATE *pPipe, const char *msg_code) const {
bool result = false;
if (pPipe->topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_LINE_LIST ||
pPipe->topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP) {
Expand Down Expand Up @@ -416,10 +415,6 @@ bool CoreChecks::ValidateDrawStateFlags(const CMD_BUFFER_STATE *pCB, const PIPEL
result |= ValidateStatus(pCB, CBSTATUS_STENCIL_REFERENCE_SET,
"Dynamic stencil reference state not set for this command buffer", msg_code);
}
if (indexed) {
result |= ValidateStatus(pCB, CBSTATUS_INDEX_BUFFER_BOUND,
"Index buffer object not bound to this command buffer when Indexed Draw attempted", msg_code);
}
if (pPipe->topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_LINE_LIST ||
pPipe->topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_LINE_STRIP) {
const auto *line_state = LvlFindInChain<VkPipelineRasterizationLineStateCreateInfoEXT>(rp_state);
Expand Down Expand Up @@ -1112,7 +1107,7 @@ bool CoreChecks::ValidatePipelineDrawtimeState(const LAST_BOUND_STATE &state, co
"Buffer is vertex buffer");
}
}
if (pCB->index_buffer_binding.buffer_state && !pCB->index_buffer_binding.buffer_state->Destroyed()) {
if (pCB->index_buffer_binding.bound()) {
skip |= ValidateProtectedBuffer(pCB, pCB->index_buffer_binding.buffer_state.get(), caller,
vuid.unprotected_command_buffer, "Buffer is index buffer");
}
Expand Down Expand Up @@ -1625,7 +1620,12 @@ bool CoreChecks::ValidateCmdBufDrawState(const CMD_BUFFER_STATE *cb_node, CMD_TY

if (VK_PIPELINE_BIND_POINT_GRAPHICS == bind_point) {
// First check flag states
result |= ValidateDrawStateFlags(cb_node, pipe, indexed, vuid.dynamic_state);
result |= ValidateDrawStateFlags(cb_node, pipe, vuid.dynamic_state);

if (indexed && !cb_node->index_buffer_binding.bound()) {
return LogError(cb_node->commandBuffer(), vuid.index_binding,
"%s: Index buffer object has not been bound to this command buffer.", function);
}

if (cb_node->activeRenderPass && cb_node->activeFramebuffer) {
// Verify attachments for unprotected/protected command buffer.
Expand Down
3 changes: 2 additions & 1 deletion layers/core_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
struct DrawDispatchVuid {
const char* pipeline_bound = kVUIDUndefined;
const char* dynamic_state = kVUIDUndefined;
const char* index_binding = kVUIDUndefined;
const char* vertex_binding = kVUIDUndefined;
const char* vertex_binding_null = kVUIDUndefined;
const char* compatible_pipeline = kVUIDUndefined;
Expand Down Expand Up @@ -223,7 +224,7 @@ class CoreChecks : public ValidationStateTracker {
bool ValidateMaxTimelineSemaphoreValueDifference(const Location& loc, const SEMAPHORE_STATE& semaphore_state,
uint64_t value) const;
bool ValidateStatus(const CMD_BUFFER_STATE* pNode, CBStatus status, const char* fail_msg, const char* msg_code) const;
bool ValidateDrawStateFlags(const CMD_BUFFER_STATE* pCB, const PIPELINE_STATE* pPipe, bool indexed, const char* msg_code) const;
bool ValidateDrawStateFlags(const CMD_BUFFER_STATE* pCB, const PIPELINE_STATE* pPipe, const char* msg_code) const;
bool LogInvalidAttachmentMessage(const char* type1_string, const RENDER_PASS_STATE* rp1_state, const char* type2_string,
const RENDER_PASS_STATE* rp2_state, uint32_t primary_attach, uint32_t secondary_attach,
const char* msg, const char* caller, const char* error_code) const;
Expand Down
6 changes: 5 additions & 1 deletion layers/drawdispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ struct DispatchVuidsCmdDrawIndexed : DrawDispatchVuid {
DispatchVuidsCmdDrawIndexed() : DrawDispatchVuid() {
pipeline_bound = "VUID-vkCmdDrawIndexed-None-02700";
dynamic_state = "VUID-vkCmdDrawIndexed-commandBuffer-02701";
index_binding = "VUID-vkCmdDrawIndexed-None-07312";
vertex_binding = "VUID-vkCmdDrawIndexed-None-04007";
vertex_binding_null = "VUID-vkCmdDrawIndexed-None-04008";
compatible_pipeline = "VUID-vkCmdDrawIndexed-None-02697";
Expand Down Expand Up @@ -275,6 +276,7 @@ struct DispatchVuidsCmdDrawMultiIndexedEXT : DrawDispatchVuid {
DispatchVuidsCmdDrawMultiIndexedEXT() : DrawDispatchVuid() {
pipeline_bound = "VUID-vkCmdDrawMultiIndexedEXT-None-02700";
dynamic_state = "VUID-vkCmdDrawMultiIndexedEXT-commandBuffer-02701";
index_binding = "VUID-vkCmdDrawMultiIndexedEXT-None-07312";
vertex_binding = "VUID-vkCmdDrawMultiIndexedEXT-None-04007";
vertex_binding_null = "VUID-vkCmdDrawMultiIndexedEXT-None-04008";
compatible_pipeline = "VUID-vkCmdDrawMultiIndexedEXT-None-02697";
Expand Down Expand Up @@ -429,6 +431,7 @@ struct DispatchVuidsCmdDrawIndexedIndirect : DrawDispatchVuid {
DispatchVuidsCmdDrawIndexedIndirect() : DrawDispatchVuid() {
pipeline_bound = "VUID-vkCmdDrawIndexedIndirect-None-02700";
dynamic_state = "VUID-vkCmdDrawIndexedIndirect-commandBuffer-02701";
index_binding = "VUID-vkCmdDrawIndexedIndirect-None-07312";
vertex_binding = "VUID-vkCmdDrawIndexedIndirect-None-04007";
vertex_binding_null = "VUID-vkCmdDrawIndexedIndirect-None-04008";
compatible_pipeline = "VUID-vkCmdDrawIndexedIndirect-None-02697";
Expand Down Expand Up @@ -648,6 +651,7 @@ struct DispatchVuidsCmdDrawIndexedIndirectCount : DrawDispatchVuid {
DispatchVuidsCmdDrawIndexedIndirectCount() : DrawDispatchVuid() {
pipeline_bound = "VUID-vkCmdDrawIndexedIndirectCount-None-02700";
dynamic_state = "VUID-vkCmdDrawIndexedIndirectCount-commandBuffer-02701";
index_binding = "VUID-vkCmdDrawIndexedIndirectCount-None-07312";
vertex_binding = "VUID-vkCmdDrawIndexedIndirectCount-None-04007";
vertex_binding_null = "VUID-vkCmdDrawIndexedIndirectCount-None-04008";
compatible_pipeline = "VUID-vkCmdDrawIndexedIndirectCount-None-02697";
Expand Down Expand Up @@ -1266,7 +1270,7 @@ bool CoreChecks::PreCallValidateCmdDrawMultiEXT(VkCommandBuffer commandBuffer, u
bool CoreChecks::ValidateCmdDrawIndexedBufferSize(const CMD_BUFFER_STATE &cb_state, uint32_t indexCount, uint32_t firstIndex,
const char *caller, const char *first_index_vuid) const {
bool skip = false;
if (cb_state.status[CBSTATUS_INDEX_BUFFER_BOUND]) {
if (cb_state.index_buffer_binding.bound()) {
const auto &index_buffer_binding = cb_state.index_buffer_binding;
const uint32_t index_size = GetIndexAlignment(index_buffer_binding.index_type);
VkDeviceSize end_offset = static_cast<VkDeviceSize>(index_size * (firstIndex + indexCount)) + index_buffer_binding.offset;
Expand Down
1 change: 0 additions & 1 deletion layers/state_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,6 @@ void ValidationStateTracker::PreCallRecordCmdBindIndexBuffer(VkCommandBuffer com
VkIndexType indexType) {
auto cb_state = GetWrite<CMD_BUFFER_STATE>(commandBuffer);

cb_state->RecordStateCmd(CMD_BINDINDEXBUFFER, CBSTATUS_INDEX_BUFFER_BOUND);
cb_state->index_buffer_binding.buffer_state = Get<BUFFER_STATE>(buffer);
cb_state->index_buffer_binding.size = cb_state->index_buffer_binding.buffer_state->createInfo.size;
cb_state->index_buffer_binding.offset = offset;
Expand Down
4 changes: 2 additions & 2 deletions layers/synchronization_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ void CommandBufferAccessContext::RecordDrawVertex(uint32_t vertexCount, uint32_t

bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, CMD_TYPE cmd_type) const {
bool skip = false;
if (cb_state_->index_buffer_binding.buffer_state == nullptr || cb_state_->index_buffer_binding.buffer_state->Destroyed()) {
if (!cb_state_->index_buffer_binding.bound()) {
return skip;
}

Expand All @@ -2347,7 +2347,7 @@ bool CommandBufferAccessContext::ValidateDrawVertexIndex(uint32_t indexCount, ui
}

void CommandBufferAccessContext::RecordDrawVertexIndex(uint32_t indexCount, uint32_t firstIndex, const ResourceUsageTag tag) {
if (cb_state_->index_buffer_binding.buffer_state == nullptr || cb_state_->index_buffer_binding.buffer_state->Destroyed()) return;
if (!cb_state_->index_buffer_binding.bound()) return;

auto *index_buf_state = cb_state_->index_buffer_binding.buffer_state.get();
const auto index_size = GetIndexAlignment(cb_state_->index_buffer_binding.index_type);
Expand Down
10 changes: 5 additions & 5 deletions tests/vklayertests_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ TEST_F(VkLayerTest, IndexBufferNotBound) {
TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");

ASSERT_NO_FATAL_FAILURE(Init());
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "Index buffer object not bound to this command buffer when Indexed ");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexed-None-07312");
VKTriangleTest(BsoFailIndexBuffer);
m_errorMonitor->VerifyFound();
}
Expand Down Expand Up @@ -5948,7 +5948,7 @@ TEST_F(VkLayerTest, IndirectDrawTests) {
vk::CmdDrawIndirect(m_commandBuffer->handle(), draw_buffer_correct.handle(), 0, 2, sizeof(VkDrawIndirectCommand));
m_errorMonitor->VerifyFound();

m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexedIndirect-commandBuffer-02701");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexedIndirect-None-07312");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexedIndirect-drawCount-00540");
vk::CmdDrawIndexedIndirect(m_commandBuffer->handle(), draw_buffer_correct.handle(), 0, 2, sizeof(VkDrawIndexedIndirectCommand));
m_errorMonitor->VerifyFound();
Expand Down Expand Up @@ -6210,7 +6210,7 @@ TEST_F(VkLayerTest, DrawIndexedIndirectCountKHR) {
VkBufferObj index_buffer;
index_buffer.init(*m_device, index_buffer_create_info);

m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexedIndirectCount-commandBuffer-02701");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexedIndirectCount-None-07312");
vkCmdDrawIndexedIndirectCountKHR(m_commandBuffer->handle(), draw_buffer.handle(), 0, count_buffer.handle(), 0, 1,
sizeof(VkDrawIndexedIndirectCommand));
m_errorMonitor->VerifyFound();
Expand Down Expand Up @@ -11097,7 +11097,7 @@ TEST_F(VkLayerTest, ValidateMultiviewUnboundResourcesAfterBeginRenderPassAndNext
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.pipeline_);
vk::CmdBindVertexBuffers(m_commandBuffer->handle(), 0, 1, &vbo.handle(), &offset);

m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexed-commandBuffer-02701");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexed-None-07312");
m_commandBuffer->DrawIndexed(0, 1, 0, 0, 0);
m_errorMonitor->VerifyFound();

Expand All @@ -11108,7 +11108,7 @@ TEST_F(VkLayerTest, ValidateMultiviewUnboundResourcesAfterBeginRenderPassAndNext
vk::CmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines[i].handle());
vk::CmdBindVertexBuffers(m_commandBuffer->handle(), 0, 1, &vbo.handle(), &offset);

m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexed-commandBuffer-02701");
m_errorMonitor->SetDesiredFailureMsg(kErrorBit, "VUID-vkCmdDrawIndexed-None-07312");
m_commandBuffer->DrawIndexed(0, 1, 0, 0, 0);
m_errorMonitor->VerifyFound();
}
Expand Down

0 comments on commit 87449a7

Please sign in to comment.