am cf930726: am cb9402de: am e5fc2a80: Relax fma() verification in builtin_functions...
[platform/upstream/VK-GL-CTS.git] / modules / egl / teglRenderCase.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program EGL Module
3  * ---------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Base class for rendering tests.
22  *//*--------------------------------------------------------------------*/
23
24 #include "teglRenderCase.hpp"
25
26 #include "teglSimpleConfigCase.hpp"
27
28 #include "egluNativeDisplay.hpp"
29 #include "egluNativeWindow.hpp"
30 #include "egluNativePixmap.hpp"
31 #include "egluUtil.hpp"
32 #include "egluUnique.hpp"
33
34 #include "eglwLibrary.hpp"
35 #include "eglwEnums.hpp"
36
37 #include "tcuRenderTarget.hpp"
38 #include "tcuTestLog.hpp"
39 #include "tcuCommandLine.hpp"
40
41 #include "deStringUtil.hpp"
42 #include "deUniquePtr.hpp"
43
44 #include <algorithm>
45 #include <iterator>
46 #include <memory>
47 #include <set>
48
49 namespace deqp
50 {
51 namespace egl
52 {
53
54 using std::string;
55 using std::vector;
56 using std::set;
57 using tcu::TestLog;
58 using namespace eglw;
59
60 static void postSurface (const Library& egl, EGLDisplay display, EGLSurface surface, EGLint typeBit)
61 {
62         if (typeBit == EGL_WINDOW_BIT)
63                 EGLU_CHECK_CALL(egl, swapBuffers(display, surface));
64         else if (typeBit == EGL_PIXMAP_BIT)
65                 EGLU_CHECK_CALL(egl, waitClient());
66         else if (typeBit == EGL_PBUFFER_BIT)
67                 EGLU_CHECK_CALL(egl, waitClient());
68         else
69                 DE_ASSERT(false);
70 }
71
72 // RenderCase
73
74 RenderCase::RenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint apiMask, EGLint surfaceTypeMask, const eglu::FilterList& filters)
75         : SimpleConfigCase      (eglTestCtx, name, description, filters)
76         , m_apiMask                     (apiMask)
77         , m_surfaceTypeMask     (surfaceTypeMask)
78 {
79 }
80
81 RenderCase::~RenderCase (void)
82 {
83 }
84
85 EGLint getBuildClientAPIMask (void)
86 {
87         EGLint apiMask = 0;
88
89         // Always supported regardless of flags - dynamically loaded
90         apiMask |= EGL_OPENGL_ES2_BIT;
91         apiMask |= EGL_OPENGL_ES3_BIT;
92         apiMask |= EGL_OPENGL_BIT;
93
94 #if defined(DEQP_SUPPORT_GLES1)
95         apiMask |= EGL_OPENGL_ES_BIT;
96 #endif
97
98 #if defined(DEQP_SUPPORT_VG)
99         apiMask |= EGL_OPENVG_BIT;
100 #endif
101
102         return apiMask;
103 }
104
105 static void checkBuildClientAPISupport (EGLint requiredAPIs)
106 {
107         const EGLint    builtClientAPIs         = getBuildClientAPIMask();
108
109         if ((requiredAPIs & builtClientAPIs) != requiredAPIs)
110                 TCU_THROW(InternalError, "Test case requires client API not supported in current build");
111 }
112
113 void RenderCase::executeForConfig (EGLDisplay display, EGLConfig config)
114 {
115         const Library&                                          egl                             = m_eglTestCtx.getLibrary();
116         tcu::TestLog&                                           log                             = m_testCtx.getLog();
117         const int                                                       width                   = 128;
118         const int                                                       height                  = 128;
119         const EGLint                                            configId                = eglu::getConfigID(egl, display, config);
120
121         const eglu::NativeDisplayFactory&       displayFactory  = m_eglTestCtx.getNativeDisplayFactory();
122         eglu::NativeDisplay&                            nativeDisplay   = m_eglTestCtx.getNativeDisplay();
123
124         bool                                                            isOk                    = true;
125         string                                                          failReason              = "";
126
127         if (m_surfaceTypeMask & EGL_WINDOW_BIT)
128         {
129                 tcu::ScopedLogSection(log,
130                                                           string("Config") + de::toString(configId) + "-Window",
131                                                           string("Config ID ") + de::toString(configId) + ", window surface");
132
133                 const eglu::NativeWindowFactory*        windowFactory   = eglu::selectNativeWindowFactory(displayFactory, m_testCtx.getCommandLine());
134
135                 if (!windowFactory)
136                         TCU_THROW(NotSupportedError, "Windows not supported");
137
138                 try
139                 {
140                         const eglu::WindowParams                        params          (width, height, eglu::parseWindowVisibility(m_testCtx.getCommandLine()));
141                         de::UniquePtr<eglu::NativeWindow>       window          (windowFactory->createWindow(&nativeDisplay, display, config, DE_NULL, params));
142                         EGLSurface                                                      eglSurface      = createWindowSurface(nativeDisplay, *window, display, config, DE_NULL);
143                         eglu::UniqueSurface                                     surface         (egl, display, eglSurface);
144
145                         executeForSurface(display, *surface, Config(config, EGL_WINDOW_BIT, 0));
146                 }
147                 catch (const tcu::TestError& e)
148                 {
149                         log << e;
150                         isOk = false;
151                         failReason = e.what();
152                 }
153         }
154
155         if (m_surfaceTypeMask & EGL_PIXMAP_BIT)
156         {
157                 tcu::ScopedLogSection(log,
158                                                           string("Config") + de::toString(configId) + "-Pixmap",
159                                                           string("Config ID ") + de::toString(configId) + ", pixmap surface");
160
161                 const eglu::NativePixmapFactory*        pixmapFactory   = eglu::selectNativePixmapFactory(displayFactory, m_testCtx.getCommandLine());
162
163                 if (!pixmapFactory)
164                         TCU_THROW(NotSupportedError, "Windows not supported");
165
166                 try
167                 {
168                         std::auto_ptr<eglu::NativePixmap>       pixmap          (pixmapFactory->createPixmap(&nativeDisplay, display, config, DE_NULL, width, height));
169                         EGLSurface                                                      eglSurface      = createPixmapSurface(nativeDisplay, *pixmap, display, config, DE_NULL);
170                         eglu::UniqueSurface                                     surface         (egl, display, eglSurface);
171
172                         executeForSurface(display, *surface, Config(config, EGL_PIXMAP_BIT, 0));
173                 }
174                 catch (const tcu::TestError& e)
175                 {
176                         log << e;
177                         isOk = false;
178                         failReason = e.what();
179                 }
180         }
181
182         if (m_surfaceTypeMask & EGL_PBUFFER_BIT)
183         {
184                 tcu::ScopedLogSection(log,
185                                                           string("Config") + de::toString(configId) + "-Pbuffer",
186                                                           string("Config ID ") + de::toString(configId) + ", pbuffer surface");
187                 try
188                 {
189                         const EGLint surfaceAttribs[] =
190                         {
191                                 EGL_WIDTH,      width,
192                                 EGL_HEIGHT,     height,
193                                 EGL_NONE
194                         };
195
196                         eglu::UniqueSurface surface(egl, display, egl.createPbufferSurface(display, config, surfaceAttribs));
197                         EGLU_CHECK_MSG(egl, "eglCreatePbufferSurface()");
198
199                         executeForSurface(display, *surface, Config(config, EGL_PBUFFER_BIT, 0));
200                 }
201                 catch (const tcu::TestError& e)
202                 {
203                         log << e;
204                         isOk = false;
205                         failReason = e.what();
206                 }
207         }
208
209         if (!isOk && m_testCtx.getTestResult() == QP_TEST_RESULT_PASS)
210                 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, failReason.c_str());
211 }
212
213 // SingleContextRenderCase
214
215 SingleContextRenderCase::SingleContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint apiMask, EGLint surfaceTypeMask, const eglu::FilterList& filters)
216         : RenderCase(eglTestCtx, name, description, apiMask, surfaceTypeMask, filters)
217 {
218 }
219
220 SingleContextRenderCase::~SingleContextRenderCase (void)
221 {
222 }
223
224 void SingleContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
225 {
226         const Library&          egl             = m_eglTestCtx.getLibrary();
227         const EGLint            apis[]  = { EGL_OPENGL_ES2_BIT, EGL_OPENGL_ES3_BIT_KHR, EGL_OPENGL_ES_BIT, EGL_OPENVG_BIT };
228         tcu::TestLog&           log             = m_testCtx.getLog();
229
230         checkBuildClientAPISupport(m_apiMask);
231
232         for (int apiNdx = 0; apiNdx < DE_LENGTH_OF_ARRAY(apis); apiNdx++)
233         {
234                 EGLint apiBit = apis[apiNdx];
235
236                 if ((apiBit & m_apiMask) == 0)
237                         continue; // Skip this api.
238
239                 EGLint                  api             = EGL_NONE;
240                 const char*             apiName = DE_NULL;
241                 vector<EGLint>  contextAttribs;
242
243                 // Select api enum and build context attributes.
244                 switch (apiBit)
245                 {
246                         case EGL_OPENGL_ES2_BIT:
247                                 api             = EGL_OPENGL_ES_API;
248                                 apiName = "OpenGL ES 2.x";
249                                 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
250                                 contextAttribs.push_back(2);
251                                 break;
252
253                         case EGL_OPENGL_ES3_BIT_KHR:
254                                 api             = EGL_OPENGL_ES_API;
255                                 apiName = "OpenGL ES 3.x";
256                                 contextAttribs.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR);
257                                 contextAttribs.push_back(3);
258                                 break;
259
260                         case EGL_OPENGL_ES_BIT:
261                                 api             = EGL_OPENGL_ES_API;
262                                 apiName = "OpenGL ES 1.x";
263                                 contextAttribs.push_back(EGL_CONTEXT_CLIENT_VERSION);
264                                 contextAttribs.push_back(1);
265                                 break;
266
267                         case EGL_OPENVG_BIT:
268                                 api             = EGL_OPENVG_API;
269                                 apiName = "OpenVG";
270                                 break;
271
272                         default:
273                                 DE_ASSERT(DE_FALSE);
274                 }
275
276                 contextAttribs.push_back(EGL_NONE);
277
278                 log << TestLog::Message << apiName << TestLog::EndMessage;
279
280                 EGLU_CHECK_CALL(egl, bindAPI(api));
281
282                 eglu::UniqueContext     context (egl, display, egl.createContext(display, config.config, EGL_NO_CONTEXT, &contextAttribs[0]));
283
284                 EGLU_CHECK_CALL(egl, makeCurrent(display, surface, surface, *context));
285                 executeForContext(display, *context, surface, Config(config.config, config.surfaceTypeBit, apiBit));
286
287                 // Call SwapBuffers() / WaitClient() to finish rendering
288                 postSurface(egl, display, surface, config.surfaceTypeBit);
289         }
290
291         EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
292 }
293
294 // MultiContextRenderCase
295
296 MultiContextRenderCase::MultiContextRenderCase (EglTestContext& eglTestCtx, const char* name, const char* description, EGLint api, EGLint surfaceType, const eglu::FilterList& filters, int numContextsPerApi)
297         : RenderCase                    (eglTestCtx, name, description, api, surfaceType, filters)
298         , m_numContextsPerApi   (numContextsPerApi)
299 {
300 }
301
302 MultiContextRenderCase::~MultiContextRenderCase (void)
303 {
304 }
305
306 void MultiContextRenderCase::executeForSurface (EGLDisplay display, EGLSurface surface, const Config& config)
307 {
308         const Library&                                                  egl             = m_eglTestCtx.getLibrary();
309         vector<std::pair<EGLint, EGLContext> >  contexts;
310         contexts.reserve(3*m_numContextsPerApi); // 3 types of contexts at maximum.
311
312         checkBuildClientAPISupport(m_apiMask);
313
314         try
315         {
316                 // Create contexts that will participate in rendering.
317                 for (int ndx = 0; ndx < m_numContextsPerApi; ndx++)
318                 {
319                         if (m_apiMask & EGL_OPENGL_ES2_BIT)
320                         {
321                                 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
322                                 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
323                                 contexts.push_back(std::make_pair(EGL_OPENGL_ES2_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
324                         }
325
326                         if (m_apiMask & EGL_OPENGL_ES3_BIT_KHR)
327                         {
328                                 static const EGLint attribs[] = { EGL_CONTEXT_MAJOR_VERSION_KHR, 3, EGL_NONE };
329                                 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
330                                 contexts.push_back(std::make_pair(EGL_OPENGL_ES3_BIT_KHR, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
331                         }
332
333                         if (m_apiMask & EGL_OPENGL_ES_BIT)
334                         {
335                                 static const EGLint attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE };
336                                 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENGL_ES_API));
337                                 contexts.push_back(std::make_pair(EGL_OPENGL_ES_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
338                         }
339
340                         if (m_apiMask & EGL_OPENVG_BIT)
341                         {
342                                 static const EGLint attribs[] = { EGL_NONE };
343                                 EGLU_CHECK_CALL(egl, bindAPI(EGL_OPENVG_API));
344                                 contexts.push_back(std::make_pair(EGL_OPENVG_BIT, egl.createContext(display, config.config, EGL_NO_CONTEXT, &attribs[0])));
345                         }
346                 }
347
348                 EGLU_CHECK_MSG(egl, "eglCreateContext()");
349
350                 // Execute for contexts.
351                 executeForContexts(display, surface, Config(config.config, config.surfaceTypeBit, m_apiMask), contexts);
352
353                 EGLU_CHECK_CALL(egl, makeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
354         }
355         catch (...)
356         {
357                 // Make sure all contexts have been destroyed.
358                 for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
359                         egl.destroyContext(display, i->second);
360                 throw;
361         }
362
363         // Destroy contexts.
364         for (vector<std::pair<EGLint, EGLContext> >::iterator i = contexts.begin(); i != contexts.end(); i++)
365                 egl.destroyContext(display, i->second);
366 }
367
368 // Utilities
369
370 template <int Red, int Green, int Blue, int Alpha>
371 static bool colorBits (const eglu::CandidateConfig& c)
372 {
373         return c.redSize()              == Red          &&
374                    c.greenSize()        == Green        &&
375                    c.blueSize()         == Blue         &&
376                    c.alphaSize()        == Alpha;
377 }
378
379 template <int Red, int Green, int Blue, int Alpha>
380 static bool notColorBits (const eglu::CandidateConfig& c)
381 {
382         return c.redSize()              != Red          ||
383                    c.greenSize()        != Green        ||
384                    c.blueSize()         != Blue         ||
385                    c.alphaSize()        != Alpha;
386 }
387
388 template <deUint32 Type>
389 static bool surfaceType (const eglu::CandidateConfig& c)
390 {
391         return (c.surfaceType() & Type) == Type;
392 }
393
394 void getDefaultRenderFilterLists (vector<RenderFilterList>& filterLists, const eglu::FilterList& baseFilters)
395 {
396         static const struct
397         {
398                 const char*                     name;
399                 eglu::ConfigFilter      filter;
400         } s_colorRules[] =
401         {
402                 { "rgb565",             colorBits<5, 6, 5, 0>   },
403                 { "rgb888",             colorBits<8, 8, 8, 0>   },
404                 { "rgba4444",   colorBits<4, 4, 4, 4>   },
405                 { "rgba5551",   colorBits<5, 5, 5, 1>   },
406                 { "rgba8888",   colorBits<8, 8, 8, 8>   },
407         };
408
409         static const struct
410         {
411                 const char*                     name;
412                 EGLint                          bits;
413                 eglu::ConfigFilter      filter;
414         } s_surfaceRules[] =
415         {
416                 { "window",             EGL_WINDOW_BIT,         surfaceType<EGL_WINDOW_BIT>             },
417                 { "pixmap",             EGL_PIXMAP_BIT,         surfaceType<EGL_PIXMAP_BIT>,    },
418                 { "pbuffer",    EGL_PBUFFER_BIT,        surfaceType<EGL_PBUFFER_BIT>    }
419         };
420
421         for (int colorNdx = 0; colorNdx < DE_LENGTH_OF_ARRAY(s_colorRules); colorNdx++)
422         {
423                 for (int surfaceNdx = 0; surfaceNdx < DE_LENGTH_OF_ARRAY(s_surfaceRules); surfaceNdx++)
424                 {
425                         const string            name    = string(s_colorRules[colorNdx].name) + "_" + s_surfaceRules[surfaceNdx].name;
426                         RenderFilterList        filters (name.c_str(), "", s_surfaceRules[surfaceNdx].bits);
427
428                         filters << baseFilters
429                                         << s_colorRules[colorNdx].filter
430                                         << s_surfaceRules[surfaceNdx].filter;
431
432                         filterLists.push_back(filters);
433                 }
434         }
435
436         // Add other config ids to "other" set
437         {
438                 RenderFilterList        filters ("other", "", EGL_WINDOW_BIT|EGL_PIXMAP_BIT|EGL_PBUFFER_BIT);
439
440                 filters << baseFilters
441                                 << notColorBits<5, 6, 5, 0>
442                                 << notColorBits<8, 8, 8, 0>
443                                 << notColorBits<4, 4, 4, 4>
444                                 << notColorBits<5, 5, 5, 1>
445                                 << notColorBits<8, 8, 8, 8>;
446
447                 filterLists.push_back(filters);
448         }
449 }
450
451 } // egl
452 } // deqp