Vulkan: Make free part of DescriptorPool.

This also fixes a missed VkResult error. In order to do this
we also return an error from ProgramImpl::destroy.

Bug: angleproject:2396
Change-Id: I649b19e64732785bb33eebadea7f361245137d0f
Reviewed-on: https://chromium-review.googlesource.com/958406
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/ProgramVk.cpp b/src/libANGLE/renderer/vulkan/ProgramVk.cpp
index 24578e9..5b2411d 100644
--- a/src/libANGLE/renderer/vulkan/ProgramVk.cpp
+++ b/src/libANGLE/renderer/vulkan/ProgramVk.cpp
@@ -154,13 +154,13 @@
 {
 }
 
-void ProgramVk::destroy(const gl::Context *contextImpl)
+gl::Error ProgramVk::destroy(const gl::Context *contextImpl)
 {
     ContextVk *contextVk = vk::GetImpl(contextImpl);
-    reset(contextVk);
+    return reset(contextVk);
 }
 
-void ProgramVk::reset(ContextVk *contextVk)
+vk::Error ProgramVk::reset(ContextVk *contextVk)
 {
     // TODO(jmadill): Handle re-linking a program that is in-use. http://anglebug.com/2397
 
@@ -184,12 +184,14 @@
     if (!mDescriptorSets.empty())
     {
         vk::DescriptorPool *descriptorPool = contextVk->getDescriptorPool();
-        vkFreeDescriptorSets(device, descriptorPool->getHandle(),
-                             static_cast<uint32_t>(mDescriptorSets.size()), mDescriptorSets.data());
+        ANGLE_TRY(descriptorPool->freeDescriptorSets(
+            device, static_cast<uint32_t>(mDescriptorSets.size()), mDescriptorSets.data()));
     }
     mDescriptorSets.clear();
     mUsedDescriptorSetRange.invalidate();
     mDirtyTextures       = false;
+
+    return vk::NoError();
 }
 
 gl::LinkResult ProgramVk::load(const gl::Context *contextImpl,
@@ -224,7 +226,7 @@
     GlslangWrapper *glslangWrapper = renderer->getGlslangWrapper();
     VkDevice device                = renderer->getDevice();
 
-    reset(contextVk);
+    ANGLE_TRY(reset(contextVk));
 
     std::vector<uint32_t> vertexCode;
     std::vector<uint32_t> fragmentCode;
diff --git a/src/libANGLE/renderer/vulkan/ProgramVk.h b/src/libANGLE/renderer/vulkan/ProgramVk.h
index 44959c2..fd0b31d 100644
--- a/src/libANGLE/renderer/vulkan/ProgramVk.h
+++ b/src/libANGLE/renderer/vulkan/ProgramVk.h
@@ -24,7 +24,7 @@
   public:
     ProgramVk(const gl::ProgramState &state);
     ~ProgramVk() override;
-    void destroy(const gl::Context *context) override;
+    gl::Error destroy(const gl::Context *context) override;
 
     gl::LinkResult load(const gl::Context *context,
                         gl::InfoLog &infoLog,
@@ -120,7 +120,7 @@
     void invalidateTextures();
 
   private:
-    void reset(ContextVk *contextVk);
+    vk::Error reset(ContextVk *contextVk);
     vk::Error initDescriptorSets(ContextVk *contextVk);
     gl::Error initDefaultUniformBlocks(const gl::Context *glContext);
     vk::Error updateDefaultUniformsDescriptorSet(ContextVk *contextVk);
diff --git a/src/libANGLE/renderer/vulkan/vk_utils.cpp b/src/libANGLE/renderer/vulkan/vk_utils.cpp
index 9b61577..a8db71c 100644
--- a/src/libANGLE/renderer/vulkan/vk_utils.cpp
+++ b/src/libANGLE/renderer/vulkan/vk_utils.cpp
@@ -1107,6 +1107,16 @@
     return NoError();
 }
 
+Error DescriptorPool::freeDescriptorSets(VkDevice device,
+                                         uint32_t descriptorSetCount,
+                                         const VkDescriptorSet *descriptorSets)
+{
+    ASSERT(valid());
+    ASSERT(descriptorSetCount > 0);
+    ANGLE_VK_TRY(vkFreeDescriptorSets(device, mHandle, descriptorSetCount, descriptorSets));
+    return NoError();
+}
+
 // Sampler implementation.
 Sampler::Sampler()
 {
diff --git a/src/libANGLE/renderer/vulkan/vk_utils.h b/src/libANGLE/renderer/vulkan/vk_utils.h
index 319f7b3..4898b3a 100644
--- a/src/libANGLE/renderer/vulkan/vk_utils.h
+++ b/src/libANGLE/renderer/vulkan/vk_utils.h
@@ -554,6 +554,9 @@
     Error allocateDescriptorSets(VkDevice device,
                                  const VkDescriptorSetAllocateInfo &allocInfo,
                                  VkDescriptorSet *descriptorSetsOut);
+    Error freeDescriptorSets(VkDevice device,
+                             uint32_t descriptorSetCount,
+                             const VkDescriptorSet *descriptorSets);
 };
 
 class Sampler final : public WrappedObject<Sampler, VkSampler>