layers: Move ValidateWriteUpdate to end of file

Reorder function that will eventually be moved to a new file to the end
of the file -- as a separate commit to keep the refactor diff readable.

Change-Id: If9f64813d710d1ea227a9f65047437f894d5ec41
diff --git a/layers/descriptor_sets.cpp b/layers/descriptor_sets.cpp
index 6c3b904..eff8dd4 100644
--- a/layers/descriptor_sets.cpp
+++ b/layers/descriptor_sets.cpp
@@ -1885,143 +1885,6 @@
     return skip;
 }
 
-// Validate the state for a given write update but don't actually perform the update
-//  If an error would occur for this update, return false and fill in details in error_msg string
-bool cvdescriptorset::ValidateWriteUpdate(const DescriptorSet *dest_set, const debug_report_data *report_data,
-                                          const VkWriteDescriptorSet *update, const char *func_name, std::string *error_code,
-                                          std::string *error_msg) {
-    const auto dest_layout = dest_set->GetLayout();
-
-    // Verify dst layout still valid
-    if (dest_layout->IsDestroyed()) {
-        *error_code = "VUID-VkWriteDescriptorSet-dstSet-00320";
-        string_sprintf(error_msg, "Cannot call %s to perform write update on %s which has been destroyed", func_name,
-                       dest_set->StringifySetAndLayout().c_str());
-        return false;
-    }
-    // Verify dst binding exists
-    if (!dest_layout->HasBinding(update->dstBinding)) {
-        *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00315";
-        std::stringstream error_str;
-        error_str << dest_set->StringifySetAndLayout() << " does not have binding " << update->dstBinding;
-        *error_msg = error_str.str();
-        return false;
-    }
-
-    DescriptorSetLayout::ConstBindingIterator dest(dest_layout.get(), update->dstBinding);
-    // Make sure binding isn't empty
-    if (0 == dest.GetDescriptorCount()) {
-        *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00316";
-        std::stringstream error_str;
-        error_str << dest_set->StringifySetAndLayout() << " cannot updated binding " << update->dstBinding
-                  << " that has 0 descriptors";
-        *error_msg = error_str.str();
-        return false;
-    }
-
-    // Verify idle ds
-    if (dest_set->in_use.load() && !(dest.GetDescriptorBindingFlags() & (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT |
-                                                                         VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
-        // TODO : Re-using Free Idle error code, need write update idle error code
-        *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309";
-        std::stringstream error_str;
-        error_str << "Cannot call " << func_name << " to perform write update on " << dest_set->StringifySetAndLayout()
-                  << " that is in use by a command buffer";
-        *error_msg = error_str.str();
-        return false;
-    }
-    // We know that binding is valid, verify update and do update on each descriptor
-    auto start_idx = dest.GetGlobalIndexRange().start + update->dstArrayElement;
-    auto type = dest.GetType();
-    if (type != update->descriptorType) {
-        *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00319";
-        std::stringstream error_str;
-        error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
-                  << " with type " << string_VkDescriptorType(type) << " but update type is "
-                  << string_VkDescriptorType(update->descriptorType);
-        *error_msg = error_str.str();
-        return false;
-    }
-    auto total_descriptors = dest_layout->GetTotalDescriptorCount();
-    if (update->descriptorCount > (total_descriptors - start_idx)) {
-        *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
-        std::stringstream error_str;
-        error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
-                  << " with " << total_descriptors - start_idx
-                  << " descriptors in that binding and all successive bindings of the set, but update of "
-                  << update->descriptorCount << " descriptors combined with update array element offset of "
-                  << update->dstArrayElement << " oversteps the available number of consecutive descriptors";
-        *error_msg = error_str.str();
-        return false;
-    }
-    if (type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
-        if ((update->dstArrayElement % 4) != 0) {
-            *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02219";
-            std::stringstream error_str;
-            error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
-                      << " with "
-                      << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4";
-            *error_msg = error_str.str();
-            return false;
-        }
-        if ((update->descriptorCount % 4) != 0) {
-            *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02220";
-            std::stringstream error_str;
-            error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
-                      << " with "
-                      << "descriptorCount  " << update->descriptorCount << " not a multiple of 4";
-            *error_msg = error_str.str();
-            return false;
-        }
-        const auto *write_inline_info = lvl_find_in_chain<VkWriteDescriptorSetInlineUniformBlockEXT>(update->pNext);
-        if (!write_inline_info || write_inline_info->dataSize != update->descriptorCount) {
-            *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02221";
-            std::stringstream error_str;
-            if (!write_inline_info) {
-                error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #"
-                          << update->dstBinding << " with "
-                          << "VkWriteDescriptorSetInlineUniformBlockEXT missing";
-            } else {
-                error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #"
-                          << update->dstBinding << " with "
-                          << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize
-                          << " not equal to "
-                          << "VkWriteDescriptorSet descriptorCount " << update->descriptorCount;
-            }
-            *error_msg = error_str.str();
-            return false;
-        }
-        // This error is probably unreachable due to the previous two errors
-        if (write_inline_info && (write_inline_info->dataSize % 4) != 0) {
-            *error_code = "VUID-VkWriteDescriptorSetInlineUniformBlockEXT-dataSize-02222";
-            std::stringstream error_str;
-            error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
-                      << " with "
-                      << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize
-                      << " not a multiple of 4";
-            *error_msg = error_str.str();
-            return false;
-        }
-    }
-    // Verify consecutive bindings match (if needed)
-    if (!VerifyUpdateConsistency(DescriptorSetLayout::ConstBindingIterator(dest_layout.get(), update->dstBinding),
-                                 update->dstArrayElement, update->descriptorCount, "write update to", dest_set->GetSet(),
-                                 error_msg)) {
-        // TODO : Should break out "consecutive binding updates" language into valid usage statements
-        *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
-        return false;
-    }
-    // Update is within bounds and consistent so last step is to validate update contents
-    if (!dest_set->VerifyWriteUpdateContents(update, start_idx, func_name, error_code, error_msg)) {
-        std::stringstream error_str;
-        error_str << "Write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
-                  << " failed with error message: " << error_msg->c_str();
-        *error_msg = error_str.str();
-        return false;
-    }
-    // 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_msg string with details and return false, else return true
 bool cvdescriptorset::DescriptorSet::ValidateBufferUsage(BUFFER_STATE const *buffer_node, VkDescriptorType type,
@@ -2603,3 +2466,141 @@
     }
     return true;
 }
+
+// Validate the state for a given write update but don't actually perform the update
+//  If an error would occur for this update, return false and fill in details in error_msg string
+bool cvdescriptorset::ValidateWriteUpdate(const DescriptorSet *dest_set, const debug_report_data *report_data,
+                                          const VkWriteDescriptorSet *update, const char *func_name, std::string *error_code,
+                                          std::string *error_msg) {
+    const auto dest_layout = dest_set->GetLayout();
+
+    // Verify dst layout still valid
+    if (dest_layout->IsDestroyed()) {
+        *error_code = "VUID-VkWriteDescriptorSet-dstSet-00320";
+        string_sprintf(error_msg, "Cannot call %s to perform write update on %s which has been destroyed", func_name,
+                       dest_set->StringifySetAndLayout().c_str());
+        return false;
+    }
+    // Verify dst binding exists
+    if (!dest_layout->HasBinding(update->dstBinding)) {
+        *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00315";
+        std::stringstream error_str;
+        error_str << dest_set->StringifySetAndLayout() << " does not have binding " << update->dstBinding;
+        *error_msg = error_str.str();
+        return false;
+    }
+
+    DescriptorSetLayout::ConstBindingIterator dest(dest_layout.get(), update->dstBinding);
+    // Make sure binding isn't empty
+    if (0 == dest.GetDescriptorCount()) {
+        *error_code = "VUID-VkWriteDescriptorSet-dstBinding-00316";
+        std::stringstream error_str;
+        error_str << dest_set->StringifySetAndLayout() << " cannot updated binding " << update->dstBinding
+                  << " that has 0 descriptors";
+        *error_msg = error_str.str();
+        return false;
+    }
+
+    // Verify idle ds
+    if (dest_set->in_use.load() && !(dest.GetDescriptorBindingFlags() & (VK_DESCRIPTOR_BINDING_UPDATE_UNUSED_WHILE_PENDING_BIT_EXT |
+                                                                         VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT_EXT))) {
+        // TODO : Re-using Free Idle error code, need write update idle error code
+        *error_code = "VUID-vkFreeDescriptorSets-pDescriptorSets-00309";
+        std::stringstream error_str;
+        error_str << "Cannot call " << func_name << " to perform write update on " << dest_set->StringifySetAndLayout()
+                  << " that is in use by a command buffer";
+        *error_msg = error_str.str();
+        return false;
+    }
+    // We know that binding is valid, verify update and do update on each descriptor
+    auto start_idx = dest.GetGlobalIndexRange().start + update->dstArrayElement;
+    auto type = dest.GetType();
+    if (type != update->descriptorType) {
+        *error_code = "VUID-VkWriteDescriptorSet-descriptorType-00319";
+        std::stringstream error_str;
+        error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
+                  << " with type " << string_VkDescriptorType(type) << " but update type is "
+                  << string_VkDescriptorType(update->descriptorType);
+        *error_msg = error_str.str();
+        return false;
+    }
+    auto total_descriptors = dest_layout->GetTotalDescriptorCount();
+    if (update->descriptorCount > (total_descriptors - start_idx)) {
+        *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
+        std::stringstream error_str;
+        error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
+                  << " with " << total_descriptors - start_idx
+                  << " descriptors in that binding and all successive bindings of the set, but update of "
+                  << update->descriptorCount << " descriptors combined with update array element offset of "
+                  << update->dstArrayElement << " oversteps the available number of consecutive descriptors";
+        *error_msg = error_str.str();
+        return false;
+    }
+    if (type == VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT) {
+        if ((update->dstArrayElement % 4) != 0) {
+            *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02219";
+            std::stringstream error_str;
+            error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
+                      << " with "
+                      << "dstArrayElement " << update->dstArrayElement << " not a multiple of 4";
+            *error_msg = error_str.str();
+            return false;
+        }
+        if ((update->descriptorCount % 4) != 0) {
+            *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02220";
+            std::stringstream error_str;
+            error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
+                      << " with "
+                      << "descriptorCount  " << update->descriptorCount << " not a multiple of 4";
+            *error_msg = error_str.str();
+            return false;
+        }
+        const auto *write_inline_info = lvl_find_in_chain<VkWriteDescriptorSetInlineUniformBlockEXT>(update->pNext);
+        if (!write_inline_info || write_inline_info->dataSize != update->descriptorCount) {
+            *error_code = "VUID-VkWriteDescriptorSet-descriptorType-02221";
+            std::stringstream error_str;
+            if (!write_inline_info) {
+                error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #"
+                          << update->dstBinding << " with "
+                          << "VkWriteDescriptorSetInlineUniformBlockEXT missing";
+            } else {
+                error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #"
+                          << update->dstBinding << " with "
+                          << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize
+                          << " not equal to "
+                          << "VkWriteDescriptorSet descriptorCount " << update->descriptorCount;
+            }
+            *error_msg = error_str.str();
+            return false;
+        }
+        // This error is probably unreachable due to the previous two errors
+        if (write_inline_info && (write_inline_info->dataSize % 4) != 0) {
+            *error_code = "VUID-VkWriteDescriptorSetInlineUniformBlockEXT-dataSize-02222";
+            std::stringstream error_str;
+            error_str << "Attempting write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
+                      << " with "
+                      << "VkWriteDescriptorSetInlineUniformBlockEXT dataSize " << write_inline_info->dataSize
+                      << " not a multiple of 4";
+            *error_msg = error_str.str();
+            return false;
+        }
+    }
+    // Verify consecutive bindings match (if needed)
+    if (!VerifyUpdateConsistency(DescriptorSetLayout::ConstBindingIterator(dest_layout.get(), update->dstBinding),
+                                 update->dstArrayElement, update->descriptorCount, "write update to", dest_set->GetSet(),
+                                 error_msg)) {
+        // TODO : Should break out "consecutive binding updates" language into valid usage statements
+        *error_code = "VUID-VkWriteDescriptorSet-dstArrayElement-00321";
+        return false;
+    }
+    // Update is within bounds and consistent so last step is to validate update contents
+    if (!dest_set->VerifyWriteUpdateContents(update, start_idx, func_name, error_code, error_msg)) {
+        std::stringstream error_str;
+        error_str << "Write update to " << dest_set->StringifySetAndLayout() << " binding #" << update->dstBinding
+                  << " failed with error message: " << error_msg->c_str();
+        *error_msg = error_str.str();
+        return false;
+    }
+    // All checks passed, update is clean
+    return true;
+}