Jeremy Gebben | b6c1813 | 2021-03-17 17:00:20 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2019-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2019-2021 Valve Corporation |
| 3 | * Copyright (c) 2019-2021 LunarG, Inc. |
| 4 | * Copyright (C) 2019-2021 Google Inc. |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * John Zulauf <jzulauf@lunarg.com> |
| 19 | * |
| 20 | */ |
John Zulauf | 5823c62 | 2019-11-25 13:33:44 -0700 | [diff] [blame] | 21 | #ifdef SPARSE_CONTAINER_UNIT_TEST |
| 22 | #include "image_layout_map.h" |
| 23 | #else |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 24 | #include "core_validation_types.h" |
| 25 | #include "chassis.h" |
| 26 | #include "descriptor_sets.h" |
John Zulauf | 5823c62 | 2019-11-25 13:33:44 -0700 | [diff] [blame] | 27 | #endif |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 28 | |
| 29 | namespace image_layout_map { |
| 30 | // Storage for the static state |
| 31 | const ImageSubresourceLayoutMap::ConstIterator ImageSubresourceLayoutMap::end_iterator = ImageSubresourceLayoutMap::ConstIterator(); |
| 32 | |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 33 | using InitialLayoutStates = ImageSubresourceLayoutMap::InitialLayoutStates; |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 34 | using LayoutEntry = ImageSubresourceLayoutMap::LayoutEntry; |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 35 | |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 36 | template <typename LayoutsMap> |
| 37 | static bool UpdateLayoutStateImpl(LayoutsMap& layouts, InitialLayoutStates& initial_layout_states, const IndexRange& range, |
| 38 | LayoutEntry& new_entry, const CMD_BUFFER_STATE& cb_state, const IMAGE_VIEW_STATE* view_state) { |
| 39 | using CachedLowerBound = typename sparse_container::cached_lower_bound_impl<LayoutsMap>; |
| 40 | CachedLowerBound pos(layouts, range.begin); |
| 41 | if (!range.includes(pos->index)) { |
| 42 | return false; |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 43 | } |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 44 | bool updated_current = false; |
| 45 | while (range.includes(pos->index)) { |
| 46 | if (!pos->valid) { |
| 47 | // Fill in the leading space (or in the case of pos at end the trailing space |
| 48 | const auto start = pos->index; |
| 49 | auto it = pos->lower_bound; |
| 50 | const auto limit = (it != layouts.end()) ? std::min(it->first.begin, range.end) : range.end; |
| 51 | if (new_entry.state == nullptr) { |
| 52 | // Allocate on demand... initial_layout_states_ holds ownership, while |
| 53 | // each subresource has a non-owning copy of the plain pointer. |
| 54 | initial_layout_states.emplace_back(cb_state, view_state); |
| 55 | new_entry.state = &initial_layout_states.back(); |
| 56 | } |
| 57 | layouts.insert(it, std::make_pair(IndexRange(start, limit), new_entry)); |
| 58 | // We inserted before pos->lower_bound, so pos->lower_bound isn't invalid, but the associated index *is* and seek |
| 59 | // will fix this (and move the state to valid) |
| 60 | pos.seek(limit); |
| 61 | updated_current = true; |
| 62 | } |
| 63 | // Note that after the "fill" operation pos may have become valid so we check again |
| 64 | if (pos->valid) { |
| 65 | LayoutEntry& orig_entry = pos->lower_bound->second; |
| 66 | assert(orig_entry.state != nullptr); |
| 67 | updated_current |= orig_entry.Update(new_entry); |
| 68 | // Point just past the end of this section, if it's within the given range, it will get filled next iteration |
| 69 | // ++pos could move us past the end of range (which would exit the loop) so we don't use it. |
| 70 | pos.seek(pos->lower_bound->first.end); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | return updated_current; |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 75 | } |
| 76 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 77 | InitialLayoutState::InitialLayoutState(const CMD_BUFFER_STATE& cb_state_, const IMAGE_VIEW_STATE* view_state_) |
| 78 | : image_view(VK_NULL_HANDLE), aspect_mask(0), label(cb_state_.debug_label) { |
| 79 | if (view_state_) { |
| 80 | image_view = view_state_->image_view; |
| 81 | aspect_mask = view_state_->create_info.subresourceRange.aspectMask; |
| 82 | } |
| 83 | } |
| 84 | bool ImageSubresourceLayoutMap::SubresourceLayout::operator==(const ImageSubresourceLayoutMap::SubresourceLayout& rhs) const { |
| 85 | bool is_equal = |
| 86 | (current_layout == rhs.current_layout) && (initial_layout == rhs.initial_layout) && (subresource == rhs.subresource); |
| 87 | return is_equal; |
| 88 | } |
| 89 | ImageSubresourceLayoutMap::ImageSubresourceLayoutMap(const IMAGE_STATE& image_state) |
John Zulauf | b58415b | 2019-12-09 15:02:32 -0700 | [diff] [blame] | 90 | : image_state_(image_state), |
locke-lunarg | 296a3c9 | 2020-03-25 01:04:29 -0600 | [diff] [blame] | 91 | encoder_(image_state.subresource_encoder), |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 92 | layouts_(encoder_.SubresourceCount()), |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 93 | initial_layout_states_() {} |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 94 | |
| 95 | ImageSubresourceLayoutMap::ConstIterator ImageSubresourceLayoutMap::Begin(bool always_get_initial) const { |
| 96 | return Find(image_state_.full_range, /* skip_invalid */ true, always_get_initial); |
| 97 | } |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 98 | |
| 99 | // Use the unwrapped maps from the BothMap in the actual implementation |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 100 | template <typename LayoutMap> |
| 101 | static bool SetSubresourceRangeLayoutImpl(LayoutMap& layouts, InitialLayoutStates& initial_layout_states, RangeGenerator& range_gen, |
| 102 | const CMD_BUFFER_STATE& cb_state, VkImageLayout layout, VkImageLayout expected_layout) { |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 103 | bool updated = false; |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 104 | LayoutEntry entry(expected_layout, layout); |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 105 | for (; range_gen->non_empty(); ++range_gen) { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 106 | updated |= UpdateLayoutStateImpl(layouts, initial_layout_states, *range_gen, entry, cb_state, nullptr); |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 107 | } |
| 108 | return updated; |
| 109 | } |
| 110 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 111 | bool ImageSubresourceLayoutMap::SetSubresourceRangeLayout(const CMD_BUFFER_STATE& cb_state, const VkImageSubresourceRange& range, |
| 112 | VkImageLayout layout, VkImageLayout expected_layout) { |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 113 | if (expected_layout == kInvalidLayout) { |
| 114 | // Set the initial layout to the set layout as we had no other layout to reference |
| 115 | expected_layout = layout; |
| 116 | } |
| 117 | if (!InRange(range)) return false; // Don't even try to track bogus subreources |
| 118 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 119 | RangeGenerator range_gen(encoder_, range); |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 120 | if (layouts_.SmallMode()) { |
| 121 | return SetSubresourceRangeLayoutImpl(layouts_.GetSmallMap(), initial_layout_states_, range_gen, cb_state, layout, |
| 122 | expected_layout); |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 123 | } else { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 124 | assert(!layouts_.Tristate()); |
| 125 | return SetSubresourceRangeLayoutImpl(layouts_.GetBigMap(), initial_layout_states_, range_gen, cb_state, layout, |
| 126 | expected_layout); |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | // Use the unwrapped maps from the BothMap in the actual implementation |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 131 | template <typename LayoutMap> |
| 132 | static void SetSubresourceRangeInitialLayoutImpl(LayoutMap& layouts, InitialLayoutStates& initial_layout_states, |
| 133 | RangeGenerator& range_gen, const CMD_BUFFER_STATE& cb_state, VkImageLayout layout, |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 134 | const IMAGE_VIEW_STATE* view_state) { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 135 | LayoutEntry entry(layout); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 136 | for (; range_gen->non_empty(); ++range_gen) { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 137 | UpdateLayoutStateImpl(layouts, initial_layout_states, *range_gen, entry, cb_state, view_state); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 138 | } |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 139 | } |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 140 | |
| 141 | // Unwrap the BothMaps entry here as this is a performance hotspot. |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 142 | void ImageSubresourceLayoutMap::SetSubresourceRangeInitialLayout(const CMD_BUFFER_STATE& cb_state, |
| 143 | const VkImageSubresourceRange& range, VkImageLayout layout) { |
| 144 | if (!InRange(range)) return; // Don't even try to track bogus subreources |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 145 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 146 | RangeGenerator range_gen(encoder_, range); |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 147 | if (layouts_.SmallMode()) { |
| 148 | SetSubresourceRangeInitialLayoutImpl(layouts_.GetSmallMap(), initial_layout_states_, range_gen, cb_state, layout, nullptr); |
John Zulauf | 81408f1 | 2019-11-27 16:40:27 -0700 | [diff] [blame] | 149 | } else { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 150 | assert(!layouts_.Tristate()); |
| 151 | SetSubresourceRangeInitialLayoutImpl(layouts_.GetBigMap(), initial_layout_states_, range_gen, cb_state, layout, nullptr); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 152 | } |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
John Zulauf | b58415b | 2019-12-09 15:02:32 -0700 | [diff] [blame] | 155 | // Unwrap the BothMaps entry here as this is a performance hotspot. |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 156 | void ImageSubresourceLayoutMap::SetSubresourceRangeInitialLayout(const CMD_BUFFER_STATE& cb_state, VkImageLayout layout, |
John Zulauf | b58415b | 2019-12-09 15:02:32 -0700 | [diff] [blame] | 157 | const IMAGE_VIEW_STATE& view_state) { |
| 158 | RangeGenerator range_gen(view_state.range_generator); |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 159 | if (layouts_.SmallMode()) { |
| 160 | SetSubresourceRangeInitialLayoutImpl(layouts_.GetSmallMap(), initial_layout_states_, range_gen, cb_state, layout, |
| 161 | &view_state); |
John Zulauf | b58415b | 2019-12-09 15:02:32 -0700 | [diff] [blame] | 162 | } else { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 163 | assert(!layouts_.Tristate()); |
| 164 | SetSubresourceRangeInitialLayoutImpl(layouts_.GetBigMap(), initial_layout_states_, range_gen, cb_state, layout, |
| 165 | &view_state); |
John Zulauf | b58415b | 2019-12-09 15:02:32 -0700 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 169 | // Saves an encode to fetch both in the same call |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 170 | const ImageSubresourceLayoutMap::LayoutEntry* ImageSubresourceLayoutMap::GetSubresourceLayouts( |
| 171 | const VkImageSubresource& subresource) const { |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 172 | IndexType index = encoder_.Encode(subresource); |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 173 | auto found = layouts_.find(index); |
| 174 | if (found != layouts_.end()) { |
| 175 | return &found->second; |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 176 | } |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 177 | return nullptr; |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
John Zulauf | 2076e81 | 2020-01-08 14:55:54 -0700 | [diff] [blame] | 180 | const InitialLayoutState* ImageSubresourceLayoutMap::GetSubresourceInitialLayoutState(const IndexType index) const { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 181 | const auto found = layouts_.find(index); |
| 182 | if (found != layouts_.end()) { |
| 183 | return found->second.state; |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 184 | } |
| 185 | return nullptr; |
| 186 | } |
| 187 | |
John Zulauf | 2076e81 | 2020-01-08 14:55:54 -0700 | [diff] [blame] | 188 | const InitialLayoutState* ImageSubresourceLayoutMap::GetSubresourceInitialLayoutState(const VkImageSubresource& subresource) const { |
| 189 | if (!InRange(subresource)) return nullptr; |
| 190 | const auto index = encoder_.Encode(subresource); |
| 191 | return GetSubresourceInitialLayoutState(index); |
| 192 | } |
| 193 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 194 | // TODO: make sure this paranoia check is sufficient and not too much. |
| 195 | uintptr_t ImageSubresourceLayoutMap::CompatibilityKey() const { |
Mike Schuchardt | e5c15cf | 2020-04-06 22:57:13 -0700 | [diff] [blame] | 196 | return (reinterpret_cast<uintptr_t>(&image_state_) ^ encoder_.AspectMask()); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | bool ImageSubresourceLayoutMap::UpdateFrom(const ImageSubresourceLayoutMap& other) { |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 200 | // Must be from matching images for the reinterpret cast to be valid |
| 201 | assert(CompatibilityKey() == other.CompatibilityKey()); |
| 202 | if (CompatibilityKey() != other.CompatibilityKey()) return false; |
| 203 | |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 204 | // NOTE -- we are copying plain state pointers from 'other' which owns them in a vector. This works because |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 205 | // currently this function is only used to import from secondary command buffers, destruction of which |
| 206 | // invalidate the referencing primary command buffer, meaning that the dangling pointer will either be |
| 207 | // cleaned up in invalidation, on not referenced by validation code. |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 208 | return sparse_container::splice(layouts_, other.layouts_, LayoutEntry::Updater()); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 209 | } |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 210 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 211 | // This is the same constant value range, subreource position advance logic as ForRange above, but suitable for use with |
| 212 | // an Increment operator. |
| 213 | void ImageSubresourceLayoutMap::ConstIterator::UpdateRangeAndValue() { |
| 214 | bool not_found = true; |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 215 | if (layouts_ == nullptr || layouts_->empty()) { |
| 216 | return; |
| 217 | } |
| 218 | while (iter_ != layouts_->end() && range_gen_->non_empty() && not_found) { |
| 219 | if (!iter_->first.includes(current_index_)) { // NOTE: empty ranges can't include anything |
| 220 | iter_ = layouts_->find(current_index_); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 221 | } |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 222 | if (iter_ == layouts_->end() || (iter_->first.empty() && skip_invalid_)) { |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 223 | // We're past the end of mapped data, and we aren't interested, so we're done |
| 224 | // Set end condtion.... |
| 225 | ForceEndCondition(); |
| 226 | } |
| 227 | // Search within the current range_ for a constant valid constant value interval |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 228 | // The while condition allows the iterator to advance constant value ranges as needed. |
| 229 | while (iter_ != layouts_->end() && range_gen_->includes(current_index_) && not_found) { |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 230 | pos_.current_layout = kInvalidLayout; |
| 231 | pos_.initial_layout = kInvalidLayout; |
| 232 | constant_value_bound_ = range_gen_->end; |
| 233 | // The generated range can validly traverse past the end of stored data |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 234 | if (!iter_->first.empty()) { |
| 235 | const LayoutEntry& entry = iter_->second; |
| 236 | pos_.current_layout = entry.current_layout; |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 237 | if (pos_.current_layout == kInvalidLayout || always_get_initial_) { |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 238 | pos_.initial_layout = entry.initial_layout; |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 239 | } |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 240 | |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 241 | // The constant value bound marks the end of contiguous (w.r.t. range_gen_) indices with the same value, allowing |
| 242 | // Increment (for example) to forgo this logic until finding a new range is needed. |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 243 | constant_value_bound_ = std::min(iter_->first.end, constant_value_bound_); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 244 | } |
| 245 | if (!skip_invalid_ || (pos_.current_layout != kInvalidLayout) || (pos_.initial_layout != kInvalidLayout)) { |
| 246 | // we found it ... set the position and exit condition. |
John Zulauf | 2ea823e | 2019-11-19 08:54:59 -0700 | [diff] [blame] | 247 | pos_.subresource = range_gen_.GetSubresource(); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 248 | not_found = false; |
| 249 | } else { |
| 250 | // We're skipping this constant value range, set the index to the exclusive end and look again |
John Zulauf | dd18b3a | 2019-11-20 08:30:23 -0700 | [diff] [blame] | 251 | // Note that we ONLY need to Seek the Subresource generator on a skip condition. |
| 252 | range_gen_.GetSubresourceGenerator().Seek( |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 253 | constant_value_bound_); // Move the subresource to the end of the skipped range |
| 254 | current_index_ = constant_value_bound_; |
| 255 | |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 256 | // Advance the iterator it if needed and possible |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 257 | // NOTE: We don't need to seek, as current_index_ can only be in the current or next constant value range |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 258 | if (!iter_->first.empty() && !iter_->first.includes(current_index_)) { |
| 259 | ++iter_; |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | if (not_found) { |
| 265 | // ++range_gen will update subres_gen. |
| 266 | ++range_gen_; |
| 267 | current_index_ = range_gen_->begin; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | if (range_gen_->empty()) { |
| 272 | ForceEndCondition(); |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | void ImageSubresourceLayoutMap::ConstIterator::Increment() { |
| 277 | ++current_index_; |
John Zulauf | 2ea823e | 2019-11-19 08:54:59 -0700 | [diff] [blame] | 278 | ++(range_gen_.GetSubresourceGenerator()); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 279 | if (constant_value_bound_ <= current_index_) { |
| 280 | UpdateRangeAndValue(); |
| 281 | } else { |
John Zulauf | 2ea823e | 2019-11-19 08:54:59 -0700 | [diff] [blame] | 282 | pos_.subresource = range_gen_.GetSubresource(); |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
Tony Barbour | 5568817 | 2020-09-23 15:19:50 -0700 | [diff] [blame] | 285 | |
| 286 | void ImageSubresourceLayoutMap::ConstIterator::IncrementInterval() { |
| 287 | // constant_value_bound_ is the exclusive upper bound of the constant value range. |
| 288 | // When current index is set to point to that, UpdateRangeAndValue skips to the next constant value range, |
| 289 | // setting that state as the current position / state for the iterator. |
| 290 | current_index_ = constant_value_bound_; |
| 291 | UpdateRangeAndValue(); |
| 292 | } |
| 293 | |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 294 | ImageSubresourceLayoutMap::ConstIterator::ConstIterator(const RangeMap& layouts, const Encoder& encoder, |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 295 | const VkImageSubresourceRange& subres, bool skip_invalid, |
| 296 | bool always_get_initial) |
| 297 | : range_gen_(encoder, subres), |
Jeremy Gebben | 5363130 | 2021-04-13 16:46:37 -0600 | [diff] [blame^] | 298 | layouts_(&layouts), |
| 299 | iter_(layouts.begin()), |
John Zulauf | 1121140 | 2019-11-15 14:02:36 -0700 | [diff] [blame] | 300 | skip_invalid_(skip_invalid), |
| 301 | always_get_initial_(always_get_initial), |
| 302 | pos_(), |
| 303 | current_index_(range_gen_->begin), |
| 304 | constant_value_bound_() { |
| 305 | UpdateRangeAndValue(); |
| 306 | } |
| 307 | |
| 308 | } // namespace image_layout_map |