1 //
2 // Copyright 2012 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ANGLETest:
7 // Implementation of common ANGLE testing fixture.
8 //
9
10 #ifndef ANGLE_TESTS_ANGLE_TEST_H_
11 #define ANGLE_TESTS_ANGLE_TEST_H_
12
13 #include <gtest/gtest.h>
14 #include <algorithm>
15 #include <array>
16
17 #include "RenderDoc.h"
18 #include "angle_test_configs.h"
19 #include "angle_test_platform.h"
20 #include "common/angleutils.h"
21 #include "common/system_utils.h"
22 #include "common/vector_utils.h"
23 #include "platform/PlatformMethods.h"
24 #include "test_expectations/GPUTestConfig.h"
25 #include "util/EGLWindow.h"
26 #include "util/shader_utils.h"
27 #include "util/util_gl.h"
28
29 namespace angle
30 {
31 struct SystemInfo;
32 class RNG;
33 } // namespace angle
34
35 #define ASSERT_GL_TRUE(a) ASSERT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
36 #define ASSERT_GL_FALSE(a) ASSERT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
37 #define EXPECT_GL_TRUE(a) EXPECT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
38 #define EXPECT_GL_FALSE(a) EXPECT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
39
40 #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
41 #define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
42
43 #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
44 #define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
45
46 #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
47 #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
48
49 // EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u.
50 #define ASSERT_EGL_TRUE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
51 #define ASSERT_EGL_FALSE(a) \
52 ASSERT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
53 #define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
54 #define EXPECT_EGL_FALSE(a) \
55 EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
56
57 #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
58 #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
59
60 #define ASSERT_GLENUM_EQ(expected, actual) \
61 ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
62 #define EXPECT_GLENUM_EQ(expected, actual) \
63 EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
64 #define ASSERT_GLENUM_NE(expected, actual) \
65 ASSERT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
66 #define EXPECT_GLENUM_NE(expected, actual) \
67 EXPECT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
68
69 testing::AssertionResult AssertEGLEnumsEqual(const char *lhsExpr,
70 const char *rhsExpr,
71 EGLenum lhs,
72 EGLenum rhs);
73
74 #define ASSERT_EGLENUM_EQ(expected, actual) \
75 ASSERT_PRED_FORMAT2(AssertEGLEnumsEqual, static_cast<EGLenum>(expected), \
76 static_cast<EGLenum>(actual))
77 #define EXPECT_EGLENUM_EQ(expected, actual) \
78 EXPECT_PRED_FORMAT2(AssertEGLEnumsEqual, static_cast<EGLenum>(expected), \
79 static_cast<EGLenum>(actual))
80
81 #define ASSERT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
82 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
83 #define EXPECT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
84 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
85
86 namespace angle
87 {
88 struct GLColorRGB
89 {
GLColorRGBGLColorRGB90 constexpr GLColorRGB() : R(0), G(0), B(0) {}
GLColorRGBGLColorRGB91 constexpr GLColorRGB(GLubyte r, GLubyte g, GLubyte b) : R(r), G(g), B(b) {}
92 GLColorRGB(const angle::Vector3 &floatColor);
93
dataGLColorRGB94 const GLubyte *data() const { return &R; }
dataGLColorRGB95 GLubyte *data() { return &R; }
96
97 GLubyte R, G, B;
98
99 static const GLColorRGB black;
100 static const GLColorRGB blue;
101 static const GLColorRGB green;
102 static const GLColorRGB red;
103 static const GLColorRGB yellow;
104 };
105
106 struct GLColorRG
107 {
GLColorRGGLColorRG108 constexpr GLColorRG() : R(0), G(0) {}
GLColorRGGLColorRG109 constexpr GLColorRG(GLubyte r, GLubyte g) : R(r), G(g) {}
110 GLColorRG(const angle::Vector2 &floatColor);
111
dataGLColorRG112 const GLubyte *data() const { return &R; }
dataGLColorRG113 GLubyte *data() { return &R; }
114
115 GLubyte R, G;
116 };
117
118 struct GLColorR
119 {
GLColorRGLColorR120 constexpr GLColorR() : R(0) {}
GLColorRGLColorR121 constexpr GLColorR(GLubyte r) : R(r) {}
122 GLColorR(const float floatColor);
123
dataGLColorR124 const GLubyte *data() const { return &R; }
dataGLColorR125 GLubyte *data() { return &R; }
126
127 GLubyte R;
128 };
129
130 struct GLColor
131 {
GLColorGLColor132 constexpr GLColor() : R(0), G(0), B(0), A(0) {}
GLColorGLColor133 constexpr GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a) {}
134 GLColor(const angle::Vector3 &floatColor);
135 GLColor(const angle::Vector4 &floatColor);
136 GLColor(GLuint colorValue);
137
138 angle::Vector4 toNormalizedVector() const;
139
140 GLubyte &operator[](size_t index) { return (&R)[index]; }
141
142 const GLubyte &operator[](size_t index) const { return (&R)[index]; }
143
dataGLColor144 const GLubyte *data() const { return &R; }
dataGLColor145 GLubyte *data() { return &R; }
146
147 GLuint asUint() const;
148
149 testing::AssertionResult ExpectNear(const GLColor &expected, const GLColor &err) const;
150
151 GLubyte R, G, B, A;
152
153 static const GLColor black;
154 static const GLColor blue;
155 static const GLColor cyan;
156 static const GLColor green;
157 static const GLColor red;
158 static const GLColor transparentBlack;
159 static const GLColor white;
160 static const GLColor yellow;
161 static const GLColor magenta;
162 };
163
164 template <typename T>
165 struct GLColorT
166 {
GLColorTGLColorT167 constexpr GLColorT() : GLColorT(0, 0, 0, 0) {}
GLColorTGLColorT168 constexpr GLColorT(T r, T g, T b, T a) : R(r), G(g), B(b), A(a) {}
169
170 T R, G, B, A;
171 };
172
173 using GLColor16 = GLColorT<uint16_t>;
174 using GLColor32F = GLColorT<float>;
175 using GLColor32I = GLColorT<int32_t>;
176 using GLColor32UI = GLColorT<uint32_t>;
177
178 static constexpr GLColor32F kFloatBlack = {0.0f, 0.0f, 0.0f, 1.0f};
179 static constexpr GLColor32F kFloatRed = {1.0f, 0.0f, 0.0f, 1.0f};
180 static constexpr GLColor32F kFloatGreen = {0.0f, 1.0f, 0.0f, 1.0f};
181 static constexpr GLColor32F kFloatBlue = {0.0f, 0.0f, 1.0f, 1.0f};
182
183 // The input here for pixelPoints are the expected integer window coordinates, we add .5 to every
184 // one of them and re-scale the numbers to be between [-1,1]. Using this technique, we can make
185 // sure the rasterization stage will end up drawing pixels at the expected locations.
186 void CreatePixelCenterWindowCoords(const std::vector<Vector2> &pixelPoints,
187 int windowWidth,
188 int windowHeight,
189 std::vector<Vector3> *outVertices);
190
191 // Useful to cast any type to GLubyte.
192 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor(TR r,TG g,TB b,TA a)193 GLColor MakeGLColor(TR r, TG g, TB b, TA a)
194 {
195 return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
196 static_cast<GLubyte>(a));
197 }
198
199 GLColor RandomColor(angle::RNG *rng);
200
201 bool operator==(const GLColor &a, const GLColor &b);
202 bool operator!=(const GLColor &a, const GLColor &b);
203 std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
204 GLColor ReadColor(GLint x, GLint y);
205
206 bool operator==(const GLColorRGB &a, const GLColorRGB &b);
207 bool operator!=(const GLColorRGB &a, const GLColorRGB &b);
208 std::ostream &operator<<(std::ostream &ostream, const GLColorRGB &color);
209
210 // Useful to cast any type to GLfloat.
211 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor32F(TR r,TG g,TB b,TA a)212 GLColor32F MakeGLColor32F(TR r, TG g, TB b, TA a)
213 {
214 return GLColor32F(static_cast<GLfloat>(r), static_cast<GLfloat>(g), static_cast<GLfloat>(b),
215 static_cast<GLfloat>(a));
216 }
217
218 template <typename T>
219 bool operator==(const GLColorT<T> &a, const GLColorT<T> &b)
220 {
221 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
222 }
223
224 std::ostream &operator<<(std::ostream &ostream, const GLColor32F &color);
225 GLColor32F ReadColor32F(GLint x, GLint y);
226
227 constexpr std::array<GLenum, 6> kCubeFaces = {
228 {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
229 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
230 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}};
231
232 void LoadEntryPointsWithUtilLoader(angle::GLESDriverType driver);
233
234 bool IsFormatEmulated(GLenum target);
235
236 GPUTestConfig::API GetTestConfigAPIFromRenderer(angle::GLESDriverType driverType,
237 EGLenum renderer,
238 EGLenum deviceType);
239 } // namespace angle
240
241 #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
242 EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
243
244 #define EXPECT_PIXEL_NE(x, y, r, g, b, a) \
245 EXPECT_NE(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
246
247 #define EXPECT_PIXEL_32F_EQ(x, y, r, g, b, a) \
248 EXPECT_EQ(angle::MakeGLColor32F(r, g, b, a), angle::ReadColor32F(x, y))
249
250 #define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
251
252 #define EXPECT_PIXEL_ALPHA_NEAR(x, y, a, abs_error) \
253 EXPECT_NEAR(a, angle::ReadColor(x, y).A, abs_error);
254
255 #define EXPECT_PIXEL_ALPHA32F_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor32F(x, y).A)
256
257 #define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
258 #define EXPECT_PIXEL_COLOR_EQ_VEC2(vec2, angleColor) \
259 EXPECT_EQ(angleColor, \
260 angle::ReadColor(static_cast<GLint>(vec2.x()), static_cast<GLint>(vec2.y())))
261
262 #define EXPECT_PIXEL_COLOR32F_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor32F(x, y))
263
264 #define EXPECT_PIXEL_RECT_T_EQ(T, x, y, width, height, format, type, color) \
265 do \
266 { \
267 std::vector<T> actualColors((width) * (height)); \
268 glReadPixels((x), (y), (width), (height), format, type, actualColors.data()); \
269 std::vector<T> expectedColors((width) * (height), color); \
270 EXPECT_EQ(expectedColors, actualColors); \
271 } while (0)
272
273 #define EXPECT_PIXEL_RECT_EQ(x, y, width, height, color) \
274 EXPECT_PIXEL_RECT_T_EQ(GLColor, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, color)
275
276 #define EXPECT_PIXEL_RECT32F_EQ(x, y, width, height, color) \
277 EXPECT_PIXEL_RECT_T_EQ(GLColor32F, x, y, width, height, GL_RGBA, GL_FLOAT, color)
278
279 #define EXPECT_PIXEL_RECT32I_EQ(x, y, width, height, color) \
280 EXPECT_PIXEL_RECT_T_EQ(GLColor32I, x, y, width, height, GL_RGBA_INTEGER, GL_INT, color)
281
282 #define EXPECT_PIXEL_RECT32UI_EQ(x, y, width, height, color) \
283 EXPECT_PIXEL_RECT_T_EQ(GLColor32UI, x, y, width, height, GL_RGBA_INTEGER, GL_UNSIGNED_INT, \
284 color)
285
286 #define EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, ctype, format, type) \
287 do \
288 { \
289 ctype pixel[4]; \
290 glReadPixels((x), (y), 1, 1, format, type, pixel); \
291 EXPECT_GL_NO_ERROR(); \
292 EXPECT_NEAR((r), pixel[0], abs_error); \
293 EXPECT_NEAR((g), pixel[1], abs_error); \
294 EXPECT_NEAR((b), pixel[2], abs_error); \
295 EXPECT_NEAR((a), pixel[3], abs_error); \
296 } while (0)
297
298 #define EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, ctype, format, type) \
299 do \
300 { \
301 ctype pixel[4]; \
302 glReadPixels((x), (y), 1, 1, format, type, pixel); \
303 EXPECT_GL_NO_ERROR(); \
304 EXPECT_EQ((r), pixel[0]); \
305 EXPECT_EQ((g), pixel[1]); \
306 EXPECT_EQ((b), pixel[2]); \
307 EXPECT_EQ((a), pixel[3]); \
308 } while (0)
309
310 #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
311 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLubyte, GL_RGBA, GL_UNSIGNED_BYTE)
312
313 #define EXPECT_PIXEL_16_NEAR(x, y, r, g, b, a, abs_error) \
314 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLushort, GL_RGBA, GL_UNSIGNED_SHORT)
315
316 #define EXPECT_PIXEL_8S_NEAR(x, y, r, g, b, a, abs_error) \
317 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLbyte, GL_RGBA, GL_BYTE)
318
319 #define EXPECT_PIXEL_16S_NEAR(x, y, r, g, b, a, abs_error) \
320 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLshort, GL_RGBA, GL_SHORT)
321
322 #define EXPECT_PIXEL_32F_NEAR(x, y, r, g, b, a, abs_error) \
323 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLfloat, GL_RGBA, GL_FLOAT)
324
325 #define EXPECT_PIXEL_8I(x, y, r, g, b, a) \
326 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLbyte, GL_RGBA_INTEGER, GL_BYTE)
327
328 #define EXPECT_PIXEL_8UI(x, y, r, g, b, a) \
329 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLubyte, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE)
330
331 #define EXPECT_PIXEL_32UI(x, y, r, g, b, a) \
332 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLuint, GL_RGBA_INTEGER, GL_UNSIGNED_INT)
333
334 #define EXPECT_PIXEL_32I(x, y, r, g, b, a) \
335 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLint, GL_RGBA_INTEGER, GL_INT)
336
337 #define EXPECT_PIXEL_32UI_COLOR(x, y, color) \
338 EXPECT_PIXEL_32UI(x, y, color.R, color.G, color.B, color.A)
339
340 #define EXPECT_PIXEL_32I_COLOR(x, y, color) \
341 EXPECT_PIXEL_32I(x, y, color.R, color.G, color.B, color.A)
342
343 // TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
344 #define EXPECT_PIXEL_COLOR_NEAR(x, y, angleColor, abs_error) \
345 EXPECT_PIXEL_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
346
347 #define EXPECT_PIXEL_COLOR16_NEAR(x, y, angleColor, abs_error) \
348 EXPECT_PIXEL_16_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
349
350 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
351 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
352
353 #define EXPECT_COLOR_NEAR(expected, actual, abs_error) \
354 do \
355 { \
356 EXPECT_NEAR(expected.R, actual.R, abs_error); \
357 EXPECT_NEAR(expected.G, actual.G, abs_error); \
358 EXPECT_NEAR(expected.B, actual.B, abs_error); \
359 EXPECT_NEAR(expected.A, actual.A, abs_error); \
360 } while (0)
361 #define EXPECT_PIXEL32F_NEAR(x, y, r, g, b, a, abs_error) \
362 do \
363 { \
364 GLfloat pixel[4]; \
365 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_FLOAT, pixel); \
366 EXPECT_GL_NO_ERROR(); \
367 EXPECT_NEAR((r), pixel[0], abs_error); \
368 EXPECT_NEAR((g), pixel[1], abs_error); \
369 EXPECT_NEAR((b), pixel[2], abs_error); \
370 EXPECT_NEAR((a), pixel[3], abs_error); \
371 } while (0)
372
373 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
374 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
375
376 #define EXPECT_PIXEL_STENCIL_EQ(x, y, expected) \
377 do \
378 { \
379 GLubyte actual; \
380 glReadPixels((x), (y), 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &actual); \
381 EXPECT_GL_NO_ERROR(); \
382 EXPECT_EQ((expected), actual); \
383 } while (0)
384
385 class ANGLETestBase;
386 class EGLWindow;
387 class GLWindowBase;
388 class OSWindow;
389 class WGLWindow;
390
391 struct TestPlatformContext final : private angle::NonCopyable
392 {
393 bool ignoreMessages = false;
394 bool warningsAsErrors = false;
395 ANGLETestBase *currentTest = nullptr;
396 };
397
398 class ANGLETestBase
399 {
400 protected:
401 ANGLETestBase(const angle::PlatformParameters ¶ms);
402 virtual ~ANGLETestBase();
403
404 public:
405 void setWindowVisible(OSWindow *osWindow, bool isVisible);
406
407 static void ReleaseFixtures();
408
isSwiftshader()409 bool isSwiftshader() const
410 {
411 // Renderer might be swiftshader even if local swiftshader not used.
412 return mCurrentParams->isSwiftshader() || angle::IsSwiftshaderDevice();
413 }
414
enableDebugLayers()415 bool enableDebugLayers() const
416 {
417 return mCurrentParams->eglParameters.debugLayersEnabled != EGL_FALSE;
418 }
419
420 void *operator new(size_t size);
421 void operator delete(void *ptr);
422
423 protected:
424 void ANGLETestSetUp();
425 void ANGLETestSetUpCL();
426 void ANGLETestPreTearDown();
427 void ANGLETestTearDown();
428 void ANGLETestTearDownCL();
429
430 virtual void swapBuffers();
431
432 void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
433 void setupIndexedQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
434 void setupIndexedQuadIndexBuffer();
435
436 void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ);
437 void drawQuad(GLuint program,
438 const std::string &positionAttribName,
439 GLfloat positionAttribZ,
440 GLfloat positionAttribXYScale);
441 void drawQuad(GLuint program,
442 const std::string &positionAttribName,
443 GLfloat positionAttribZ,
444 GLfloat positionAttribXYScale,
445 bool useVertexBuffer);
446 void drawQuadInstanced(GLuint program,
447 const std::string &positionAttribName,
448 GLfloat positionAttribZ,
449 GLfloat positionAttribXYScale,
450 bool useVertexBuffer,
451 GLuint numInstances);
452 void drawPatches(GLuint program,
453 const std::string &positionAttribName,
454 GLfloat positionAttribZ,
455 GLfloat positionAttribXYScale,
456 bool useVertexBuffer);
457
458 void drawQuadPPO(GLuint vertProgram,
459 const std::string &positionAttribName,
460 const GLfloat positionAttribZ,
461 const GLfloat positionAttribXYScale);
462
463 static std::array<angle::Vector3, 6> GetQuadVertices();
464 static std::array<GLushort, 6> GetQuadIndices();
465 static std::array<angle::Vector3, 4> GetIndexedQuadVertices();
466
467 void drawIndexedQuad(GLuint program,
468 const std::string &positionAttribName,
469 GLfloat positionAttribZ);
470 void drawIndexedQuad(GLuint program,
471 const std::string &positionAttribName,
472 GLfloat positionAttribZ,
473 GLfloat positionAttribXYScale);
474 void drawIndexedQuad(GLuint program,
475 const std::string &positionAttribName,
476 GLfloat positionAttribZ,
477 GLfloat positionAttribXYScale,
478 bool useBufferObject);
479
480 void drawIndexedQuad(GLuint program,
481 const std::string &positionAttribName,
482 GLfloat positionAttribZ,
483 GLfloat positionAttribXYScale,
484 bool useBufferObject,
485 bool restrictedRange);
486
487 void draw2DTexturedQuad(GLfloat positionAttribZ,
488 GLfloat positionAttribXYScale,
489 bool useVertexBuffer);
490
491 // The layer parameter chooses the 3D texture layer to sample from.
492 void draw3DTexturedQuad(GLfloat positionAttribZ,
493 GLfloat positionAttribXYScale,
494 bool useVertexBuffer,
495 float layer);
496
497 // The layer parameter chooses the 2DArray texture layer to sample from.
498 void draw2DArrayTexturedQuad(GLfloat positionAttribZ,
499 GLfloat positionAttribXYScale,
500 bool useVertexBuffer,
501 float layer);
502
503 void setWindowWidth(int width);
504 void setWindowHeight(int height);
505 void setConfigRedBits(int bits);
506 void setConfigGreenBits(int bits);
507 void setConfigBlueBits(int bits);
508 void setConfigAlphaBits(int bits);
509 void setConfigDepthBits(int bits);
510 void setConfigStencilBits(int bits);
511 void setConfigComponentType(EGLenum componentType);
512 void setMultisampleEnabled(bool enabled);
513 void setSamples(EGLint samples);
514 void setDebugEnabled(bool enabled);
515 void setNoErrorEnabled(bool enabled);
516 void setWebGLCompatibilityEnabled(bool webglCompatibility);
517 void setExtensionsEnabled(bool extensionsEnabled);
518 void setRobustAccess(bool enabled);
519 void setBindGeneratesResource(bool bindGeneratesResource);
520 void setClientArraysEnabled(bool enabled);
521 void setRobustResourceInit(bool enabled);
522 void setMutableRenderBuffer(bool enabled);
523 void setContextProgramCacheEnabled(bool enabled);
524 void setContextResetStrategy(EGLenum resetStrategy);
525 void forceNewDisplay();
526
527 // Some EGL extension tests would like to defer the Context init until the test body.
528 void setDeferContextInit(bool enabled);
529
530 int getClientMajorVersion() const;
531 int getClientMinorVersion() const;
532
533 GLWindowBase *getGLWindow() const;
534 EGLWindow *getEGLWindow() const;
535 int getWindowWidth() const;
536 int getWindowHeight() const;
537
538 EGLint getPlatformRenderer() const;
539
540 void ignoreD3D11SDKLayersWarnings();
541
getOSWindow()542 OSWindow *getOSWindow() { return mFixture->osWindow; }
543
544 GLuint get2DTexturedQuadProgram();
545
546 // Has a float uniform "u_layer" to choose the 3D texture layer.
547 GLuint get3DTexturedQuadProgram();
548
549 // Has a float uniform "u_layer" to choose the 2DArray texture layer.
550 GLuint get2DArrayTexturedQuadProgram();
551
552 class [[nodiscard]] ScopedIgnorePlatformMessages : angle::NonCopyable
553 {
554 public:
555 ScopedIgnorePlatformMessages();
556 ~ScopedIgnorePlatformMessages();
557 };
558
559 // Can be used before we get a GL context.
isGLRenderer()560 bool isGLRenderer() const
561 {
562 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
563 }
564
isGLESRenderer()565 bool isGLESRenderer() const
566 {
567 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
568 }
569
isD3D11Renderer()570 bool isD3D11Renderer() const
571 {
572 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
573 }
574
isVulkanRenderer()575 bool isVulkanRenderer() const
576 {
577 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
578 }
579
isVulkanSwiftshaderRenderer()580 bool isVulkanSwiftshaderRenderer() const
581 {
582 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&
583 mCurrentParams->isSwiftshader();
584 }
585
586 bool platformSupportsMultithreading() const;
587
588 bool mIsSetUp = false;
589
590 private:
591 void checkD3D11SDKLayersMessages();
592
593 void drawQuad(GLuint program,
594 const std::string &positionAttribName,
595 GLfloat positionAttribZ,
596 GLfloat positionAttribXYScale,
597 bool useVertexBuffer,
598 bool useInstancedDrawCalls,
599 bool useTessellationPatches,
600 GLuint numInstances);
601
602 void initOSWindow();
603
604 struct TestFixture
605 {
606 TestFixture();
607 ~TestFixture();
608
609 EGLWindow *eglWindow = nullptr;
610 WGLWindow *wglWindow = nullptr;
611 OSWindow *osWindow = nullptr;
612 ConfigParameters configParams;
613 uint32_t reuseCounter = 0;
614 };
615
616 int mWidth;
617 int mHeight;
618
619 bool mIgnoreD3D11SDKLayersWarnings;
620
621 // Used for indexed quad rendering
622 GLuint mQuadVertexBuffer;
623 GLuint mQuadIndexBuffer;
624
625 // Used for texture rendering.
626 GLuint m2DTexturedQuadProgram;
627 GLuint m3DTexturedQuadProgram;
628 GLuint m2DArrayTexturedQuadProgram;
629
630 bool mDeferContextInit;
631 bool mAlwaysForceNewDisplay;
632 bool mForceNewDisplay;
633
634 bool mSetUpCalled;
635 bool mTearDownCalled;
636
637 // Usually, we use an OS Window per "fixture" (a frontend and backend combination).
638 // This allows:
639 // 1. Reusing EGL Display on Windows.
640 // Other platforms have issues with display reuse even if a window per fixture is used.
641 // 2. Hiding only SwiftShader OS Window on Linux.
642 // OS Windows for other backends must be visible, to allow driver to communicate with X11.
643 // However, we must use a single OS Window for all backends on Android,
644 // since test Application can have only one window.
645 static OSWindow *mOSWindowSingleton;
646
647 static std::map<angle::PlatformParameters, TestFixture> gFixtures;
648 const angle::PlatformParameters *mCurrentParams;
649 TestFixture *mFixture;
650
651 RenderDoc mRenderDoc;
652
653 // Workaround for NVIDIA not being able to share a window with OpenGL and Vulkan.
654 static Optional<EGLint> mLastRendererType;
655 static Optional<angle::GLESDriverType> mLastLoadedDriver;
656 };
657
658 template <typename Params = angle::PlatformParameters>
659 class ANGLETest : public ANGLETestBase, public ::testing::TestWithParam<Params>
660 {
661 protected:
662 ANGLETest();
663
testSetUp()664 virtual void testSetUp() {}
testTearDown()665 virtual void testTearDown() {}
666
recreateTestFixture()667 void recreateTestFixture()
668 {
669 TearDown();
670 SetUp();
671 }
672
673 private:
SetUp()674 void SetUp() final
675 {
676 ANGLETestBase::ANGLETestSetUp();
677
678 if (mIsSetUp)
679 {
680 testSetUp();
681 }
682 }
683
TearDown()684 void TearDown() final
685 {
686 ANGLETestBase::ANGLETestPreTearDown();
687 if (mIsSetUp)
688 {
689 testTearDown();
690 }
691 ANGLETestBase::ANGLETestTearDown();
692 }
693 };
694
695 enum class APIExtensionVersion
696 {
697 Core,
698 OES,
699 EXT,
700 KHR,
701 };
702
703 template <typename Params>
ANGLETest()704 ANGLETest<Params>::ANGLETest()
705 : ANGLETestBase(std::get<angle::PlatformParameters>(this->GetParam()))
706 {}
707
708 template <>
ANGLETest()709 inline ANGLETest<angle::PlatformParameters>::ANGLETest() : ANGLETestBase(this->GetParam())
710 {}
711
712 class ANGLETestEnvironment : public testing::Environment
713 {
714 public:
715 void SetUp() override;
716 void TearDown() override;
717
718 static angle::Library *GetDriverLibrary(angle::GLESDriverType driver);
719
720 private:
721 static angle::Library *GetAngleEGLLibrary();
722 static angle::Library *GetAngleVulkanSecondariesEGLLibrary();
723 static angle::Library *GetMesaEGLLibrary();
724 static angle::Library *GetSystemEGLLibrary();
725 static angle::Library *GetSystemWGLLibrary();
726
727 // For loading entry points.
728 static std::unique_ptr<angle::Library> gAngleEGLLibrary;
729 static std::unique_ptr<angle::Library> gAngleVulkanSecondariesEGLLibrary;
730 static std::unique_ptr<angle::Library> gMesaEGLLibrary;
731 static std::unique_ptr<angle::Library> gSystemEGLLibrary;
732 static std::unique_ptr<angle::Library> gSystemWGLLibrary;
733 };
734
735 extern angle::PlatformMethods gDefaultPlatformMethods;
736
737 int GetTestStartDelaySeconds();
738
739 #endif // ANGLE_TESTS_ANGLE_TEST_H_
740