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/RenderTargetVk.cpp b/src/libANGLE/renderer/vulkan/RenderTargetVk.cpp
index 83b609a..508c827 100644
--- a/src/libANGLE/renderer/vulkan/RenderTargetVk.cpp
+++ b/src/libANGLE/renderer/vulkan/RenderTargetVk.cpp
@@ -59,10 +59,8 @@
     renderPassDesc->packAttachment(mImage->getFormat());
 
     // TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
-    mImage->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT,
-                                   VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
-                                   VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
-                                   VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, commandBuffer);
+    mImage->changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::ColorAttachment,
+                         commandBuffer);
 
     // Set up dependencies between the RT resource and the Framebuffer.
     mImage->addWriteDependency(framebufferVk);
@@ -82,9 +80,7 @@
     const angle::Format &format    = mImage->getFormat().textureFormat();
     VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
 
-    mImage->changeLayoutWithStages(aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
-                                   VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
-                                   VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, commandBuffer);
+    mImage->changeLayout(aspectFlags, vk::ImageLayout::DepthStencilAttachment, commandBuffer);
 
     // Set up dependencies between the RT resource and the Framebuffer.
     mImage->addWriteDependency(framebufferVk);
@@ -134,7 +130,7 @@
 }
 
 vk::ImageHelper *RenderTargetVk::getImageForRead(vk::CommandGraphResource *readingResource,
-                                                 VkImageLayout layout,
+                                                 vk::ImageLayout layout,
                                                  vk::CommandBuffer *commandBuffer)
 {
     ASSERT(mImage && mImage->valid());
@@ -142,9 +138,7 @@
     // TODO(jmadill): Better simultaneous resource access. http://anglebug.com/2679
     mImage->addWriteDependency(readingResource);
 
-    mImage->changeLayoutWithStages(mImage->getAspectFlags(), layout,
-                                   VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
-                                   VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer);
+    mImage->changeLayout(mImage->getAspectFlags(), layout, commandBuffer);
 
     return mImage;
 }