layers:Check for descriptor with invalid sampler
authorTobin Ehlis <tobine@google.com>
Fri, 16 Mar 2018 13:54:24 +0000 (07:54 -0600)
committerTobin Ehlis <tobine@google.com>
Fri, 16 Mar 2018 16:39:15 +0000 (10:39 -0600)
Fixes #2485

Verify that a descriptor's sampler is still valid at draw time. We had
a validation hole here where we missed this case if the sampler was
destroyed before the related descriptor was bound to a cmd buffer. This
plugs that hole by making sure all sampler descriptors used at draw
time still have a valid sampler.

layers/descriptor_sets.cpp

index 66a8a48..26796a0 100644 (file)
@@ -620,6 +620,22 @@ bool cvdescriptorset::DescriptorSet::ValidateDrawState(const std::map<uint32_t,
                         return false;
                     }
                 }
+                if (descriptor_class == ImageSampler || descriptor_class == PlainSampler) {
+                    // Verify Sampler still valid
+                    VkSampler sampler;
+                    if (descriptor_class == ImageSampler) {
+                        sampler = static_cast<ImageSamplerDescriptor *>(descriptors_[i].get())->GetSampler();
+                    } else {
+                        sampler = static_cast<SamplerDescriptor *>(descriptors_[i].get())->GetSampler();
+                    }
+                    if (!ValidateSampler(sampler, device_data_)) {
+                        std::stringstream error_str;
+                        error_str << "Descriptor in binding #" << binding << " at global descriptor index " << i
+                                  << " is using sampler " << sampler << " that has been destroyed.";
+                        *error = error_str.str();
+                        return false;
+                    }
+                }
             }
         }
     }