layers: threading with cmd buffer handle reuse
A driver may reuse a command buffer handle in another thread.
The threading layer needs to remove command buffer information
before calling FreeCommandBuffers.
This addresses part of github issue #719.
diff --git a/layers/threading.cpp b/layers/threading.cpp
index ed7663a..2228d90 100644
--- a/layers/threading.cpp
+++ b/layers/threading.cpp
@@ -374,17 +374,19 @@
for (uint32_t index = 0; index < commandBufferCount; index++) {
startWriteObject(my_data, pCommandBuffers[index], lockCommandPool);
}
+ // The driver may immediately reuse command buffers in another thread.
+ // These updates need to be done before calling down to the driver.
+ for (uint32_t index = 0; index < commandBufferCount; index++) {
+ finishWriteObject(my_data, pCommandBuffers[index], lockCommandPool);
+ std::lock_guard<std::mutex> lock(command_pool_lock);
+ command_pool_map.erase(pCommandBuffers[index]);
+ }
}
pTable->FreeCommandBuffers(device, commandPool, commandBufferCount, pCommandBuffers);
if (threadChecks) {
finishReadObject(my_data, device);
finishWriteObject(my_data, commandPool);
- for (uint32_t index = 0; index < commandBufferCount; index++) {
- finishWriteObject(my_data, pCommandBuffers[index], lockCommandPool);
- std::lock_guard<std::mutex> lock(command_pool_lock);
- command_pool_map.erase(pCommandBuffers[index]);
- }
} else {
finishMultiThread();
}