diff options
| author | Tobin Ehlis <tobine@google.com> | 2016-05-24 12:33:42 -0600 |
|---|---|---|
| committer | Tobin Ehlis <tobine@google.com> | 2016-05-31 08:49:43 -0600 |
| commit | 6eaa12d7fc3aa90e433d7f694238a72306453925 (patch) | |
| tree | cabdd85fdb060f517be01d17f1a09d0b430b4b27 | |
| parent | 580f8733d50dc60a82ae252fcc758771f511a5e5 (diff) | |
| download | usermoji-6eaa12d7fc3aa90e433d7f694238a72306453925.tar.xz | |
layers: Add usage bit validation for buffer descriptors
Verify that buffer used to update all buffer descriptor types (texel or
general) has the correct usage bits set.
descriptor
| -rw-r--r-- | layers/descriptor_sets.cpp | 63 | ||||
| -rw-r--r-- | layers/descriptor_sets.h | 1 |
2 files changed, 61 insertions, 3 deletions
diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp index 72299ccf..c3f9e3b1 100644 --- a/layers/descriptor_sets.cpp +++ b/layers/descriptor_sets.cpp @@ -982,6 +982,55 @@ bool cvdescriptorset::DescriptorSet::ValidateWriteUpdate(const debug_report_data // All checks passed, update is clean return true; } +// For the given buffer, verify that its creation parameters are appropriate for the given type +// If there's an error, update the error string with details and return false, else return true +bool cvdescriptorset::DescriptorSet::ValidateBufferUpdate(VkBuffer buffer, VkDescriptorType type, std::string *error) const { + // First make sure that buffer is valid + auto buff_it = buffer_map_->find(buffer); + if (buff_it == buffer_map_->end()) { + std::stringstream error_str; + error_str << "Invalid VkBuffer: " << buffer; + *error = error_str.str(); + return false; + } + // Verify that usage bits set correctly for given type + auto usage = buff_it->second.createInfo.usage; + std::string error_usage_bit; + switch (type) { + case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: + if (!(usage & VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) { + error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT"; + } + break; + case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: + if (!(usage & VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT)) { + error_usage_bit = "VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT"; + } + break; + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: + case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: + if (!(usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) { + error_usage_bit = "VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT"; + } + break; + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: + case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: + if (!(usage & VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) { + error_usage_bit = "VK_BUFFER_USAGE_STORAGE_BUFFER_BIT"; + } + break; + default: + break; + } + if (!error_usage_bit.empty()) { + std::stringstream error_str; + error_str << "Buffer (" << buffer << ") with usage mask 0x" << usage << " being used for a descriptor update of type " + << string_VkDescriptorType(type) << " does not have " << error_usage_bit << " set."; + *error = error_str.str(); + return false; + } + return true; +} // Verify that the contents of the update are ok, but don't perform actual update bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDescriptorSet *update, const uint32_t index, std::string *error) const { @@ -1037,12 +1086,20 @@ bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDesc case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: { for (uint32_t di = 0; di < update->descriptorCount; ++di) { auto buffer_view = update->pTexelBufferView[di]; - if (!buffer_view_map_->count(buffer_view)) { + auto buffer_view_it = buffer_view_map_->find(buffer_view); + if (buffer_view_it == buffer_view_map_->end()) { std::stringstream error_str; error_str << "Attempted write update to texel buffer descriptor with invalid buffer view: " << buffer_view; *error = error_str.str(); return false; } + auto buffer = buffer_view_it->second.buffer; + if (!ValidateBufferUpdate(buffer, update->descriptorType, error)) { + std::stringstream error_str; + error_str << "Attempted write update to texel buffer descriptor failed due to: " << error->c_str(); + *error = error_str.str(); + return false; + } } break; } @@ -1052,9 +1109,9 @@ bool cvdescriptorset::DescriptorSet::VerifyWriteUpdateContents(const VkWriteDesc case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: { for (uint32_t di = 0; di < update->descriptorCount; ++di) { auto buffer = update->pBufferInfo[di].buffer; - if (!buffer_map_->count(buffer)) { + if (!ValidateBufferUpdate(buffer, update->descriptorType, error)) { std::stringstream error_str; - error_str << "Attempted write update to buffer descriptor with invalid buffer: " << buffer; + error_str << "Attempted write update to buffer descriptor failed due to: " << error->c_str(); *error = error_str.str(); return false; } diff --git a/layers/descriptor_sets.h b/layers/descriptor_sets.h index a3cf28df..a211d2f6 100644 --- a/layers/descriptor_sets.h +++ b/layers/descriptor_sets.h @@ -346,6 +346,7 @@ class DescriptorSet : public BASE_NODE { private: bool VerifyWriteUpdateContents(const VkWriteDescriptorSet *, const uint32_t, std::string *) const; bool VerifyCopyUpdateContents(const VkCopyDescriptorSet *, const DescriptorSet *, const uint32_t, std::string *) const; + bool ValidateBufferUpdate(VkBuffer, VkDescriptorType, std::string *) const; // Private helper to set all bound cmd buffers to INVALID state void InvalidateBoundCmdBuffers(); bool some_update_; // has any part of the set ever been updated? |
