1 //
2 // Copyright 2015 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 // RendererTest:
7 //   These tests are designed to ensure that the various configurations of the test fixtures work as expected.
8 //   If one of these tests fails, then it is likely that some of the other tests are being configured incorrectly.
9 //   For example, they might be using the D3D11 renderer when the test is meant to be using the D3D9 renderer.
10 
11 #include "test_utils/ANGLETest.h"
12 
13 using namespace angle;
14 
15 namespace
16 {
17 
18 class RendererTest : public ANGLETest
19 {
20   protected:
RendererTest()21     RendererTest()
22     {
23         setWindowWidth(128);
24         setWindowHeight(128);
25     }
26 };
27 
TEST_P(RendererTest,RequestedRendererCreated)28 TEST_P(RendererTest, RequestedRendererCreated)
29 {
30     std::string rendererString = std::string(reinterpret_cast<const char*>(glGetString(GL_RENDERER)));
31     std::transform(rendererString.begin(), rendererString.end(), rendererString.begin(), ::tolower);
32 
33     std::string versionString = std::string(reinterpret_cast<const char*>(glGetString(GL_VERSION)));
34     std::transform(versionString.begin(), versionString.end(), versionString.begin(), ::tolower);
35 
36     const EGLPlatformParameters &platform = GetParam().eglParameters;
37 
38     // Ensure that the renderer string contains D3D11, if we requested a D3D11 renderer.
39     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
40     {
41         ASSERT_NE(rendererString.find(std::string("direct3d11")), std::string::npos);
42     }
43 
44     // Ensure that the renderer string contains D3D9, if we requested a D3D9 renderer.
45     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE)
46     {
47         ASSERT_NE(rendererString.find(std::string("direct3d9")), std::string::npos);
48     }
49 
50     // Ensure that the major and minor versions trigger expected behavior in D3D11
51     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
52     {
53         // Ensure that the renderer uses WARP, if we requested it.
54         if (platform.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE)
55         {
56             auto basicRenderPos = rendererString.find(std::string("microsoft basic render"));
57             auto softwareAdapterPos = rendererString.find(std::string("software adapter"));
58             ASSERT_TRUE(basicRenderPos != std::string::npos || softwareAdapterPos != std::string::npos);
59         }
60 
61         std::vector<std::string> acceptableShaderModels;
62 
63         // When no specific major/minor version is requested, then ANGLE should return the highest possible feature level by default.
64         // The current hardware driver might not support Feature Level 11_0, but WARP always does.
65         // Therefore if WARP is specified but no major/minor version is specified, then we test to check that ANGLE returns FL11_0.
66         if (platform.majorVersion >= 11 || platform.majorVersion == EGL_DONT_CARE)
67         {
68             // Feature Level 10_0 corresponds to shader model 5_0
69             acceptableShaderModels.push_back("ps_5_0");
70         }
71 
72         if (platform.majorVersion >= 10 || platform.majorVersion == EGL_DONT_CARE)
73         {
74             if (platform.minorVersion >= 1 || platform.minorVersion == EGL_DONT_CARE)
75             {
76                 // Feature Level 10_1 corresponds to shader model 4_1
77                 acceptableShaderModels.push_back("ps_4_1");
78             }
79 
80             if (platform.minorVersion >= 0 || platform.minorVersion == EGL_DONT_CARE)
81             {
82                 // Feature Level 10_0 corresponds to shader model 4_0
83                 acceptableShaderModels.push_back("ps_4_0");
84             }
85         }
86 
87         if (platform.majorVersion == 9 && platform.minorVersion == 3)
88         {
89             acceptableShaderModels.push_back("ps_4_0_level_9_3");
90         }
91 
92         bool found = false;
93         for (size_t i = 0; i < acceptableShaderModels.size(); i++)
94         {
95             if (rendererString.find(acceptableShaderModels[i]) != std::string::npos)
96             {
97                 found = true;
98             }
99         }
100 
101         ASSERT_TRUE(found);
102     }
103 
104     EGLint glesMajorVersion = GetParam().majorVersion;
105 
106     // Ensure that the renderer string contains GL ES 3.0, if we requested a GL ES 3.0
107     if (glesMajorVersion == 3)
108     {
109         ASSERT_NE(versionString.find(std::string("es 3.0")), std::string::npos);
110     }
111 
112     // Ensure that the version string contains GL ES 2.0, if we requested GL ES 2.0
113     if (glesMajorVersion == 2)
114     {
115         ASSERT_NE(versionString.find(std::string("es 2.0")), std::string::npos);
116     }
117 }
118 
119 // Perform a simple operation (clear and read pixels) to verify the device is working
TEST_P(RendererTest,SimpleOperation)120 TEST_P(RendererTest, SimpleOperation)
121 {
122     glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
123     glClear(GL_COLOR_BUFFER_BIT);
124     EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
125 }
126 
127 // Select configurations (e.g. which renderer, which GLES major version) these tests should be run against.
128 
129 ANGLE_INSTANTIATE_TEST(RendererTest,
130                        // ES2 on top of D3D9
131                        ES2_D3D9(),
132                        ES2_D3D9_REFERENCE(),
133 
134                        // ES2 on top of D3D11 feature level 9.3 to 11.0
135                        ES2_D3D11(),
136                        ES2_D3D11_FL11_0(),
137                        ES2_D3D11_FL10_1(),
138                        ES2_D3D11_FL10_0(),
139                        ES2_D3D11_FL9_3(),
140 
141                        // ES2 on top of D3D11 WARP feature level 9.3 to 11.0
142                        ES2_D3D11_WARP(),
143                        ES2_D3D11_FL11_0_WARP(),
144                        ES2_D3D11_FL10_1_WARP(),
145                        ES2_D3D11_FL10_0_WARP(),
146                        ES2_D3D11_FL9_3_WARP(),
147 
148                        // ES2 on top of D3D11 reference feature level 9.3 to 11.0
149                        ES2_D3D11_REFERENCE(),
150                        ES2_D3D11_FL11_0_REFERENCE(),
151                        ES2_D3D11_FL10_1_REFERENCE(),
152                        ES2_D3D11_FL10_0_REFERENCE(),
153                        ES2_D3D11_FL9_3_REFERENCE(),
154 
155                        // ES3 on top of D3D11 feature level 9.3 to 11.0
156                        ES3_D3D11(),
157                        ES3_D3D11_FL11_0(),
158                        ES3_D3D11_FL10_1(),
159                        ES3_D3D11_FL10_0(),
160 
161                        // ES3 on top of D3D11 WARP feature level 9.3 to 11.0
162                        ES3_D3D11_WARP(),
163                        ES3_D3D11_FL11_0_WARP(),
164                        ES3_D3D11_FL10_1_WARP(),
165                        ES3_D3D11_FL10_0_WARP(),
166 
167                        // ES3 on top of D3D11 reference feature level 9.3 to 11.0
168                        ES3_D3D11_REFERENCE(),
169                        ES3_D3D11_FL11_0_REFERENCE(),
170                        ES3_D3D11_FL10_1_REFERENCE(),
171                        ES3_D3D11_FL10_0_REFERENCE(),
172 
173                        // ES2 on top of desktop OpenGL versions 2.1 to 4.5
174                        ES2_OPENGL(),
175                        ES2_OPENGL(2, 1),
176                        ES2_OPENGL(3, 0),
177                        ES2_OPENGL(3, 1),
178                        ES2_OPENGL(3, 2),
179                        ES2_OPENGL(3, 3),
180                        ES2_OPENGL(4, 0),
181                        ES2_OPENGL(4, 1),
182                        ES2_OPENGL(4, 2),
183                        ES2_OPENGL(4, 3),
184                        ES2_OPENGL(4, 4),
185                        ES2_OPENGL(4, 5),
186 
187                        // ES2 on top of desktop OpenGL versions 3.2 to 4.5
188                        ES3_OPENGL(),
189                        ES3_OPENGL(3, 2),
190                        ES3_OPENGL(3, 3),
191                        ES3_OPENGL(4, 0),
192                        ES3_OPENGL(4, 1),
193                        ES3_OPENGL(4, 2),
194                        ES3_OPENGL(4, 3),
195                        ES3_OPENGL(4, 4),
196                        ES3_OPENGL(4, 5),
197 
198                        // ES2 on top of OpenGL ES 2.0 to 3.2
199                        ES2_OPENGLES(),
200                        ES2_OPENGLES(2, 0),
201                        ES2_OPENGLES(3, 0),
202                        ES2_OPENGLES(3, 1),
203                        ES2_OPENGLES(3, 2),
204 
205                        // ES2 on top of OpenGL ES 3.0 to 3.2
206                        ES3_OPENGLES(),
207                        ES3_OPENGLES(3, 0),
208                        ES3_OPENGLES(3, 1),
209                        ES3_OPENGLES(3, 2));
210 }
211