layers: GH616 Improve descriptor set invalid binding handling
Prior to calls to get an global index from a binding, make sure that
HasBinding() is called to verify that the binding exists.
Added HasBinding() calls to a couple of validation functions for
early exist.
Updated code comment to indicate that HasBinding() call should
precede GetGlobal*IndexFromBinding() calls.
Added assert() to GetGlobal*IndexFromBinding() calls in the error case
to make error more obvious in debug builds.
Note that Perform*Update() functions already indicate that they should
be preceded by their matching Validate*Update() functions, which include
the appropriate checks for HasBinding().
case the Validate*Update() funciont
diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp
index 9f3b239..1f72d44 100644
--- a/layers/descriptor_sets.cpp
+++ b/layers/descriptor_sets.cpp
@@ -131,6 +131,7 @@
return btgsi_itr->second;
}
// In error case max uint32_t so index is out of bounds to break ASAP
+ assert(0);
return 0xFFFFFFFF;
}
// For the given binding, return end index
@@ -141,6 +142,7 @@
return btgei_itr->second;
}
// In error case max uint32_t so index is out of bounds to break ASAP
+ assert(0);
return 0xFFFFFFFF;
}
// For given binding, return ptr to ImmutableSampler array
@@ -337,6 +339,13 @@
const std::vector<uint32_t> &dynamic_offsets, std::string *error) const {
auto dyn_offset_index = 0;
for (auto binding : bindings) {
+ if (!p_layout_->HasBinding(binding)) {
+ std::stringstream error_str;
+ error_str << "Attempting to validate DrawState for binding #" << binding
+ << " which is an invalid binding for this descriptor set.";
+ *error = error_str.str();
+ return false;
+ }
auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
if (descriptors_[start_idx]->IsImmutableSampler()) {
// Nothing to do for strictly immutable sampler
@@ -413,6 +422,10 @@
std::unordered_set<VkImageView> *image_set) const {
auto num_updates = 0;
for (auto binding : bindings) {
+ // If a binding doesn't exist, skip it
+ if (!p_layout_->HasBinding(binding)) {
+ continue;
+ }
auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
if (descriptors_[start_idx]->IsStorage()) {
if (Image == descriptors_[start_idx]->descriptor_class) {