Skip to content
This repository was archived by the owner on Jul 19, 2018. It is now read-only.

Commit 4d43c6a

Browse files
committed
layers: Use CB invalidation mechanism for VU135.
Makes more sense to use command buffer invalidation to drive this than maintaining parallel logic and only picking this up at draw time. Drops some additional TODOs in around areas that need some more work to make this nice.
1 parent d807198 commit 4d43c6a

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

layers/core_validation.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,6 @@ static void resetCB(layer_data *dev_data, const VkCommandBuffer cb) {
17361736
pCB->drawData.clear();
17371737
pCB->currentDrawData.buffers.clear();
17381738
pCB->vertex_buffer_used = false;
1739-
pCB->primaryCommandBuffer = VK_NULL_HANDLE;
17401739
// If secondary, invalidate any primary command buffer that may call us.
17411740
if (pCB->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
17421741
invalidateCommandBuffers(dev_data,
@@ -2509,6 +2508,8 @@ static bool validatePrimaryCommandBufferState(layer_data *dev_data, GLOBAL_CB_NO
25092508
// Track in-use for resources off of primary and any secondary CBs
25102509
bool skip = false;
25112510

2511+
// TODO: inline this function into sole caller
2512+
25122513
// If USAGE_SIMULTANEOUS_USE_BIT not set then CB cannot already be executing
25132514
// on device
25142515
skip |= validateCommandBufferSimultaneousUse(dev_data, pCB, current_submit_count);
@@ -2517,16 +2518,6 @@ static bool validatePrimaryCommandBufferState(layer_data *dev_data, GLOBAL_CB_NO
25172518

25182519
for (auto pSubCB : pCB->linkedCommandBuffers) {
25192520
skip |= validateResources(dev_data, pSubCB);
2520-
// TODO: replace with invalidateCommandBuffers() at recording.
2521-
if ((pSubCB->primaryCommandBuffer != pCB->commandBuffer) &&
2522-
!(pSubCB->beginInfo.flags & VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT)) {
2523-
log_msg(dev_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, 0,
2524-
__LINE__, VALIDATION_ERROR_31a00092, "DS",
2525-
"Commandbuffer 0x%p was submitted with secondary buffer 0x%p but that buffer has subsequently been bound to "
2526-
"primary cmd buffer 0x%p and it does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set. %s",
2527-
pCB->commandBuffer, pSubCB->commandBuffer, pSubCB->primaryCommandBuffer,
2528-
validation_error_map[VALIDATION_ERROR_31a00092]);
2529-
}
25302521
}
25312522

25322523
skip |= validateCommandBufferState(dev_data, pCB, "vkQueueSubmit()", current_submit_count, VALIDATION_ERROR_31a00090);
@@ -4109,7 +4100,7 @@ VKAPI_ATTR VkResult VKAPI_CALL ResetFences(VkDevice device, uint32_t fenceCount,
41094100
}
41104101

41114102
// For given cb_nodes, invalidate them and track object causing invalidation
4112-
void invalidateCommandBuffers(const layer_data *dev_data, std::unordered_set<GLOBAL_CB_NODE *> const &cb_nodes, VK_OBJECT obj) {
4103+
void invalidateCommandBuffers(const layer_data *dev_data, std::unordered_set<GLOBAL_CB_NODE *> const &cb_nodes, VK_OBJECT obj, bool track_invalidator) {
41134104
for (auto cb_node : cb_nodes) {
41144105
if (cb_node->state == CB_RECORDING) {
41154106
log_msg(dev_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
@@ -4120,11 +4111,13 @@ void invalidateCommandBuffers(const layer_data *dev_data, std::unordered_set<GLO
41204111
else {
41214112
cb_node->state = CB_INVALID_COMPLETE;
41224113
}
4123-
cb_node->broken_bindings.push_back(obj);
4114+
if (track_invalidator) {
4115+
cb_node->broken_bindings.push_back(obj);
4116+
}
41244117

41254118
// if secondary, then propagate the invalidation to the primaries that will call us.
41264119
if (cb_node->createInfo.level == VK_COMMAND_BUFFER_LEVEL_SECONDARY) {
4127-
invalidateCommandBuffers(dev_data, cb_node->linkedCommandBuffers, obj);
4120+
invalidateCommandBuffers(dev_data, cb_node->linkedCommandBuffers, obj, track_invalidator);
41284121
}
41294122
}
41304123
}
@@ -8320,6 +8313,13 @@ VKAPI_ATTR void VKAPI_CALL CmdExecuteCommands(VkCommandBuffer commandBuffer, uin
83208313
pCommandBuffers[i], pCB->commandBuffer);
83218314
pCB->beginInfo.flags &= ~VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
83228315
}
8316+
if (pSubCB->linkedCommandBuffers.size()) {
8317+
// TODO: adjust message support so we can report an accurate error message for this.
8318+
invalidateCommandBuffers(dev_data, pSubCB->linkedCommandBuffers,
8319+
{HandleToUint64(pCommandBuffers[i]), kVulkanObjectTypeCommandBuffer},
8320+
false /* don't track invalidator. we've already complained. */);
8321+
// TODO: consistent strategy for removing links.
8322+
}
83238323
}
83248324
if (!pCB->activeQueries.empty() && !dev_data->enabled_features.inheritedQueries) {
83258325
skip |=
@@ -8336,7 +8336,6 @@ VKAPI_ATTR void VKAPI_CALL CmdExecuteCommands(VkCommandBuffer commandBuffer, uin
83368336
for (auto ilm_entry : pSubCB->imageLayoutMap) {
83378337
SetLayout(dev_data, pCB, ilm_entry.first, ilm_entry.second);
83388338
}
8339-
pSubCB->primaryCommandBuffer = pCB->commandBuffer;
83408339
pCB->linkedCommandBuffers.insert(pSubCB);
83418340
pSubCB->linkedCommandBuffers.insert(pCB);
83428341
for (auto &function : pSubCB->queryUpdates) {

layers/core_validation_types.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,6 @@ struct GLOBAL_CB_NODE : public BASE_NODE {
671671
std::vector<DRAW_DATA> drawData;
672672
DRAW_DATA currentDrawData;
673673
bool vertex_buffer_used; // Track for perf warning to make sure any bound vtx buffer used
674-
VkCommandBuffer primaryCommandBuffer;
675674
// Track images and buffers that are updated by this CB at the point of a draw
676675
std::unordered_set<VkImageView> updateImages;
677676
std::unordered_set<VkBuffer> updateBuffers;
@@ -787,7 +786,6 @@ const PHYS_DEV_PROPERTIES_NODE *GetPhysDevProperties(const layer_data *device_da
787786
const VkPhysicalDeviceFeatures *GetEnabledFeatures(const layer_data *device_data);
788787
const DeviceExtensions *GetEnabledExtensions(const layer_data *device_data);
789788

790-
void invalidateCommandBuffers(const layer_data *, std::unordered_set<GLOBAL_CB_NODE *> const &, VK_OBJECT);
791789
bool ValidateMemoryIsBoundToBuffer(const layer_data *, const BUFFER_STATE *, const char *, UNIQUE_VALIDATION_ERROR_CODE);
792790
bool ValidateMemoryIsBoundToImage(const layer_data *, const IMAGE_STATE *, const char *, UNIQUE_VALIDATION_ERROR_CODE);
793791
void AddCommandBufferBindingSampler(GLOBAL_CB_NODE *, SAMPLER_STATE *);
@@ -796,7 +794,7 @@ void AddCommandBufferBindingImageView(const layer_data *, GLOBAL_CB_NODE *, IMAG
796794
void AddCommandBufferBindingBuffer(const layer_data *, GLOBAL_CB_NODE *, BUFFER_STATE *);
797795
void AddCommandBufferBindingBufferView(const layer_data *, GLOBAL_CB_NODE *, BUFFER_VIEW_STATE *);
798796
bool ValidateObjectNotInUse(const layer_data *dev_data, BASE_NODE *obj_node, VK_OBJECT obj_struct, UNIQUE_VALIDATION_ERROR_CODE error_code);
799-
void invalidateCommandBuffers(const layer_data *dev_data, std::unordered_set<GLOBAL_CB_NODE *> const &cb_nodes, VK_OBJECT obj);
797+
void invalidateCommandBuffers(const layer_data *dev_data, std::unordered_set<GLOBAL_CB_NODE *> const &cb_nodes, VK_OBJECT obj, bool track_invalidator=true);
800798
void RemoveImageMemoryRange(uint64_t handle, DEVICE_MEM_INFO *mem_info);
801799
void RemoveBufferMemoryRange(uint64_t handle, DEVICE_MEM_INFO *mem_info);
802800
bool ClearMemoryObjectBindings(layer_data *dev_data, uint64_t handle, VulkanObjectType type);

0 commit comments

Comments
 (0)