Commit 29fedbac by Ian Elliott Committed by Commit Bot

Vulkan: Create a pre-rotation test for 400x300 windows

This test reproduces the cause of the failures with the following dEQP tests: dEQP.GLES31/functional_texture_multisample_samples_*_sample_position This CL also fixes a problem with the previous test, and puts the common rendering/ReadPixels code in a common method. Bug: b/156395519 Change-Id: Id38476b6caf6f25c52f7504187fb500a39109438 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2207550Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Ian Elliott <ianelliott@google.com>
parent 4c974793
...@@ -575,6 +575,74 @@ class EGLPreRotationSurfaceTest : public EGLSurfaceTest ...@@ -575,6 +575,74 @@ class EGLPreRotationSurfaceTest : public EGLSurfaceTest
initializeSurface(config); initializeSurface(config);
} }
void testDrawingAndReadPixels()
{
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor::yellow);
ASSERT_GL_NO_ERROR();
eglSwapBuffers(mDisplay, mWindowSurface);
ASSERT_EGL_SUCCESS();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor::yellow);
ASSERT_GL_NO_ERROR();
{
// Now, test a 4x4 area in the center of the window, which should tell us if a non-1x1
// ReadPixels is oriented correctly for the device's orientation:
GLint xOffset = 126;
GLint yOffset = 126;
GLsizei width = 4;
GLsizei height = 4;
std::vector<GLColor> pixels(width * height);
glReadPixels(xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
EXPECT_GL_NO_ERROR();
// Expect that all red values equate to x and green values equate to y
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = (y * width) + x;
GLColor expectedPixel(xOffset + x, yOffset + y, 0, 255);
GLColor actualPixel = pixels[index];
EXPECT_EQ(expectedPixel, actualPixel);
}
}
}
{
// Now, test a 8x4 area off-the-center of the window, just to make sure that works too:
GLint xOffset = 13;
GLint yOffset = 26;
GLsizei width = 8;
GLsizei height = 4;
std::vector<GLColor> pixels2(width * height);
glReadPixels(xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels2[0]);
EXPECT_GL_NO_ERROR();
// Expect that all red values equate to x and green values equate to y
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = (y * width) + x;
GLColor expectedPixel(xOffset + x, yOffset + y, 0, 255);
GLColor actualPixel = pixels2[index];
EXPECT_EQ(expectedPixel, actualPixel);
}
}
}
eglSwapBuffers(mDisplay, mWindowSurface);
ASSERT_EGL_SUCCESS();
}
int mSize; int mSize;
}; };
...@@ -632,6 +700,8 @@ TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw) ...@@ -632,6 +700,8 @@ TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw)
std::vector<GLuint> vertexBuffers(2); std::vector<GLuint> vertexBuffers(2);
glGenBuffers(2, &vertexBuffers[0]); glGenBuffers(2, &vertexBuffers[0]);
glBindVertexArray(vertexArray);
std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0}; std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0};
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0], glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
...@@ -640,9 +710,6 @@ TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw) ...@@ -640,9 +710,6 @@ TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw)
std::vector<GLfloat> positionData = {// quad vertices std::vector<GLfloat> positionData = {// quad vertices
-1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f}; -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
glBindVertexArray(vertexArray);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0], glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
GL_STATIC_DRAW); GL_STATIC_DRAW);
...@@ -660,70 +727,100 @@ TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw) ...@@ -660,70 +727,100 @@ TEST_P(EGLPreRotationSurfaceTest, OrientedWindowWithDraw)
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr); testDrawingAndReadPixels();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black); }
EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor::yellow);
ASSERT_GL_NO_ERROR();
eglSwapBuffers(mDisplay, mWindowSurface);
ASSERT_EGL_SUCCESS();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, nullptr); // A slight variation of EGLPreRotationSurfaceTest, where the initial window size is 400x300, yet
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black); // the drawing is still 256x256. In addition, gl_FragCoord is used in a "clever" way, as the color
EXPECT_PIXEL_COLOR_EQ(0, mSize - 1, GLColor::green); // of the 256x256 drawing area, which reproduces an interesting pre-rotation case from the
EXPECT_PIXEL_COLOR_EQ(mSize - 1, 0, GLColor::red); // following dEQP tests:
EXPECT_PIXEL_COLOR_EQ(mSize - 1, mSize - 1, GLColor::yellow); //
ASSERT_GL_NO_ERROR(); // - dEQP.GLES31/functional_texture_multisample_samples_*_sample_position
//
// This will test the rotation of gl_FragCoord, as well as the viewport, scissor, and rendering
// area calculations, especially when the Android device is rotated.
class EGLPreRotationLargeSurfaceTest : public EGLPreRotationSurfaceTest
{
protected:
EGLPreRotationLargeSurfaceTest() : mSize(256) {}
void testSetUp() override
{ {
// Now, test a 4x4 area in the center of the window, which should tell us if a non-1x1 mOSWindow = OSWindow::New();
// ReadPixels is oriented correctly for the device's orientation: mOSWindow->initialize("EGLSurfaceTest", 400, 300);
GLint xOffset = 126;
GLint yOffset = 126;
GLsizei width = 4;
GLsizei height = 4;
std::vector<GLColor> pixels(width * height);
glReadPixels(xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
EXPECT_GL_NO_ERROR();
// Expect that all red values equate to x and green values equate to y
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = (y * width) + x;
GLColor expectedPixel(xOffset + x, yOffset + y, 0, 255);
GLColor actualPixel = pixels[index];
EXPECT_EQ(expectedPixel, actualPixel);
}
}
} }
{ int mSize;
// Now, test a 8x4 area off-the-center of the window, just to make sure that works too: };
GLint xOffset = 13;
GLint yOffset = 26;
GLsizei width = 8;
GLsizei height = 4;
std::vector<GLColor> pixels2(width * height);
glReadPixels(xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, &pixels2[0]);
EXPECT_GL_NO_ERROR();
// Expect that all red values equate to x and green values equate to y
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int index = (y * width) + x;
GLColor expectedPixel(xOffset + x, yOffset + y, 0, 255);
GLColor actualPixel = pixels2[index];
EXPECT_EQ(expectedPixel, actualPixel);
}
}
}
eglSwapBuffers(mDisplay, mWindowSurface); // Provide a predictable pattern for testing pre-rotation
TEST_P(EGLPreRotationLargeSurfaceTest, OrientedWindowWithDraw)
{
// http://anglebug.com/4453
ANGLE_SKIP_TEST_IF(isVulkanRenderer() && IsLinux() && IsIntel());
// Flaky on Linux SwANGLE http://anglebug.com/4453
ANGLE_SKIP_TEST_IF(IsLinux() && isSwiftshader());
// To aid in debugging, we want this window visible
setWindowVisible(mOSWindow, true);
initializeDisplay();
initializeSurfaceWithRGBA8888Config();
initializeContext();
eglMakeCurrent(mDisplay, mWindowSurface, mWindowSurface, mContext);
ASSERT_EGL_SUCCESS(); ASSERT_EGL_SUCCESS();
// Init program
constexpr char kVS[] =
"attribute vec2 position;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
"}";
constexpr char kFS[] =
"void main() {\n"
" gl_FragColor = vec4(gl_FragCoord.x / 256.0, gl_FragCoord.y / 256.0, 0.0, 1.0);\n"
"}";
GLuint program = CompileProgram(kVS, kFS);
ASSERT_NE(0u, program);
glUseProgram(program);
GLint positionLocation = glGetAttribLocation(program, "position");
ASSERT_NE(-1, positionLocation);
GLuint indexBuffer;
glGenBuffers(1, &indexBuffer);
GLuint vertexArray;
glGenVertexArrays(1, &vertexArray);
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
glBindVertexArray(vertexArray);
std::vector<GLushort> indices = {0, 1, 2, 2, 3, 0};
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLushort) * indices.size(), &indices[0],
GL_STATIC_DRAW);
std::vector<GLfloat> positionData = {// quad vertices
-1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * positionData.size(), &positionData[0],
GL_STATIC_DRAW);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 2, nullptr);
glEnableVertexAttribArray(positionLocation);
ASSERT_GL_NO_ERROR();
glViewport(0, 0, mSize, mSize);
testDrawingAndReadPixels();
} }
// Test that the window can be reset repeatedly before surface creation. // Test that the window can be reset repeatedly before surface creation.
...@@ -1144,6 +1241,9 @@ ANGLE_INSTANTIATE_TEST(EGLSurfaceTest, ...@@ -1144,6 +1241,9 @@ ANGLE_INSTANTIATE_TEST(EGLSurfaceTest,
ANGLE_INSTANTIATE_TEST(EGLPreRotationSurfaceTest, ANGLE_INSTANTIATE_TEST(EGLPreRotationSurfaceTest,
WithNoFixture(ES2_VULKAN()), WithNoFixture(ES2_VULKAN()),
WithNoFixture(ES3_VULKAN())); WithNoFixture(ES3_VULKAN()));
ANGLE_INSTANTIATE_TEST(EGLPreRotationLargeSurfaceTest,
WithNoFixture(ES2_VULKAN()),
WithNoFixture(ES3_VULKAN()));
ANGLE_INSTANTIATE_TEST(EGLFloatSurfaceTest, ANGLE_INSTANTIATE_TEST(EGLFloatSurfaceTest,
WithNoFixture(ES2_OPENGL()), WithNoFixture(ES2_OPENGL()),
WithNoFixture(ES3_OPENGL()), WithNoFixture(ES3_OPENGL()),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment