From: Tobin Ehlis Date: Thu, 2 Jun 2016 18:13:32 +0000 (-0600) Subject: layers: Add getSwapchainFromImage() helper X-Git-Tag: upstream/1.1.92~3040^2~66 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b6cb17cbade092a74b25c40b9042fb4cd804b167;p=platform%2Fupstream%2FVulkan-Tools.git layers: Add getSwapchainFromImage() helper Add getSwapchainFromImage() to core_validation and use it from DescriptorSet class. --- diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index f0dede6..4c63a80 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -293,6 +293,14 @@ BUFFER_NODE *getBufferNode(const layer_data *dev_data, const VkBuffer buffer) { } return buff_it->second.get(); } +// Return swapchain for specified image or else NULL +VkSwapchainKHR getSwapchainFromImage(const layer_data *dev_data, const VkImage image) { + auto img_it = dev_data->device_extensions.imageToSwapchainMap.find(image); + if (img_it == dev_data->device_extensions.imageToSwapchainMap.end()) { + return VK_NULL_HANDLE; + } + return img_it->second; +} // Return buffer node ptr for specified buffer or else NULL VkBufferViewCreateInfo *getBufferViewInfo(const layer_data *my_data, const VkBufferView buffer_view) { auto bv_it = my_data->bufferViewMap.find(buffer_view); @@ -5907,8 +5915,7 @@ static void PostCallRecordAllocateDescriptorSets(layer_data *dev_data, const VkD const cvdescriptorset::AllocateDescriptorSetsData *common_data) { // All the updates are contained in a single cvdescriptorset function cvdescriptorset::PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, common_data, &dev_data->descriptorPoolMap, - &dev_data->setMap, dev_data, dev_data->device_extensions.imageToSwapchainMap, - dev_data->device_extensions.swapchainMap); + &dev_data->setMap, dev_data, dev_data->device_extensions.swapchainMap); } VKAPI_ATTR VkResult VKAPI_CALL @@ -7652,9 +7659,9 @@ static bool ValidateBarriers(const char *funcName, VkCommandBuffer cmdBuffer, ui mipLevels = image_data->createInfo.mipLevels; imageFound = true; } else if (dev_data->device_extensions.wsi_enabled) { - auto imageswap_data = dev_data->device_extensions.imageToSwapchainMap.find(mem_barrier->image); - if (imageswap_data != dev_data->device_extensions.imageToSwapchainMap.end()) { - auto swapchain_data = dev_data->device_extensions.swapchainMap.find(imageswap_data->second); + auto imageswap_data = getSwapchainFromImage(dev_data, mem_barrier->image); + if (imageswap_data) { + auto swapchain_data = dev_data->device_extensions.swapchainMap.find(imageswap_data); if (swapchain_data != dev_data->device_extensions.swapchainMap.end()) { format = swapchain_data->second->createInfo.imageFormat; arrayLayers = swapchain_data->second->createInfo.imageArrayLayers; diff --git a/layers/core_validation_types.h b/layers/core_validation_types.h index 4b97988..1d601f4 100644 --- a/layers/core_validation_types.h +++ b/layers/core_validation_types.h @@ -492,6 +492,7 @@ DEVICE_MEM_INFO *getMemObjInfo(const layer_data *, const VkDeviceMemory); VkBufferViewCreateInfo *getBufferViewInfo(const layer_data *, const VkBufferView); SAMPLER_NODE *getSamplerNode(const layer_data *, const VkSampler); VkImageViewCreateInfo *getImageViewData(const layer_data *, const VkImageView); +VkSwapchainKHR getSwapchainFromImage(const layer_data *, const VkImage); } #endif // CORE_VALIDATION_TYPES_H_ 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::AllocateDescriptorSetsData::AllocateDescriptorSetsData(uint32_t cvdescriptorset::DescriptorSet::DescriptorSet(const VkDescriptorSet set, const DescriptorSetLayout *layout, const core_validation::layer_data *dev_data, - const std::unordered_map *image_to_swapchain_map, const std::unordered_map *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::ValidateSampler(const VkSampler sampler, const core_valida bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, const core_validation::layer_data *dev_data, - const std::unordered_map *image_to_swapchain_map, const std::unordered_map *swapchain_map, std::string *error) { auto iv_data = getImageViewData(dev_data, image_view); @@ -605,9 +602,8 @@ bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout 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 @@ bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDesc // 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 @@ bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDesc 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 @@ bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescri // 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 @@ bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescri auto img_desc = static_cast(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 @@ void cvdescriptorset::PerformAllocateDescriptorSets( const VkDescriptorSetAllocateInfo *p_alloc_info, const VkDescriptorSet *descriptor_sets, const AllocateDescriptorSetsData *ds_data, std::unordered_map *pool_map, std::unordered_map *set_map, const core_validation::layer_data *dev_data, - const std::unordered_map &image_to_swapchain_map, const std::unordered_map &swapchain_map) { auto pool_state = (*pool_map)[p_alloc_info->descriptorPool]; /* Account for sets and individual descriptors allocated from pool */ @@ -1292,8 +1283,7 @@ void cvdescriptorset::PerformAllocateDescriptorSets( * 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); diff --git a/layers/descriptor_sets.h b/layers/descriptor_sets.h index 365dedf..88bcef2 100644 --- a/layers/descriptor_sets.h +++ b/layers/descriptor_sets.h @@ -162,7 +162,6 @@ class Descriptor { // performs common functions with both sampler and image descriptors so they can share their common functions bool ValidateSampler(const VkSampler, const core_validation::layer_data *); bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType, const core_validation::layer_data *, - const std::unordered_map *, const std::unordered_map *, std::string *); class SamplerDescriptor : public Descriptor { @@ -267,7 +266,6 @@ void PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *, const Vk std::unordered_map *, std::unordered_map *, const core_validation::layer_data *, - const std::unordered_map &, const std::unordered_map &); /* @@ -292,7 +290,6 @@ class DescriptorSet : public BASE_NODE { public: using BASE_NODE::in_use; DescriptorSet(const VkDescriptorSet, const DescriptorSetLayout *, const core_validation::layer_data *, - const std::unordered_map *, const std::unordered_map *); ~DescriptorSet(); // A number of common Get* functions that return data based on layout from which this set was created @@ -371,7 +368,6 @@ class DescriptorSet : public BASE_NODE { // Ptrs to object containers to verify bound data const core_validation::layer_data *device_data_; // TODO : For next 3 maps all we really need (currently) is an image to format mapping - const std::unordered_map *image_to_swapchain_map_; const std::unordered_map *swapchain_map_; }; }