Hash :
9550c603
Author :
Date :
2018-02-13T14:47:05
Code refactoring for end2end tests. This change: 1) uses the new style ANGLE_SKIP_TEST_IF to skip tests. 2) replaces compile-time definition for OSX to skip tests by run-time function IsOSX() to skip tests, in order to align with ANGLE_SKIP_TEST_IF. 3) fixes a couple of typos. BUG=angleproject:2005 Change-Id: I5af77d82257536b9eb79e26afa502f5b91ff6d31 Reviewed-on: https://chromium-review.googlesource.com/915861 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Some of the pointsprite tests below were ported from Khronos WebGL
// conformance test suite.
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include <cmath>
using namespace angle;
class PointSpritesTest : public ANGLETest
{
protected:
const int windowWidth = 256;
const int windowHeight = 256;
PointSpritesTest()
{
setWindowWidth(windowWidth);
setWindowHeight(windowHeight);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
virtual void SetUp() { ANGLETest::SetUp(); }
float s2p(float s) { return (s + 1.0f) * 0.5f * (GLfloat)windowWidth; }
};
// Checks gl_PointCoord and gl_PointSize
// https://www.khronos.org/registry/webgl/sdk/tests/conformance/glsl/variables/gl-pointcoord.html
TEST_P(PointSpritesTest, PointCoordAndPointSizeCompliance)
{
// TODO(jmadill): Investigate potential AMD driver bug.
// http://anglebug.com/1643
ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL() && IsWindows());
const std::string fs =
R"(precision mediump float;
void main()
{
gl_FragColor = vec4(gl_PointCoord.x, gl_PointCoord.y, 0, 1);
})";
const std::string vs =
R"(attribute vec4 vPosition;
uniform float uPointSize;
void main()
{
gl_PointSize = uPointSize;
gl_Position = vPosition;
})";
ANGLE_GL_PROGRAM(program, vs, fs);
glUseProgram(program);
GLfloat pointSizeRange[2] = {};
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
GLfloat maxPointSize = pointSizeRange[1];
ASSERT_TRUE(maxPointSize >= 1);
maxPointSize = floorf(maxPointSize);
ASSERT_TRUE((int)maxPointSize % 1 == 0);
maxPointSize = std::min(maxPointSize, 64.0f);
GLfloat pointWidth = maxPointSize / windowWidth;
GLint step = static_cast<GLint>(floorf(maxPointSize / 4));
GLint pointStep = std::max<GLint>(1, step);
GLint pointSizeLoc = glGetUniformLocation(program, "uPointSize");
ASSERT_GL_NO_ERROR();
glUniform1f(pointSizeLoc, maxPointSize);
ASSERT_GL_NO_ERROR();
GLfloat pixelOffset = ((int)maxPointSize % 2) ? (1.0f / (GLfloat)windowWidth) : 0;
GLBuffer vertexObject;
glBindBuffer(GL_ARRAY_BUFFER, vertexObject.get());
ASSERT_GL_NO_ERROR();
GLfloat thePoints[] = {-0.5f + pixelOffset, -0.5f + pixelOffset, 0.5f + pixelOffset,
-0.5f + pixelOffset, -0.5f + pixelOffset, 0.5f + pixelOffset,
0.5f + pixelOffset, 0.5f + pixelOffset};
glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW);
ASSERT_GL_NO_ERROR();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_POINTS, 0, 4);
ASSERT_GL_NO_ERROR();
std::string debugText;
for (float py = 0; py < 2; ++py)
{
for (float px = 0; px < 2; ++px)
{
float pointX = -0.5f + px + pixelOffset;
float pointY = -0.5f + py + pixelOffset;
for (int yy = 0; yy < maxPointSize; yy += pointStep)
{
for (int xx = 0; xx < maxPointSize; xx += pointStep)
{
// formula for s and t from OpenGL ES 2.0 spec section 3.3
float xw = s2p(pointX);
float yw = s2p(pointY);
float u = xx / maxPointSize * 2 - 1;
float v = yy / maxPointSize * 2 - 1;
int xf = static_cast<int>(floorf(s2p(pointX + u * pointWidth)));
int yf = static_cast<int>(floorf(s2p(pointY + v * pointWidth)));
float s = 0.5f + (xf + 0.5f - xw) / maxPointSize;
float t = 0.5f + (yf + 0.5f - yw) / maxPointSize;
GLubyte color[4] = {static_cast<GLubyte>(floorf(s * 255)),
static_cast<GLubyte>(floorf((1 - t) * 255)), 0, 255};
EXPECT_PIXEL_NEAR(xf, yf, color[0], color[1], color[2], color[3], 4);
}
}
}
}
}
// Verify that drawing a point without enabling any attributes succeeds
// https://www.khronos.org/registry/webgl/sdk/tests/conformance/rendering/point-no-attributes.html
TEST_P(PointSpritesTest, PointWithoutAttributesCompliance)
{
// TODO(jmadill): Investigate potential AMD driver bug.
// http://anglebug.com/1643
ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL() && IsWindows());
const std::string fs =
R"(precision mediump float;
void main()
{
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
})";
const std::string vs =
R"(void main()
{
gl_PointSize = 2.0;
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, vs, fs);
ASSERT_GL_NO_ERROR();
glUseProgram(program);
glDrawArrays(GL_POINTS, 0, 1);
ASSERT_GL_NO_ERROR();
// expect the center pixel to be green
EXPECT_PIXEL_EQ((windowWidth - 1) / 2, (windowHeight - 1) / 2, 0, 255, 0, 255);
}
// This is a regression test for a graphics driver bug affecting end caps on roads in MapsGL
// https://www.khronos.org/registry/webgl/sdk/tests/conformance/rendering/point-with-gl-pointcoord-in-fragment-shader.html
TEST_P(PointSpritesTest, PointCoordRegressionTest)
{
// TODO(jmadill): Investigate potential AMD driver bug.
// http://anglebug.com/1643
ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL() && IsWindows());
const std::string fs =
R"(precision mediump float;
varying vec4 v_color;
void main()
{
// It seems as long as this mathematical expression references
// gl_PointCoord, the fragment's color is incorrect.
vec2 diff = gl_PointCoord - vec2(.5, .5);
if (length(diff) > 0.5)
discard;
// The point should be a solid color.
gl_FragColor = v_color;
})";
const std::string vs =
R"(varying vec4 v_color;
// The X and Y coordinates of the center of the point.
attribute vec2 a_vertex;
uniform float u_pointSize;
void main()
{
gl_PointSize = u_pointSize;
gl_Position = vec4(a_vertex, 0.0, 1.0);
// The color of the point.
v_color = vec4(0.0, 1.0, 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, vs, fs);
ASSERT_GL_NO_ERROR();
glUseProgram(program);
GLfloat pointSizeRange[2] = {};
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
GLfloat maxPointSize = pointSizeRange[1];
ASSERT_TRUE(maxPointSize > 2);
glClearColor(0, 0, 0, 1);
glDisable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT);
GLint pointSizeLoc = glGetUniformLocation(program, "u_pointSize");
ASSERT_GL_NO_ERROR();
GLfloat pointSize = std::min<GLfloat>(20.0f, maxPointSize);
glUniform1f(pointSizeLoc, pointSize);
ASSERT_GL_NO_ERROR();
GLBuffer vertexObject;
ASSERT_GL_NO_ERROR();
glBindBuffer(GL_ARRAY_BUFFER, vertexObject.get());
ASSERT_GL_NO_ERROR();
GLfloat thePoints[] = {0.0f, 0.0f};
glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW);
ASSERT_GL_NO_ERROR();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_POINTS, 0, 1);
ASSERT_GL_NO_ERROR();
// expect the center pixel to be green
EXPECT_PIXEL_EQ((windowWidth - 1) / 2, (windowHeight - 1) / 2, 0, 255, 0, 255);
}
// Verify GL_VERTEX_PROGRAM_POINT_SIZE is enabled
// https://www.khronos.org/registry/webgl/sdk/tests/conformance/rendering/point-size.html
TEST_P(PointSpritesTest, PointSizeEnabledCompliance)
{
// TODO(jmadill): Investigate potential AMD driver bug.
// http://anglebug.com/1643
ANGLE_SKIP_TEST_IF(IsAMD() && IsDesktopOpenGL() && IsWindows());
const std::string fs =
R"(precision mediump float;
varying vec4 color;
void main()
{
gl_FragColor = color;
})";
const std::string vs =
R"(attribute vec3 pos;
attribute vec4 colorIn;
uniform float pointSize;
varying vec4 color;
void main()
{
gl_PointSize = pointSize;
color = colorIn;
gl_Position = vec4(pos, 1.0);
})";
// The WebGL test is drawn on a 2x2 canvas. Emulate this by setting a 2x2 viewport.
glViewport(0, 0, 2, 2);
ANGLE_GL_PROGRAM(program, vs, fs);
ASSERT_GL_NO_ERROR();
glUseProgram(program);
glDisable(GL_BLEND);
// The choice of (0.4, 0.4) ensures that the centers of the surrounding
// pixels are not contained within the point when it is of size 1, but
// that they definitely are when it is of size 2.
GLfloat vertices[] = {0.4f, 0.4f, 0.0f};
GLubyte colors[] = {255, 0, 0, 255};
GLBuffer vertexObject;
ASSERT_GL_NO_ERROR();
glBindBuffer(GL_ARRAY_BUFFER, vertexObject.get());
ASSERT_GL_NO_ERROR();
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) + sizeof(colors), nullptr, GL_STATIC_DRAW);
ASSERT_GL_NO_ERROR();
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
ASSERT_GL_NO_ERROR();
glBufferSubData(GL_ARRAY_BUFFER, sizeof(vertices), sizeof(colors), colors);
ASSERT_GL_NO_ERROR();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0,
reinterpret_cast<void *>(sizeof(vertices)));
glEnableVertexAttribArray(1);
GLint pointSizeLoc = glGetUniformLocation(program, "pointSize");
ASSERT_GL_NO_ERROR();
glUniform1f(pointSizeLoc, 1.0f);
ASSERT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(ArraySize(vertices)) / 3);
ASSERT_GL_NO_ERROR();
// Test the pixels around the target Red pixel to ensure
// they are the expected color values
for (GLint y = 0; y < 2; ++y)
{
for (GLint x = 0; x < 2; ++x)
{
// 1x1 is expected to be a red pixel
// All others are black
GLubyte expectedColor[4] = {0, 0, 0, 0};
if (x == 1 && y == 1)
{
expectedColor[0] = 255;
expectedColor[3] = 255;
}
EXPECT_PIXEL_EQ(x, y, expectedColor[0], expectedColor[1], expectedColor[2],
expectedColor[3]);
}
}
GLfloat pointSizeRange[2] = {};
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
if (pointSizeRange[1] >= 2.0)
{
// Draw a point of size 2 and verify it fills the appropriate region.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUniform1f(pointSizeLoc, 2.0f);
ASSERT_GL_NO_ERROR();
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(ArraySize(vertices)) / 3);
ASSERT_GL_NO_ERROR();
// Test the pixels to ensure the target is ALL Red pixels
for (GLint y = 0; y < 2; ++y)
{
for (GLint x = 0; x < 2; ++x)
{
EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
}
}
}
}
// Verify that rendering works correctly when gl_PointSize is declared in a shader but isn't used
TEST_P(PointSpritesTest, PointSizeDeclaredButUnused)
{
const std::string vs =
R"(attribute highp vec4 position;
void main(void)
{
gl_PointSize = 1.0;
gl_Position = position;
})";
const std::string fs =
R"(void main(void)
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, vs, fs);
ASSERT_GL_NO_ERROR();
glUseProgram(program);
drawQuad(program, "position", 0.5f, 1.0f);
ASSERT_GL_NO_ERROR();
// expect the center pixel to be red
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 255, 0, 0, 255);
}
// Test to cover a bug where the D3D11 rasterizer state would not be update when switching between
// draw types. This causes the cull face to potentially be incorrect when drawing emulated point
// spites.
TEST_P(PointSpritesTest, PointSpriteAlternatingDrawTypes)
{
const std::string pointFS =
R"(precision mediump float;
void main()
{
gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
})";
const std::string pointVS =
R"(void main()
{
gl_PointSize = 16.0;
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
})";
const std::string quadFS =
R"(precision mediump float;
void main()
{
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
})";
const std::string quadVS =
R"(precision mediump float;
attribute vec4 pos;
void main()
{
gl_Position = pos;
})";
ANGLE_GL_PROGRAM(pointProgram, pointVS, pointFS);
ANGLE_GL_PROGRAM(quadProgram, quadVS, quadFS);
ASSERT_GL_NO_ERROR();
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
const GLfloat quadVertices[] = {
-1.0f, 1.0f, 0.5f, 1.0f, -1.0f, 0.5f, -1.0f, -1.0f, 0.5f,
-1.0f, 1.0f, 0.5f, 1.0f, 1.0f, 0.5f, 1.0f, -1.0f, 0.5f,
};
glUseProgram(quadProgram);
GLint positionLocation = glGetAttribLocation(quadProgram, "pos");
glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, quadVertices);
glEnableVertexAttribArray(positionLocation);
glDrawArrays(GL_TRIANGLES, 0, 6);
glUseProgram(pointProgram);
glDrawArrays(GL_POINTS, 0, 1);
ASSERT_GL_NO_ERROR();
// expect the center pixel to be green
EXPECT_PIXEL_EQ(getWindowWidth() / 2, getWindowHeight() / 2, 0, 255, 0, 255);
}
// This checks for an NVIDIA driver bug where points larger than the maximum reported point size can
// be drawn. Point size should be clamped to the point size range as specified in GLES 3.0.5 section
// 3.4.
TEST_P(PointSpritesTest, PointSizeAboveMaxIsClamped)
{
// Failed on NVIDIA GeForce GTX 1080 - no pixels from the point were detected in the
// framebuffer. http://anglebug.com/2111
ANGLE_SKIP_TEST_IF(IsD3D9());
// Failed on AMD OSX and Windows trybots - no pixels from the point were detected in the
// framebuffer. http://anglebug.com/2113
ANGLE_SKIP_TEST_IF(IsAMD() && IsOpenGL());
GLfloat pointSizeRange[2] = {};
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
GLfloat maxPointSize = pointSizeRange[1];
if (maxPointSize < 4)
{
// This test is only able to test larger points.
return;
}
const std::string &vs =
"attribute vec4 vPosition;\n"
"uniform float uPointSize;\n"
"void main()\n"
"{\n"
" gl_PointSize = uPointSize;\n"
" gl_Position = vPosition;\n"
"}\n";
const std::string &fs =
"precision mediump float;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(1, 0, 0, 1);\n"
"}\n";
ANGLE_GL_PROGRAM(program, vs, fs);
glUseProgram(program);
ASSERT_GL_NO_ERROR();
GLfloat testPointSize = floorf(maxPointSize * 2.0f);
GLint pointSizeLoc = glGetUniformLocation(program, "uPointSize");
glUniform1f(pointSizeLoc, testPointSize);
ASSERT_GL_NO_ERROR();
// The point will be a square centered at gl_Position. We'll offset it from the center of the
// viewport on the x axis so that the left edge of the point square is at the center of the
// viewport.
GLfloat pointXPosition = (0.5f * maxPointSize) * (2.0f / (GLfloat)getWindowWidth());
GLBuffer vertexBuffer;
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
GLfloat thePoints[] = {pointXPosition, 0.0f};
glBufferData(GL_ARRAY_BUFFER, sizeof(thePoints), thePoints, GL_STATIC_DRAW);
ASSERT_GL_NO_ERROR();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_POINTS, 0, 1);
ASSERT_GL_NO_ERROR();
// Pixel on the right of the viewport center should be covered by the point.
EXPECT_PIXEL_NEAR(getWindowWidth() / 2 + 2, getWindowHeight() / 2, 255, 0, 0, 255, 4);
// Pixel on the left of the viewport center should not be covered by the point.
EXPECT_PIXEL_NEAR(getWindowWidth() / 2 - 2, getWindowHeight() / 2, 0, 0, 0, 0, 4);
}
// Use this to select which configurations (e.g. which renderer, which GLES
// major version) these tests should be run against.
//
// We test on D3D11 9_3 because the existing D3D11 PointSprite implementation
// uses Geometry Shaders which are not supported for 9_3.
// D3D9 and D3D11 are also tested to ensure no regressions.
ANGLE_INSTANTIATE_TEST(PointSpritesTest,
ES2_D3D9(),
ES2_D3D11(),
ES2_D3D11_FL9_3(),
ES2_OPENGL(),
ES2_OPENGLES());