layers: Refactor DescriptorSet Update code
This migrates code for DescriptorSet in_use and flagging bound
command buffers as invalid from core_validation.cpp into DescriptorSet
class.
diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp
index 89c44c6..437dcdc 100644
--- a/layers/descriptor_sets.cpp
+++ b/layers/descriptor_sets.cpp
@@ -260,6 +260,7 @@
}
cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const DescriptorSetLayout *layout,
+ const debug_report_data *debug_report_data,
const std::unordered_map<VkBuffer, BUFFER_NODE> *buffer_map,
const std::unordered_map<VkDeviceMemory, DEVICE_MEM_INFO> *memory_map,
const std::unordered_map<VkBufferView, VkBufferViewCreateInfo> *buffer_view_map,
@@ -268,9 +269,9 @@
const std::unordered_map<VkImage, IMAGE_NODE> *image_map,
const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map)
- : some_update_(false), set_(set), p_layout_(layout), buffer_map_(buffer_map), memory_map_(memory_map),
- buffer_view_map_(buffer_view_map), sampler_map_(sampler_map), image_view_map_(image_view_map), image_map_(image_map),
- image_to_swapchain_map_(image_to_swapchain_map), swapchain_map_(swapchain_map) {
+ : some_update_(false), set_(set), p_layout_(layout), report_data_(debug_report_data), buffer_map_(buffer_map),
+ memory_map_(memory_map), buffer_view_map_(buffer_view_map), sampler_map_(sampler_map), image_view_map_(image_view_map),
+ image_map_(image_map), image_to_swapchain_map_(image_to_swapchain_map), swapchain_map_(swapchain_map) {
// Foreach binding, create default descriptors of given type
for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
auto type = p_layout_->GetTypeFromIndex(i);
@@ -456,6 +457,14 @@
bool cvdescriptorset::DescriptorSet::WriteUpdate(debug_report_data *report_data, const VkWriteDescriptorSet *update,
std::string *error_msg) {
auto num_updates = 0;
+ // Verify idle ds
+ if (in_use.load()) {
+ std::stringstream error_str;
+ error_str << "Cannot call vkUpdateDescriptorSets() to perform write update on descriptor set " << set_
+ << " that is in use by a command buffer.";
+ *error_msg = error_str.str();
+ return false;
+ }
// Verify dst binding exists
if (!p_layout_->HasBinding(update->dstBinding)) {
std::stringstream error_str;
@@ -505,12 +514,24 @@
if (num_updates != 0) {
some_update_ = true;
}
+ // Invalidate any bound command buffers
+ for (auto cb_node : bound_cmd_buffers_) {
+ cb_node->state = CB_INVALID;
+ }
return true;
}
// Copy update
bool cvdescriptorset::DescriptorSet::CopyUpdate(debug_report_data *report_data, const VkCopyDescriptorSet *update,
const DescriptorSet *src_set, std::string *error) {
auto num_updates = 0;
+ // Verify idle ds
+ if (in_use.load()) {
+ std::stringstream error_str;
+ error_str << "Cannot call vkUpdateDescriptorSets() to perform copy update on descriptor set " << set_
+ << " that is in use by a command buffer.";
+ *error = error_str.str();
+ return false;
+ }
if (!p_layout_->HasBinding(update->dstBinding)) {
std::stringstream error_str;
error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << ".";
@@ -574,6 +595,10 @@
if (num_updates != 0) {
some_update_ = true;
}
+ // Invalidate any bound command buffers
+ for (auto cb_node : bound_cmd_buffers_) {
+ cb_node->state = CB_INVALID;
+ }
return true;
}
cvdescriptorset::SamplerDescriptor::SamplerDescriptor(
@@ -974,4 +999,4 @@
updated = true;
buffer_view_ = buffer_view;
return true;
-}
\ No newline at end of file
+}