Vulkan: Support texture base and max levels

The Vulkan backend uses a vkImage that matches the number
of effective levels in the GL texture. This is due to the fact
that GL textures can have really strange layouts that only make
sense when base level and max level are applied.

For instance, take the following layout with disjoint mip levels:

  Level 0: 4x4 RGBA
  Level 1: 2x2 RGBA
  Level 2: 10x10 RGB

If base level is set to zero and max level is set to 1, the image is
still considered mip-complete:

  Level 0: 4x4 RGBA  ==> Base Level 0 ==>  Level 0: 4x4 RGBA
  Level 1: 2x2 RGBA  ==> Max Level 1  ==>  Level 1: 2x2 RGBA
  Level 2: 10x10 RGB

If base and max level are then both set to 2, the texture is still
considered complete, but of a different size and format:

  Level 0: 4x4 RGBA
  Level 1: 2x2 RGBA
  Level 2: 10x10 RGB ==> Base/Max Level 2 ==> Level 2: 10x10 RGB

When the base or max level is changed, we must recreate the vkImage to
match the new level count.

To support that, we:

 - Stage updates from the current image to the new image
 - Only stage updates if there aren't already staged updates for a level
 - Free the current image and so it can be recreated at the next draw

This CL does the following:

 - Refactors TextureVk::copyImageDataToBuffer to support staging updates
   without flush
 - Adds TextureVk::copyImageDataToBufferAndGetData to support previous
   use model
 - Adds TextureVk::changeLevels, triggered during syncState, which stages
   updates and releases the current image.
 - Updates ImageHelper::flushStagedUpdates to understand base/max levels
 - Updates TextureVk::ensureImageInitialized and TextureVk::generateMipmap
   to account for base/max level
 - Tracks base and max levels in ImageHelper
 - Adds ImageHelper::stageSubresourceUpdateFromBuffer to support
   this use case
 - Adds ImageHelper::isUpdateStaged to determine if changeLevels
   should propagate data
 - Makes gl::TextureTypeToTarget available for use outside of ImageIndex
 - Enables several deqp and end2end tests

Bug: angleproject:3148
Test: dEQP-GLES3.functional.texture.mipmap.*base_level*
Test: dEQP-GLES3.functional.texture.mipmap.*max_level*
Change-Id: I14ca071c9c62eb310dfed7ef9290dc65fc3ff696
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1776933
Reviewed-by: Courtney Goeltzenleuchter <courtneygo@google.com>
Commit-Queue: Cody Northrop <cnorthrop@google.com>
diff --git a/src/tests/gl_tests/TextureTest.cpp b/src/tests/gl_tests/TextureTest.cpp
index 7963491..7ba8bf0 100644
--- a/src/tests/gl_tests/TextureTest.cpp
+++ b/src/tests/gl_tests/TextureTest.cpp
@@ -1970,6 +1970,8 @@
     ANGLE_SKIP_TEST_IF(IsWindows() && IsAMD() && IsOpenGL());
     // D3D Debug device reports an error. http://anglebug.com/3501
     ANGLE_SKIP_TEST_IF(IsWindows() && IsD3D11());
+    // TODO(cnorthrop): Needs triage on Vulkan backend. http://anglebug.com/3148
+    ANGLE_SKIP_TEST_IF(IsVulkan());
 
     // The workaround in the GL backend required to trigger this bug generates driver warning
     // messages.
@@ -2015,6 +2017,9 @@
     // TODO(geofflang): Investigate on D3D11. http://anglebug.com/2291
     ANGLE_SKIP_TEST_IF(IsD3D11());
 
+    // TODO(cnorthrop): Framebuffer level support. http://anglebug.com/3148
+    ANGLE_SKIP_TEST_IF(IsVulkan());
+
     setUpProgram();
 
     constexpr GLint width  = 8;
@@ -2301,6 +2306,9 @@
     // TODO(crbug.com/998505): Test failing on Android FYI Release (NVIDIA Shield TV)
     ANGLE_SKIP_TEST_IF(IsNVIDIAShield());
 
