From d975e91286da24af56770b1b6734edc0bcab6ece Mon Sep 17 00:00:00 2001 From: Tobin Ehlis Date: Tue, 21 Jun 2016 12:34:33 -0600 Subject: 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 --- layers/descriptor_sets.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'layers/descriptor_sets.cpp') diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp index 9f3b239d..1f72d447 100644 --- a/layers/descriptor_sets.cpp +++ b/layers/descriptor_sets.cpp @@ -131,6 +131,7 @@ uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(co 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 @@ uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(cons 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 @@ bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::unordered_set< const std::vector &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 @@ uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::unordered_ std::unordered_set *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) { -- cgit v1.2.3