layers: Add getSwapchainFromImage() helper
Add getSwapchainFromImage() to core_validation and use it from
DescriptorSet class.
diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp
index 795f5d7..2393d30 100644
--- a/layers/descriptor_sets.cpp
+++ b/layers/descriptor_sets.cpp
@@ -265,10 +265,8 @@
cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const DescriptorSetLayout *layout,
const core_validation::layer_data *dev_data,
- const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map)
- : some_update_(false), set_(set), p_layout_(layout), device_data_(dev_data), image_to_swapchain_map_(image_to_swapchain_map),
- swapchain_map_(swapchain_map) {
+ : some_update_(false), set_(set), p_layout_(layout), device_data_(dev_data), swapchain_map_(swapchain_map) {
// Foreach binding, create default descriptors of given type
for (uint32_t i = 0; i < p_layout_->GetBindingCount(); ++i) {
auto type = p_layout_->GetTypeFromIndex(i);
@@ -583,7 +581,6 @@
bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type,
const core_validation::layer_data *dev_data,
- const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map,
const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map,
std::string *error) {
auto iv_data = getImageViewData(dev_data, image_view);
@@ -605,9 +602,8 @@
usage = image_node->createInfo.usage;
} else {
// Also need to check the swapchains.
- auto swapchain_pair = image_to_swapchain_map->find(image);
- if (swapchain_pair != image_to_swapchain_map->end()) {
- VkSwapchainKHR swapchain = swapchain_pair->second;
+ auto swapchain = getSwapchainFromImage(dev_data, image);
+ if (swapchain) {
auto swapchain_pair = swapchain_map->find(swapchain);
if (swapchain_pair != swapchain_map->end()) {
format = swapchain_pair->second->createInfo.imageFormat;
@@ -1032,8 +1028,7 @@
// Validate image
auto image_view = update->pImageInfo[di].imageView;
auto image_layout = update->pImageInfo[di].imageLayout;
- if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, image_to_swapchain_map_,
- swapchain_map_, error)) {
+ if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, swapchain_map_, error)) {
std::stringstream error_str;
error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error->c_str();
*error = error_str.str();
@@ -1064,8 +1059,7 @@
for (uint32_t di = 0; di < update->descriptorCount; ++di) {
auto image_view = update->pImageInfo[di].imageView;
auto image_layout = update->pImageInfo[di].imageLayout;
- if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, image_to_swapchain_map_,
- swapchain_map_, error)) {
+ if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, swapchain_map_, error)) {
std::stringstream error_str;
error_str << "Attempted write update to image descriptor failed due to: " << error->c_str();
*error = error_str.str();
@@ -1155,8 +1149,7 @@
// Validate image
auto image_view = img_samp_desc->GetImageView();
auto image_layout = img_samp_desc->GetImageLayout();
- if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, image_to_swapchain_map_, swapchain_map_,
- error)) {
+ if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, swapchain_map_, error)) {
std::stringstream error_str;
error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error->c_str();
*error = error_str.str();
@@ -1169,8 +1162,7 @@
auto img_desc = static_cast<const ImageDescriptor *>(src_set->descriptors_[index + di].get());
auto image_view = img_desc->GetImageView();
auto image_layout = img_desc->GetImageLayout();
- if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, image_to_swapchain_map_, swapchain_map_,
- error)) {
+ if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, swapchain_map_, error)) {
std::stringstream error_str;
error_str << "Attempted copy update to image descriptor failed due to: " << error->c_str();
*error = error_str.str();
@@ -1280,7 +1272,6 @@
const VkDescriptorSetAllocateInfo *p_alloc_info, const VkDescriptorSet *descriptor_sets,
const AllocateDescriptorSetsData *ds_data, std::unordered_map<VkDescriptorPool, DESCRIPTOR_POOL_NODE *> *pool_map,
std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *set_map, const core_validation::layer_data *dev_data,
- const std::unordered_map<VkImage, VkSwapchainKHR> &image_to_swapchain_map,
const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> &swapchain_map) {
auto pool_state = (*pool_map)[p_alloc_info->descriptorPool];
/* Account for sets and individual descriptors allocated from pool */
@@ -1292,8 +1283,7 @@
* global map and the pool's set.
*/
for (uint32_t i = 0; i < p_alloc_info->descriptorSetCount; i++) {
- auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], ds_data->layout_nodes[i], dev_data,
- &image_to_swapchain_map, &swapchain_map);
+ auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], ds_data->layout_nodes[i], dev_data, &swapchain_map);
pool_state->sets.insert(new_ds);
new_ds->in_use.store(0);