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 "common/string_utils.h"
13 #include "test_utils/ANGLETest.h"
14 #include "test_utils/gl_raii.h"
15 #include "util/shader_utils.h"
16 #include "util/test_utils.h"
17
18 using namespace angle;
19
20 namespace angle
21 {
22
23 class RendererTest : public ANGLETest<>
24 {
25 protected:
RendererTest()26 RendererTest()
27 {
28 setWindowWidth(128);
29 setWindowHeight(128);
30 }
31 };
32
33 // Print vendor, renderer, version and extension strings. Useful for debugging.
TEST_P(RendererTest,Strings)34 TEST_P(RendererTest, Strings)
35 {
36 std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
37 std::cout << "Vendor: " << glGetString(GL_VENDOR) << std::endl;
38 std::cout << "Version: " << glGetString(GL_VERSION) << std::endl;
39 std::cout << "Extensions: " << glGetString(GL_EXTENSIONS) << std::endl;
40 EXPECT_GL_NO_ERROR();
41 }
42
TEST_P(RendererTest,RequestedRendererCreated)43 TEST_P(RendererTest, RequestedRendererCreated)
44 {
45 std::string rendererString =
46 std::string(reinterpret_cast<const char *>(glGetString(GL_RENDERER)));
47 angle::ToLower(&rendererString);
48
49 std::string versionString =
50 std::string(reinterpret_cast<const char *>(glGetString(GL_VERSION)));
51 angle::ToLower(&versionString);
52
53 const EGLPlatformParameters &platform = GetParam().eglParameters;
54
55 // Ensure that the renderer string contains D3D11, if we requested a D3D11 renderer.
56 if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
57 {
58 ASSERT_NE(rendererString.find(std::string("direct3d11")), std::string::npos);
59 }
60
61 // Ensure that the renderer string contains D3D9, if we requested a D3D9 renderer.
62 if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE)
63 {
64 ASSERT_NE(rendererString.find(std::string("direct3d9")), std::string::npos);
65 }
66
67 // Ensure that the major and minor versions trigger expected behavior in D3D11
68 if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
69 {
70 // Ensure that the renderer uses WARP, if we requested it.
71 if (platform.deviceType == EGL_PLATFORM_ANGLE_DEVICE_TYPE_D3D_WARP_ANGLE)
72 {
73 auto basicRenderPos = rendererString.find(std::string("microsoft basic render"));
74 auto softwareAdapterPos = rendererString.find(std::string("software adapter"));
75 ASSERT_TRUE(basicRenderPos != std::string::npos ||
76 softwareAdapterPos != std::string::npos);
77 }
78
79 std::vector<std::string> acceptableShaderModels;
80
81 // When no specific major/minor version is requested, then ANGLE should return the highest
82 // possible feature level by default. The current hardware driver might not support Feature
83 // Level 11_0, but WARP always does. Therefore if WARP is specified but no major/minor
84 // version is specified, then we test to check that ANGLE returns FL11_0.
85 if (platform.majorVersion >= 11 || platform.majorVersion == EGL_DONT_CARE)
86 {
87 // Feature Level 10_0 corresponds to shader model 5_0
88 acceptableShaderModels.push_back("ps_5_0");
89 }
90
91 if (platform.majorVersion >= 10 || platform.majorVersion == EGL_DONT_CARE)
92 {
93 if (platform.minorVersion >= 1 || platform.minorVersion == EGL_DONT_CARE)
94 {
95 // Feature Level 10_1 corresponds to shader model 4_1
96 acceptableShaderModels.push_back("ps_4_1");
97 }
98
99 if (platform.minorVersion >= 0 || platform.minorVersion == EGL_DONT_CARE)
100 {
101 // Feature Level 10_0 corresponds to shader model 4_0
102 acceptableShaderModels.push_back("ps_4_0");
103 }
104 }
105
106 if (platform.majorVersion == 9 && platform.minorVersion == 3)
107 {
108 acceptableShaderModels.push_back("ps_4_0_level_9_3");
109 }
110
111 bool found = false;
112 for (size_t i = 0; i < acceptableShaderModels.size(); i++)
113 {
114 if (rendererString.find(acceptableShaderModels[i]) != std::string::npos)
115 {
116 found = true;
117 }
118 }
119
120 ASSERT_TRUE(found);
121 }
122
123 if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE)
124 {
125 ASSERT_TRUE(IsNULL());
126 }
127
128 if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
129 {
130 ASSERT_TRUE(IsVulkan());
131 }
132
133 EGLint glesMajorVersion = GetParam().majorVersion;
134 EGLint glesMinorVersion = GetParam().minorVersion;
135
136 std::ostringstream expectedVersionString;
137 if (GetParam().clientType == EGL_OPENGL_ES_API)
138 {
139 expectedVersionString << "es ";
140 }
141 expectedVersionString << glesMajorVersion << "." << glesMinorVersion;
142
143 ASSERT_NE(versionString.find(expectedVersionString.str()), std::string::npos);
144
145 ASSERT_GL_NO_ERROR();
146 ASSERT_EGL_SUCCESS();
147 }
148
149 // Perform a simple operation (clear and read pixels) to verify the device is working
TEST_P(RendererTest,SimpleOperation)150 TEST_P(RendererTest, SimpleOperation)
151 {
152 if (IsNULL())
153 {
154 std::cout << "ANGLE NULL backend clears are not functional" << std::endl;
155 return;
156 }
157
158 glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
159 glClear(GL_COLOR_BUFFER_BIT);
160 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
161
162 ASSERT_GL_NO_ERROR();
163 }
164
165 // Perform a simple buffer operation.
TEST_P(RendererTest,BufferData)166 TEST_P(RendererTest, BufferData)
167 {
168 constexpr size_t kBufferSize = 1024;
169 std::array<uint8_t, kBufferSize> data;
170 for (size_t i = 0; i < kBufferSize; i++)
171 {
172 data[i] = static_cast<uint8_t>(i);
173 }
174
175 // All at once in the glBufferData call
176 {
177 GLBuffer buffer;
178 glBindBuffer(GL_ARRAY_BUFFER, buffer);
179
180 glBufferData(GL_ARRAY_BUFFER, 1024, data.data(), GL_STATIC_DRAW);
181 }
182
183 // Set data with sub data
184 {
185 GLBuffer buffer;
186 glBindBuffer(GL_ARRAY_BUFFER, buffer);
187
188 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
189 glBufferSubData(GL_ARRAY_BUFFER, 0, kBufferSize, data.data());
190 }
191 }
192
193 // Compile simple vertex and fragment shaders
TEST_P(RendererTest,CompileShader)194 TEST_P(RendererTest, CompileShader)
195 {
196 GLuint vs = CompileShader(GL_VERTEX_SHADER, essl1_shaders::vs::Zero());
197 EXPECT_NE(vs, 0u);
198 glDeleteShader(vs);
199
200 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, essl1_shaders::fs::Red());
201 EXPECT_NE(fs, 0u);
202 glDeleteShader(fs);
203 }
204
205 // Link a simple program
TEST_P(RendererTest,LinkProgram)206 TEST_P(RendererTest, LinkProgram)
207 {
208 ANGLE_GL_PROGRAM(prog, essl1_shaders::vs::Zero(), essl1_shaders::fs::Red());
209 }
210
211 // Select configurations (e.g. which renderer, which GLES major version) these tests should be run
212 // against.
213 // TODO(http://anglebug.com/8485): move ES2_WEBGPU to the definition of ANGLE_ALL_TEST_PLATFORMS_ES2
214 // once webgpu is developed enough to run more tests.
215 ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND_ES31_AND_NULL_AND(RendererTest,
216 ANGLE_ALL_TEST_PLATFORMS_GL32_CORE,
217 ES2_WEBGPU());
218 } // namespace angle
219