blob: dc2d03bcc5ee5ae930d5f406ee845c743684d7be [file] [log] [blame]
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06001/* Copyright (c) 2015-2016 The Khronos Group Inc.
2 * Copyright (c) 2015-2016 Valve Corporation
3 * Copyright (c) 2015-2016 LunarG, Inc.
4 * Copyright (C) 2015-2016 Google Inc.
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 * Author: Tobin Ehlis <tobine@google.com>
19 */
20
21#include "descriptor_sets.h"
22#include "vk_enum_string_helper.h"
23#include "vk_safe_struct.h"
24#include <sstream>
25
26// Construct DescriptorSetLayout instance from given create info
27cvdescriptorset::DescriptorSetLayout::DescriptorSetLayout(debug_report_data *report_data,
28 const VkDescriptorSetLayoutCreateInfo *p_create_info,
29 const VkDescriptorSetLayout layout)
30 : layout_(layout), binding_count_(p_create_info->bindingCount), descriptor_count_(0), dynamic_descriptor_count_(0) {
31 uint32_t global_index = 0;
32 for (uint32_t i = 0; i < binding_count_; ++i) {
33 descriptor_count_ += p_create_info->pBindings[i].descriptorCount;
34 if (!binding_to_index_map_.emplace(p_create_info->pBindings[i].binding, i).second) {
35 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT_EXT,
36 reinterpret_cast<uint64_t &>(layout_), __LINE__, DRAWSTATE_INVALID_LAYOUT, "DS",
37 "duplicated binding number in "
38 "VkDescriptorSetLayoutBinding");
39 }
40 binding_to_global_start_index_map_[p_create_info->pBindings[i].binding] = global_index;
41 global_index += p_create_info->pBindings[i].descriptorCount ? p_create_info->pBindings[i].descriptorCount - 1 : 0;
42 binding_to_global_end_index_map_[p_create_info->pBindings[i].binding] = global_index;
43 global_index++;
44 bindings_.push_back(new safe_VkDescriptorSetLayoutBinding(&p_create_info->pBindings[i]));
45 // In cases where we should ignore pImmutableSamplers make sure it's NULL
46 if ((p_create_info->pBindings[i].pImmutableSamplers) &&
47 ((p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) &&
48 (p_create_info->pBindings[i].descriptorType != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER))) {
49 bindings_.back()->pImmutableSamplers = nullptr;
50 }
51 if (p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC ||
52 p_create_info->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC) {
53 dynamic_descriptor_count_++;
54 }
55 }
56}
57cvdescriptorset::DescriptorSetLayout::~DescriptorSetLayout() {
58 for (auto binding : bindings_)
59 delete binding;
60}
61// put all bindings into the given set
62void cvdescriptorset::DescriptorSetLayout::FillBindingSet(std::unordered_set<uint32_t> *binding_set) const {
63 for (auto binding_index_pair : binding_to_index_map_)
64 binding_set->insert(binding_index_pair.first);
65}
66VkDescriptorSetLayoutBinding const *
67cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromBinding(const uint32_t binding) const {
68 if (!binding_to_index_map_.count(binding))
69 return nullptr;
70 return bindings_.at(binding_to_index_map_.at(binding))->ptr();
71}
72VkDescriptorSetLayoutBinding const *
73cvdescriptorset::DescriptorSetLayout::GetDescriptorSetLayoutBindingPtrFromIndex(const uint32_t index) const {
74 if (index >= bindings_.size())
75 return nullptr;
76 return bindings_[index]->ptr();
77}
78// Return descriptorCount for given binding, 0 if index is unavailable
79uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromBinding(const uint32_t binding) const {
80 if (!binding_to_index_map_.count(binding))
81 return 0;
82 return bindings_.at(binding_to_index_map_.at(binding))->descriptorCount;
83}
84// Return descriptorCount for given index, 0 if index is unavailable
85uint32_t cvdescriptorset::DescriptorSetLayout::GetDescriptorCountFromIndex(const uint32_t index) const {
86 if (index >= bindings_.size())
87 return 0;
88 return bindings_[index]->descriptorCount;
89}
90// For the given binding, return descriptorType
91VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromBinding(const uint32_t binding) const {
92 assert(binding_to_index_map_.count(binding));
93 return bindings_.at(binding_to_index_map_.at(binding))->descriptorType;
94}
95// For the given index, return descriptorType
96VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromIndex(const uint32_t index) const {
97 assert(index < bindings_.size());
98 return bindings_[index]->descriptorType;
99}
100// For the given global index, return descriptorType
101// Currently just counting up through bindings_, may improve this in future
102VkDescriptorType cvdescriptorset::DescriptorSetLayout::GetTypeFromGlobalIndex(const uint32_t index) const {
103 uint32_t global_offset = 0;
104 for (auto binding : bindings_) {
105 global_offset += binding->descriptorCount;
106 if (index < global_offset)
107 return binding->descriptorType;
108 }
109 assert(0); // requested global index is out of bounds
110 return VK_DESCRIPTOR_TYPE_MAX_ENUM;
111}
112// For the given binding, return stageFlags
113VkShaderStageFlags cvdescriptorset::DescriptorSetLayout::GetStageFlagsFromBinding(const uint32_t binding) const {
114 assert(binding_to_index_map_.count(binding));
115 return bindings_.at(binding_to_index_map_.at(binding))->stageFlags;
116}
117// For the given binding, return start index
118uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalStartIndexFromBinding(const uint32_t binding) const {
119 assert(binding_to_global_start_index_map_.count(binding));
120 return binding_to_global_start_index_map_.at(binding);
121}
122// For the given binding, return end index
123uint32_t cvdescriptorset::DescriptorSetLayout::GetGlobalEndIndexFromBinding(const uint32_t binding) const {
124 assert(binding_to_global_end_index_map_.count(binding));
125 return binding_to_global_end_index_map_.at(binding);
126}
127// For given binding, return ptr to ImmutableSampler array
128VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromBinding(const uint32_t binding) const {
129 assert(binding_to_index_map_.count(binding));
130 return bindings_.at(binding_to_index_map_.at(binding))->pImmutableSamplers;
131}
132// For given index, return ptr to ImmutableSampler array
133VkSampler const *cvdescriptorset::DescriptorSetLayout::GetImmutableSamplerPtrFromIndex(const uint32_t index) const {
134 assert(index < bindings_.size());
135 return bindings_[index]->pImmutableSamplers;
136}
137// If our layout is compatible with rh_ds_layout, return true,
138// else return false and fill in error_msg will description of what causes incompatibility
139bool cvdescriptorset::DescriptorSetLayout::IsCompatible(const DescriptorSetLayout *rh_ds_layout, std::string *error_msg) const {
140 // Trivial case
141 if (layout_ == rh_ds_layout->GetDescriptorSetLayout())
142 return true;
143 if (descriptor_count_ != rh_ds_layout->descriptor_count_) {
144 std::stringstream error_str;
145 error_str << "DescriptorSetLayout " << layout_ << " has " << descriptor_count_ << " descriptors, but DescriptorSetLayout "
146 << rh_ds_layout->GetDescriptorSetLayout() << " has " << rh_ds_layout->descriptor_count_ << " descriptors.";
147 *error_msg = error_str.str();
148 return false; // trivial fail case
149 }
150 // Descriptor counts match so need to go through bindings one-by-one
151 // and verify that type and stageFlags match
152 for (auto binding : bindings_) {
153 // TODO : Do we also need to check immutable samplers?
154 // VkDescriptorSetLayoutBinding *rh_binding;
155 // rh_ds_layout->FillDescriptorSetLayoutBindingStructFromBinding(binding->binding, rh_binding);
156 if (binding->descriptorCount != rh_ds_layout->GetDescriptorCountFromBinding(binding->binding)) {
157 std::stringstream error_str;
158 error_str << "Binding " << binding->binding << " for DescriptorSetLayout " << layout_ << " has a descriptorCount of "
159 << binding->descriptorCount << " but binding " << binding->binding << " for DescriptorSetLayout "
160 << rh_ds_layout->GetDescriptorSetLayout() << " has a descriptorCount of "
161 << rh_ds_layout->GetDescriptorCountFromBinding(binding->binding);
162 *error_msg = error_str.str();
163 return false;
164 } else if (binding->descriptorType != rh_ds_layout->GetTypeFromBinding(binding->binding)) {
165 std::stringstream error_str;
166 error_str << "Binding " << binding->binding << " for DescriptorSetLayout " << layout_ << " is type '"
167 << string_VkDescriptorType(binding->descriptorType) << "' but binding " << binding->binding
168 << " for DescriptorSetLayout " << rh_ds_layout->GetDescriptorSetLayout() << " is type '"
169 << string_VkDescriptorType(rh_ds_layout->GetTypeFromBinding(binding->binding)) << "'";
170 *error_msg = error_str.str();
171 return false;
172 } else if (binding->stageFlags != rh_ds_layout->GetStageFlagsFromBinding(binding->binding)) {
173 std::stringstream error_str;
174 error_str << "Binding " << binding->binding << " for DescriptorSetLayout " << layout_ << " has stageFlags "
175 << binding->stageFlags << " but binding " << binding->binding << " for DescriptorSetLayout "
176 << rh_ds_layout->GetDescriptorSetLayout() << " has stageFlags "
177 << rh_ds_layout->GetStageFlagsFromBinding(binding->binding);
178 *error_msg = error_str.str();
179 return false;
180 }
181 }
182 return true;
183}
184
185bool cvdescriptorset::DescriptorSetLayout::IsNextBindingConsistent(const uint32_t binding) const {
186 if (!binding_to_index_map_.count(binding + 1))
187 return false;
188 auto type = bindings_.at(binding_to_index_map_.at(binding))->descriptorType;
189 auto stage_flags = bindings_.at(binding_to_index_map_.at(binding))->stageFlags;
190 auto immut_samp = bindings_.at(binding_to_index_map_.at(binding))->pImmutableSamplers ? true : false;
191 if ((type != bindings_.at(binding_to_index_map_.at(binding + 1))->descriptorType) ||
192 (stage_flags != bindings_.at(binding_to_index_map_.at(binding + 1))->stageFlags) ||
193 (immut_samp != (bindings_.at(binding_to_index_map_.at(binding + 1))->pImmutableSamplers ? true : false))) {
194 return false;
195 }
196 return true;
197}
198
199cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const DescriptorSetLayout *layout,
200 const std::unordered_map<VkBuffer, BUFFER_NODE> *buffer_map,
201 const std::unordered_map<VkDeviceMemory, DEVICE_MEM_INFO> *memory_map,
202 const std::unordered_map<VkBufferView, VkBufferViewCreateInfo> *buffer_view_map,
203 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map,
204 const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map,
205 const std::unordered_map<VkImage, IMAGE_NODE> *image_map,
206 const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
207 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map)
208 : some_update_(false), full_update_(false), set_(set), p_layout_(layout), buffer_map_(buffer_map), memory_map_(memory_map),
209 buffer_view_map_(buffer_view_map), sampler_map_(sampler_map), image_view_map_(image_view_map), image_map_(image_map),
210 image_to_swapchain_map_(image_to_swapchain_map), swapchain_map_(swapchain_map) {
211 // Foreach binding, create default descriptors of given type
212 for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
213 auto type = p_layout_->GetTypeFromIndex(i);
214 switch (type) {
215 case VK_DESCRIPTOR_TYPE_SAMPLER: {
216 auto immut_sampler = p_layout_->GetImmutableSamplerPtrFromIndex(i);
217 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
218 if (immut_sampler)
219 descriptors_.push_back(std::unique_ptr<Descriptor>(new SamplerDescriptor(immut_sampler + di, sampler_map_)));
220 else
221 descriptors_.push_back(std::unique_ptr<Descriptor>(new SamplerDescriptor(sampler_map_)));
222 }
223 break;
224 }
225 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: {
226 auto immut = p_layout_->GetImmutableSamplerPtrFromIndex(i);
227 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di) {
228 if (immut)
229 descriptors_.push_back(std::unique_ptr<Descriptor>(new ImageSamplerDescriptor(
230 immut + di, image_view_map_, image_map_, image_to_swapchain_map_, swapchain_map_, sampler_map_)));
231 else
232 descriptors_.push_back(std::unique_ptr<Descriptor>(new ImageSamplerDescriptor(
233 image_view_map_, image_map_, image_to_swapchain_map_, swapchain_map_, sampler_map_)));
234 }
235 break;
236 }
237 // ImageDescriptors
238 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
239 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
240 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
241 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
242 descriptors_.push_back(std::unique_ptr<Descriptor>(
243 new ImageDescriptor(type, image_view_map_, image_map_, image_to_swapchain_map_, swapchain_map_)));
244 break;
245 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
246 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
247 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
248 descriptors_.push_back(std::unique_ptr<Descriptor>(new TexelDescriptor(type, buffer_view_map_)));
249 break;
250 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
251 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
252 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
253 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
254 for (uint32_t di = 0; di < p_layout_->GetDescriptorCountFromIndex(i); ++di)
255 descriptors_.push_back(std::unique_ptr<Descriptor>(new BufferDescriptor(type, buffer_map_)));
256 break;
257 default:
258 break;
259 }
260 }
261}
262// For given global_index return bool of whether or not the underlying descriptor has been updated
263bool cvdescriptorset::DescriptorSet::IsUpdated(const uint32_t global_index) const {
264 if (global_index >= descriptors_.size() || !descriptors_.at(global_index))
265 return false;
266 return descriptors_.at(global_index)->updated;
267}
268// Is this sets underlying layout compatible with passed in layout according to "Pipeline Layout Compatibility" in spec?
269bool cvdescriptorset::DescriptorSet::IsCompatible(const DescriptorSetLayout *layout, std::string *error) const {
270 return layout->IsCompatible(p_layout_, error);
271}
272// Validate that the state of this set is appropriate for the given bindings and dynami_offsets at Draw time
273// This includes validating that all descriptors in the given bindings are updated,
274// that any update buffers are valid, and that any dynamic offsets are within the bounds of their buffers.
275// Return true if state is acceptable, or false and write an error message into error string
276bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::unordered_set<uint32_t> &bindings,
277 const std::vector<uint32_t> &dynamic_offsets, std::string *error) const {
278 for (auto binding : bindings) {
279 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
280 if (descriptors_.at(start_idx)->IsImmutableSampler()) {
281 // Nothing to do for strictly immutable sampler
282 } else {
283 auto end_idx = p_layout_->GetGlobalEndIndexFromBinding(binding);
284 auto dyn_offset_index = 0;
285 for (uint32_t i = start_idx; i <= end_idx; ++i) {
286 if (!descriptors_.at(i)->updated) {
287 std::stringstream error_str;
288 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
289 << " is being used in draw but has not been updated.";
290 *error = error_str.str();
291 return false;
292 } else {
293 if (GeneralBuffer == descriptors_.at(i)->GetClass()) {
294 // Verify that buffers are valid
295 auto buffer = static_cast<BufferDescriptor *>(descriptors_.at(i).get())->GetBuffer();
296 auto buffer_node = buffer_map_->find(buffer);
297 if (buffer_node == buffer_map_->end()) {
298 std::stringstream error_str;
299 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
300 << " references invalid buffer " << buffer << ".";
301 *error = error_str.str();
302 return false;
303 } else {
304 auto mem_entry = memory_map_->find(buffer_node->second.mem);
305 if (mem_entry == memory_map_->end()) {
306 std::stringstream error_str;
307 error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
308 << " uses buffer " << buffer << " that references invalid memory "
309 << buffer_node->second.mem << ".";
310 *error = error_str.str();
311 return false;
312 }
313 }
314 if (descriptors_.at(i)->IsDynamic()) {
315 // Validate that dynamic offsets are within the buffer
316 auto buffer_size = buffer_node->second.createInfo.size;
317 auto range = static_cast<BufferDescriptor *>(descriptors_.at(i).get())->GetRange();
318 auto desc_offset = static_cast<BufferDescriptor *>(descriptors_.at(i).get())->GetOffset();
319 auto dyn_offset = dynamic_offsets[dyn_offset_index++];
320 if (VK_WHOLE_SIZE == range) {
321 if ((dyn_offset + desc_offset) > buffer_size) {
322 std::stringstream error_str;
323 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
324 << " uses buffer " << buffer
325 << " with update range of VK_WHOLE_SIZE has dynamic offset " << dyn_offset
326 << " combined with offset " << desc_offset << " that oversteps the buffer size of "
327 << buffer_size << ".";
328 *error = error_str.str();
329 return false;
330 }
331 } else {
332 if ((dyn_offset + desc_offset + range) > buffer_size) {
333 std::stringstream error_str;
334 error_str << "Dynamic descriptor in binding #" << binding << " at global descriptor index " << i
335 << " uses buffer " << buffer << " with dynamic offset " << dyn_offset
336 << " combined with offset " << desc_offset << " and range " << range
337 << " that oversteps the buffer size of " << buffer_size << ".";
338 *error = error_str.str();
339 return false;
340 }
341 }
342 }
343 }
344 }
345 }
346 }
347 }
348 return true;
349}
350// For given bindings, place any update buffers or images into the passed-in unordered_sets
351uint32_t cvdescriptorset::DescriptorSet::GetStorageUpdates(const std::unordered_set<uint32_t> &bindings,
352 std::unordered_set<VkBuffer> *buffer_set,
353 std::unordered_set<VkImageView> *image_set) const {
354 auto num_updates = 0;
355 for (auto binding : bindings) {
356 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(binding);
357 if (descriptors_.at(start_idx)->IsStorage()) {
358 if (Image == descriptors_.at(start_idx)->descriptor_class) {
359 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
360 if (descriptors_.at(start_idx + i)->updated) {
361 image_set->insert(static_cast<ImageDescriptor *>(descriptors_.at(start_idx + i).get())->GetImageView());
362 num_updates++;
363 }
364 }
365 } else if (TexelBuffer == descriptors_.at(start_idx)->descriptor_class) {
366 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
367 if (descriptors_.at(start_idx + i)->updated) {
368 auto bufferview = static_cast<TexelDescriptor *>(descriptors_.at(start_idx + i).get())->GetBufferView();
369 auto buffer = buffer_view_map_->at(bufferview).buffer;
370 buffer_set->insert(buffer);
371 num_updates++;
372 }
373 }
374 } else if (GeneralBuffer == descriptors_.at(start_idx)->descriptor_class) {
375 for (uint32_t i = 0; i < p_layout_->GetDescriptorCountFromBinding(binding); ++i) {
376 if (descriptors_.at(start_idx + i)->updated) {
377 buffer_set->insert(static_cast<BufferDescriptor *>(descriptors_.at(start_idx + i).get())->GetBuffer());
378 num_updates++;
379 }
380 }
381 }
382 }
383 }
384 return num_updates;
385}
386// This is a special case for compute shaders that should eventually be removed once we have proper valid binding info for compute
387// case
388uint32_t cvdescriptorset::DescriptorSet::GetAllStorageUpdates(std::unordered_set<VkBuffer> *buffer_set,
389 std::unordered_set<VkImageView> *image_set) const {
390 std::unordered_set<uint32_t> binding_set;
391 p_layout_->FillBindingSet(&binding_set);
392 return GetStorageUpdates(binding_set, buffer_set, image_set);
393}
394// Starting at given current_binding with binding_remaining descriptors, parse over update_count
395// descriptor updates and verify that for any binding boundaries that are crossed, the next binding(s) are all consistent
396// Consistency means that their type, stage flags, and whether or not they use immutable samplers matches
397// If so, return true. If not, fill in error_msg and return false
398bool cvdescriptorset::DescriptorSet::VerifyUpdateConsistency(uint32_t current_binding, uint32_t binding_remaining,
399 uint32_t update_count, const char *type,
400 std::string *error_msg) const {
401 // Verify consecutive bindings match (if needed)
402 auto orig_binding = current_binding;
403 while (update_count > binding_remaining) { // While our updates overstep current binding
404 // Verify next consecutive binding matches type, stage flags & immutable sampler use
405 if (!p_layout_->IsNextBindingConsistent(current_binding++)) {
406 std::stringstream error_str;
407 error_str << "Attempting " << type << " descriptor set " << set_ << " binding #" << orig_binding << " with #"
408 << update_count << " descriptors being updated but this update oversteps the bounds of this binding and then "
409 "next binding is not consistent with current binding so this update is invalid.";
410 *error_msg = error_str.str();
411 return false;
412 }
413 // For sake of this check consider the bindings updated and advance to next binding
414 update_count -= binding_remaining;
415 binding_remaining = p_layout_->GetDescriptorCountFromBinding(current_binding);
416 }
417 return true;
418}
419// Perform write update in given update struct
420// If an error occurs, return false and fill in details in error_msg string
421bool cvdescriptorset::DescriptorSet::WriteUpdate(debug_report_data *report_data, const VkWriteDescriptorSet *update,
422 std::string *error_msg) {
423 auto num_updates = 0;
424 // Verify dst binding exists
425 if (!p_layout_->HasBinding(update->dstBinding)) {
426 std::stringstream error_str;
427 error_str << "DescriptorSet " << set_ << " does not have binding " << update->dstBinding << ".";
428 *error_msg = error_str.str();
429 return false;
430 } else {
431 // We know that binding is valid, verify update and do update on each descriptor
432 auto start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
433 auto type = p_layout_->GetTypeFromBinding(update->dstBinding);
434 if (type != update->descriptorType) {
435 std::stringstream error_str;
436 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with type "
437 << string_VkDescriptorType(type) << " but update type is " << string_VkDescriptorType(update->descriptorType);
438 *error_msg = error_str.str();
439 return false;
440 }
441 if ((start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
442 std::stringstream error_str;
443 error_str << "Attempting write update to descriptor set " << set_ << " binding #" << update->dstBinding << " with "
444 << p_layout_->GetTotalDescriptorCount() << " total descriptors but update of " << update->descriptorCount
445 << " descriptors starting at binding offset of "
446 << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
447 << " combined with update array element offset of " << update->dstArrayElement
448 << " oversteps the size of this descriptor set.";
449 *error_msg = error_str.str();
450 return false;
451 }
452 // Verify consecutive bindings match (if needed)
453 auto binding_remaining = p_layout_->GetDescriptorCountFromBinding(update->dstBinding) - update->dstArrayElement;
454 if (!VerifyUpdateConsistency(update->dstBinding, binding_remaining, update->descriptorCount, "write update to", error_msg))
455 return false;
456 // Update is within bounds and consistent so perform update
457 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
458 if (!descriptors_[start_idx + di]->WriteUpdate(update, di, error_msg)) {
459 std::stringstream error_str;
460 error_str << "Write update to descriptor at global index " << start_idx + di << " within set " << set_
461 << " binding #" << update->dstBinding << " failed with error message: " << error_msg->c_str();
462 *error_msg = error_str.str();
463 return false;
464 }
465 ++num_updates;
466 }
467 }
468 if (num_updates != 0) {
469 some_update_ = true;
470 full_update_ = (descriptors_.size() == num_updates);
471 }
472 return true;
473}
474// Copy update
475bool cvdescriptorset::DescriptorSet::CopyUpdate(debug_report_data *report_data, const VkCopyDescriptorSet *update,
476 const DescriptorSet *src_set, std::string *error) {
477 auto num_updates = 0;
478 if (!p_layout_->HasBinding(update->dstBinding)) {
479 std::stringstream error_str;
480 error_str << "DescriptorSet " << set_ << " does not have copy update dest binding of " << update->dstBinding << ".";
481 *error = error_str.str();
482 return false;
483 }
484 if (!src_set->HasBinding(update->srcBinding)) {
485 std::stringstream error_str;
486 error_str << "DescriptorSet " << set_ << " does not have copy update src binding of " << update->srcBinding << ".";
487 *error = error_str.str();
488 return false;
489 }
490 // src & dst set bindings are valid
491 // Check bounds of src & dst
492 auto src_start_idx = src_set->GetGlobalStartIndexFromBinding(update->srcBinding) + update->srcArrayElement;
493 if ((src_start_idx + update->descriptorCount) > src_set->GetTotalDescriptorCount()) {
494 // SRC update out of bounds
495 std::stringstream error_str;
496 error_str << "Attempting copy update from descriptorSet " << update->srcSet << " binding#" << update->srcBinding
497 << " with offset index of " << src_set->GetGlobalStartIndexFromBinding(update->srcBinding)
498 << " plus update array offset of " << update->srcArrayElement << " and update of " << update->descriptorCount
499 << " descriptors oversteps total number of descriptors in set: " << src_set->GetTotalDescriptorCount() << ".";
500 *error = error_str.str();
501 return false;
502 }
503 auto dst_start_idx = p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding) + update->dstArrayElement;
504 if ((dst_start_idx + update->descriptorCount) > p_layout_->GetTotalDescriptorCount()) {
505 // DST update out of bounds
506 std::stringstream error_str;
507 error_str << "Attempting copy update to descriptorSet " << set_ << " binding#" << update->dstBinding
508 << " with offset index of " << p_layout_->GetGlobalStartIndexFromBinding(update->dstBinding)
509 << " plus update array offset of " << update->dstArrayElement << " and update of " << update->descriptorCount
510 << " descriptors oversteps total number of descriptors in set: " << p_layout_->GetTotalDescriptorCount() << ".";
511 *error = error_str.str();
512 return false;
513 }
514 // Check that types match
515 auto src_type = src_set->GetTypeFromBinding(update->srcBinding);
516 auto dst_type = p_layout_->GetTypeFromBinding(update->dstBinding);
517 if (src_type != dst_type) {
518 std::stringstream error_str;
519 error_str << "Attempting copy update to descriptorSet " << set_ << " binding #" << update->dstBinding << " with type "
520 << string_VkDescriptorType(dst_type) << " from descriptorSet " << src_set->GetSet() << " binding #"
521 << update->srcBinding << " with type " << string_VkDescriptorType(src_type) << ". Types do not match.";
522 *error = error_str.str();
523 return false;
524 }
525 // Verify consistency of src & dst bindings if update crosses binding boundaries
526 auto src_binding_remaining = src_set->GetDescriptorCountFromBinding(update->srcBinding) - update->srcArrayElement;
527 auto dst_binding_remaining = p_layout_->GetDescriptorCountFromBinding(update->dstBinding) - update->dstArrayElement;
528 if ((!VerifyUpdateConsistency(update->srcBinding, src_binding_remaining, update->descriptorCount, "copy update from", error)) ||
529 (!VerifyUpdateConsistency(update->dstBinding, dst_binding_remaining, update->descriptorCount, "copy update to", error))) {
530 return false;
531 }
532 // Update parameters all look good so perform update
533 for (uint32_t di = 0; di < update->descriptorCount; ++di) {
534 if (!descriptors_.at(dst_start_idx)->CopyUpdate(src_set->descriptors_.at(src_start_idx).get(), error))
535 return false;
536 ++num_updates;
537 }
538 if (num_updates != 0) {
539 some_update_ = true;
540 full_update_ = (descriptors_.size() == num_updates);
541 }
542 return true;
543}
544cvdescriptorset::SamplerDescriptor::SamplerDescriptor(
545 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map)
546 : sampler_(VK_NULL_HANDLE), immutable_(false), sampler_map_(sampler_map) {
547 updated = false;
548 descriptor_class = PlainSampler;
549};
550
551cvdescriptorset::SamplerDescriptor::SamplerDescriptor(
552 const VkSampler *immut, const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map)
553 : sampler_(VK_NULL_HANDLE), immutable_(false), sampler_map_(sampler_map) {
554 updated = false;
555 descriptor_class = PlainSampler;
556 if (immut) {
557 sampler_ = *immut;
558 immutable_ = true;
559 updated = true;
560 }
561}
562bool cvdescriptorset::ValidateSampler(const VkSampler sampler,
563 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map) {
564 return (sampler_map->count(sampler) != 0) ? true : false;
565}
566bool cvdescriptorset::ValidateImageUpdate(const VkImageView image_view, const VkImageLayout image_layout,
567 const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map,
568 const std::unordered_map<VkImage, IMAGE_NODE> *image_map,
569 const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
570 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map,
571 std::string *error) {
572 auto image_pair = image_view_map->find(image_view);
573 if (image_pair == image_view_map->end()) {
574 std::stringstream error_str;
575 error_str << "Invalid VkImageView: " << image_view;
576 *error = error_str.str();
577 return false;
578 } else {
579 // Validate that imageLayout is compatible with aspect_mask and image format
580 VkImageAspectFlags aspect_mask = image_pair->second.subresourceRange.aspectMask;
581 VkImage image = image_pair->second.image;
582 VkFormat format = VK_FORMAT_MAX_ENUM;
583 auto img_pair = image_map->find(image);
584 if (img_pair != image_map->end()) {
585 format = img_pair->second.createInfo.format;
586 } else {
587 // Also need to check the swapchains.
588 auto swapchain_pair = image_to_swapchain_map->find(image);
589 if (swapchain_pair != image_to_swapchain_map->end()) {
590 VkSwapchainKHR swapchain = swapchain_pair->second;
591 auto swapchain_pair = swapchain_map->find(swapchain);
592 if (swapchain_pair != swapchain_map->end()) {
593 format = swapchain_pair->second->createInfo.imageFormat;
594 }
595 }
596 }
597 if (format == VK_FORMAT_MAX_ENUM) {
598 std::stringstream error_str;
599 error_str << "Invalid image (" << image << ") in imageView (" << image_view << ").";
600 *error = error_str.str();
601 return false;
602 } else {
603 bool ds = vk_format_is_depth_or_stencil(format);
604 switch (image_layout) {
605 case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL:
606 // Only Color bit must be set
607 if ((aspect_mask & VK_IMAGE_ASPECT_COLOR_BIT) != VK_IMAGE_ASPECT_COLOR_BIT) {
608 std::stringstream error_str;
609 error_str << "ImageView (" << image_view << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but does "
610 "not have VK_IMAGE_ASPECT_COLOR_BIT set.";
611 *error = error_str.str();
612 return false;
613 }
614 // format must NOT be DS
615 if (ds) {
616 std::stringstream error_str;
617 error_str << "ImageView (" << image_view
618 << ") uses layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL but the image format is "
619 << string_VkFormat(format) << " which is not a color format.";
620 *error = error_str.str();
621 return false;
622 }
623 break;
624 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL:
625 case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
626 // Depth or stencil bit must be set, but both must NOT be set
627 if (aspect_mask & VK_IMAGE_ASPECT_DEPTH_BIT) {
628 if (aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT) {
629 // both must NOT be set
630 std::stringstream error_str;
631 error_str << "ImageView (" << image_view << ") has both STENCIL and DEPTH aspects set";
632 *error = error_str.str();
633 return false;
634 }
635 } else if (!(aspect_mask & VK_IMAGE_ASPECT_STENCIL_BIT)) {
636 // Neither were set
637 std::stringstream error_str;
638 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
639 << " but does not have STENCIL or DEPTH aspects set";
640 *error = error_str.str();
641 return false;
642 }
643 // format must be DS
644 if (!ds) {
645 std::stringstream error_str;
646 error_str << "ImageView (" << image_view << ") has layout " << string_VkImageLayout(image_layout)
647 << " but the image format is " << string_VkFormat(format) << " which is not a depth/stencil format.";
648 *error = error_str.str();
649 return false;
650 }
651 break;
652 default:
653 // anything to check for other layouts?
654 break;
655 }
656 }
657 }
658 return true;
659}
660bool cvdescriptorset::SamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index, std::string *error) {
661 if (!immutable_) {
662 if (!ValidateSampler(update->pImageInfo[index].sampler, sampler_map_)) {
663 std::stringstream error_str;
664 error_str << "Attempted write update to sampler descriptor with invalid sampler: " << update->pImageInfo[index].sampler
665 << ".";
666 *error = error_str.str();
667 return false;
668 }
669 sampler_ = update->pImageInfo[index].sampler;
670 } else {
671 if (!ValidateSampler(sampler_, sampler_map_)) {
672 std::stringstream error_str;
673 error_str << "Attempted write update to immutable sampler descriptor which has invalid immutable sampler: " << sampler_
674 << ".";
675 *error = error_str.str();
676 return false;
677 }
678 // TODO : Do we want a way to warn here in case of updating immutable sampler (which can't be updated)?
679 }
680 updated = true;
681 return true;
682}
683
684bool cvdescriptorset::SamplerDescriptor::CopyUpdate(const Descriptor *src, std::string *error) {
685 if (!immutable_) {
686 auto update_sampler = static_cast<const SamplerDescriptor *>(src)->sampler_;
687 if (!ValidateSampler(update_sampler, sampler_map_)) {
688 std::stringstream error_str;
689 error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << ".";
690 *error = error_str.str();
691 return false;
692 }
693 sampler_ = update_sampler;
694 } else {
695 if (!ValidateSampler(sampler_, sampler_map_)) {
696 std::stringstream error_str;
697 error_str << "Attempted copy update to immutable sampler descriptor which has invalid immutable sampler: " << sampler_
698 << ".";
699 *error = error_str.str();
700 return false;
701 }
702 // TODO : Do we want a way to warn here in case of updating immutable sampler (which can't be updated)?
703 }
704 updated = true;
705 return true;
706}
707cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(
708 const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map,
709 const std::unordered_map<VkImage, IMAGE_NODE> *image_map,
710 const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
711 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map,
712 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map)
713 : sampler_(VK_NULL_HANDLE), immutable_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED),
714 sampler_map_(sampler_map), image_view_map_(image_view_map), image_map_(image_map),
715 image_to_swapchain_map_(image_to_swapchain_map), swapchain_map_(swapchain_map) {
716 updated = false;
717 descriptor_class = ImageSampler;
718}
719
720cvdescriptorset::ImageSamplerDescriptor::ImageSamplerDescriptor(
721 const VkSampler *immut, const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map,
722 const std::unordered_map<VkImage, IMAGE_NODE> *image_map,
723 const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
724 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map,
725 const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map)
726 : sampler_(VK_NULL_HANDLE), immutable_(true), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED),
727 sampler_map_(sampler_map), image_view_map_(image_view_map), image_map_(image_map),
728 image_to_swapchain_map_(image_to_swapchain_map), swapchain_map_(swapchain_map) {
729 updated = false;
730 descriptor_class = ImageSampler;
731 if (immut) {
732 sampler_ = *immut;
733 immutable_ = true;
734 updated = true;
735 }
736}
737bool cvdescriptorset::ImageSamplerDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index,
738 std::string *error) {
739 // First check sampler
740 if (!immutable_) {
741 if (!ValidateSampler(update->pImageInfo[index].sampler, sampler_map_)) {
742 std::stringstream error_str;
743 error_str << "Attempted write update to combined image sampler descriptor with invalid sampler: "
744 << update->pImageInfo[index].sampler << ".";
745 *error = error_str.str();
746 return false;
747 }
748 sampler_ = update->pImageInfo[index].sampler;
749 } else {
750 if (!ValidateSampler(sampler_, sampler_map_)) {
751 std::stringstream error_str;
752 error_str << "Attempted write update to combined image sampler descriptor with immutable sampler which has invalid "
753 "immutable sampler: "
754 << sampler_ << ".";
755 *error = error_str.str();
756 return false;
757 }
758 // TODO : Do we want a way to warn here in case of updating immutable sampler (which can't be updated)?
759 }
760 // Now validate images
761 auto image_view = update->pImageInfo[index].imageView;
762 auto image_layout = update->pImageInfo[index].imageLayout;
763 if (!ValidateImageUpdate(image_view, image_layout, image_view_map_, image_map_, image_to_swapchain_map_, swapchain_map_,
764 error)) {
765 std::stringstream error_str;
766 error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error->c_str();
767 *error = error_str.str();
768 return false;
769 }
770 updated = true;
771 image_view_ = image_view;
772 image_layout_ = image_layout;
773 return true;
774}
775
776bool cvdescriptorset::ImageSamplerDescriptor::CopyUpdate(const Descriptor *src, std::string *error) {
777 if (!immutable_) {
778 auto update_sampler = static_cast<const ImageSamplerDescriptor *>(src)->sampler_;
779 if (!ValidateSampler(update_sampler, sampler_map_)) {
780 std::stringstream error_str;
781 error_str << "Attempted copy update to combined image sampler descriptor with invalid sampler: " << update_sampler
782 << ".";
783 *error = error_str.str();
784 return false;
785 }
786 sampler_ = update_sampler;
787 } else {
788 if (!ValidateSampler(sampler_, sampler_map_)) {
789 std::stringstream error_str;
790 error_str << "Attempted copy update to combined image sampler descriptor with immutable sampler that has invalid "
791 "immutable sampler: "
792 << sampler_ << ".";
793 *error = error_str.str();
794 return false;
795 }
796 // TODO : Do we want a way to warn here in case of updating immutable sampler (which can't be updated)?
797 }
798 // Now validate images
799 auto image_view = static_cast<const ImageSamplerDescriptor *>(src)->image_view_;
800 auto image_layout = static_cast<const ImageSamplerDescriptor *>(src)->image_layout_;
801 if (!ValidateImageUpdate(image_view, image_layout, image_view_map_, image_map_, image_to_swapchain_map_, swapchain_map_,
802 error)) {
803 std::stringstream error_str;
804 error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error->c_str();
805 *error = error_str.str();
806 return false;
807 }
808 updated = true;
809 image_view_ = image_view;
810 image_layout_ = image_layout;
811 return true;
812}
813
814cvdescriptorset::ImageDescriptor::ImageDescriptor(const VkDescriptorType type,
815 const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map,
816 const std::unordered_map<VkImage, IMAGE_NODE> *image_map,
817 const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
818 const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map)
819 : storage_(false), image_view_(VK_NULL_HANDLE), image_layout_(VK_IMAGE_LAYOUT_UNDEFINED), image_view_map_(image_view_map),
820 image_map_(image_map), image_to_swapchain_map_(image_to_swapchain_map), swapchain_map_(swapchain_map) {
821 updated = false;
822 descriptor_class = Image;
823 if (VK_DESCRIPTOR_TYPE_STORAGE_IMAGE == type)
824 storage_ = true;
825};
826
827bool cvdescriptorset::ImageDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index, std::string *error) {
828 // First validate that the write update is valid
829 auto image_view = update->pImageInfo[index].imageView;
830 auto image_layout = update->pImageInfo[index].imageLayout;
831 if (!ValidateImageUpdate(image_view, image_layout, image_view_map_, image_map_, image_to_swapchain_map_, swapchain_map_,
832 error)) {
833 std::stringstream error_str;
834 error_str << "Attempted write update to image descriptor failed due to: " << error->c_str();
835 *error = error_str.str();
836 return false;
837 }
838 // Update is clean so process it
839 updated = true;
840 image_view_ = image_view;
841 image_layout_ = image_layout;
842 return true;
843}
844
845bool cvdescriptorset::ImageDescriptor::CopyUpdate(const Descriptor *src, std::string *error) {
846 // First validate update
847 auto image_view = static_cast<const ImageDescriptor *>(src)->image_view_;
848 auto image_layout = static_cast<const ImageDescriptor *>(src)->image_layout_;
849 if (!ValidateImageUpdate(image_view, image_layout, image_view_map_, image_map_, image_to_swapchain_map_, swapchain_map_,
850 error)) {
851 std::stringstream error_str;
852 error_str << "Attempted copy update to image descriptor failed due to: " << error->c_str();
853 *error = error_str.str();
854 return false;
855 }
856 updated = true;
857 image_view_ = image_view;
858 image_layout_ = image_layout;
859 return true;
860}
861
862cvdescriptorset::BufferDescriptor::BufferDescriptor(const VkDescriptorType type,
863 const std::unordered_map<VkBuffer, BUFFER_NODE> *buffer_map)
864 : storage_(false), dynamic_(false), buffer_(VK_NULL_HANDLE), offset_(0), range_(0), buffer_map_(buffer_map) {
865 updated = false;
866 descriptor_class = GeneralBuffer;
867 if (VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC == type) {
868 dynamic_ = true;
869 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER == type) {
870 storage_ = true;
871 } else if (VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC == type) {
872 dynamic_ = true;
873 storage_ = true;
874 }
875}
876bool cvdescriptorset::BufferDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index, std::string *error) {
877 // First validate bufferinfo
878 auto buffer = update->pBufferInfo[index].buffer;
879 if (!buffer_map_->count(buffer)) {
880 std::stringstream error_str;
881 error_str << "Attempted write update to buffer descriptor with invalid buffer: " << buffer;
882 *error = error_str.str();
883 return false;
884 }
885 updated = true;
886 buffer_ = buffer;
887 offset_ = update->pBufferInfo[index].offset;
888 range_ = update->pBufferInfo[index].range;
889 return true;
890}
891
892bool cvdescriptorset::BufferDescriptor::CopyUpdate(const Descriptor *src, std::string *error) {
893 // First validate bufferinfo
894 auto buffer = static_cast<const BufferDescriptor *>(src)->buffer_;
895 if (!buffer_map_->count(buffer)) {
896 std::stringstream error_str;
897 error_str << "Attempted copy update to buffer descriptor with invalid buffer: " << buffer;
898 *error = error_str.str();
899 return false;
900 }
901 updated = true;
902 buffer_ = buffer;
903 offset_ = static_cast<const BufferDescriptor *>(src)->offset_;
904 range_ = static_cast<const BufferDescriptor *>(src)->range_;
905 return true;
906}
907
908cvdescriptorset::TexelDescriptor::TexelDescriptor(const VkDescriptorType type,
909 const std::unordered_map<VkBufferView, VkBufferViewCreateInfo> *buffer_view_map)
910 : buffer_view_(VK_NULL_HANDLE), storage_(false), buffer_view_map_(buffer_view_map) {
911 updated = false;
912 descriptor_class = TexelBuffer;
913 if (VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER == type)
914 storage_ = true;
915};
916bool cvdescriptorset::TexelDescriptor::WriteUpdate(const VkWriteDescriptorSet *update, const uint32_t index, std::string *error) {
917 // First validate buffer view
918 auto buffer_view = update->pTexelBufferView[index];
919 if (!buffer_view_map_->count(buffer_view)) {
920 std::stringstream error_str;
921 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
922 *error = error_str.str();
923 return false;
924 }
925 updated = true;
926 buffer_view_ = buffer_view;
927 return true;
928}
929
930bool cvdescriptorset::TexelDescriptor::CopyUpdate(const Descriptor *src, std::string *error) {
931 // First validate buffer view
932 auto buffer_view = static_cast<const TexelDescriptor *>(src)->buffer_view_;
933 if (!buffer_view_map_->count(buffer_view)) {
934 std::stringstream error_str;
935 error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view;
936 *error = error_str.str();
937 return false;
938 }
939 updated = true;
940 buffer_view_ = buffer_view;
941 return true;
942}