+    // TODO(cnorthrop): Depth vs. array issue in VK backend. http://anglebug.com/3148
+    ANGLE_SKIP_TEST_IF(IsVulkan());
+
     glActiveTexture(GL_TEXTURE0);
     glBindTexture(GL_TEXTURE_3D, m2DArrayTexture);
     std::vector<GLColor> texDataRed(8u * 8u * 8u, GLColor::red);
@@ -2672,6 +2680,9 @@
 // samplerCubeShadow: TextureCube + SamplerComparisonState
 TEST_P(SamplerTypeMixTestES3, SamplerTypeMixDraw)
 {
+    // TODO(cnorthrop): Requires non-color staging buffer support. http://anglebug.com/3148
+    ANGLE_SKIP_TEST_IF(IsVulkan());
+
     glActiveTexture(GL_TEXTURE0);
     glBindTexture(GL_TEXTURE_2D, mTexture2D);
     GLubyte texData[4];
@@ -4771,6 +4782,9 @@
     // Seems to fail on AMD D3D11. Possibly driver bug. http://anglebug.com/3342
     ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsD3D11());
 
+    // TODO(cnorthrop): Also failing on Vulkan/Windows/AMD. http://anglebug.com/3148
+    ANGLE_SKIP_TEST_IF(IsAMD() && IsWindows() && IsVulkan());
+
     const int size = getWindowWidth();
 
     auto dim   = [size](int level) { return size >> level; };
@@ -5392,6 +5406,9 @@
 // this led to not sampling your texture data when minification occurred.
 TEST_P(Texture2DTestES3, MinificationWithSamplerNoMipmapping)
 {
+    // TODO: Triage this failure on Vulkan: http://anglebug.com/3148
+    ANGLE_SKIP_TEST_IF(IsVulkan());
+
     constexpr char kVS[] =
         "#version 300 es\n"
         "out vec2 texcoord;\n"
@@ -5659,8 +5676,8 @@
                        ES2_OPENGL(),
                        ES2_OPENGLES(),
                        ES2_VULKAN());
-ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
-ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
+ANGLE_INSTANTIATE_TEST(Texture2DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES(), ES3_VULKAN());
+ANGLE_INSTANTIATE_TEST(Texture3DTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES(), ES3_VULKAN());
 ANGLE_INSTANTIATE_TEST(Texture2DIntegerAlpha1TestES3,
                        ES3_D3D11(),
                        ES3_OPENGL(),
@@ -5680,7 +5697,11 @@
                        ES3_OPENGL(),
                        ES3_OPENGLES(),
                        ES3_VULKAN());
-ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
+ANGLE_INSTANTIATE_TEST(Texture2DArrayTestES3,
+                       ES3_D3D11(),
+                       ES3_OPENGL(),
+                       ES3_OPENGLES(),
+                       ES3_VULKAN());
 ANGLE_INSTANTIATE_TEST(TextureSizeTextureArrayTest, ES3_D3D11(), ES3_OPENGL());
 ANGLE_INSTANTIATE_TEST(SamplerInStructTest,
                        ES2_D3D11(),
@@ -5747,13 +5768,16 @@
                        ES2_OPENGL(),
                        ES2_OPENGLES(),
                        ES2_VULKAN());
-ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
-ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
-ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
+ANGLE_INSTANTIATE_TEST(TextureCubeTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES(), ES3_VULKAN());
+ANGLE_INSTANTIATE_TEST(Texture2DIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_VULKAN());
+ANGLE_INSTANTIATE_TEST(TextureCubeIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_VULKAN());
 ANGLE_INSTANTIATE_TEST(TextureCubeIntegerEdgeTestES3, ES3_D3D11(), ES3_OPENGL());
-ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3, ES3_D3D11(), ES3_OPENGL());
-ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
-ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL());
+ANGLE_INSTANTIATE_TEST(Texture2DIntegerProjectiveOffsetTestES3,
+                       ES3_D3D11(),
+                       ES3_OPENGL(),
+                       ES3_VULKAN());
+ANGLE_INSTANTIATE_TEST(Texture2DArrayIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_VULKAN());
+ANGLE_INSTANTIATE_TEST(Texture3DIntegerTestES3, ES3_D3D11(), ES3_OPENGL(), ES3_VULKAN());
 ANGLE_INSTANTIATE_TEST(Texture2DDepthTest,
                        ES2_D3D9(),
                        ES2_D3D11(),