diff options
| author | Tobin Ehlis <tobine@google.com> | 2016-06-21 12:34:33 -0600 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-06-27 14:26:55 -0600 |
| commit | d975e91286da24af56770b1b6734edc0bcab6ece (patch) | |
| tree | b0e6608a5af3d8c3e503a508d38b9c537484a9f7 /layers/descriptor_sets.cpp | |
| parent | 294ebb116165dc57fcfc712009b872267fd3ad98 (diff) | |
| download | usermoji-d975e91286da24af56770b1b6734edc0bcab6ece.tar.xz | |
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
Diffstat (limited to 'layers/descriptor_sets.cpp')
| -rw-r--r-- | layers/descriptor_sets.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
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<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 @@ uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::unordered_ 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) { |
