Vulkan: Implement copyImage and enable all tests for it

Bug: angleproject:2500
Change-Id: I9066861ed4db0330754b32995ed82c658d66a590
Reviewed-on: https://chromium-review.googlesource.com/1058034
Commit-Queue: Luc Ferron <lucferron@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/TextureVk.cpp b/src/libANGLE/renderer/vulkan/TextureVk.cpp
index 948c732..8b59e69 100644
--- a/src/libANGLE/renderer/vulkan/TextureVk.cpp
+++ b/src/libANGLE/renderer/vulkan/TextureVk.cpp
@@ -408,8 +408,13 @@
                                GLenum internalFormat,
                                gl::Framebuffer *source)
 {
-    UNIMPLEMENTED();
-    return gl::InternalError();
+    gl::Extents newImageSize(sourceArea.width, sourceArea.height, 1);
+    const gl::InternalFormat &internalFormatInfo =
+        gl::GetInternalFormatInfo(internalFormat, GL_UNSIGNED_BYTE);
+    ANGLE_TRY(setImage(context, index, internalFormat, newImageSize, internalFormatInfo.format,
+                       internalFormatInfo.type, gl::PixelUnpackState(), nullptr));
+    return copySubImageImpl(context, index, gl::Offset(0, 0, 0), sourceArea, internalFormatInfo,
+                            source);
 }
 
 gl::Error TextureVk::copySubImage(const gl::Context *context,
@@ -418,6 +423,17 @@
                                   const gl::Rectangle &sourceArea,
                                   gl::Framebuffer *source)
 {
+    const gl::InternalFormat &currentFormat = *mState.getBaseLevelDesc().format.info;
+    return copySubImageImpl(context, index, destOffset, sourceArea, currentFormat, source);
+}
+
+gl::Error TextureVk::copySubImageImpl(const gl::Context *context,
+                                      const gl::ImageIndex &index,
+                                      const gl::Offset &destOffset,
+                                      const gl::Rectangle &sourceArea,
+                                      const gl::InternalFormat &internalFormat,
+                                      gl::Framebuffer *source)
+{
     gl::Extents fbSize = source->getReadColorbuffer()->getSize();
     gl::Rectangle clippedSourceArea;
     if (!ClipRectangle(sourceArea, gl::Rectangle(0, 0, fbSize.width, fbSize.height),
@@ -431,9 +447,8 @@
 
     ContextVk *contextVk = vk::GetImpl(context);
 
-    FramebufferVk *framebufferVk            = vk::GetImpl(source);
-    RenderTargetVk *renderTarget            = framebufferVk->getColorReadRenderTarget();
-    const gl::InternalFormat &currentFormat = *mState.getBaseLevelDesc().format.info;
+    FramebufferVk *framebufferVk = vk::GetImpl(source);
+    RenderTargetVk *renderTarget = framebufferVk->getColorReadRenderTarget();
 
     vk::CommandBuffer *commandBuffer = nullptr;
     ANGLE_TRY(framebufferVk->beginWriteResource(contextVk->getRenderer(), &commandBuffer));
@@ -444,7 +459,7 @@
     // when its supported.
     ANGLE_TRY(mPixelBuffer.stageSubresourceUpdateFromRenderTarget(
         context, index, clippedSourceArea, modifiedDestOffset,
-        gl::Extents(clippedSourceArea.width, clippedSourceArea.height, 1), currentFormat,
+        gl::Extents(clippedSourceArea.width, clippedSourceArea.height, 1), internalFormat,
         commandBuffer, renderTarget));
 
     vk::CommandGraphNode *writingNode = getNewWritingNode(contextVk->getRenderer());