Vulkan: optimize image memory barriers

Each image was tracking its current layout, but not the pipeline stage
it was used.  Additionally, the barrier access masks were inferred from
the layout.  This incurred two inefficiencies:

- The src pipeline stage mask often included all stages, causing
  unnecessarily heavy barriers.
- The access masks included all possible accesses by a layout, which in
  some cases was overkill, like VK_ACCESS_MEMORY_WRITE_BIT for
  VK_IMAGE_LAYOUT_GENERAL (which will eventually used for compute shader
  output).

This change instead creates an enum where each element represents the
layout, the stage and access masks when transitioning into the layout
and the stage and access masks when transitioning out of that layout.
The image will instead track a value of this enum (instead of
VkImageLayout), which allows it to create the layout transition barriers
as tight as possible, since it includes all the necessary information.

Bug: angleproject:2999
Change-Id: I91535ce06d10530a6fc217ad3b94b7e288521e25
Reviewed-on: https://chromium-review.googlesource.com/c/1440074
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
index fc63464..01deec6 100644
--- a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
+++ b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
@@ -427,7 +427,7 @@
     ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer));
 
     vk::ImageHelper *readImage = readRenderTarget->getImageForRead(
-        &mFramebuffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, commandBuffer);
+        &mFramebuffer, vk::ImageLayout::TransferSrc, commandBuffer);
 
     VkImageAspectFlags aspectMask =
         vk::GetDepthStencilAspectFlagsForCopy(blitDepthBuffer, blitStencilBuffer);
@@ -505,9 +505,8 @@
     // destination target.
     vk::ImageHelper *imageForWrite = drawRenderTarget->getImageForWrite(&mFramebuffer);
 
-    imageForWrite->changeLayoutWithStages(
-        imageForWrite->getAspectFlags(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
-        VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer);
+    imageForWrite->changeLayout(imageForWrite->getAspectFlags(), vk::ImageLayout::TransferDst,
+                                commandBuffer);
 
     commandBuffer->copyBufferToImage(destBufferHandle, imageForWrite->getImage(),
                                      VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copyRegion);
@@ -667,7 +666,7 @@
         colorBlit ? VK_IMAGE_ASPECT_COLOR_BIT
                   : vk::GetDepthStencilAspectFlags(readImageFormat.textureFormat());
     vk::ImageHelper *srcImage = readRenderTarget->getImageForRead(
-        &mFramebuffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, commandBuffer);
+        &mFramebuffer, vk::ImageLayout::TransferSrc, commandBuffer);
 
     const gl::Extents sourceFrameBufferExtents = readRenderTarget->getImageExtents();
     gl::Rectangle readRect                     = readRectIn;
@@ -702,9 +701,7 @@
 
     // Requirement of the copyImageToBuffer, the dst image must be in
     // VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL layout.
-    dstImage->changeLayoutWithStages(aspectMask, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
-                                     VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
-                                     VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer);
+    dstImage->changeLayout(aspectMask, vk::ImageLayout::TransferDst, commandBuffer);
 
     commandBuffer->blitImage(srcImage->getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
                              dstImage->getImage(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit,
@@ -1108,8 +1105,8 @@
 
     // Note that although we're reading from the image, we need to update the layout below.
 
-    vk::ImageHelper *srcImage = renderTarget->getImageForRead(
-        &mFramebuffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, commandBuffer);
+    vk::ImageHelper *srcImage =
+        renderTarget->getImageForRead(&mFramebuffer, vk::ImageLayout::TransferSrc, commandBuffer);
 
     const angle::Format *readFormat = &srcImage->getFormat().textureFormat();