layers: Add getSamplerNode() helper
Kill sampler_map_ in DescriptorSet and add getSamplerNode() helper
and use it instead.
diff --git a/layers/core_validation.cpp b/layers/core_validation.cpp
index 844503d..2f4a5e8 100644
--- a/layers/core_validation.cpp
+++ b/layers/core_validation.cpp
@@ -261,6 +261,14 @@
// 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 @@
// 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 fd71b61..e915ade 100644
--- a/layers/core_validation_types.h
+++ b/layers/core_validation_types.h
@@ -489,6 +489,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);
}
#endif // CORE_VALIDATION_TYPES_H_
diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp
index 193a8b7..ed25030 100644
--- a/layers/descriptor_sets.cpp
+++ b/layers/descriptor_sets.cpp
@@ -265,14 +265,12 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
* 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 fcb409c..eddbff3 100644
--- a/layers/descriptor_sets.h
+++ b/layers/descriptor_sets.h
@@ -160,7 +160,7 @@
};
// 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 @@
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 @@
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 @@
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_;