Vulkan: Fix RTs attached to textures with non-0 mip
Cleared confusion between GL level indices and VK level indices by
adding the corresponding suffix to variables and function arguments. A
handful of places that sent one index and expected the other are fixed.
A couple more places needed this adjustment that were missed in the
first CL. Also included a test to provoke those situations.
The conversion between the two is given by:
levelIndexGL = levelIndexVk + baseLevel;
Bug: angleproject:4695
Change-Id: I3b8e5699abee1b011e52b666e6e245f44cb8ad6f
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2302549
Reviewed-by: Cody Northrop <cnorthrop@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
diff --git a/src/tests/gl_tests/FramebufferTest.cpp b/src/tests/gl_tests/FramebufferTest.cpp
index 2f9139a..53f694d 100644
--- a/src/tests/gl_tests/FramebufferTest.cpp
+++ b/src/tests/gl_tests/FramebufferTest.cpp
@@ -513,6 +513,46 @@
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
}
+// TextureAttachmentMipLevelsReadBackWithDraw is a copy of TextureAttachmentMipLevelsReadBack except
+// for adding a draw after the last clear. The draw forces ANGLE's Vulkan backend to use the
+// framebuffer that is level 1 of the texture which will trigger the mismatch use of the GL level
+// and Vulkan level in referring to that rendertarget.
+TEST_P(FramebufferTest_ES3, TextureAttachmentMipLevelsReadBackWithDraw)
+{
+#if defined(ADDRESS_SANITIZER)
+ // http://anglebug.com/4737
+ ANGLE_SKIP_TEST_IF(IsOSX());
+#endif
+
+ ANGLE_GL_PROGRAM(greenProgram, essl1_shaders::vs::Simple(), essl1_shaders::fs::Green());
+
+ GLFramebuffer framebuffer;
+ glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
+
+ GLTexture texture;
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ const std::array<GLColor, 2 * 2> mip0Data = {GLColor::red, GLColor::red, GLColor::red,
+ GLColor::red};
+ const std::array<GLColor, 1 * 1> mip1Data = {GLColor::green};
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip0Data.data());
+ glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip1Data.data());
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 1);
+ EXPECT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
+
+ glClearColor(0, 0, 1.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ // This draw triggers the use of the framebuffer
+ glUseProgram(greenProgram);
+ drawQuad(greenProgram.get(), std::string(essl1_shaders::PositionAttrib()), 0.0f);
+ ASSERT_GL_NO_ERROR();
+ EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
+}
+
// Test that passing an attachment COLOR_ATTACHMENTm where m is equal to MAX_COLOR_ATTACHMENTS
// generates an INVALID_OPERATION.
// OpenGL ES Version 3.0.5 (November 3, 2016), 4.4.2.4 Attaching Texture Images to a Framebuffer, p.