diff options
| author | Tobin Ehlis <tobine@google.com> | 2016-06-02 10:54:09 -0600 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-06-02 16:58:47 -0600 |
| commit | 402540ef8a1ea7df6a48130409714cddcb803d07 (patch) | |
| tree | af4a0f6c02e8c66508ab71dc52ac7063cb19d5b4 /layers | |
| parent | 50414339385babe11cfdf08b2b4d3bdd3ee73277 (diff) | |
| download | usermoji-402540ef8a1ea7df6a48130409714cddcb803d07.tar.xz | |
layers: Add getImageViewData() helper
Switch imageViewMap to store unique_ptrs. Add getImageViewDate() helper
to core_validation and update DescriptorSet to use it.
Diffstat (limited to 'layers')
| -rw-r--r-- | layers/core_validation.cpp | 79 | ||||
| -rw-r--r-- | layers/core_validation_types.h | 1 | ||||
| -rw-r--r-- | layers/descriptor_sets.cpp | 28 | ||||
| -rw-r--r-- | layers/descriptor_sets.h | 8 |
4 files changed, 59 insertions, 57 deletions
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 2f4a5e82..e7aa6dbf 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -124,7 +124,7 @@ struct layer_data { unordered_set<VkCommandBuffer> globalInFlightCmdBuffers; // Layer specific data unordered_map<VkSampler, unique_ptr<SAMPLER_NODE>> samplerMap; - unordered_map<VkImageView, VkImageViewCreateInfo> imageViewMap; + unordered_map<VkImageView, unique_ptr<VkImageViewCreateInfo>> imageViewMap; unordered_map<VkImage, IMAGE_NODE> imageMap; unordered_map<VkBufferView, unique_ptr<VkBufferViewCreateInfo>> bufferViewMap; unordered_map<VkBuffer, unique_ptr<BUFFER_NODE>> bufferMap; @@ -261,18 +261,26 @@ struct shader_module { // TODO : This can be much smarter, using separate locks for separate global data static std::mutex global_lock; +// Return ImageViewCreateInfo ptr for specified imageView or else NULL +VkImageViewCreateInfo *getImageViewData(const layer_data *dev_data, const VkImageView image_view) { + auto iv_it = dev_data->imageViewMap.find(image_view); + if (iv_it == dev_data->imageViewMap.end()) { + return nullptr; + } + return iv_it->second.get(); +} // Return sampler node ptr for specified sampler or else NULL -SAMPLER_NODE *getSamplerNode(const layer_data *my_data, const VkSampler sampler) { - auto sampler_it = my_data->samplerMap.find(sampler); - if (sampler_it == my_data->samplerMap.end()) { +SAMPLER_NODE *getSamplerNode(const layer_data *dev_data, const VkSampler sampler) { + auto sampler_it = dev_data->samplerMap.find(sampler); + if (sampler_it == dev_data->samplerMap.end()) { return nullptr; } return sampler_it->second.get(); } // Return buffer node ptr for specified buffer or else NULL -BUFFER_NODE *getBufferNode(const layer_data *my_data, const VkBuffer buffer) { - auto buff_it = my_data->bufferMap.find(buffer); - if (buff_it == my_data->bufferMap.end()) { +BUFFER_NODE *getBufferNode(const layer_data *dev_data, const VkBuffer buffer) { + auto buff_it = dev_data->bufferMap.find(buffer); + if (buff_it == dev_data->bufferMap.end()) { return nullptr; } return buff_it->second.get(); @@ -3385,10 +3393,10 @@ template <class OBJECT, class LAYOUT> void SetLayout(OBJECT *pObject, VkImage im } void SetLayout(const layer_data *dev_data, GLOBAL_CB_NODE *pCB, VkImageView imageView, const VkImageLayout &layout) { - auto image_view_data = dev_data->imageViewMap.find(imageView); - assert(image_view_data != dev_data->imageViewMap.end()); - const VkImage &image = image_view_data->second.image; - const VkImageSubresourceRange &subRange = image_view_data->second.subresourceRange; + auto iv_data = getImageViewData(dev_data, imageView); + assert(iv_data); + const VkImage &image = iv_data->image; + const VkImageSubresourceRange &subRange = iv_data->subresourceRange; // TODO: Do not iterate over every possibility - consolidate where possible for (uint32_t j = 0; j < subRange.levelCount; j++) { uint32_t level = subRange.baseMipLevel + j; @@ -5523,9 +5531,8 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateImageView(VkDevice device, const VkImageVie if (VK_SUCCESS == result) { std::lock_guard<std::mutex> lock(global_lock); - VkImageViewCreateInfo localCI = VkImageViewCreateInfo(*pCreateInfo); - ResolveRemainingLevelsLayers(dev_data, &localCI.subresourceRange, pCreateInfo->image); - dev_data->imageViewMap[*pView] = localCI; + dev_data->imageViewMap[*pView] = unique_ptr<VkImageViewCreateInfo>(new VkImageViewCreateInfo(*pCreateInfo)); + ResolveRemainingLevelsLayers(dev_data, &dev_data->imageViewMap[*pView].get()->subresourceRange, pCreateInfo->image); } return result; @@ -5891,10 +5898,10 @@ static void PostCallRecordAllocateDescriptorSets(layer_data *dev_data, const VkD VkDescriptorSet *pDescriptorSets, 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->descriptorSetLayoutMap, dev_data->imageViewMap, dev_data->imageMap, - dev_data->device_extensions.imageToSwapchainMap, dev_data->device_extensions.swapchainMap); + cvdescriptorset::PerformAllocateDescriptorSets(pAllocateInfo, pDescriptorSets, common_data, &dev_data->descriptorPoolMap, + &dev_data->setMap, dev_data, dev_data->descriptorSetLayoutMap, + dev_data->imageMap, dev_data->device_extensions.imageToSwapchainMap, + dev_data->device_extensions.swapchainMap); } VKAPI_ATTR VkResult VKAPI_CALL @@ -6676,10 +6683,10 @@ static bool markStoreImagesAndBuffersAsWritten(layer_data *dev_data, GLOBAL_CB_N bool skip_call = false; for (auto imageView : pCB->updateImages) { - auto iv_data = dev_data->imageViewMap.find(imageView); - if (iv_data == dev_data->imageViewMap.end()) + auto iv_data = getImageViewData(dev_data, imageView); + if (!iv_data) continue; - VkImage image = iv_data->second.image; + VkImage image = iv_data->image; VkDeviceMemory mem; skip_call |= get_mem_binding_from_object(dev_data, (uint64_t)image, VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, &mem); @@ -8126,14 +8133,14 @@ VKAPI_ATTR VkResult VKAPI_CALL CreateFramebuffer(VkDevice device, const VkFrameb } for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) { VkImageView view = pCreateInfo->pAttachments[i]; - auto view_data = dev_data->imageViewMap.find(view); - if (view_data == dev_data->imageViewMap.end()) { + auto view_data = getImageViewData(dev_data, view); + if (!view_data) { continue; } MT_FB_ATTACHMENT_INFO fb_info; - get_mem_binding_from_object(dev_data, (uint64_t)(view_data->second.image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, + get_mem_binding_from_object(dev_data, (uint64_t)(view_data->image), VK_DEBUG_REPORT_OBJECT_TYPE_IMAGE_EXT, &fb_info.mem); - fb_info.image = view_data->second.image; + fb_info.image = view_data->image; fbNode.attachments.push_back(fb_info); } } @@ -8258,19 +8265,19 @@ static bool ValidateDependencies(const layer_data *my_data, FRAMEBUFFER_NODE con overlapping_attachments[j].push_back(i); continue; } - auto view_data_i = my_data->imageViewMap.find(viewi); - auto view_data_j = my_data->imageViewMap.find(viewj); - if (view_data_i == my_data->imageViewMap.end() || view_data_j == my_data->imageViewMap.end()) { + auto view_data_i = getImageViewData(my_data, viewi); + auto view_data_j = getImageViewData(my_data, viewj); + if (!view_data_i || !view_data_j) { continue; } - if (view_data_i->second.image == view_data_j->second.image && - isRegionOverlapping(view_data_i->second.subresourceRange, view_data_j->second.subresourceRange)) { + if (view_data_i->image == view_data_j->image && + isRegionOverlapping(view_data_i->subresourceRange, view_data_j->subresourceRange)) { overlapping_attachments[i].push_back(j); overlapping_attachments[j].push_back(i); continue; } - auto image_data_i = my_data->imageMap.find(view_data_i->second.image); - auto image_data_j = my_data->imageMap.find(view_data_j->second.image); + auto image_data_i = my_data->imageMap.find(view_data_i->image); + auto image_data_j = my_data->imageMap.find(view_data_j->image); if (image_data_i == my_data->imageMap.end() || image_data_j == my_data->imageMap.end()) { continue; } @@ -8723,10 +8730,10 @@ static bool VerifyFramebufferAndRenderPassLayouts(layer_data *dev_data, GLOBAL_C } for (uint32_t i = 0; i < pRenderPassInfo->attachmentCount; ++i) { const VkImageView &image_view = framebufferInfo.pAttachments[i]; - auto image_data = dev_data->imageViewMap.find(image_view); - assert(image_data != dev_data->imageViewMap.end()); - const VkImage &image = image_data->second.image; - const VkImageSubresourceRange &subRange = image_data->second.subresourceRange; + auto image_data = getImageViewData(dev_data, image_view); + assert(image_data); + const VkImage &image = image_data->image; + const VkImageSubresourceRange &subRange = image_data->subresourceRange; IMAGE_CMD_BUF_LAYOUT_NODE newNode = {pRenderPassInfo->pAttachments[i].initialLayout, pRenderPassInfo->pAttachments[i].initialLayout}; // TODO: Do not iterate over every possibility - consolidate where possible diff --git a/layers/core_validation_types.h b/layers/core_validation_types.h index e915ade7..e6dcdc85 100644 --- a/layers/core_validation_types.h +++ b/layers/core_validation_types.h @@ -490,6 +490,7 @@ BUFFER_NODE *getBufferNode(const layer_data *, const VkBuffer); 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); } #endif // CORE_VALIDATION_TYPES_H_ diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp index ed25030f..e3f6e9d4 100644 --- a/layers/descriptor_sets.cpp +++ b/layers/descriptor_sets.cpp @@ -265,12 +265,11 @@ 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<VkImageView, VkImageViewCreateInfo> *image_view_map, const std::unordered_map<VkImage, IMAGE_NODE> *image_map, 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_view_map_(image_view_map), - image_map_(image_map), image_to_swapchain_map_(image_to_swapchain_map), swapchain_map_(swapchain_map) { + : some_update_(false), set_(set), p_layout_(layout), device_data_(dev_data), image_map_(image_map), + image_to_swapchain_map_(image_to_swapchain_map), 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); @@ -584,13 +583,13 @@ bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_valida } bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, - const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map, + const core_validation::layer_data *dev_data, const std::unordered_map<VkImage, IMAGE_NODE> *image_map, const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map, const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *swapchain_map, std::string *error) { - auto image_pair = image_view_map->find(image_view); - if (image_pair == image_view_map->end()) { + auto iv_data = getImageViewData(dev_data, image_view); + if (!iv_data) { std::stringstream error_str; error_str << "Invalid VkImageView: " << image_view; *error = error_str.str(); @@ -598,8 +597,8 @@ bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout } // Validate that imageLayout is compatible with aspect_mask and image format // and validate that image usage bits are correct for given usage - VkImageAspectFlags aspect_mask = image_pair->second.subresourceRange.aspectMask; - VkImage image = image_pair->second.image; + VkImageAspectFlags aspect_mask = iv_data->subresourceRange.aspectMask; + VkImage image = iv_data->image; VkFormat format = VK_FORMAT_MAX_ENUM; VkImageUsageFlags usage = 0; auto img_pair = image_map->find(image); @@ -1035,7 +1034,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, image_view_map_, image_map_, + if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, image_map_, image_to_swapchain_map_, swapchain_map_, error)) { std::stringstream error_str; error_str << "Attempted write update to combined image sampler descriptor failed due to: " << error->c_str(); @@ -1067,7 +1066,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, image_view_map_, image_map_, + if (!ValidateImageUpdate(image_view, image_layout, update->descriptorType, device_data_, image_map_, image_to_swapchain_map_, swapchain_map_, error)) { std::stringstream error_str; error_str << "Attempted write update to image descriptor failed due to: " << error->c_str(); @@ -1158,7 +1157,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, image_view_map_, image_map_, image_to_swapchain_map_, + if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, image_map_, image_to_swapchain_map_, swapchain_map_, error)) { std::stringstream error_str; error_str << "Attempted copy update to combined image sampler descriptor failed due to: " << error->c_str(); @@ -1172,7 +1171,7 @@ bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescri 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, image_view_map_, image_map_, image_to_swapchain_map_, + if (!ValidateImageUpdate(image_view, image_layout, type, device_data_, image_map_, image_to_swapchain_map_, swapchain_map_, error)) { std::stringstream error_str; error_str << "Attempted copy update to image descriptor failed due to: " << error->c_str(); @@ -1284,7 +1283,6 @@ void cvdescriptorset::PerformAllocateDescriptorSets( 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<VkDescriptorSetLayout, cvdescriptorset::DescriptorSetLayout *> &layout_map, - const std::unordered_map<VkImageView, VkImageViewCreateInfo> &image_view_map, const std::unordered_map<VkImage, IMAGE_NODE> &image_map, const std::unordered_map<VkImage, VkSwapchainKHR> &image_to_swapchain_map, const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> &swapchain_map) { @@ -1298,8 +1296,8 @@ 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_view_map, - &image_map, &image_to_swapchain_map, &swapchain_map); + auto new_ds = new cvdescriptorset::DescriptorSet(descriptor_sets[i], ds_data->layout_nodes[i], dev_data, &image_map, + &image_to_swapchain_map, &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 eddbff32..16763f84 100644 --- a/layers/descriptor_sets.h +++ b/layers/descriptor_sets.h @@ -161,8 +161,7 @@ class Descriptor { // Shared helper functions - These are useful because the shared sampler image descriptor type // 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 std::unordered_map<VkImageView, VkImageViewCreateInfo> *, +bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType, const core_validation::layer_data *, const std::unordered_map<VkImage, IMAGE_NODE> *, const std::unordered_map<VkImage, VkSwapchainKHR> *, const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *, std::string *); @@ -269,7 +268,6 @@ void PerformAllocateDescriptorSets(const VkDescriptorSetAllocateInfo *, const Vk std::unordered_map<VkDescriptorSet, cvdescriptorset::DescriptorSet *> *, const core_validation::layer_data *, const std::unordered_map<VkDescriptorSetLayout, cvdescriptorset::DescriptorSetLayout *> &, - const std::unordered_map<VkImageView, VkImageViewCreateInfo> &, const std::unordered_map<VkImage, IMAGE_NODE> &, const std::unordered_map<VkImage, VkSwapchainKHR> &, const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> &); @@ -296,8 +294,7 @@ 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<VkImageView, VkImageViewCreateInfo> *, const std::unordered_map<VkImage, IMAGE_NODE> *, - const std::unordered_map<VkImage, VkSwapchainKHR> *, + const std::unordered_map<VkImage, IMAGE_NODE> *, const std::unordered_map<VkImage, VkSwapchainKHR> *, const std::unordered_map<VkSwapchainKHR, SWAPCHAIN_NODE *> *); ~DescriptorSet(); // A number of common Get* functions that return data based on layout from which this set was created @@ -375,7 +372,6 @@ class DescriptorSet : public BASE_NODE { std::vector<std::unique_ptr<Descriptor>> descriptors_; // Ptrs to object containers to verify bound data const core_validation::layer_data *device_data_; - const std::unordered_map<VkImageView, VkImageViewCreateInfo> *image_view_map_; // TODO : For next 3 maps all we really need (currently) is an image to format mapping const std::unordered_map<VkImage, IMAGE_NODE> *image_map_; const std::unordered_map<VkImage, VkSwapchainKHR> *image_to_swapchain_map_; |
