• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8 //   expected. If one of these tests fails, then it is likely that some of the other tests are being
9 //   configured incorrectly. For example, they might be using the D3D11 renderer when the test is
10 //   meant to be using the D3D9 renderer.
11 
12 #include "test_utils/ANGLETest.h"
13 
14 #include "common/string_utils.h"
15 
16 using namespace angle;
17 
18 namespace
19 {
20 
21 class RendererTest : public ANGLETest
22 {
23   protected:
RendererTest()24     RendererTest()
25     {
26         setWindowWidth(128);
27         setWindowHeight(128);
28     }
29 };
30 
31 // Print vendor, renderer, version and extension strings. Useful for debugging.
TEST_P(RendererTest,Strings)32 TEST_P(RendererTest, Strings)
33 {
34     std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
35     std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
36     std::cout << "Version: " << glGetString(GL_VERSION) << std::endl;
37     std::cout << "Extensions: " << glGetString(GL_EXTENSIONS) << std::endl;
38     EXPECT_GL_NO_ERROR();
39 }
40 
TEST_P(RendererTest,RequestedRendererCreated)41 TEST_P(RendererTest, RequestedRendererCreated)
42 {
43     std::string rendererString =
44         std::string(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
45     angle::ToLower(&rendererString);
46 
47     std::string versionString =
48         std::string(reinterpret_cast<const char *>(glGetString(GL_VERSION)));
49     angle::ToLower(&versionString);
50 
51     const EGLPlatformParameters &platform = GetParam().eglParameters;
52 
53     // Ensure that the renderer string contains D3D11, if we requested a D3D11 renderer.
54     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
55     {
56         ASSERT_NE(rendererString.find(std::string("direct3d11")), std::string::npos);
57     }
58 
59     // Ensure that the renderer string contains D3D9, if we requested a D3D9 renderer.
60     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE)
61     {
62         ASSERT_NE(rendererString.find(std::string("direct3d9")), std::string::npos);
63     }
64 
65     // Ensure that the major and minor versions trigger expected behavior in D3D11
66     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
67     {
68         // Ensure that the renderer uses WARP, if we requested it.
69         if (platform.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_D3D_WARP_ANGLE)
70         {
71             auto basicRenderPos     = rendererString.find(std::string("microsoft basic render"));
72             auto softwareAdapterPos = rendererString.find(std::string("software adapter"));
73             ASSERT_TRUE(basicRenderPos != std::string::npos ||
74                         softwareAdapterPos != std::string::npos);
75         }
76 
77         std::vector<std::string> acceptableShaderModels;
78 
79         // When no specific major/minor version is requested, then ANGLE should return the highest
80         // possible feature level by default. The current hardware driver might not support Feature
81         // Level 11_0, but WARP always does. Therefore if WARP is specified but no major/minor
82         // version is specified, then we test to check that ANGLE returns FL11_0.
83         if (platform.majorVersion >= 11 || platform.majorVersion == EGL_DONT_CARE)
84         {
85             // Feature Level 10_0 corresponds to shader model 5_0
86             acceptableShaderModels.push_back("ps_5_0");
87         }
88 
89         if (platform.majorVersion >= 10 || platform.majorVersion == EGL_DONT_CARE)
90         {
91             if (platform.minorVersion >= 1 || platform.minorVersion == EGL_DONT_CARE)
92             {
93                 // Feature Level 10_1 corresponds to shader model 4_1
94                 acceptableShaderModels.push_back("ps_4_1");
95             }
96 
97             if (platform.minorVersion >= 0 || platform.minorVersion == EGL_DONT_CARE)
98             {
99                 // Feature Level 10_0 corresponds to shader model 4_0
100                 acceptableShaderModels.push_back("ps_4_0");
101             }
102         }
103 
104         if (platform.majorVersion == 9 && platform.minorVersion == 3)
105         {
106             acceptableShaderModels.push_back("ps_4_0_level_9_3");
107         }
108 
109         bool found = false;
110         for (size_t i = 0; i < acceptableShaderModels.size(); i++)
111         {
112             if (rendererString.find(acceptableShaderModels[i]) != std::string::npos)
113             {
114                 found = true;
115             }
116         }
117 
118         ASSERT_TRUE(found);
119     }
120 
121     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE)
122     {
123         ASSERT_TRUE(IsNULL());
124     }
125 
126     if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
127     {
128         ASSERT_TRUE(IsVulkan());
129     }
130 
131     EGLint glesMajorVersion = GetParam().majorVersion;
132     EGLint glesMinorVersion = GetParam().minorVersion;
133 
134     // Ensure that the renderer string contains the requested version number
135     if (glesMajorVersion == 3 && glesMinorVersion == 1)
136     {
137         ASSERT_NE(versionString.find(std::string("es 3.1")), std::string::npos);
138     }
139     else if (glesMajorVersion == 3 && glesMinorVersion == 0)
140     {
141         ASSERT_NE(versionString.find(std::string("es 3.0")), std::string::npos);
142     }
143     else if (glesMajorVersion == 2 && glesMinorVersion == 0)
144     {
145         ASSERT_NE(versionString.find(std::string("es 2.0")), std::string::npos);
146     }
147     else
148     {
149         FAIL() << "Unhandled GL ES client version.";
150     }
151 
152     ASSERT_GL_NO_ERROR();
153     ASSERT_EGL_SUCCESS();
154 }
155 
156 // Perform a simple operation (clear and read pixels) to verify the device is working
TEST_P(RendererTest,SimpleOperation)157 TEST_P(RendererTest, SimpleOperation)
158 {
159     if (IsNULL())
160     {
161         std::cout << "ANGLE NULL backend clears are not functional" << std::endl;
162         return;
163     }
164 
165     glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
166     glClear(GL_COLOR_BUFFER_BIT);
167     EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
168 
169     ASSERT_GL_NO_ERROR();
170 }
171 
172 // Select configurations (e.g. which renderer, which GLES major version) these tests should be run
173 // against.
174 
175 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND_ES31_AND_NULL(RendererTest);
176 }  // anonymous namespace
177