diff options
| author | Tobin Ehlis <tobine@google.com> | 2016-06-02 10:08:53 -0600 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-06-02 16:58:47 -0600 |
| commit | 50414339385babe11cfdf08b2b4d3bdd3ee73277 (patch) | |
| tree | 0a022e76e874c90b6bf55028eacee56e25f667bf | |
| parent | f6a1232fbcbfe7af4974f70b0014c8b72a362633 (diff) | |
| download | usermoji-50414339385babe11cfdf08b2b4d3bdd3ee73277.tar.xz | |
layers: Add getSamplerNode() helper
Kill sampler_map_ in DescriptorSet and add getSamplerNode() helper
and use it instead.
| -rw-r--r-- | layers/core_validation.cpp | 10 | ||||
| -rw-r--r-- | layers/core_validation_types.h | 1 | ||||
| -rw-r--r-- | layers/descriptor_sets.cpp | 24 | ||||
| -rw-r--r-- | layers/descriptor_sets.h | 6 |
4 files changed, 21 insertions, 20 deletions
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp index 844503dc..2f4a5e82 100644 --- a/layers/core_validation.cpp +++ b/layers/core_validation.cpp @@ -261,6 +261,14 @@ struct shader_module { // TODO : This can be much smarter, using separate locks for separate global data static std::mutex global_lock; +// 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()) { + 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); @@ -5885,7 +5893,7 @@ static void PostCallRecordAllocateDescriptorSets(layer_data *dev_data, const VkD // 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->samplerMap, dev_data->imageViewMap, dev_data->imageMap, + dev_data->descriptorSetLayoutMap, dev_data->imageViewMap, dev_data->imageMap, dev_data->device_extensions.imageToSwapchainMap, dev_data->device_extensions.swapchainMap); } diff --git a/layers/core_validation_types.h b/layers/core_validation_types.h index fd71b61f..e915ade7 100644 --- a/layers/core_validation_types.h +++ b/layers/core_validation_types.h @@ -489,6 +489,7 @@ cvdescriptorset::DescriptorSet *getSetNode(const layer_data *, const VkDescripto 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); } #endif // CORE_VALIDATION_TYPES_H_ diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp index 193a8b74..ed25030f 100644 --- a/layers/descriptor_sets.cpp +++ b/layers/descriptor_sets.cpp @@ -265,14 +265,12 @@ 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<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_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) - : some_update_(false), set_(set), p_layout_(layout), device_data_(dev_data), sampler_map_(sampler_map), - 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_view_map_(image_view_map), + 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); @@ -580,10 +578,9 @@ cvdescriptorset::SamplerDescriptor::SamplerDescriptor(const VkSampler *immut) : updated = true; } } - -bool cvdescriptorset::ValidateSampler(const VkSampler sampler, - const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map) { - return (sampler_map->count(sampler) != 0); +// Validate given sampler. Currently this only checks to make sure it exists in the samplerMap +bool cvdescriptorset::ValidateSampler(const VkSampler sampler, const core_validation::layer_data *dev_data) { + return (getSamplerNode(dev_data, sampler) != nullptr); } bool cvdescriptorset::ValidateImageUpdate(VkImageView image_view, VkImageLayout image_layout, VkDescriptorType type, @@ -1051,7 +1048,7 @@ bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDesc case VK_DESCRIPTOR_TYPE_SAMPLER: { for (uint32_t di = 0; di < update->descriptorCount; ++di) { if (!descriptors_[index + di].get()->IsImmutableSampler()) { - if (!ValidateSampler(update->pImageInfo[di].sampler, sampler_map_)) { + if (!ValidateSampler(update->pImageInfo[di].sampler, device_data_)) { std::stringstream error_str; error_str << "Attempted write update to sampler descriptor with invalid sampler: " << update->pImageInfo[di].sampler << "."; @@ -1131,7 +1128,7 @@ bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescri for (uint32_t di = 0; di < update->descriptorCount; ++di) { if (!src_set->descriptors_[index + di]->IsImmutableSampler()) { auto update_sampler = static_cast<SamplerDescriptor *>(src_set->descriptors_[index + di].get())->GetSampler(); - if (!ValidateSampler(update_sampler, sampler_map_)) { + if (!ValidateSampler(update_sampler, device_data_)) { std::stringstream error_str; error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; *error = error_str.str(); @@ -1149,7 +1146,7 @@ bool cvdescriptorset::DescriptorSet::VerifyCopyUpdateContents(const VkCopyDescri // First validate sampler if (!img_samp_desc->IsImmutableSampler()) { auto update_sampler = img_samp_desc->GetSampler(); - if (!ValidateSampler(update_sampler, sampler_map_)) { + if (!ValidateSampler(update_sampler, device_data_)) { std::stringstream error_str; error_str << "Attempted copy update to sampler descriptor with invalid sampler: " << update_sampler << "."; *error = error_str.str(); @@ -1287,7 +1284,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<VkSampler, std::unique_ptr<SAMPLER_NODE>> &sampler_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, @@ -1302,8 +1298,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, &sampler_map, - &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_view_map, + &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 fcb409cc..eddbff32 100644 --- a/layers/descriptor_sets.h +++ b/layers/descriptor_sets.h @@ -160,7 +160,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 std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *); +bool ValidateSampler(const VkSampler, const core_validation::layer_data *); bool ValidateImageUpdate(VkImageView, VkImageLayout, VkDescriptorType, const std::unordered_map<VkImageView, VkImageViewCreateInfo> *, const std::unordered_map<VkImage, IMAGE_NODE> *, const std::unordered_map<VkImage, VkSwapchainKHR> *, @@ -269,7 +269,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<VkSampler, std::unique_ptr<SAMPLER_NODE>> &, const std::unordered_map<VkImageView, VkImageViewCreateInfo> &, const std::unordered_map<VkImage, IMAGE_NODE> &, const std::unordered_map<VkImage, VkSwapchainKHR> &, @@ -297,7 +296,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<VkSampler, std::unique_ptr<SAMPLER_NODE>> *, 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 *> *); @@ -377,8 +375,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<VkBufferView, VkBufferViewCreateInfo> *buffer_view_map_; - const std::unordered_map<VkSampler, std::unique_ptr<SAMPLER_NODE>> *sampler_map_; 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_; |
