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