4686f5b22a45705eea19cb74a98a5d3c05b93d5c
[platform/upstream/VK-GL-CTS.git] / external / openglcts / modules / gl / gl4cEnhancedLayoutsTests.cpp
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
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
22  */ /*-------------------------------------------------------------------*/
23
24 /**
25  * \file  gl4cEnhancedLayoutsTests.cpp
26  * \brief Implements conformance tests for "Enhanced Layouts" functionality.
27  */ /*-------------------------------------------------------------------*/
28
29 #include "gl4cEnhancedLayoutsTests.hpp"
30
31 #include "gluContextInfo.hpp"
32 #include "gluDefs.hpp"
33 #include "gluStrUtil.hpp"
34 #include "glwEnums.hpp"
35 #include "glwFunctions.hpp"
36 #include "tcuTestLog.hpp"
37
38 #include <algorithm>
39 #include <iomanip>
40 #include <string>
41 #include <vector>
42
43 /* DEBUG */
44 #define USE_NSIGHT 0
45 #define DEBUG_ENBALE_MESSAGE_CALLBACK 0
46 #define DEBUG_NEG_LOG_ERROR 0
47 #define DEBUG_REPLACE_TOKEN 0
48 #define DEBUG_REPEAT_TEST_CASE 0
49 #define DEBUG_REPEATED_TEST_CASE 0
50
51 /* Texture test base */
52 #define DEBUG_TTB_VERIFICATION_SNIPPET_STAGE 0
53 #define DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE 0
54
55 /* Tests */
56 #define DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE 0
57
58 /* WORKAROUNDS */
59 #define WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST 0
60 #define WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST 0
61 #define WRKARD_UNIFORMBLOCKALIGNMENT 0
62 #define WRKARD_VARYINGLOCATIONSTEST 0
63
64 using namespace glw;
65
66 namespace gl4cts
67 {
68 namespace EnhancedLayouts
69 {
70 namespace Utils
71 {
72 /** Constants used by "random" generators **/
73 static const GLuint s_rand_start        = 3;
74 static const GLuint s_rand_max          = 16;
75 static const GLuint s_rand_max_half = s_rand_max / 2;
76
77 /** Seed used by "random" generators **/
78 static GLuint s_rand = s_rand_start;
79
80 /** Get "random" unsigned int value
81  *
82  * @return Value
83  **/
84 static GLuint GetRandUint()
85 {
86         const GLuint rand = s_rand++;
87
88         if (s_rand_max <= s_rand)
89         {
90                 s_rand = s_rand_start;
91         }
92
93         return rand;
94 }
95
96 /** Get "random" int value
97  *
98  * @return Value
99  **/
100 GLint GetRandInt()
101 {
102         const GLint rand = GetRandUint() - s_rand_max_half;
103
104         return rand;
105 }
106
107 /** Get "random" double value
108  *
109  * @return Value
110  **/
111 GLdouble GetRandDouble()
112 {
113         const GLint rand = GetRandInt();
114
115         GLdouble result = (GLfloat)rand / (GLdouble)s_rand_max_half;
116
117         return result;
118 }
119
120 /** Get "random" float value
121  *
122  * @return Value
123  **/
124 GLfloat GetRandFloat()
125 {
126         const GLint rand = GetRandInt();
127
128         GLfloat result = (GLfloat)rand / (GLfloat)s_rand_max_half;
129
130         return result;
131 }
132
133 /** String used by list routines **/
134 static const GLchar* const g_list = "LIST";
135
136 /** Type constants **/
137 const Type Type::_double = Type::GetType(Type::Double, 1, 1);
138 const Type Type::dmat2   = Type::GetType(Type::Double, 2, 2);
139 const Type Type::dmat2x3 = Type::GetType(Type::Double, 2, 3);
140 const Type Type::dmat2x4 = Type::GetType(Type::Double, 2, 4);
141 const Type Type::dmat3x2 = Type::GetType(Type::Double, 3, 2);
142 const Type Type::dmat3   = Type::GetType(Type::Double, 3, 3);
143 const Type Type::dmat3x4 = Type::GetType(Type::Double, 3, 4);
144 const Type Type::dmat4x2 = Type::GetType(Type::Double, 4, 2);
145 const Type Type::dmat4x3 = Type::GetType(Type::Double, 4, 3);
146 const Type Type::dmat4   = Type::GetType(Type::Double, 4, 4);
147 const Type Type::dvec2   = Type::GetType(Type::Double, 1, 2);
148 const Type Type::dvec3   = Type::GetType(Type::Double, 1, 3);
149 const Type Type::dvec4   = Type::GetType(Type::Double, 1, 4);
150 const Type Type::_int   = Type::GetType(Type::Int, 1, 1);
151 const Type Type::ivec2   = Type::GetType(Type::Int, 1, 2);
152 const Type Type::ivec3   = Type::GetType(Type::Int, 1, 3);
153 const Type Type::ivec4   = Type::GetType(Type::Int, 1, 4);
154 const Type Type::_float  = Type::GetType(Type::Float, 1, 1);
155 const Type Type::mat2   = Type::GetType(Type::Float, 2, 2);
156 const Type Type::mat2x3  = Type::GetType(Type::Float, 2, 3);
157 const Type Type::mat2x4  = Type::GetType(Type::Float, 2, 4);
158 const Type Type::mat3x2  = Type::GetType(Type::Float, 3, 2);
159 const Type Type::mat3   = Type::GetType(Type::Float, 3, 3);
160 const Type Type::mat3x4  = Type::GetType(Type::Float, 3, 4);
161 const Type Type::mat4x2  = Type::GetType(Type::Float, 4, 2);
162 const Type Type::mat4x3  = Type::GetType(Type::Float, 4, 3);
163 const Type Type::mat4   = Type::GetType(Type::Float, 4, 4);
164 const Type Type::vec2   = Type::GetType(Type::Float, 1, 2);
165 const Type Type::vec3   = Type::GetType(Type::Float, 1, 3);
166 const Type Type::vec4   = Type::GetType(Type::Float, 1, 4);
167 const Type Type::uint   = Type::GetType(Type::Uint, 1, 1);
168 const Type Type::uvec2   = Type::GetType(Type::Uint, 1, 2);
169 const Type Type::uvec3   = Type::GetType(Type::Uint, 1, 3);
170 const Type Type::uvec4   = Type::GetType(Type::Uint, 1, 4);
171
172 /** Generate data for type. This routine follows STD140 rules
173  *
174  * @return Vector of bytes filled with data
175  **/
176 std::vector<GLubyte> Type::GenerateData() const
177 {
178         const GLuint alignment = GetActualAlignment(0, false);
179
180         std::vector<GLubyte> data;
181         data.resize(alignment * m_n_columns);
182
183         for (GLuint column = 0; column < m_n_columns; ++column)
184         {
185                 GLvoid* ptr = (GLvoid*)&data[column * alignment];
186
187                 switch (m_basic_type)
188                 {
189                 case Double:
190                 {
191                         GLdouble* d_ptr = (GLdouble*)ptr;
192
193                         for (GLuint i = 0; i < m_n_rows; ++i)
194                         {
195                                 d_ptr[i] = GetRandDouble();
196                         }
197                 }
198                 break;
199                 case Float:
200                 {
201                         GLfloat* f_ptr = (GLfloat*)ptr;
202
203                         for (GLuint i = 0; i < m_n_rows; ++i)
204                         {
205                                 f_ptr[i] = GetRandFloat();
206                         }
207                 }
208                 break;
209                 case Int:
210                 {
211                         GLint* i_ptr = (GLint*)ptr;
212
213                         for (GLuint i = 0; i < m_n_rows; ++i)
214                         {
215                                 i_ptr[i] = GetRandInt();
216                         }
217                 }
218                 break;
219                 case Uint:
220                 {
221                         GLuint* ui_ptr = (GLuint*)ptr;
222
223                         for (GLuint i = 0; i < m_n_rows; ++i)
224                         {
225                                 ui_ptr[i] = GetRandUint();
226                         }
227                 }
228                 break;
229                 }
230         }
231
232         return data;
233 }
234
235 /** Generate data for type. This routine packs data tightly.
236  *
237  * @return Vector of bytes filled with data
238  **/
239 std::vector<GLubyte> Type::GenerateDataPacked() const
240 {
241         const GLuint basic_size = GetTypeSize(m_basic_type);
242         const GLuint n_elements = m_n_columns * m_n_rows;
243         const GLuint size               = basic_size * n_elements;
244
245         std::vector<GLubyte> data;
246         data.resize(size);
247
248         GLvoid* ptr = (GLvoid*)&data[0];
249
250         switch (m_basic_type)
251         {
252         case Double:
253         {
254                 GLdouble* d_ptr = (GLdouble*)ptr;
255
256                 for (GLuint i = 0; i < n_elements; ++i)
257                 {
258                         d_ptr[i] = GetRandDouble();
259                 }
260         }
261         break;
262         case Float:
263         {
264                 GLfloat* f_ptr = (GLfloat*)ptr;
265
266                 for (GLuint i = 0; i < n_elements; ++i)
267                 {
268                         f_ptr[i] = GetRandFloat();
269                 }
270         }
271         break;
272         case Int:
273         {
274                 GLint* i_ptr = (GLint*)ptr;
275
276                 for (GLuint i = 0; i < n_elements; ++i)
277                 {
278                         i_ptr[i] = GetRandInt();
279                 }
280         }
281         break;
282         case Uint:
283         {
284                 GLuint* ui_ptr = (GLuint*)ptr;
285
286                 for (GLuint i = 0; i < n_elements; ++i)
287                 {
288                         ui_ptr[i] = GetRandUint();
289                 }
290         }
291         break;
292         }
293
294         return data;
295 }
296
297 /** Calculate "actual alignment". It work under assumption that align value is valid
298  *
299  * @param align    Requested alignment, eg with "align" qualifier
300  * @param is_array Selects if an array of type or single instance should be considered
301  *
302  * @return Calculated value
303  **/
304 GLuint Type::GetActualAlignment(GLuint align, bool is_array) const
305 {
306         const GLuint base_alignment = GetBaseAlignment(is_array);
307
308         return std::max(align, base_alignment);
309 }
310
311 /** Align given ofset with specified alignment
312  *
313  * @param offset    Offset
314  * @param alignment Alignment
315  *
316  * @return Calculated value
317  **/
318 GLuint align(GLuint offset, GLuint alignment)
319 {
320         const GLuint rest = offset % alignment;
321
322         if (0 != rest)
323         {
324                 GLuint missing = alignment - rest;
325                 offset += missing;
326         }
327
328         return offset;
329 }
330
331 /** Calculate "actual offset"
332  *
333  * @param start_offset     Requested offset
334  * @param actual_alignment Actual alignemnt
335  *
336  * @return Calculated value
337  **/
338 GLuint Type::GetActualOffset(GLuint start_offset, GLuint actual_alignment)
339 {
340         GLuint offset = align(start_offset, actual_alignment);
341
342         return offset;
343 }
344
345 /** Calculate "base alignment" for given type
346  *
347  * @param is_array Select if array or single instance should be considered
348  *
349  * @return Calculated value
350  **/
351 GLuint Type::GetBaseAlignment(bool is_array) const
352 {
353         GLuint elements = 1;
354
355         switch (m_n_rows)
356         {
357         case 2:
358                 elements = 2;
359                 break;
360         case 3:
361         case 4:
362                 elements = 4;
363                 break;
364         default:
365                 break;
366         }
367
368         GLuint N                 = GetTypeSize(m_basic_type);
369         GLuint alignment = N * elements;
370
371         if ((true == is_array) || (1 != m_n_columns))
372         {
373                 alignment = align(alignment, 16 /* vec4 alignment */);
374         }
375
376         return alignment;
377 }
378
379 /** Returns string representing GLSL constructor of type with arguments provided in data
380  *
381  * @param data Array of values that will be used as construcotr arguments.
382  *             It is interpreted as tightly packed array of type matching this type.
383  *
384  * @return String in form "Type(args)"
385  **/
386 std::string Type::GetGLSLConstructor(const GLvoid* data) const
387 {
388         const GLchar* type = GetGLSLTypeName();
389
390         std::stringstream stream;
391
392         stream << type << "(";
393
394         /* Scalar or vector */
395         if (1 == m_n_columns)
396         {
397                 for (GLuint row = 0; row < m_n_rows; ++row)
398                 {
399                         switch (m_basic_type)
400                         {
401                         case Double:
402                                 stream << ((GLdouble*)data)[row];
403                                 break;
404                         case Float:
405                                 stream << ((GLfloat*)data)[row];
406                                 break;
407                         case Int:
408                                 stream << ((GLint*)data)[row];
409                                 break;
410                         case Uint:
411                                 stream << ((GLuint*)data)[row];
412                                 break;
413                         }
414
415                         if (row + 1 != m_n_rows)
416                         {
417                                 stream << ", ";
418                         }
419                 }
420         }
421         else /* Matrix: mat(vec(), vec() .. ) */
422         {
423                 const GLuint basic_size = GetTypeSize(m_basic_type);
424                 // Very indescoverable defect, the column stride should be calculated by rows, such as mat2x3, which is 2, columns 3 rows, its column stride should be 3 * sizeof(float)
425                 const GLuint column_stride = m_n_rows * basic_size;
426                 const Type   column_type   = GetType(m_basic_type, 1, m_n_rows);
427
428                 for (GLuint column = 0; column < m_n_columns; ++column)
429                 {
430                         const GLuint  column_offset = column * column_stride;
431                         const GLvoid* column_data   = (GLubyte*)data + column_offset;
432
433                         stream << column_type.GetGLSLConstructor(column_data);
434
435                         if (column + 1 != m_n_columns)
436                         {
437                                 stream << ", ";
438                         }
439                 }
440         }
441
442         stream << ")";
443
444         return stream.str();
445 }
446
447 /** Get glsl name of the type
448  *
449  * @return Name of glsl type
450  **/
451 const glw::GLchar* Type::GetGLSLTypeName() const
452 {
453         static const GLchar* float_lut[4][4] = {
454                 { "float", "vec2", "vec3", "vec4" },
455                 { 0, "mat2", "mat2x3", "mat2x4" },
456                 { 0, "mat3x2", "mat3", "mat3x4" },
457                 { 0, "mat4x2", "mat4x3", "mat4" },
458         };
459
460         static const GLchar* double_lut[4][4] = {
461                 { "double", "dvec2", "dvec3", "dvec4" },
462                 { 0, "dmat2", "dmat2x3", "dmat2x4" },
463                 { 0, "dmat3x2", "dmat3", "dmat3x4" },
464                 { 0, "dmat4x2", "dmat4x3", "dmat4" },
465         };
466
467         static const GLchar* int_lut[4] = { "int", "ivec2", "ivec3", "ivec4" };
468
469         static const GLchar* uint_lut[4] = { "uint", "uvec2", "uvec3", "uvec4" };
470
471         const GLchar* result = 0;
472
473         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
474         {
475                 return 0;
476         }
477
478         switch (m_basic_type)
479         {
480         case Float:
481                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
482                 break;
483         case Double:
484                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
485                 break;
486         case Int:
487                 result = int_lut[m_n_rows - 1];
488                 break;
489         case Uint:
490                 result = uint_lut[m_n_rows - 1];
491                 break;
492         default:
493                 TCU_FAIL("Invliad enum");
494         }
495
496         return result;
497 }
498
499 /** Get number of locations required for the type
500  *
501  * @return Number of columns times:
502  *          - 2 when type is double with 3 or 4 rows,
503  *          - 1 otherwise.
504  **/
505 GLuint Type::GetLocations() const
506 {
507         GLuint n_loc_per_column;
508
509         /* 1 or 2 doubles any for rest */
510         if ((2 >= m_n_rows) || (Double != m_basic_type))
511         {
512                 n_loc_per_column = 1;
513         }
514         else
515         {
516                 /* 3 and 4 doubles */
517                 n_loc_per_column = 2;
518         }
519
520         return n_loc_per_column * m_n_columns;
521 }
522
523 /** Get size of the type in bytes.
524  * Note that this routine doesn't consider arrays and assumes
525  * column_major matrices.
526  *
527  * @return Formula:
528  *          - If std140 packaging and matrix; number of columns * base alignment
529  *          - Otherwise; number of elements * sizeof(base_type)
530  **/
531 GLuint Type::GetSize(const bool is_std140) const
532 {
533         const GLuint basic_type_size = GetTypeSize(m_basic_type);
534         const GLuint n_elements          = m_n_columns * m_n_rows;
535
536         if (is_std140 && m_n_columns > 1)
537         {
538                 return m_n_columns * GetBaseAlignment(false);
539         }
540
541         return basic_type_size * n_elements;
542 }
543
544 /** Get GLenum representing the type
545  *
546  * @return GLenum
547  **/
548 GLenum Type::GetTypeGLenum() const
549 {
550         static const GLenum float_lut[4][4] = {
551                 { GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4 },
552                 { 0, GL_FLOAT_MAT2, GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4 },
553                 { 0, GL_FLOAT_MAT3x2, GL_FLOAT_MAT3, GL_FLOAT_MAT3x4 },
554                 { 0, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3, GL_FLOAT_MAT4 },
555         };
556
557         static const GLenum double_lut[4][4] = {
558                 { GL_DOUBLE, GL_DOUBLE_VEC2, GL_DOUBLE_VEC3, GL_DOUBLE_VEC4 },
559                 { 0, GL_DOUBLE_MAT2, GL_DOUBLE_MAT2x3, GL_DOUBLE_MAT2x4 },
560                 { 0, GL_DOUBLE_MAT3x2, GL_DOUBLE_MAT3, GL_DOUBLE_MAT3x4 },
561                 { 0, GL_DOUBLE_MAT4x2, GL_DOUBLE_MAT4x3, GL_DOUBLE_MAT4 },
562         };
563
564         static const GLenum int_lut[4] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 };
565
566         static const GLenum uint_lut[4] = { GL_UNSIGNED_INT, GL_UNSIGNED_INT_VEC2, GL_UNSIGNED_INT_VEC3,
567                                                                                 GL_UNSIGNED_INT_VEC4 };
568
569         GLenum result = 0;
570
571         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
572         {
573                 return 0;
574         }
575
576         switch (m_basic_type)
577         {
578         case Float:
579                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
580                 break;
581         case Double:
582                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
583                 break;
584         case Int:
585                 result = int_lut[m_n_rows - 1];
586                 break;
587         case Uint:
588                 result = uint_lut[m_n_rows - 1];
589                 break;
590         default:
591                 TCU_FAIL("Invliad enum");
592         }
593
594         return result;
595 }
596
597 /** Calculate the numbe of components consumed by a type
598  *   according to 11.1.2.1 Output Variables
599  *
600  * @return Calculated number of components for the type
601  **/
602 GLuint Type::GetNumComponents() const
603 {
604         // Rule 3 of Section 7.6.2.2
605         // If the member is a three-component vector with components consuming N
606         // basic machine units, the base alignment is 4N.
607         GLuint num_components = (m_n_rows == 3 ? 4 : m_n_rows) * m_n_columns;
608
609         if (m_basic_type == Double)
610         {
611                 num_components *= 2;
612         }
613
614         return num_components;
615 }
616
617 /** Calculate stride for the type according to std140 rules
618  *
619  * @param alignment        Alignment of type
620  * @param n_columns        Number of columns
621  * @param n_array_elements Number of elements in array
622  *
623  * @return Calculated value
624  **/
625 GLuint Type::CalculateStd140Stride(GLuint alignment, GLuint n_columns, GLuint n_array_elements)
626 {
627         GLuint stride = alignment * n_columns;
628         if (0 != n_array_elements)
629         {
630                 stride *= n_array_elements;
631         }
632
633         return stride;
634 }
635
636 /** Check if glsl support matrices for specific basic type
637  *
638  * @param type Basic type
639  *
640  * @return true if matrices of <type> are supported, false otherwise
641  **/
642 bool Type::DoesTypeSupportMatrix(TYPES type)
643 {
644         bool result = false;
645
646         switch (type)
647         {
648         case Float:
649         case Double:
650                 result = true;
651                 break;
652         case Int:
653         case Uint:
654                 result = false;
655                 break;
656         default:
657                 TCU_FAIL("Invliad enum");
658         }
659
660         return result;
661 }
662
663 /** Creates instance of Type
664  *
665  * @param basic_type Select basic type of instance
666  * @param n_columns  Number of columns
667  * @param n_rows     Number of rows
668  *
669  * @return Type instance
670  **/
671 Type Type::GetType(TYPES basic_type, glw::GLuint n_columns, glw::GLuint n_rows)
672 {
673         Type type = { basic_type, n_columns, n_rows };
674
675         return type;
676 }
677
678 /** Get Size of given type in bytes
679  *
680  * @param type
681  *
682  * @return Size of type
683  **/
684 GLuint Type::GetTypeSize(TYPES type)
685 {
686         GLuint result = 0;
687
688         switch (type)
689         {
690         case Float:
691                 result = sizeof(GLfloat);
692                 break;
693         case Double:
694                 result = sizeof(GLdouble);
695                 break;
696         case Int:
697                 result = sizeof(GLint);
698                 break;
699         case Uint:
700                 result = sizeof(GLuint);
701                 break;
702         default:
703                 TCU_FAIL("Invalid enum");
704         }
705
706         return result;
707 }
708
709 /** Get GLenum representing given type
710  *
711  * @param type
712  *
713  * @return GLenum value
714  **/
715 GLenum Type::GetTypeGLenum(TYPES type)
716 {
717         GLenum result = 0;
718
719         switch (type)
720         {
721         case Float:
722                 result = GL_FLOAT;
723                 break;
724         case Double:
725                 result = GL_DOUBLE;
726                 break;
727         case Int:
728                 result = GL_INT;
729                 break;
730         case Uint:
731                 result = GL_UNSIGNED_INT;
732                 break;
733         default:
734                 TCU_FAIL("Invalid enum");
735         }
736
737         return result;
738 }
739
740 /** Get proper glUniformNdv routine for vectors with specified number of rows
741  *
742  * @param gl     GL functions
743  * @param n_rows Number of rows
744  *
745  * @return Function address
746  **/
747 uniformNdv getUniformNdv(const glw::Functions& gl, glw::GLuint n_rows)
748 {
749         uniformNdv result = 0;
750
751         switch (n_rows)
752         {
753         case 1:
754                 result = gl.uniform1dv;
755                 break;
756         case 2:
757                 result = gl.uniform2dv;
758                 break;
759         case 3:
760                 result = gl.uniform3dv;
761                 break;
762         case 4:
763                 result = gl.uniform4dv;
764                 break;
765         default:
766                 TCU_FAIL("Invalid number of rows");
767         }
768
769         return result;
770 }
771
772 /** Get proper glUniformNfv routine for vectors with specified number of rows
773  *
774  * @param gl     GL functions
775  * @param n_rows Number of rows
776  *
777  * @return Function address
778  **/
779 uniformNfv getUniformNfv(const glw::Functions& gl, glw::GLuint n_rows)
780 {
781         uniformNfv result = 0;
782
783         switch (n_rows)
784         {
785         case 1:
786                 result = gl.uniform1fv;
787                 break;
788         case 2:
789                 result = gl.uniform2fv;
790                 break;
791         case 3:
792                 result = gl.uniform3fv;
793                 break;
794         case 4:
795                 result = gl.uniform4fv;
796                 break;
797         default:
798                 TCU_FAIL("Invalid number of rows");
799         }
800
801         return result;
802 }
803
804 /** Get proper glUniformNiv routine for vectors with specified number of rows
805  *
806  * @param gl     GL functions
807  * @param n_rows Number of rows
808  *
809  * @return Function address
810  **/
811 uniformNiv getUniformNiv(const glw::Functions& gl, glw::GLuint n_rows)
812 {
813         uniformNiv result = 0;
814
815         switch (n_rows)
816         {
817         case 1:
818                 result = gl.uniform1iv;
819                 break;
820         case 2:
821                 result = gl.uniform2iv;
822                 break;
823         case 3:
824                 result = gl.uniform3iv;
825                 break;
826         case 4:
827                 result = gl.uniform4iv;
828                 break;
829         default:
830                 TCU_FAIL("Invalid number of rows");
831         }
832
833         return result;
834 }
835
836 /** Get proper glUniformNuiv routine for vectors with specified number of rows
837  *
838  * @param gl     GL functions
839  * @param n_rows Number of rows
840  *
841  * @return Function address
842  **/
843 uniformNuiv getUniformNuiv(const glw::Functions& gl, glw::GLuint n_rows)
844 {
845         uniformNuiv result = 0;
846
847         switch (n_rows)
848         {
849         case 1:
850                 result = gl.uniform1uiv;
851                 break;
852         case 2:
853                 result = gl.uniform2uiv;
854                 break;
855         case 3:
856                 result = gl.uniform3uiv;
857                 break;
858         case 4:
859                 result = gl.uniform4uiv;
860                 break;
861         default:
862                 TCU_FAIL("Invalid number of rows");
863         }
864
865         return result;
866 }
867
868 /** Get proper glUniformMatrixNdv routine for matrix with specified number of columns and rows
869  *
870  * @param gl     GL functions
871  * @param n_rows Number of rows
872  *
873  * @return Function address
874  **/
875 uniformMatrixNdv getUniformMatrixNdv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
876 {
877         uniformMatrixNdv result = 0;
878
879         switch (n_columns)
880         {
881         case 2:
882                 switch (n_rows)
883                 {
884                 case 2:
885                         result = gl.uniformMatrix2dv;
886                         break;
887                 case 3:
888                         result = gl.uniformMatrix2x3dv;
889                         break;
890                 case 4:
891                         result = gl.uniformMatrix2x4dv;
892                         break;
893                 default:
894                         TCU_FAIL("Invalid number of rows");
895                 }
896                 break;
897         case 3:
898                 switch (n_rows)
899                 {
900                 case 2:
901                         result = gl.uniformMatrix3x2dv;
902                         break;
903                 case 3:
904                         result = gl.uniformMatrix3dv;
905                         break;
906                 case 4:
907                         result = gl.uniformMatrix3x4dv;
908                         break;
909                 default:
910                         TCU_FAIL("Invalid number of rows");
911                 }
912                 break;
913         case 4:
914                 switch (n_rows)
915                 {
916                 case 2:
917                         result = gl.uniformMatrix4x2dv;
918                         break;
919                 case 3:
920                         result = gl.uniformMatrix4x3dv;
921                         break;
922                 case 4:
923                         result = gl.uniformMatrix4dv;
924                         break;
925                 default:
926                         TCU_FAIL("Invalid number of rows");
927                 }
928                 break;
929         default:
930                 TCU_FAIL("Invalid number of columns");
931         }
932
933         return result;
934 }
935
936 /** Get proper glUniformMatrixNfv routine for vectors with specified number of columns and rows
937  *
938  * @param gl     GL functions
939  * @param n_rows Number of rows
940  *
941  * @return Function address
942  **/
943 uniformMatrixNfv getUniformMatrixNfv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
944 {
945         uniformMatrixNfv result = 0;
946
947         switch (n_columns)
948         {
949         case 2:
950                 switch (n_rows)
951                 {
952                 case 2:
953                         result = gl.uniformMatrix2fv;
954                         break;
955                 case 3:
956                         result = gl.uniformMatrix2x3fv;
957                         break;
958                 case 4:
959                         result = gl.uniformMatrix2x4fv;
960                         break;
961                 default:
962                         TCU_FAIL("Invalid number of rows");
963                 }
964                 break;
965         case 3:
966                 switch (n_rows)
967                 {
968                 case 2:
969                         result = gl.uniformMatrix3x2fv;
970                         break;
971                 case 3:
972                         result = gl.uniformMatrix3fv;
973                         break;
974                 case 4:
975                         result = gl.uniformMatrix3x4fv;
976                         break;
977                 default:
978                         TCU_FAIL("Invalid number of rows");
979                 }
980                 break;
981         case 4:
982                 switch (n_rows)
983                 {
984                 case 2:
985                         result = gl.uniformMatrix4x2fv;
986                         break;
987                 case 3:
988                         result = gl.uniformMatrix4x3fv;
989                         break;
990                 case 4:
991                         result = gl.uniformMatrix4fv;
992                         break;
993                 default:
994                         TCU_FAIL("Invalid number of rows");
995                 }
996                 break;
997         default:
998                 TCU_FAIL("Invalid number of columns");
999         }
1000
1001         return result;
1002 }
1003
1004 bool verifyVarying(Program& program, const std::string& parent_name, const Variable::Descriptor& desc,
1005                                    std::stringstream& stream, bool is_input)
1006 {
1007         GLint  component = 0;
1008         GLuint index     = 0;
1009         GLenum interface = GL_PROGRAM_INPUT;
1010         GLint  location  = 0;
1011
1012         if (false == is_input)
1013         {
1014                 interface = GL_PROGRAM_OUTPUT;
1015         }
1016
1017         const std::string& name = Utils::Variable::GetReference(parent_name, desc, Utils::Variable::BASIC, 0);
1018
1019         try
1020         {
1021                 index = program.GetResourceIndex(name, interface);
1022
1023                 program.GetResource(interface, index, GL_LOCATION, 1 /* size */, &location);
1024                 program.GetResource(interface, index, GL_LOCATION_COMPONENT, 1 /* size */, &component);
1025         }
1026         catch (std::exception& exc)
1027         {
1028                 stream << "Failed to query program for varying: " << desc.m_name << ". Reason: " << exc.what() << "\n";
1029
1030                 return false;
1031         }
1032
1033         bool result = true;
1034
1035         if (location != desc.m_expected_location)
1036         {
1037                 stream << "Attribute: " << desc.m_name << " - invalid location: " << location
1038                            << " expected: " << desc.m_expected_location << std::endl;
1039                 result = false;
1040         }
1041         if (component != desc.m_expected_component)
1042         {
1043                 stream << "Attribute: " << desc.m_name << " - invalid component: " << component
1044                            << " expected: " << desc.m_expected_component << std::endl;
1045                 result = false;
1046         }
1047
1048         return result;
1049 }
1050
1051 /** Query program resource for given variable and verify that everything is as expected
1052  *
1053  * @param program  Program object
1054  * @param variable Variable object
1055  * @param stream   Stream that will be used to log any error
1056  * @param is_input Selects if varying is input or output
1057  *
1058  * @return true if verification is positive, false otherwise
1059  **/
1060 bool checkVarying(Program& program, const Variable& variable, std::stringstream& stream, bool is_input)
1061 {
1062         bool result = true;
1063
1064         if (variable.IsBlock())
1065         {
1066                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1067                 const size_t      n_members = interface->m_members.size();
1068
1069                 for (size_t i = 0; i < n_members; ++i)
1070                 {
1071                         const Variable::Descriptor& member = interface->m_members[i];
1072                         bool member_result                                 = verifyVarying(program, interface->m_name, member, stream, is_input);
1073
1074                         if (false == member_result)
1075                         {
1076                                 result = false;
1077                         }
1078                 }
1079         }
1080         /*
1081          To query the the location of struct member by glGetProgramResource, we need pass the variable name "gs_fs_output[0].single",
1082          but in original implementation, the test pass the name "Data.single", which can't get any valid result.
1083          struct Data {
1084          dmat2 single;
1085          dmat2 array[1];
1086          };
1087          layout (location = 0) in Data gs_fs_output[1];
1088          */
1089         else if (variable.IsStruct())
1090         {
1091                 Utils::Interface* interface              = variable.m_descriptor.m_interface;
1092                 const size_t      n_members              = interface->m_members.size();
1093                 std::string               structVariable = variable.m_descriptor.m_name;
1094                 // If struct variable is an array
1095                 if (0 != variable.m_descriptor.m_n_array_elements)
1096                 {
1097                         for (GLuint i = 0; i < variable.m_descriptor.m_n_array_elements; i++)
1098                         {
1099                                 GLchar buffer[16];
1100                                 sprintf(buffer, "%d", i);
1101                                 structVariable.append("[");
1102                                 structVariable.append(buffer);
1103                                 structVariable.append("]");
1104                                 for (size_t j = 0; j < n_members; ++j)
1105                                 {
1106                                         const Variable::Descriptor& member = interface->m_members[j];
1107                                         bool member_result = verifyVarying(program, structVariable, member, stream, is_input);
1108
1109                                         if (false == member_result)
1110                                         {
1111                                                 result = false;
1112                                         }
1113                                 }
1114                         }
1115                 }
1116                 else
1117                 {
1118                         for (GLuint i = 0; i < n_members; ++i)
1119                         {
1120                                 const Variable::Descriptor& member = interface->m_members[i];
1121                                 bool member_result                                 = verifyVarying(program, structVariable, member, stream, is_input);
1122
1123                                 if (false == member_result)
1124                                 {
1125                                         result = false;
1126                                 }
1127                         }
1128                 }
1129         }
1130         else
1131         {
1132                 result = verifyVarying(program, "", variable.m_descriptor, stream, is_input);
1133         }
1134         return result;
1135 }
1136
1137 /** Query program resource for given variable and verify that everything is as expected
1138  *
1139  * @param program  Program object
1140  * @param variable Variable object
1141  * @param stream   Stream that will be used to log any error
1142  *
1143  * @return true if verification is positive, false otherwise
1144  **/
1145 bool checkUniform(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1146 {
1147         bool result = true;
1148
1149         if (false == variable.IsBlock())
1150         {
1151                 TCU_FAIL("Not implemented");
1152         }
1153         else
1154         {
1155                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1156
1157                 size_t size = interface->m_members.size();
1158
1159                 std::vector<GLuint>              indices;
1160                 std::vector<const char*> names;
1161                 std::vector<std::string> names_str;
1162                 std::vector<GLint>               offsets;
1163
1164                 indices.resize(size);
1165                 names.resize(size);
1166                 names_str.resize(size);
1167                 offsets.resize(size);
1168
1169                 for (size_t i = 0; i < size; ++i)
1170                 {
1171                         indices[i] = 0;
1172                         offsets[i] = 0;
1173
1174                         const std::string& name =
1175                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1176
1177                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1178                         {
1179                                 const std::string& member_name = Utils::Variable::GetReference(
1180                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1181
1182                                 names_str[i] = member_name;
1183                         }
1184                         else
1185                         {
1186                                 names_str[i] = name;
1187                         }
1188
1189                         names[i] = names_str[i].c_str();
1190                 }
1191
1192                 try
1193                 {
1194                         program.GetUniformIndices(static_cast<glw::GLsizei>(size), &names[0], &indices[0]);
1195                         program.GetActiveUniformsiv(static_cast<glw::GLsizei>(size), &indices[0], GL_UNIFORM_OFFSET, &offsets[0]);
1196                 }
1197                 catch (std::exception& exc)
1198                 {
1199                         stream << "Failed to query program for uniforms in block: " << variable.m_descriptor.m_name
1200                                    << ". Reason: " << exc.what() << "\n";
1201
1202                         return false;
1203                 }
1204
1205                 for (size_t i = 0; i < size; ++i)
1206                 {
1207                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1208
1209                         if (offsets[i] != (GLint)desc.m_offset)
1210                         {
1211                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offsets[i]
1212                                            << " expected: " << desc.m_offset << std::endl;
1213                                 result = false;
1214                         }
1215                 }
1216         }
1217
1218         return result;
1219 }
1220
1221 /** Query program resource for given variable and verify that everything is as expected
1222  *
1223  * @param program  Program object
1224  * @param variable Variable object
1225  * @param stream   Stream that will be used to log any error
1226  *
1227  * @return true if verification is positive, false otherwise
1228  **/
1229 bool checkSSB(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1230 {
1231         bool result = true;
1232
1233         if (false == variable.IsBlock())
1234         {
1235                 TCU_FAIL("Not implemented");
1236         }
1237         else
1238         {
1239                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1240
1241                 size_t size = interface->m_members.size();
1242
1243                 for (size_t i = 0; i < size; ++i)
1244                 {
1245                         GLuint          index   = 0;
1246                         std::string name_str = "";
1247                         GLint           offset   = 0;
1248
1249                         const std::string& name =
1250                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1251
1252                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1253                         {
1254                                 const std::string& member_name = Utils::Variable::GetReference(
1255                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1256
1257                                 name_str = member_name;
1258                         }
1259                         else
1260                         {
1261                                 name_str = name;
1262                         }
1263
1264                         try
1265                         {
1266                                 index = program.GetResourceIndex(name_str, GL_BUFFER_VARIABLE);
1267
1268                                 program.GetResource(GL_BUFFER_VARIABLE, index, GL_OFFSET, 1, &offset);
1269                         }
1270                         catch (std::exception& exc)
1271                         {
1272                                 stream << "Failed to query program for buffer variable: " << variable.m_descriptor.m_name
1273                                            << ". Reason: " << exc.what() << "\n";
1274
1275                                 return false;
1276                         }
1277
1278                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1279
1280                         if (offset != (GLint)desc.m_offset)
1281                         {
1282                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offset
1283                                            << " expected: " << desc.m_offset << std::endl;
1284                                 result = false;
1285                         }
1286                 }
1287         }
1288
1289         return result;
1290 }
1291
1292 /** Query program resources at given stage and verifies results
1293  *
1294  * @param program           Program object
1295  * @param program_interface Definition of program interface
1296  * @param stage             Stage to be verified
1297  * @param check_inputs      Select if inputs should be verified
1298  * @param check_outputs     Select if output should be verified
1299  * @param check_uniforms    Select if uniforms should be verified
1300  * @param check_ssbs        Select if buffers should be verified
1301  * @param stream            Stream that will be used to log any error
1302  *
1303  * @return true if verification is positive, false otherwise
1304  **/
1305 bool checkProgramStage(Program& program, const ProgramInterface& program_interface, Utils::Shader::STAGES stage,
1306                                            bool check_inputs, bool check_outputs, bool check_uniforms, bool check_ssbs,
1307                                            std::stringstream& stream)
1308 {
1309         typedef Variable::PtrVector::const_iterator const_iterator;
1310
1311         const ShaderInterface& interface = program_interface.GetShaderInterface(stage);
1312
1313         bool result = true;
1314
1315         /* Inputs */
1316         if (true == check_inputs)
1317         {
1318                 const Variable::PtrVector& inputs = interface.m_inputs;
1319
1320                 for (const_iterator it = inputs.begin(); it != inputs.end(); ++it)
1321                 {
1322                         if (false == checkVarying(program, **it, stream, true))
1323                         {
1324                                 result = false;
1325                         }
1326                 }
1327         }
1328
1329         /* Outputs */
1330         if (true == check_outputs)
1331         {
1332                 const Variable::PtrVector& outputs = interface.m_outputs;
1333
1334                 for (const_iterator it = outputs.begin(); it != outputs.end(); ++it)
1335                 {
1336                         if (false == checkVarying(program, **it, stream, false))
1337                         {
1338                                 result = false;
1339                         }
1340                 }
1341         }
1342
1343         /* Uniforms */
1344         if (true == check_uniforms)
1345         {
1346                 const Variable::PtrVector& uniforms = interface.m_uniforms;
1347
1348                 for (const_iterator it = uniforms.begin(); it != uniforms.end(); ++it)
1349                 {
1350                         if (false == checkUniform(program, **it, stream))
1351                         {
1352                                 result = false;
1353                         }
1354                 }
1355         }
1356
1357         /* SSBs */
1358         if (true == check_ssbs)
1359         {
1360                 const Variable::PtrVector& ssbs = interface.m_ssb_blocks;
1361
1362                 for (const_iterator it = ssbs.begin(); it != ssbs.end(); ++it)
1363                 {
1364                         if (false == checkSSB(program, **it, stream))
1365                         {
1366                                 result = false;
1367                         }
1368                 }
1369         }
1370
1371         return result;
1372 }
1373
1374 /** Query resources of monolithic compute program and verifies results
1375  *
1376  * @param program           Program object
1377  * @param program_interface Definition of program interface
1378  * @param stream            Stream that will be used to log any error
1379  *
1380  * @return true if verification is positive, false otherwise
1381  **/
1382 bool checkMonolithicComputeProgramInterface(Program& program, const ProgramInterface& program_interface,
1383                                                                                         std::stringstream& stream)
1384 {
1385         bool result = true;
1386
1387         if (false == checkProgramStage(program, program_interface, Shader::COMPUTE, false, false, true, true, stream))
1388         {
1389                 result = false;
1390         }
1391
1392         /* Done */
1393         return result;
1394 }
1395
1396 /** Query resources of monolithic draw program and verifies results
1397  *
1398  * @param program           Program object
1399  * @param program_interface Definition of program interface
1400  * @param stream            Stream that will be used to log any error
1401  *
1402  * @return true if verification is positive, false otherwise
1403  **/
1404 bool checkMonolithicDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1405                                                                                  std::stringstream& stream)
1406 {
1407         bool result = true;
1408
1409         if (false == checkProgramStage(program, program_interface, Shader::VERTEX, true, false, true, true, stream))
1410         {
1411                 result = false;
1412         }
1413
1414         /* Done */
1415         return result;
1416 }
1417
1418 /** Query resources of separable draw program and verifies results
1419  *
1420  * @param program           Program object
1421  * @param program_interface Definition of program interface
1422  * @param stream            Stream that will be used to log any error
1423  *
1424  * @return true if verification is positive, false otherwise
1425  **/
1426 bool checkSeparableDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1427                                                                                 Utils::Shader::STAGES stage, std::stringstream& stream)
1428 {
1429         bool result = true;
1430
1431         if (false == checkProgramStage(program, program_interface, stage, true, true, true, true, stream))
1432         {
1433                 result = false;
1434         }
1435
1436         /* Done */
1437         return result;
1438 }
1439
1440 /** Check if extension is supported
1441  *
1442  * @param context        Test context
1443  * @param extension_name Name of extension
1444  *
1445  * @return true if extension is supported, false otherwise
1446  **/
1447 bool isExtensionSupported(deqp::Context& context, const GLchar* extension_name)
1448 {
1449         const std::vector<std::string>& extensions = context.getContextInfo().getExtensions();
1450
1451         if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1452         {
1453                 return false;
1454         }
1455
1456         return true;
1457 }
1458
1459 /** Check if GL context meets version requirements
1460  *
1461  * @param gl             Functions
1462  * @param required_major Minimum required MAJOR_VERSION
1463  * @param required_minor Minimum required MINOR_VERSION
1464  *
1465  * @return true if GL context version is at least as requested, false otherwise
1466  **/
1467 bool isGLVersionAtLeast(const Functions& gl, GLint required_major, GLint required_minor)
1468 {
1469         glw::GLint major = 0;
1470         glw::GLint minor = 0;
1471
1472         gl.getIntegerv(GL_MAJOR_VERSION, &major);
1473         gl.getIntegerv(GL_MINOR_VERSION, &minor);
1474
1475         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1476
1477         if (major > required_major)
1478         {
1479                 /* Major is higher than required one */
1480                 return true;
1481         }
1482         else if (major == required_major)
1483         {
1484                 if (minor >= required_minor)
1485                 {
1486                         /* Major is equal to required one */
1487                         /* Minor is higher than or equal to required one */
1488                         return true;
1489                 }
1490                 else
1491                 {
1492                         /* Major is equal to required one */
1493                         /* Minor is lower than required one */
1494                         return false;
1495                 }
1496         }
1497         else
1498         {
1499                 /* Major is lower than required one */
1500                 return false;
1501         }
1502 }
1503
1504 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1505  *
1506  * @param token           Token string
1507  * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1508  * @param text            String that will be used as replacement for <token>
1509  * @param string          String to work on
1510  **/
1511 void replaceToken(const GLchar* token, size_t& search_position, const GLchar* text, std::string& string)
1512 {
1513         const size_t text_length        = strlen(text);
1514         const size_t token_length   = strlen(token);
1515         const size_t token_position = string.find(token, search_position);
1516
1517 #if DEBUG_REPLACE_TOKEN
1518         if (std::string::npos == token_position)
1519         {
1520                 string.append("\n\nInvalid token: ");
1521                 string.append(token);
1522
1523                 TCU_FAIL(string.c_str());
1524         }
1525 #endif /* DEBUG_REPLACE_TOKEN */
1526
1527         string.replace(token_position, token_length, text, text_length);
1528
1529         search_position = token_position + text_length;
1530 }
1531
1532 /** Replace all occurances of <token> with <text> in <string>
1533  *
1534  * @param token           Token string
1535  * @param text            String that will be used as replacement for <token>
1536  * @param string          String to work on
1537  **/
1538 void replaceAllTokens(const GLchar* token, const GLchar* text, std::string& string)
1539 {
1540         const size_t text_length  = strlen(text);
1541         const size_t token_length = strlen(token);
1542
1543         size_t search_position = 0;
1544
1545         while (1)
1546         {
1547                 const size_t token_position = string.find(token, search_position);
1548
1549                 if (std::string::npos == token_position)
1550                 {
1551                         break;
1552                 }
1553
1554                 search_position = token_position + text_length;
1555
1556                 string.replace(token_position, token_length, text, text_length);
1557         }
1558 }
1559
1560 /** Rounds up the value to the next power of 2.
1561  * This routine does not work for 0, see the url for explanations.
1562  *
1563  * @param value Starting point
1564  *
1565  * @return Calculated value
1566  **/
1567 glw::GLuint roundUpToPowerOf2(glw::GLuint value)
1568 {
1569         /* Taken from: graphics.stanford.edu/~seander/bithacks.html */
1570         --value;
1571
1572         value |= value >> 1;
1573         value |= value >> 2;
1574         value |= value >> 4;
1575         value |= value >> 8;
1576         value |= value >> 16;
1577
1578         ++value;
1579
1580         return value;
1581 }
1582
1583 /** Insert elements of list into string.
1584  * List in string is represented either by token "LIST" or "SEPARATORLIST".
1585  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>.
1586  * LIST is replaced with <element>SEPARATORLIST
1587  *
1588  * @param element         Element to be inserted
1589  * @param separator       Separator inserted between elements
1590  * @param search_position Position in string, where search for list should start
1591  * @param string          String
1592  **/
1593 void insertElementOfList(const GLchar* element, const GLchar* separator, size_t& search_position, std::string& string)
1594 {
1595         static const char* list         = g_list;
1596         static const char* sep_list = "SEPARATORLIST";
1597
1598         /* Try to get "list" positions */
1599         const size_t list_position       = string.find(list, search_position);
1600         const size_t sep_list_position = string.find(sep_list, search_position);
1601
1602         /* There is no list in string */
1603         if (std::string::npos == list_position)
1604         {
1605                 return;
1606         }
1607
1608         if (9 /* strlen(SEPARATOR) */ == list_position - sep_list_position)
1609         {
1610                 replaceToken("SEPARATOR", search_position, separator, string);
1611         }
1612
1613         /* Save search_position */
1614         const size_t start_position = search_position;
1615
1616         /* Prepare new element */
1617         replaceToken("LIST", search_position, "ELEMENTSEPARATORLIST", string);
1618
1619         /* Restore search_position */
1620         search_position = start_position;
1621
1622         /* Replace element and separator */
1623         replaceToken("ELEMENT", search_position, element, string);
1624 }
1625
1626 /** Close list in string.
1627  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>
1628  * LIST is replaced with ""
1629  *
1630  * @param separator       Separator inserted between elements
1631  * @param search_position Position in string, where search for list should start
1632  * @param string          String
1633  **/
1634 void endList(const glw::GLchar* separator, size_t& search_position, std::string& string)
1635 {
1636         const size_t sep_position = string.find("SEPARATOR", search_position);
1637         if (std::string::npos != sep_position)
1638         {
1639                 replaceToken("SEPARATOR", search_position, separator, string);
1640         }
1641
1642         replaceToken("LIST", search_position, "", string);
1643 }
1644
1645 /* Buffer constants */
1646 const GLuint Buffer::m_invalid_id = -1;
1647
1648 /** Constructor.
1649  *
1650  * @param context CTS context.
1651  **/
1652 Buffer::Buffer(deqp::Context& context) : m_id(m_invalid_id), m_buffer(Array), m_context(context)
1653 {
1654 }
1655
1656 /** Destructor
1657  *
1658  **/
1659 Buffer::~Buffer()
1660 {
1661         Release();
1662 }
1663
1664 /** Initialize buffer instance
1665  *
1666  * @param buffer Buffer type
1667  * @param usage  Buffer usage enum
1668  * @param size   <size> parameter
1669  * @param data   <data> parameter
1670  **/
1671 void Buffer::Init(BUFFERS buffer, USAGE usage, GLsizeiptr size, GLvoid* data)
1672 {
1673         /* Delete previous buffer instance */
1674         Release();
1675
1676         m_buffer = buffer;
1677
1678         const Functions& gl = m_context.getRenderContext().getFunctions();
1679
1680         Generate(gl, m_id);
1681         Bind(gl, m_id, m_buffer);
1682         Data(gl, m_buffer, usage, size, data);
1683 }
1684
1685 /** Release buffer instance
1686  *
1687  **/
1688 void Buffer::Release()
1689 {
1690         if (m_invalid_id != m_id)
1691         {
1692                 const Functions& gl = m_context.getRenderContext().getFunctions();
1693
1694                 gl.deleteBuffers(1, &m_id);
1695                 m_id = m_invalid_id;
1696         }
1697 }
1698
1699 /** Binds buffer to its target
1700  *
1701  **/
1702 void Buffer::Bind() const
1703 {
1704         const Functions& gl = m_context.getRenderContext().getFunctions();
1705
1706         Bind(gl, m_id, m_buffer);
1707 }
1708
1709 /** Binds indexed buffer
1710  *
1711  * @param index <index> parameter
1712  **/
1713 void Buffer::BindBase(GLuint index) const
1714 {
1715         const Functions& gl = m_context.getRenderContext().getFunctions();
1716
1717         BindBase(gl, m_id, m_buffer, index);
1718 }
1719
1720 /** Binds range of buffer
1721  *
1722  * @param index  <index> parameter
1723  * @param offset <offset> parameter
1724  * @param size   <size> parameter
1725  **/
1726 void Buffer::BindRange(GLuint index, GLintptr offset, GLsizeiptr size) const
1727 {
1728         const Functions& gl = m_context.getRenderContext().getFunctions();
1729
1730         BindRange(gl, m_id, m_buffer, index, offset, size);
1731 }
1732
1733 /** Allocate memory for buffer and sends initial content
1734  *
1735  * @param usage  Buffer usage enum
1736  * @param size   <size> parameter
1737  * @param data   <data> parameter
1738  **/
1739 void Buffer::Data(USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1740 {
1741         const Functions& gl = m_context.getRenderContext().getFunctions();
1742
1743         Data(gl, m_buffer, usage, size, data);
1744 }
1745
1746 /** Maps contents of buffer into CPU space
1747  *
1748  * @param access Requested access
1749  *
1750  * @return Pointer to memory region available for CPU
1751  **/
1752 GLvoid* Buffer::Map(ACCESS access)
1753 {
1754         const Functions& gl = m_context.getRenderContext().getFunctions();
1755
1756         return Map(gl, m_buffer, access);
1757 }
1758
1759 /** Allocate memory for buffer and sends initial content
1760  *
1761  * @param offset Offset in buffer
1762  * @param size   <size> parameter
1763  * @param data   <data> parameter
1764  **/
1765 void Buffer::SubData(glw::GLintptr offset, glw::GLsizeiptr size, glw::GLvoid* data)
1766 {
1767         const Functions& gl = m_context.getRenderContext().getFunctions();
1768
1769         SubData(gl, m_buffer, offset, size, data);
1770 }
1771
1772 /** Maps contents of buffer into CPU space
1773  **/
1774 void Buffer::UnMap()
1775 {
1776         const Functions& gl = m_context.getRenderContext().getFunctions();
1777
1778         return UnMap(gl, m_buffer);
1779 }
1780
1781 /** Bind buffer to given target
1782  *
1783  * @param gl     GL functions
1784  * @param id     Id of buffer
1785  * @param buffer Buffer enum
1786  **/
1787 void Buffer::Bind(const Functions& gl, GLuint id, BUFFERS buffer)
1788 {
1789         GLenum target = GetBufferGLenum(buffer);
1790
1791         gl.bindBuffer(target, id);
1792         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
1793 }
1794
1795 /** Binds indexed buffer
1796  *
1797  * @param gl     GL functions
1798  * @param id     Id of buffer
1799  * @param buffer Buffer enum
1800  * @param index  <index> parameter
1801  **/
1802 void Buffer::BindBase(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index)
1803 {
1804         GLenum target = GetBufferGLenum(buffer);
1805
1806         gl.bindBufferBase(target, index, id);
1807         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferBase");
1808 }
1809
1810 /** Binds buffer range
1811  *
1812  * @param gl     GL functions
1813  * @param id     Id of buffer
1814  * @param buffer Buffer enum
1815  * @param index  <index> parameter
1816  * @param offset <offset> parameter
1817  * @param size   <size> parameter
1818  **/
1819 void Buffer::BindRange(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1820 {
1821         GLenum target = GetBufferGLenum(buffer);
1822
1823         gl.bindBufferRange(target, index, id, offset, size);
1824         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
1825 }
1826
1827 /** Allocate memory for buffer and sends initial content
1828  *
1829  * @param gl     GL functions
1830  * @param buffer Buffer enum
1831  * @param usage  Buffer usage enum
1832  * @param size   <size> parameter
1833  * @param data   <data> parameter
1834  **/
1835 void Buffer::Data(const glw::Functions& gl, BUFFERS buffer, USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1836 {
1837         GLenum target   = GetBufferGLenum(buffer);
1838         GLenum gl_usage = GetUsageGLenum(usage);
1839
1840         gl.bufferData(target, size, data, gl_usage);
1841         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferData");
1842 }
1843
1844 /** Allocate memory for buffer and sends initial content
1845  *
1846  * @param gl     GL functions
1847  * @param buffer Buffer enum
1848  * @param offset Offset in buffer
1849  * @param size   <size> parameter
1850  * @param data   <data> parameter
1851  **/
1852 void Buffer::SubData(const glw::Functions& gl, BUFFERS buffer, glw::GLintptr offset, glw::GLsizeiptr size,
1853                                          glw::GLvoid* data)
1854 {
1855         GLenum target = GetBufferGLenum(buffer);
1856
1857         gl.bufferSubData(target, offset, size, data);
1858         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferSubData");
1859 }
1860
1861 /** Generate buffer
1862  *
1863  * @param gl     GL functions
1864  * @param out_id Id of buffer
1865  **/
1866 void Buffer::Generate(const Functions& gl, GLuint& out_id)
1867 {
1868         GLuint id = m_invalid_id;
1869
1870         gl.genBuffers(1, &id);
1871         GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
1872
1873         if (m_invalid_id == id)
1874         {
1875                 TCU_FAIL("Got invalid id");
1876         }
1877
1878         out_id = id;
1879 }
1880
1881 /** Maps buffer content
1882  *
1883  * @param gl     GL functions
1884  * @param buffer Buffer enum
1885  * @param access Access rights for mapped region
1886  *
1887  * @return Mapped memory
1888  **/
1889 void* Buffer::Map(const Functions& gl, BUFFERS buffer, ACCESS access)
1890 {
1891         GLenum target   = GetBufferGLenum(buffer);
1892         GLenum gl_access = GetAccessGLenum(access);
1893
1894         void* result = gl.mapBuffer(target, gl_access);
1895         GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
1896
1897         return result;
1898 }
1899
1900 /** Unmaps buffer
1901  *
1902  **/
1903 void Buffer::UnMap(const Functions& gl, BUFFERS buffer)
1904 {
1905         GLenum target = GetBufferGLenum(buffer);
1906
1907         gl.unmapBuffer(target);
1908         GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
1909 }
1910
1911 /** Return GLenum representation of requested access
1912  *
1913  * @param access Requested access
1914  *
1915  * @return GLenum value
1916  **/
1917 GLenum Buffer::GetAccessGLenum(ACCESS access)
1918 {
1919         GLenum result = 0;
1920
1921         switch (access)
1922         {
1923         case ReadOnly:
1924                 result = GL_READ_ONLY;
1925                 break;
1926         case WriteOnly:
1927                 result = GL_WRITE_ONLY;
1928                 break;
1929         case ReadWrite:
1930                 result = GL_READ_WRITE;
1931                 break;
1932         default:
1933                 TCU_FAIL("Invalid enum");
1934         }
1935
1936         return result;
1937 }
1938
1939 /** Return GLenum representation of requested buffer type
1940  *
1941  * @param buffer Requested buffer type
1942  *
1943  * @return GLenum value
1944  **/
1945 GLenum Buffer::GetBufferGLenum(BUFFERS buffer)
1946 {
1947         GLenum result = 0;
1948
1949         switch (buffer)
1950         {
1951         case Array:
1952                 result = GL_ARRAY_BUFFER;
1953                 break;
1954         case Element:
1955                 result = GL_ELEMENT_ARRAY_BUFFER;
1956                 break;
1957         case Shader_Storage:
1958                 result = GL_SHADER_STORAGE_BUFFER;
1959                 break;
1960         case Texture:
1961                 result = GL_TEXTURE_BUFFER;
1962                 break;
1963         case Transform_feedback:
1964                 result = GL_TRANSFORM_FEEDBACK_BUFFER;
1965                 break;
1966         case Uniform:
1967                 result = GL_UNIFORM_BUFFER;
1968                 break;
1969         default:
1970                 TCU_FAIL("Invalid enum");
1971         }
1972
1973         return result;
1974 }
1975
1976 /** Return GLenum representation of requested usage
1977  *
1978  * @param usage Requested usage
1979  *
1980  * @return GLenum value
1981  **/
1982 GLenum Buffer::GetUsageGLenum(USAGE usage)
1983 {
1984         GLenum result = 0;
1985
1986         switch (usage)
1987         {
1988         case DynamicCopy:
1989                 result = GL_DYNAMIC_COPY;
1990                 break;
1991         case DynamicDraw:
1992                 result = GL_DYNAMIC_DRAW;
1993                 break;
1994         case DynamicRead:
1995                 result = GL_DYNAMIC_READ;
1996                 break;
1997         case StaticCopy:
1998                 result = GL_STATIC_COPY;
1999                 break;
2000         case StaticDraw:
2001                 result = GL_STATIC_DRAW;
2002                 break;
2003         case StaticRead:
2004                 result = GL_STATIC_READ;
2005                 break;
2006         case StreamCopy:
2007                 result = GL_STREAM_COPY;
2008                 break;
2009         case StreamDraw:
2010                 result = GL_STREAM_DRAW;
2011                 break;
2012         case StreamRead:
2013                 result = GL_STREAM_READ;
2014                 break;
2015         default:
2016                 TCU_FAIL("Invalid enum");
2017         }
2018
2019         return result;
2020 }
2021
2022 /** Returns name of buffer target
2023  *
2024  * @param buffer Target enum
2025  *
2026  * @return Name of target
2027  **/
2028 const GLchar* Buffer::GetBufferName(BUFFERS buffer)
2029 {
2030         const GLchar* name = 0;
2031
2032         switch (buffer)
2033         {
2034         case Array:
2035                 name = "Array";
2036                 break;
2037         case Element:
2038                 name = "Element";
2039                 break;
2040         case Shader_Storage:
2041                 name = "Shader_Storage";
2042                 break;
2043         case Texture:
2044                 name = "Texture";
2045                 break;
2046         case Transform_feedback:
2047                 name = "Transform_feedback";
2048                 break;
2049         case Uniform:
2050                 name = "Uniform";
2051                 break;
2052         default:
2053                 TCU_FAIL("Invalid enum");
2054         }
2055
2056         return name;
2057 }
2058
2059 /* Framebuffer constants */
2060 const GLuint Framebuffer::m_invalid_id = -1;
2061
2062 /** Constructor
2063  *
2064  * @param context CTS context
2065  **/
2066 Framebuffer::Framebuffer(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2067 {
2068         /* Nothing to be done here */
2069 }
2070
2071 /** Destructor
2072  *
2073  **/
2074 Framebuffer::~Framebuffer()
2075 {
2076         Release();
2077 }
2078
2079 /** Initialize framebuffer instance
2080  *
2081  **/
2082 void Framebuffer::Init()
2083 {
2084         /* Delete previous instance */
2085         Release();
2086
2087         const Functions& gl = m_context.getRenderContext().getFunctions();
2088
2089         Generate(gl, m_id);
2090 }
2091
2092 /** Release framebuffer instance
2093  *
2094  **/
2095 void Framebuffer::Release()
2096 {
2097         if (m_invalid_id != m_id)
2098         {
2099                 const Functions& gl = m_context.getRenderContext().getFunctions();
2100
2101                 gl.deleteFramebuffers(1, &m_id);
2102                 m_id = m_invalid_id;
2103         }
2104 }
2105
2106 /** Attach texture to specified attachment
2107  *
2108  * @param attachment Attachment
2109  * @param texture_id Texture id
2110  * @param width      Texture width
2111  * @param height     Texture height
2112  **/
2113 void Framebuffer::AttachTexture(GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2114 {
2115         const Functions& gl = m_context.getRenderContext().getFunctions();
2116
2117         AttachTexture(gl, attachment, texture_id, width, height);
2118 }
2119
2120 /** Binds framebuffer to DRAW_FRAMEBUFFER
2121  *
2122  **/
2123 void Framebuffer::Bind()
2124 {
2125         const Functions& gl = m_context.getRenderContext().getFunctions();
2126
2127         Bind(gl, m_id);
2128 }
2129
2130 /** Clear framebuffer
2131  *
2132  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2133  **/
2134 void Framebuffer::Clear(GLenum mask)
2135 {
2136         const Functions& gl = m_context.getRenderContext().getFunctions();
2137
2138         Clear(gl, mask);
2139 }
2140
2141 /** Specifies clear color
2142  *
2143  * @param red   Red channel
2144  * @param green Green channel
2145  * @param blue  Blue channel
2146  * @param alpha Alpha channel
2147  **/
2148 void Framebuffer::ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2149 {
2150         const Functions& gl = m_context.getRenderContext().getFunctions();
2151
2152         ClearColor(gl, red, green, blue, alpha);
2153 }
2154
2155 /** Attach texture to specified attachment
2156  *
2157  * @param gl         GL functions
2158  * @param attachment Attachment
2159  * @param texture_id Texture id
2160  * @param width      Texture width
2161  * @param height     Texture height
2162  **/
2163 void Framebuffer::AttachTexture(const Functions& gl, GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2164 {
2165         gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, attachment, texture_id, 0 /* level */);
2166         GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture");
2167
2168         gl.viewport(0 /* x */, 0 /* y */, width, height);
2169         GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
2170 }
2171
2172 /** Binds framebuffer to DRAW_FRAMEBUFFER
2173  *
2174  * @param gl GL functions
2175  * @param id ID of framebuffer
2176  **/
2177 void Framebuffer::Bind(const Functions& gl, GLuint id)
2178 {
2179         gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, id);
2180         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
2181 }
2182
2183 /** Clear framebuffer
2184  *
2185  * @param gl   GL functions
2186  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2187  **/
2188 void Framebuffer::Clear(const Functions& gl, GLenum mask)
2189 {
2190         gl.clear(mask);
2191         GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
2192 }
2193
2194 /** Specifies clear color
2195  *
2196  * @param gl    GL functions
2197  * @param red   Red channel
2198  * @param green Green channel
2199  * @param blue  Blue channel
2200  * @param alpha Alpha channel
2201  **/
2202 void Framebuffer::ClearColor(const Functions& gl, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2203 {
2204         gl.clearColor(red, green, blue, alpha);
2205         GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
2206 }
2207
2208 /** Generate framebuffer
2209  *
2210  **/
2211 void Framebuffer::Generate(const Functions& gl, GLuint& out_id)
2212 {
2213         GLuint id = m_invalid_id;
2214
2215         gl.genFramebuffers(1, &id);
2216         GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
2217
2218         if (m_invalid_id == id)
2219         {
2220                 TCU_FAIL("Invalid id");
2221         }
2222
2223         out_id = id;
2224 }
2225
2226 /* Shader's constants */
2227 const GLuint Shader::m_invalid_id = 0;
2228
2229 /** Constructor.
2230  *
2231  * @param context CTS context.
2232  **/
2233 Shader::Shader(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2234 {
2235         /* Nothing to be done here */
2236 }
2237
2238 /** Destructor
2239  *
2240  **/
2241 Shader::~Shader()
2242 {
2243         Release();
2244 }
2245
2246 /** Initialize shader instance
2247  *
2248  * @param stage  Shader stage
2249  * @param source Source code
2250  **/
2251 void Shader::Init(STAGES stage, const std::string& source)
2252 {
2253         if (true == source.empty())
2254         {
2255                 /* No source == no shader */
2256                 return;
2257         }
2258
2259         /* Delete any previous shader */
2260         Release();
2261
2262         /* Create, set source and compile */
2263         const Functions& gl = m_context.getRenderContext().getFunctions();
2264
2265         Create(gl, stage, m_id);
2266         Source(gl, m_id, source);
2267
2268         try
2269         {
2270                 Compile(gl, m_id);
2271         }
2272         catch (const CompilationException& exc)
2273         {
2274                 throw InvalidSourceException(exc.what(), source, stage);
2275         }
2276 }
2277
2278 /** Release shader instance
2279  *
2280  **/
2281 void Shader::Release()
2282 {
2283         if (m_invalid_id != m_id)
2284         {
2285                 const Functions& gl = m_context.getRenderContext().getFunctions();
2286
2287                 gl.deleteShader(m_id);
2288                 m_id = m_invalid_id;
2289         }
2290 }
2291
2292 /** Compile shader
2293  *
2294  * @param gl GL functions
2295  * @param id Shader id
2296  **/
2297 void Shader::Compile(const Functions& gl, GLuint id)
2298 {
2299         GLint status = GL_FALSE;
2300
2301         /* Compile */
2302         gl.compileShader(id);
2303         GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
2304
2305         /* Get compilation status */
2306         gl.getShaderiv(id, GL_COMPILE_STATUS, &status);
2307         GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2308
2309         /* Log compilation error */
2310         if (GL_TRUE != status)
2311         {
2312                 glw::GLint  length = 0;
2313                 std::string message;
2314
2315                 /* Error log length */
2316                 gl.getShaderiv(id, GL_INFO_LOG_LENGTH, &length);
2317                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2318
2319                 /* Prepare storage */
2320                 message.resize(length, 0);
2321
2322                 /* Get error log */
2323                 gl.getShaderInfoLog(id, length, 0, &message[0]);
2324                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
2325
2326                 throw CompilationException(message.c_str());
2327         }
2328 }
2329
2330 /** Create shader
2331  *
2332  * @param gl     GL functions
2333  * @param stage  Shader stage
2334  * @param out_id Shader id
2335  **/
2336 void Shader::Create(const Functions& gl, STAGES stage, GLuint& out_id)
2337 {
2338         const GLenum shaderType = GetShaderStageGLenum(stage);
2339         const GLuint id                 = gl.createShader(shaderType);
2340         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
2341
2342         if (m_invalid_id == id)
2343         {
2344                 TCU_FAIL("Failed to create shader");
2345         }
2346
2347         out_id = id;
2348 }
2349
2350 /** Set shader's source code
2351  *
2352  * @param gl     GL functions
2353  * @param id     Shader id
2354  * @param source Shader source code
2355  **/
2356 void Shader::Source(const Functions& gl, GLuint id, const std::string& source)
2357 {
2358         const GLchar* code = source.c_str();
2359
2360         gl.shaderSource(id, 1 /* count */, &code, 0 /* lengths */);
2361         GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
2362 }
2363
2364 /** Get GLenum repesenting shader stage
2365  *
2366  * @param stage Shader stage
2367  *
2368  * @return GLenum
2369  **/
2370 GLenum Shader::GetShaderStageGLenum(STAGES stage)
2371 {
2372         GLenum result = 0;
2373
2374         switch (stage)
2375         {
2376         case COMPUTE:
2377                 result = GL_COMPUTE_SHADER;
2378                 break;
2379         case FRAGMENT:
2380                 result = GL_FRAGMENT_SHADER;
2381                 break;
2382         case GEOMETRY:
2383                 result = GL_GEOMETRY_SHADER;
2384                 break;
2385         case TESS_CTRL:
2386                 result = GL_TESS_CONTROL_SHADER;
2387                 break;
2388         case TESS_EVAL:
2389                 result = GL_TESS_EVALUATION_SHADER;
2390                 break;
2391         case VERTEX:
2392                 result = GL_VERTEX_SHADER;
2393                 break;
2394         default:
2395                 TCU_FAIL("Invalid enum");
2396         }
2397
2398         return result;
2399 }
2400
2401 /** Get string representing name of shader stage
2402  *
2403  * @param stage Shader stage
2404  *
2405  * @return String with name of shader stage
2406  **/
2407 const glw::GLchar* Shader::GetStageName(STAGES stage)
2408 {
2409         const GLchar* result = 0;
2410
2411         switch (stage)
2412         {
2413         case COMPUTE:
2414                 result = "compute";
2415                 break;
2416         case VERTEX:
2417                 result = "vertex";
2418                 break;
2419         case TESS_CTRL:
2420                 result = "tessellation control";
2421                 break;
2422         case TESS_EVAL:
2423                 result = "tessellation evaluation";
2424                 break;
2425         case GEOMETRY:
2426                 result = "geometry";
2427                 break;
2428         case FRAGMENT:
2429                 result = "fragment";
2430                 break;
2431         default:
2432                 TCU_FAIL("Invalid enum");
2433         }
2434
2435         return result;
2436 }
2437
2438 /** Logs shader source
2439  *
2440  * @param context CTS context
2441  * @param source  Source of shader
2442  * @param stage   Shader stage
2443  **/
2444 void Shader::LogSource(deqp::Context& context, const std::string& source, STAGES stage)
2445 {
2446         /* Skip empty shaders */
2447         if (true == source.empty())
2448         {
2449                 return;
2450         }
2451
2452         context.getTestContext().getLog() << tcu::TestLog::Message
2453                                                                           << "Shader source. Stage: " << Shader::GetStageName(stage)
2454                                                                           << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(source);
2455 }
2456
2457 /** Constructor
2458  *
2459  * @param message Compilation error message
2460  **/
2461 Shader::CompilationException::CompilationException(const GLchar* message)
2462 {
2463         m_message = message;
2464 }
2465
2466 /** Returns error messages
2467  *
2468  * @return Compilation error message
2469  **/
2470 const char* Shader::CompilationException::what() const throw()
2471 {
2472         return m_message.c_str();
2473 }
2474
2475 /** Constructor
2476  *
2477  * @param message Compilation error message
2478  **/
2479 Shader::InvalidSourceException::InvalidSourceException(const GLchar* error_message, const std::string& source,
2480                                                                                                            STAGES stage)
2481         : m_message(error_message), m_source(source), m_stage(stage)
2482 {
2483 }
2484
2485 /** Returns error messages
2486  *
2487  * @return Compilation error message
2488  **/
2489 const char* Shader::InvalidSourceException::what() const throw()
2490 {
2491         return "Compilation error";
2492 }
2493
2494 /** Logs error message and shader sources **/
2495 void Shader::InvalidSourceException::log(deqp::Context& context) const
2496 {
2497         context.getTestContext().getLog() << tcu::TestLog::Message << "Failed to compile shader: " << m_message.c_str()
2498                                                                           << tcu::TestLog::EndMessage;
2499
2500         LogSource(context, m_source, m_stage);
2501 }
2502
2503 /* Program constants */
2504 const GLuint Pipeline::m_invalid_id = 0;
2505
2506 /** Constructor.
2507  *
2508  * @param context CTS context.
2509  **/
2510 Pipeline::Pipeline(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2511 {
2512         /* Nothing to be done here */
2513 }
2514
2515 /** Destructor
2516  *
2517  **/
2518 Pipeline::~Pipeline()
2519 {
2520         Release();
2521 }
2522
2523 /** Initialize pipline object
2524  *
2525  **/
2526 void Pipeline::Init()
2527 {
2528         Release();
2529
2530         const Functions& gl = m_context.getRenderContext().getFunctions();
2531
2532         /* Generate */
2533         gl.genProgramPipelines(1, &m_id);
2534         GLU_EXPECT_NO_ERROR(gl.getError(), "GenProgramPipelines");
2535 }
2536
2537 /** Release pipeline object
2538  *
2539  **/
2540 void Pipeline::Release()
2541 {
2542         if (m_invalid_id != m_id)
2543         {
2544                 const Functions& gl = m_context.getRenderContext().getFunctions();
2545
2546                 /* Generate */
2547                 gl.deleteProgramPipelines(1, &m_id);
2548                 GLU_EXPECT_NO_ERROR(gl.getError(), "DeleteProgramPipelines");
2549
2550                 m_id = m_invalid_id;
2551         }
2552 }
2553
2554 /** Bind pipeline
2555  *
2556  **/
2557 void Pipeline::Bind()
2558 {
2559         const Functions& gl = m_context.getRenderContext().getFunctions();
2560
2561         Bind(gl, m_id);
2562 }
2563
2564 /** Set which stages should be active
2565  *
2566  * @param program_id Id of program
2567  * @param stages     Logical combination of enums representing stages
2568  **/
2569 void Pipeline::UseProgramStages(GLuint program_id, GLenum stages)
2570 {
2571         const Functions& gl = m_context.getRenderContext().getFunctions();
2572
2573         UseProgramStages(gl, m_id, program_id, stages);
2574 }
2575
2576 /** Bind pipeline
2577  *
2578  * @param gl Functiions
2579  * @param id Pipeline id
2580  **/
2581 void Pipeline::Bind(const Functions& gl, GLuint id)
2582 {
2583         gl.bindProgramPipeline(id);
2584         GLU_EXPECT_NO_ERROR(gl.getError(), "BindProgramPipeline");
2585 }
2586
2587 /** Set which stages should be active
2588  *
2589  * @param gl         Functiions
2590  * @param id         Pipeline id
2591  * @param program_id Id of program
2592  * @param stages     Logical combination of enums representing stages
2593  **/
2594 void Pipeline::UseProgramStages(const Functions& gl, GLuint id, GLuint program_id, GLenum stages)
2595 {
2596         gl.useProgramStages(id, stages, program_id);
2597         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgramStages");
2598 }
2599
2600 /* Program constants */
2601 const GLuint Program::m_invalid_id = 0;
2602
2603 /** Constructor.
2604  *
2605  * @param context CTS context.
2606  **/
2607 Program::Program(deqp::Context& context)
2608         : m_id(m_invalid_id)
2609         , m_compute(context)
2610         , m_fragment(context)
2611         , m_geometry(context)
2612         , m_tess_ctrl(context)
2613         , m_tess_eval(context)
2614         , m_vertex(context)
2615         , m_context(context)
2616 {
2617         /* Nothing to be done here */
2618 }
2619
2620 /** Destructor
2621  *
2622  **/
2623 Program::~Program()
2624 {
2625         Release();
2626 }
2627
2628 /** Initialize program instance
2629  *
2630  * @param compute_shader                    Compute shader source code
2631  * @param fragment_shader                   Fragment shader source code
2632  * @param geometry_shader                   Geometry shader source code
2633  * @param tessellation_control_shader       Tessellation control shader source code
2634  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2635  * @param vertex_shader                     Vertex shader source code
2636  * @param captured_varyings                 Vector of variables to be captured with transfrom feedback
2637  * @param capture_interleaved               Select mode of transform feedback (separate or interleaved)
2638  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2639  **/
2640 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2641                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2642                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2643                                    const NameVector& captured_varyings, bool capture_interleaved, bool is_separable)
2644 {
2645         /* Delete previous program */
2646         Release();
2647
2648         /* GL entry points */
2649         const Functions& gl = m_context.getRenderContext().getFunctions();
2650
2651         /* Initialize shaders */
2652         m_compute.Init(Shader::COMPUTE, compute_shader);
2653         m_fragment.Init(Shader::FRAGMENT, fragment_shader);
2654         m_geometry.Init(Shader::GEOMETRY, geometry_shader);
2655         m_tess_ctrl.Init(Shader::TESS_CTRL, tessellation_control_shader);
2656         m_tess_eval.Init(Shader::TESS_EVAL, tessellation_evaluation_shader);
2657         m_vertex.Init(Shader::VERTEX, vertex_shader);
2658
2659         /* Create program, set up transform feedback and attach shaders */
2660         Create(gl, m_id);
2661         Capture(gl, m_id, captured_varyings, capture_interleaved);
2662         Attach(gl, m_id, m_compute.m_id);
2663         Attach(gl, m_id, m_fragment.m_id);
2664         Attach(gl, m_id, m_geometry.m_id);
2665         Attach(gl, m_id, m_tess_ctrl.m_id);
2666         Attach(gl, m_id, m_tess_eval.m_id);
2667         Attach(gl, m_id, m_vertex.m_id);
2668
2669         /* Set separable parameter */
2670         if (true == is_separable)
2671         {
2672                 gl.programParameteri(m_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
2673                 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
2674         }
2675
2676         try
2677         {
2678                 /* Link program */
2679                 Link(gl, m_id);
2680         }
2681         catch (const LinkageException& exc)
2682         {
2683                 throw BuildException(exc.what(), compute_shader, fragment_shader, geometry_shader, tessellation_control_shader,
2684                                                          tessellation_evaluation_shader, vertex_shader);
2685         }
2686 }
2687
2688 /** Initialize program instance
2689  *
2690  * @param compute_shader                    Compute shader source code
2691  * @param fragment_shader                   Fragment shader source code
2692  * @param geometry_shader                   Geometry shader source code
2693  * @param tessellation_control_shader       Tessellation control shader source code
2694  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2695  * @param vertex_shader                     Vertex shader source code
2696  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2697  **/
2698 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2699                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2700                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2701                                    bool is_separable)
2702 {
2703         NameVector captured_varying;
2704
2705         Init(compute_shader, fragment_shader, geometry_shader, tessellation_control_shader, tessellation_evaluation_shader,
2706                  vertex_shader, captured_varying, true, is_separable);
2707 }
2708
2709 /** Release program instance
2710  *
2711  **/
2712 void Program::Release()
2713 {
2714         const Functions& gl = m_context.getRenderContext().getFunctions();
2715
2716         if (m_invalid_id != m_id)
2717         {
2718                 Use(gl, m_invalid_id);
2719
2720                 gl.deleteProgram(m_id);
2721                 m_id = m_invalid_id;
2722         }
2723
2724         m_compute.Release();
2725         m_fragment.Release();
2726         m_geometry.Release();
2727         m_tess_ctrl.Release();
2728         m_tess_eval.Release();
2729         m_vertex.Release();
2730 }
2731
2732 /** Get <pname> for a set of active uniforms
2733  *
2734  * @param count   Number of indices
2735  * @param indices Indices of uniforms
2736  * @param pname   Queired pname
2737  * @param params  Array that will be filled with values of parameters
2738  **/
2739 void Program::GetActiveUniformsiv(GLsizei count, const GLuint* indices, GLenum pname, GLint* params) const
2740 {
2741         const Functions& gl = m_context.getRenderContext().getFunctions();
2742
2743         GetActiveUniformsiv(gl, m_id, count, indices, pname, params);
2744 }
2745
2746 /** Get location of attribute
2747  *
2748  * @param name Name of attribute
2749  *
2750  * @return Result of query
2751  **/
2752 glw::GLint Program::GetAttribLocation(const std::string& name) const
2753 {
2754         const Functions& gl = m_context.getRenderContext().getFunctions();
2755
2756         return GetAttribLocation(gl, m_id, name);
2757 }
2758
2759 /** Query resource
2760  *
2761  * @param interface Interface to be queried
2762  * @param index     Index of resource
2763  * @param property  Property to be queried
2764  * @param buf_size  Size of <params> buffer
2765  * @param params    Results of query
2766  **/
2767 void Program::GetResource(GLenum interface, GLuint index, GLenum property, GLsizei buf_size, GLint* params) const
2768 {
2769         const Functions& gl = m_context.getRenderContext().getFunctions();
2770
2771         GetResource(gl, m_id, interface, index, property, buf_size, params);
2772 }
2773
2774 /** Query for index of resource
2775  *
2776  * @param name      Name of resource
2777  * @param interface Interface to be queried
2778  *
2779  * @return Result of query
2780  **/
2781 glw::GLuint Program::GetResourceIndex(const std::string& name, GLenum interface) const
2782 {
2783         const Functions& gl = m_context.getRenderContext().getFunctions();
2784
2785         return GetResourceIndex(gl, m_id, name, interface);
2786 }
2787
2788 /** Get indices for a set of uniforms
2789  *
2790  * @param count   Count number of uniforms
2791  * @param names   Names of uniforms
2792  * @param indices Buffer that will be filled with indices
2793  **/
2794 void Program::GetUniformIndices(GLsizei count, const GLchar** names, GLuint* indices) const
2795 {
2796         const Functions& gl = m_context.getRenderContext().getFunctions();
2797
2798         GetUniformIndices(gl, m_id, count, names, indices);
2799 }
2800
2801 /** Get uniform location
2802  *
2803  * @param name Name of uniform
2804  *
2805  * @return Results of query
2806  **/
2807 glw::GLint Program::GetUniformLocation(const std::string& name) const
2808 {
2809         const Functions& gl = m_context.getRenderContext().getFunctions();
2810
2811         return GetUniformLocation(gl, m_id, name);
2812 }
2813
2814 /** Set program as active
2815  *
2816  **/
2817 void Program::Use() const
2818 {
2819         const Functions& gl = m_context.getRenderContext().getFunctions();
2820
2821         Use(gl, m_id);
2822 }
2823
2824 /** Attach shader to program
2825  *
2826  * @param gl         GL functions
2827  * @param program_id Id of program
2828  * @param shader_id  Id of shader
2829  **/
2830 void Program::Attach(const Functions& gl, GLuint program_id, GLuint shader_id)
2831 {
2832         /* Sanity checks */
2833         if ((m_invalid_id == program_id) || (Shader::m_invalid_id == shader_id))
2834         {
2835                 return;
2836         }
2837
2838         gl.attachShader(program_id, shader_id);
2839         GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
2840 }
2841
2842 /** Set up captured varyings
2843  *
2844  * @param gl                  GL functions
2845  * @param id                  Id of program
2846  * @param captured_varyings   Vector of varyings
2847  * @param capture_interleaved Selects if interleaved or separate mode should be used
2848  **/
2849 void Program::Capture(const Functions& gl, GLuint id, const NameVector& captured_varyings, bool capture_interleaved)
2850 {
2851         const size_t n_varyings = captured_varyings.size();
2852
2853         if (0 == n_varyings)
2854         {
2855                 /* empty list, skip */
2856                 return;
2857         }
2858
2859         std::vector<const GLchar*> varying_names;
2860         varying_names.resize(n_varyings);
2861
2862         for (size_t i = 0; i < n_varyings; ++i)
2863         {
2864                 varying_names[i] = captured_varyings[i].c_str();
2865         }
2866
2867         GLenum mode = 0;
2868         if (true == capture_interleaved)
2869         {
2870                 mode = GL_INTERLEAVED_ATTRIBS;
2871         }
2872         else
2873         {
2874                 mode = GL_SEPARATE_ATTRIBS;
2875         }
2876
2877         gl.transformFeedbackVaryings(id, static_cast<GLsizei>(n_varyings), &varying_names[0], mode);
2878         GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
2879 }
2880
2881 /** Create program instance
2882  *
2883  * @param gl     GL functions
2884  * @param out_id Id of program
2885  **/
2886 void Program::Create(const Functions& gl, GLuint& out_id)
2887 {
2888         const GLuint id = gl.createProgram();
2889         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
2890
2891         if (m_invalid_id == id)
2892         {
2893                 TCU_FAIL("Failed to create program");
2894         }
2895
2896         out_id = id;
2897 }
2898
2899 /** Get <pname> for a set of active uniforms
2900  *
2901  * @param gl         Functions
2902  * @param program_id Id of program
2903  * @param count      Number of indices
2904  * @param indices    Indices of uniforms
2905  * @param pname      Queired pname
2906  * @param params     Array that will be filled with values of parameters
2907  **/
2908 void Program::GetActiveUniformsiv(const Functions& gl, GLuint program_id, GLsizei count, const GLuint* indices,
2909                                                                   GLenum pname, GLint* params)
2910 {
2911         gl.getActiveUniformsiv(program_id, count, indices, pname, params);
2912         GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformsiv");
2913 }
2914
2915 /** Get indices for a set of uniforms
2916  *
2917  * @param gl         Functions
2918  * @param program_id Id of program
2919  * @param count      Count number of uniforms
2920  * @param names      Names of uniforms
2921  * @param indices    Buffer that will be filled with indices
2922  **/
2923 void Program::GetUniformIndices(const Functions& gl, GLuint program_id, GLsizei count, const GLchar** names,
2924                                                                 GLuint* indices)
2925 {
2926         gl.getUniformIndices(program_id, count, names, indices);
2927         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformIndices");
2928 }
2929
2930 /** Link program
2931  *
2932  * @param gl GL functions
2933  * @param id Id of program
2934  **/
2935 void Program::Link(const Functions& gl, GLuint id)
2936 {
2937         GLint status = GL_FALSE;
2938
2939         gl.linkProgram(id);
2940         GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
2941
2942         /* Get link status */
2943         gl.getProgramiv(id, GL_LINK_STATUS, &status);
2944         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2945
2946         /* Log link error */
2947         if (GL_TRUE != status)
2948         {
2949                 glw::GLint  length = 0;
2950                 std::string message;
2951
2952                 /* Get error log length */
2953                 gl.getProgramiv(id, GL_INFO_LOG_LENGTH, &length);
2954                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2955
2956                 message.resize(length, 0);
2957
2958                 /* Get error log */
2959                 gl.getProgramInfoLog(id, length, 0, &message[0]);
2960                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
2961
2962                 throw LinkageException(message.c_str());
2963         }
2964 }
2965
2966 /** Set generic uniform
2967  *
2968  * @param gl       Functions
2969  * @param type     Type of uniform
2970  * @param count    Length of array
2971  * @param location Location of uniform
2972  * @param data     Data that will be used
2973  **/
2974 void Program::Uniform(const Functions& gl, const Type& type, GLsizei count, GLint location, const GLvoid* data)
2975 {
2976         if (-1 == location)
2977         {
2978                 TCU_FAIL("Uniform is inactive");
2979         }
2980
2981         switch (type.m_basic_type)
2982         {
2983         case Type::Double:
2984                 if (1 == type.m_n_columns)
2985                 {
2986                         getUniformNdv(gl, type.m_n_rows)(location, count, (const GLdouble*)data);
2987                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
2988                 }
2989                 else
2990                 {
2991                         getUniformMatrixNdv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLdouble*)data);
2992                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
2993                 }
2994                 break;
2995         case Type::Float:
2996                 if (1 == type.m_n_columns)
2997                 {
2998                         getUniformNfv(gl, type.m_n_rows)(location, count, (const GLfloat*)data);
2999                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
3000                 }
3001                 else
3002                 {
3003                         getUniformMatrixNfv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLfloat*)data);
3004                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
3005                 }
3006                 break;
3007         case Type::Int:
3008                 getUniformNiv(gl, type.m_n_rows)(location, count, (const GLint*)data);
3009                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
3010                 break;
3011         case Type::Uint:
3012                 getUniformNuiv(gl, type.m_n_rows)(location, count, (const GLuint*)data);
3013                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
3014                 break;
3015         default:
3016                 TCU_FAIL("Invalid enum");
3017         }
3018 }
3019
3020 /** Use program
3021  *
3022  * @param gl GL functions
3023  * @param id Id of program
3024  **/
3025 void Program::Use(const Functions& gl, GLuint id)
3026 {
3027         gl.useProgram(id);
3028         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
3029 }
3030
3031 /** Get location of attribute
3032  *
3033  * @param gl   GL functions
3034  * @param id   Id of program
3035  * @param name Name of attribute
3036  *
3037  * @return Location of attribute
3038  **/
3039 GLint Program::GetAttribLocation(const Functions& gl, GLuint id, const std::string& name)
3040 {
3041         GLint location = gl.getAttribLocation(id, name.c_str());
3042         GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
3043
3044         return location;
3045 }
3046
3047 /** Query resource
3048  *
3049  * @param gl        GL functions
3050  * @param id        Id of program
3051  * @param interface Interface to be queried
3052  * @param index     Index of resource
3053  * @param property  Property to be queried
3054  * @param buf_size  Size of <params> buffer
3055  * @param params    Results of query
3056  **/
3057 void Program::GetResource(const Functions& gl, GLuint id, GLenum interface, GLuint index, GLenum property,
3058                                                   GLsizei buf_size, GLint* params)
3059 {
3060         gl.getProgramResourceiv(id, interface, index, 1 /* propCount */, &property, buf_size /* bufSize */, 0 /* length */,
3061                                                         params);
3062         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceiv");
3063 }
3064
3065 /** Get index of resource
3066  *
3067  * @param gl        GL functions
3068  * @param id        Id of program
3069  * @param name      Name of resource
3070  * @param interface Program interface to queried
3071  *
3072  * @return Location of attribute
3073  **/
3074 GLuint Program::GetResourceIndex(const Functions& gl, GLuint id, const std::string& name, GLenum interface)
3075 {
3076         GLuint index = gl.getProgramResourceIndex(id, interface, name.c_str());
3077         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceIndex");
3078
3079         return index;
3080 }
3081
3082 /** Get location of attribute
3083  *
3084  * @param gl   GL functions
3085  * @param id   Id of program
3086  * @param name Name of attribute
3087  *
3088  * @return Location of uniform
3089  **/
3090 GLint Program::GetUniformLocation(const Functions& gl, GLuint id, const std::string& name)
3091 {
3092         GLint location = gl.getUniformLocation(id, name.c_str());
3093         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
3094
3095         return location;
3096 }
3097
3098 /** Constructor
3099  *
3100  * @param error_message    Error message
3101  * @param compute_shader   Source code for compute stage
3102  * @param fragment_shader  Source code for fragment stage
3103  * @param geometry_shader  Source code for geometry stage
3104  * @param tess_ctrl_shader Source code for tessellation control stage
3105  * @param tess_eval_shader Source code for tessellation evaluation stage
3106  * @param vertex_shader    Source code for vertex stage
3107  **/
3108 Program::BuildException::BuildException(const glw::GLchar* error_message, const std::string compute_shader,
3109                                                                                 const std::string fragment_shader, const std::string geometry_shader,
3110                                                                                 const std::string tess_ctrl_shader, const std::string tess_eval_shader,
3111                                                                                 const std::string vertex_shader)
3112         : m_error_message(error_message)
3113         , m_compute_shader(compute_shader)
3114         , m_fragment_shader(fragment_shader)
3115         , m_geometry_shader(geometry_shader)
3116         , m_tess_ctrl_shader(tess_ctrl_shader)
3117         , m_tess_eval_shader(tess_eval_shader)
3118         , m_vertex_shader(vertex_shader)
3119 {
3120 }
3121
3122 /** Overwrites std::exception::what method
3123  *
3124  * @return Message compossed from error message and shader sources
3125  **/
3126 const char* Program::BuildException::what() const throw()
3127 {
3128         return "Failed to link program";
3129 }
3130
3131 /** Logs error message and shader sources **/
3132 void Program::BuildException::log(deqp::Context& context) const
3133 {
3134         context.getTestContext().getLog() << tcu::TestLog::Message << "Link failure: " << m_error_message
3135                                                                           << tcu::TestLog::EndMessage;
3136
3137         Shader::LogSource(context, m_vertex_shader, Shader::VERTEX);
3138         Shader::LogSource(context, m_tess_ctrl_shader, Shader::TESS_CTRL);
3139         Shader::LogSource(context, m_tess_eval_shader, Shader::TESS_EVAL);
3140         Shader::LogSource(context, m_geometry_shader, Shader::GEOMETRY);
3141         Shader::LogSource(context, m_fragment_shader, Shader::FRAGMENT);
3142         Shader::LogSource(context, m_compute_shader, Shader::COMPUTE);
3143 }
3144
3145 /** Constructor
3146  *
3147  * @param message Linking error message
3148  **/
3149 Program::LinkageException::LinkageException(const glw::GLchar* message) : m_error_message(message)
3150 {
3151         /* Nothing to be done */
3152 }
3153
3154 /** Returns error messages
3155  *
3156  * @return Linking error message
3157  **/
3158 const char* Program::LinkageException::what() const throw()
3159 {
3160         return m_error_message.c_str();
3161 }
3162
3163 /* Texture constants */
3164 const GLuint Texture::m_invalid_id = -1;
3165
3166 /** Constructor.
3167  *
3168  * @param context CTS context.
3169  **/
3170 Texture::Texture(deqp::Context& context) : m_id(m_invalid_id), m_context(context), m_type(TEX_2D)
3171 {
3172         /* Nothing to done here */
3173 }
3174
3175 /** Destructor
3176  *
3177  **/
3178 Texture::~Texture()
3179 {
3180         Release();
3181 }
3182
3183 /** Initialize texture instance
3184  *
3185  * @param tex_type        Type of texture
3186  * @param width           Width of texture
3187  * @param height          Height of texture
3188  * @param depth           Depth of texture
3189  * @param internal_format Internal format of texture
3190  * @param format          Format of texture data
3191  * @param type            Type of texture data
3192  * @param data            Texture data
3193  **/
3194 void Texture::Init(TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum internal_format, GLenum format,
3195                                    GLenum type, GLvoid* data)
3196 {
3197         const Functions& gl = m_context.getRenderContext().getFunctions();
3198
3199         /* Delete previous texture */
3200         Release();
3201
3202         m_type = tex_type;
3203
3204         /* Generate, bind, allocate storage and upload data */
3205         Generate(gl, m_id);
3206         Bind(gl, m_id, tex_type);
3207         Storage(gl, tex_type, width, height, depth, internal_format);
3208         Update(gl, tex_type, width, height, depth, format, type, data);
3209 }
3210
3211 /** Initialize buffer texture
3212  *
3213  * @param internal_format Internal format of texture
3214  * @param buffer_id       Id of buffer that will be used as data source
3215  **/
3216 void Texture::Init(GLenum internal_format, GLuint buffer_id)
3217 {
3218         const Functions& gl = m_context.getRenderContext().getFunctions();
3219
3220         /* Delete previous texture */
3221         Release();
3222
3223         m_type = TEX_BUFFER;
3224
3225         /* Generate, bind and attach buffer */
3226         Generate(gl, m_id);
3227         Bind(gl, m_id, TEX_BUFFER);
3228         TexBuffer(gl, buffer_id, internal_format);
3229 }
3230
3231 /** Release texture instance
3232  *
3233  **/
3234 void Texture::Release()
3235 {
3236         if (m_invalid_id != m_id)
3237         {
3238                 const Functions& gl = m_context.getRenderContext().getFunctions();
3239
3240                 gl.deleteTextures(1, &m_id);
3241                 m_id = m_invalid_id;
3242         }
3243 }
3244
3245 /** Bind texture to its target
3246  *
3247  **/
3248 void Texture::Bind() const
3249 {
3250         const Functions& gl = m_context.getRenderContext().getFunctions();
3251
3252         Bind(gl, m_id, m_type);
3253 }
3254
3255 /** Get texture data
3256  *
3257  * @param format   Format of data
3258  * @param type     Type of data
3259  * @param out_data Buffer for data
3260  **/
3261 void Texture::Get(GLenum format, GLenum type, GLvoid* out_data) const
3262 {
3263         const Functions& gl = m_context.getRenderContext().getFunctions();
3264
3265         Bind(gl, m_id, m_type);
3266         Get(gl, m_type, format, type, out_data);
3267 }
3268
3269 /** Bind texture to target
3270  *
3271  * @param gl       GL functions
3272  * @param id       Id of texture
3273  * @param tex_type Type of texture
3274  **/
3275 void Texture::Bind(const Functions& gl, GLuint id, TYPES tex_type)
3276 {
3277         GLenum target = GetTargetGLenum(tex_type);
3278
3279         gl.bindTexture(target, id);
3280         GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
3281 }
3282
3283 /** Generate texture instance
3284  *
3285  * @param gl     GL functions
3286  * @param out_id Id of texture
3287  **/
3288 void Texture::Generate(const Functions& gl, GLuint& out_id)
3289 {
3290         GLuint id = m_invalid_id;
3291
3292         gl.genTextures(1, &id);
3293         GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
3294
3295         if (m_invalid_id == id)
3296         {
3297                 TCU_FAIL("Invalid id");
3298         }
3299
3300         out_id = id;
3301 }
3302
3303 /** Get texture data
3304  *
3305  * @param gl       GL functions
3306  * @param format   Format of data
3307  * @param type     Type of data
3308  * @param out_data Buffer for data
3309  **/
3310 void Texture::Get(const Functions& gl, TYPES tex_type, GLenum format, GLenum type, GLvoid* out_data)
3311 {
3312         GLenum target = GetTargetGLenum(tex_type);
3313
3314         if (TEX_CUBE != tex_type)
3315         {
3316                 gl.getTexImage(target, 0 /* level */, format, type, out_data);
3317                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3318         }
3319         else
3320         {
3321                 GLint width;
3322                 GLint height;
3323
3324                 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
3325                 {
3326                         TCU_FAIL("Not implemented");
3327                 }
3328
3329                 GLuint texel_size = 4;
3330
3331                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
3332                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3333
3334                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
3335                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3336
3337                 const GLuint image_size = width * height * texel_size;
3338
3339                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
3340                                            (GLvoid*)((GLchar*)out_data + (image_size * 0)));
3341                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
3342                                            (GLvoid*)((GLchar*)out_data + (image_size * 1)));
3343                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
3344                                            (GLvoid*)((GLchar*)out_data + (image_size * 2)));
3345                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
3346                                            (GLvoid*)((GLchar*)out_data + (image_size * 3)));
3347                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
3348                                            (GLvoid*)((GLchar*)out_data + (image_size * 4)));
3349                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
3350                                            (GLvoid*)((GLchar*)out_data + (image_size * 5)));
3351                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3352         }
3353 }
3354
3355 /** Allocate storage for texture
3356  *
3357  * @param gl              GL functions
3358  * @param tex_type        Type of texture
3359  * @param width           Width of texture
3360  * @param height          Height of texture
3361  * @param depth           Depth of texture
3362  * @param internal_format Internal format of texture
3363  **/
3364 void Texture::Storage(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth,
3365                                           GLenum internal_format)
3366 {
3367         static const GLuint levels = 1;
3368
3369         GLenum target = GetTargetGLenum(tex_type);
3370
3371         switch (tex_type)
3372         {
3373         case TEX_1D:
3374                 gl.texStorage1D(target, levels, internal_format, width);
3375                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3376                 break;
3377         case TEX_2D:
3378         case TEX_1D_ARRAY:
3379         case TEX_2D_RECT:
3380         case TEX_CUBE:
3381                 gl.texStorage2D(target, levels, internal_format, width, height);
3382                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3383                 break;
3384         case TEX_3D:
3385         case TEX_2D_ARRAY:
3386                 gl.texStorage3D(target, levels, internal_format, width, height, depth);
3387                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3388                 break;
3389         default:
3390                 TCU_FAIL("Invliad enum");
3391                 break;
3392         }
3393 }
3394
3395 /** Attach buffer as source of texture buffer data
3396  *
3397  * @param gl              GL functions
3398  * @param internal_format Internal format of texture
3399  * @param buffer_id       Id of buffer that will be used as data source
3400  **/
3401 void Texture::TexBuffer(const Functions& gl, GLenum internal_format, GLuint& buffer_id)
3402 {
3403         gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
3404         GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
3405 }
3406
3407 /** Update contents of texture
3408  *
3409  * @param gl       GL functions
3410  * @param tex_type Type of texture
3411  * @param width    Width of texture
3412  * @param height   Height of texture
3413  * @param format   Format of data
3414  * @param type     Type of data
3415  * @param data     Buffer with image data
3416  **/
3417 void Texture::Update(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum format,
3418                                          GLenum type, GLvoid* data)
3419 {
3420         static const GLuint level = 0;
3421
3422         GLenum target = GetTargetGLenum(tex_type);
3423
3424         switch (tex_type)
3425         {
3426         case TEX_1D:
3427                 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
3428                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3429                 break;
3430         case TEX_2D:
3431         case TEX_1D_ARRAY:
3432         case TEX_2D_RECT:
3433                 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
3434                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3435                 break;
3436         case TEX_CUBE:
3437                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3438                                                  data);
3439                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3440                                                  data);
3441                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3442                                                  data);
3443                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3444                                                  data);
3445                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3446                                                  data);
3447                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3448                                                  data);
3449                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3450                 break;
3451         case TEX_3D:
3452         case TEX_2D_ARRAY:
3453                 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
3454                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3455                 break;
3456         default:
3457                 TCU_FAIL("Invliad enum");
3458                 break;
3459         }
3460 }
3461
3462 /** Get target for given texture type
3463  *
3464  * @param type Type of texture
3465  *
3466  * @return Target
3467  **/
3468 GLenum Texture::GetTargetGLenum(TYPES type)
3469 {
3470         GLenum result = 0;
3471
3472         switch (type)
3473         {
3474         case TEX_BUFFER:
3475                 result = GL_TEXTURE_BUFFER;
3476                 break;
3477         case TEX_2D:
3478                 result = GL_TEXTURE_2D;
3479                 break;
3480         case TEX_2D_RECT:
3481                 result = GL_TEXTURE_RECTANGLE;
3482                 break;
3483         case TEX_2D_ARRAY:
3484                 result = GL_TEXTURE_2D_ARRAY;
3485                 break;
3486         case TEX_3D:
3487                 result = GL_TEXTURE_3D;
3488                 break;
3489         case TEX_CUBE:
3490                 result = GL_TEXTURE_CUBE_MAP;
3491                 break;
3492         case TEX_1D:
3493                 result = GL_TEXTURE_1D;
3494                 break;
3495         case TEX_1D_ARRAY:
3496                 result = GL_TEXTURE_1D_ARRAY;
3497                 break;
3498         }
3499
3500         return result;
3501 }
3502
3503 /* VertexArray constants */
3504 const GLuint VertexArray::m_invalid_id = -1;
3505
3506 /** Constructor.
3507  *
3508  * @param context CTS context.
3509  **/
3510 VertexArray::VertexArray(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
3511 {
3512 }
3513
3514 /** Destructor
3515  *
3516  **/
3517 VertexArray::~VertexArray()
3518 {
3519         Release();
3520 }
3521
3522 /** Initialize vertex array instance
3523  *
3524  **/
3525 void VertexArray::Init()
3526 {
3527         /* Delete previous instance */
3528         Release();
3529
3530         const Functions& gl = m_context.getRenderContext().getFunctions();
3531
3532         Generate(gl, m_id);
3533 }
3534
3535 /** Release vertex array object instance
3536  *
3537  **/
3538 void VertexArray::Release()
3539 {
3540         if (m_invalid_id != m_id)
3541         {
3542                 const Functions& gl = m_context.getRenderContext().getFunctions();
3543
3544                 gl.deleteVertexArrays(1, &m_id);
3545
3546                 m_id = m_invalid_id;
3547         }
3548 }
3549
3550 /** Set attribute in VAO
3551  *
3552  * @param index            Index of attribute
3553  * @param type             Type of attribute
3554  * @param n_array_elements Arary length
3555  * @param normalized       Selectis if values should be normalized
3556  * @param stride           Stride
3557  * @param pointer          Pointer to data, or offset in buffer
3558  **/
3559 void VertexArray::Attribute(GLuint index, const Type& type, GLuint n_array_elements, GLboolean normalized,
3560                                                         GLsizei stride, const GLvoid* pointer)
3561 {
3562         const Functions& gl = m_context.getRenderContext().getFunctions();
3563
3564         AttribPointer(gl, index, type, n_array_elements, normalized, stride, pointer);
3565         Enable(gl, index, type, n_array_elements);
3566 }
3567
3568 /** Binds Vertex array object
3569  *
3570  **/
3571 void VertexArray::Bind()
3572 {
3573         const Functions& gl = m_context.getRenderContext().getFunctions();
3574
3575         Bind(gl, m_id);
3576 }
3577
3578 /** Set attribute in VAO
3579  *
3580  * @param gl               Functions
3581  * @param index            Index of attribute
3582  * @param type             Type of attribute
3583  * @param n_array_elements Arary length
3584  * @param normalized       Selectis if values should be normalized
3585  * @param stride           Stride
3586  * @param pointer          Pointer to data, or offset in buffer
3587  **/
3588 void VertexArray::AttribPointer(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements,
3589                                                                 GLboolean normalized, GLsizei stride, const GLvoid* pointer)
3590 {
3591         const GLuint basic_type_size = Type::GetTypeSize(type.m_basic_type);
3592         const GLint  size                        = (GLint)type.m_n_rows;
3593         const GLuint column_size         = (GLuint)size * basic_type_size;
3594         const GLenum gl_type             = Type::GetTypeGLenum(type.m_basic_type);
3595
3596         GLuint offset = 0;
3597
3598         /* If attribute is not an array */
3599         if (0 == n_array_elements)
3600         {
3601                 n_array_elements = 1;
3602         }
3603
3604         /* For each element in array */
3605         for (GLuint element = 0; element < n_array_elements; ++element)
3606         {
3607                 /* For each column in matrix */
3608                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3609                 {
3610                         /* Calculate offset */
3611                         const GLvoid* ptr = (GLubyte*)pointer + offset;
3612
3613                         /* Set up attribute */
3614                         switch (type.m_basic_type)
3615                         {
3616                         case Type::Float:
3617                                 gl.vertexAttribPointer(index, size, gl_type, normalized, stride, ptr);
3618                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
3619                                 break;
3620                         case Type::Int:
3621                         case Type::Uint:
3622                                 gl.vertexAttribIPointer(index, size, gl_type, stride, ptr);
3623                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
3624                                 break;
3625                         case Type::Double:
3626                                 gl.vertexAttribLPointer(index, size, gl_type, stride, ptr);
3627                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribLPointer");
3628                                 break;
3629                         default:
3630                                 TCU_FAIL("Invalid enum");
3631                         }
3632
3633                         /* Next location */
3634                         offset += column_size;
3635                         index += 1;
3636                 }
3637         }
3638 }
3639
3640 /** Binds Vertex array object
3641  *
3642  * @param gl GL functions
3643  * @param id ID of vertex array object
3644  **/
3645 void VertexArray::Bind(const glw::Functions& gl, glw::GLuint id)
3646 {
3647         gl.bindVertexArray(id);
3648         GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
3649 }
3650
3651 /** Disable attribute in VAO
3652  *
3653  * @param gl               Functions
3654  * @param index            Index of attribute
3655  * @param type             Type of attribute
3656  * @param n_array_elements Arary length
3657  **/
3658 void VertexArray::Disable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3659 {
3660         /* If attribute is not an array */
3661         if (0 == n_array_elements)
3662         {
3663                 n_array_elements = 1;
3664         }
3665
3666         /* For each element in array */
3667         for (GLuint element = 0; element < n_array_elements; ++element)
3668         {
3669                 /* For each column in matrix */
3670                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3671                 {
3672                         /* Enable attribute array */
3673                         gl.disableVertexAttribArray(index);
3674                         GLU_EXPECT_NO_ERROR(gl.getError(), "DisableVertexAttribArray");
3675
3676                         /* Next location */
3677                         index += 1;
3678                 }
3679         }
3680 }
3681
3682 /** Set divisor for attribute
3683  *
3684  * @param gl               Functions
3685  * @param index            Index of attribute
3686  * @param divisor          New divisor value
3687  **/
3688 void VertexArray::Divisor(const Functions& gl, GLuint index, GLuint divisor)
3689 {
3690         gl.vertexAttribDivisor(index, divisor);
3691         GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribDivisor");
3692 }
3693
3694 /** Enables attribute in VAO
3695  *
3696  * @param gl               Functions
3697  * @param index            Index of attribute
3698  * @param type             Type of attribute
3699  * @param n_array_elements Arary length
3700  **/
3701 void VertexArray::Enable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3702 {
3703         /* If attribute is not an array */
3704         if (0 == n_array_elements)
3705         {
3706                 n_array_elements = 1;
3707         }
3708
3709         /* For each element in array */
3710         for (GLuint element = 0; element < n_array_elements; ++element)
3711         {
3712                 /* For each column in matrix */
3713                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3714                 {
3715                         /* Enable attribute array */
3716                         gl.enableVertexAttribArray(index);
3717                         GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
3718
3719                         /* Next location */
3720                         index += 1;
3721                 }
3722         }
3723 }
3724
3725 /** Generates Vertex array object
3726  *
3727  * @param gl     GL functions
3728  * @param out_id ID of vertex array object
3729  **/
3730 void VertexArray::Generate(const glw::Functions& gl, glw::GLuint& out_id)
3731 {
3732         GLuint id = m_invalid_id;
3733
3734         gl.genVertexArrays(1, &id);
3735         GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
3736
3737         if (m_invalid_id == id)
3738         {
3739                 TCU_FAIL("Invalid id");
3740         }
3741
3742         out_id = id;
3743 }
3744
3745 /* Constatns used by Variable */
3746 const GLint Variable::m_automatic_location = -1;
3747
3748 /** Copy constructor
3749  *
3750  **/
3751 Variable::Variable(const Variable& var)
3752         : m_data(var.m_data)
3753         , m_data_size(var.m_data_size)
3754         , m_descriptor(var.m_descriptor.m_name.c_str(), var.m_descriptor.m_qualifiers.c_str(),
3755                                    var.m_descriptor.m_expected_component, var.m_descriptor.m_expected_location,
3756                                    var.m_descriptor.m_builtin, var.m_descriptor.m_normalized, var.m_descriptor.m_n_array_elements,
3757                                    var.m_descriptor.m_expected_stride_of_element, var.m_descriptor.m_offset)
3758         , m_storage(var.m_storage)
3759 {
3760         m_descriptor.m_type = var.m_descriptor.m_type;
3761
3762         if (BUILTIN != var.m_descriptor.m_type)
3763         {
3764                 m_descriptor.m_interface = var.m_descriptor.m_interface;
3765         }
3766 }
3767
3768 /** Get code that defines variable
3769  *
3770  * @param flavour Provides info if variable is array or not
3771  *
3772  * @return String with code
3773  **/
3774 std::string Variable::GetDefinition(FLAVOUR flavour) const
3775 {
3776         return m_descriptor.GetDefinition(flavour, m_storage);
3777 }
3778
3779 /** Calcualtes stride of variable
3780  *
3781  * @return Calculated value
3782  **/
3783 GLuint Variable::GetStride() const
3784 {
3785         GLint variable_stride = 0;
3786
3787         if (0 == m_descriptor.m_n_array_elements)
3788         {
3789                 variable_stride = m_descriptor.m_expected_stride_of_element;
3790         }
3791         else
3792         {
3793                 variable_stride = m_descriptor.m_expected_stride_of_element * m_descriptor.m_n_array_elements;
3794         }
3795
3796         return variable_stride;
3797 }
3798
3799 /** Check if variable is block
3800  *
3801  * @return true if variable type is block, false otherwise
3802  **/
3803 bool Variable::IsBlock() const
3804 {
3805         if (BUILTIN == m_descriptor.m_type)
3806         {
3807                 return false;
3808         }
3809
3810         const Interface* interface = m_descriptor.m_interface;
3811         if (0 == interface)
3812         {
3813                 TCU_FAIL("Nullptr");
3814         }
3815
3816         return (Interface::BLOCK == interface->m_type);
3817 }
3818
3819 /** Check if variable is struct
3820  *
3821  * @return true if variable type is struct, false otherwise
3822  **/
3823 bool Variable::IsStruct() const
3824 {
3825         if (BUILTIN == m_descriptor.m_type)
3826         {
3827                 return false;
3828         }
3829
3830         const Interface* interface = m_descriptor.m_interface;
3831         if (0 == interface)
3832         {
3833                 TCU_FAIL("Nullptr");
3834         }
3835
3836         return (Interface::STRUCT == interface->m_type);
3837 }
3838 /** Get code that reference variable
3839  *
3840  * @param parent_name Name of parent
3841  * @param variable    Descriptor of variable
3842  * @param flavour     Provides info about how variable should be referenced
3843  * @param array_index Index of array, ignored when variable is not array
3844  *
3845  * @return String with code
3846  **/
3847 std::string Variable::GetReference(const std::string& parent_name, const Descriptor& variable, FLAVOUR flavour,
3848                                                                    GLuint array_index)
3849 {
3850         std::string name;
3851
3852         /* Prepare name */
3853         if (false == parent_name.empty())
3854         {
3855                 name = parent_name;
3856                 name.append(".");
3857                 name.append(variable.m_name);
3858         }
3859         else
3860         {
3861                 name = variable.m_name;
3862         }
3863
3864         /* */
3865         switch (flavour)
3866         {
3867         case Utils::Variable::BASIC:
3868                 break;
3869
3870         case Utils::Variable::ARRAY:
3871                 name.append("[0]");
3872                 break;
3873
3874         case Utils::Variable::INDEXED_BY_INVOCATION_ID:
3875                 name.append("[gl_InvocationID]");
3876                 break;
3877         }
3878
3879         /* Assumption that both variables have same lengths */
3880         if (0 != variable.m_n_array_elements)
3881         {
3882                 GLchar buffer[16];
3883                 sprintf(buffer, "%d", array_index);
3884                 name.append("[");
3885                 name.append(buffer);
3886                 name.append("]");
3887         }
3888
3889         return name;
3890 }
3891
3892 /** Get "flavour" of varying
3893  *
3894  * @param stage     Stage of shader
3895  * @param direction Selects if varying is in or out
3896  *
3897  * @return Flavour
3898  **/
3899 Variable::FLAVOUR Variable::GetFlavour(Shader::STAGES stage, VARYING_DIRECTION direction)
3900 {
3901         FLAVOUR result = BASIC;
3902
3903         switch (stage)
3904         {
3905         case Shader::GEOMETRY:
3906         case Shader::TESS_EVAL:
3907                 if (INPUT == direction)
3908                 {
3909                         result = ARRAY;
3910                 }
3911                 break;
3912         case Shader::TESS_CTRL:
3913                 result = INDEXED_BY_INVOCATION_ID;
3914                 break;
3915         default:
3916                 break;
3917         }
3918
3919         return result;
3920 }
3921
3922 /** Constructor, for built-in types
3923  *
3924  * @param name                       Name
3925  * @param qualifiers                 Qualifiers
3926  * @param expected_component         Expected component of variable
3927  * @param expected_location          Expected location
3928  * @param type                       Type
3929  * @param normalized                 Selects if data should be normalized
3930  * @param n_array_elements           Length of array
3931  * @param expected_stride_of_element Expected stride of element
3932  * @param offset                     Offset
3933  **/
3934 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
3935                                                                  GLint expected_location, const Type& type, GLboolean normalized,
3936                                                                  GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
3937         : m_expected_component(expected_component)
3938         , m_expected_location(expected_location)
3939         , m_expected_stride_of_element(expected_stride_of_element)
3940         , m_n_array_elements(n_array_elements)
3941         , m_name(name)
3942         , m_normalized(normalized)
3943         , m_offset(offset)
3944         , m_qualifiers(qualifiers)
3945         , m_type(BUILTIN)
3946         , m_builtin(type)
3947 {
3948 }
3949
3950 /** Constructor, for interface types
3951  *
3952  * @param name                       Name
3953  * @param qualifiers                 Qualifiers
3954  * @param expected_component         Expected component of variable
3955  * @param expected_location          Expected location
3956  * @param interface                  Interface of variable
3957  * @param n_array_elements           Length of array
3958  * @param expected_stride_of_element Expected stride of element
3959  * @param offset                     Offset
3960  **/
3961 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_componenet,
3962                                                                  GLint expected_location, Interface* interface, GLuint n_array_elements,
3963                                                                  GLint expected_stride_of_element, GLuint offset)
3964         : m_expected_component(expected_componenet)
3965         , m_expected_location(expected_location)
3966         , m_expected_stride_of_element(expected_stride_of_element)
3967         , m_n_array_elements(n_array_elements)
3968         , m_name(name)
3969         , m_normalized(GL_FALSE)
3970         , m_offset(offset)
3971         , m_qualifiers(qualifiers)
3972         , m_type(INTERFACE)
3973         , m_interface(interface)
3974 {
3975 }
3976
3977 /** Get definition of variable
3978  *
3979  * @param flavour Flavour of variable
3980  * @param storage Storage used for variable
3981  *
3982  * @return code with defintion
3983  **/
3984 std::string Variable::Descriptor::GetDefinition(FLAVOUR flavour, STORAGE storage) const
3985 {
3986         static const GLchar* basic_template = "QUALIFIERS STORAGETYPE NAMEARRAY;";
3987         static const GLchar* array_template = "QUALIFIERS STORAGETYPE NAME[]ARRAY;";
3988         const GLchar*            storage_str    = 0;
3989
3990         std::string definition;
3991         size_t          position = 0;
3992
3993         /* Select definition template */
3994         switch (flavour)
3995         {
3996         case BASIC:
3997                 definition = basic_template;
3998                 break;
3999         case ARRAY:
4000         case INDEXED_BY_INVOCATION_ID:
4001                 definition = array_template;
4002                 break;
4003         default:
4004                 TCU_FAIL("Invliad enum");
4005                 break;
4006         }
4007
4008         if (BUILTIN != m_type)
4009         {
4010                 if (0 == m_interface)
4011                 {
4012                         TCU_FAIL("Nullptr");
4013                 }
4014         }
4015
4016         /* Qualifiers */
4017         if (true == m_qualifiers.empty())
4018         {
4019                 replaceToken("QUALIFIERS ", position, "", definition);
4020         }
4021         else
4022         {
4023                 replaceToken("QUALIFIERS", position, m_qualifiers.c_str(), definition);
4024         }
4025
4026         // According to spec: integer or unsigned integer type must always be declared with flat qualifier
4027         bool flat_qualifier = false;
4028         if (m_type != BUILTIN && m_interface != NULL)
4029         {
4030                 if (m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Int ||
4031                         m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Uint)
4032                 {
4033                         flat_qualifier = true;
4034                 }
4035         }
4036         /* Storage */
4037         switch (storage)
4038         {
4039         case VARYING_INPUT:
4040                 storage_str = flat_qualifier ? "flat in " : "in ";
4041                 break;
4042         case VARYING_OUTPUT:
4043                 storage_str = "out ";
4044                 break;
4045         case UNIFORM:
4046                 storage_str = "uniform ";
4047                 break;
4048         case SSB:
4049                 storage_str = "buffer ";
4050                 break;
4051         case MEMBER:
4052                 storage_str = "";
4053                 break;
4054         default:
4055                 TCU_FAIL("Invalid enum");
4056                 break;
4057         }
4058
4059         replaceToken("STORAGE", position, storage_str, definition);
4060
4061         /* Type */
4062         if (BUILTIN == m_type)
4063         {
4064                 replaceToken("TYPE", position, m_builtin.GetGLSLTypeName(), definition);
4065         }
4066         else
4067         {
4068                 if (Interface::STRUCT == m_interface->m_type)
4069                 {
4070                         replaceToken("TYPE", position, m_interface->m_name.c_str(), definition);
4071                 }
4072                 else
4073                 {
4074                         const std::string& block_definition = m_interface->GetDefinition();
4075
4076                         replaceToken("TYPE", position, block_definition.c_str(), definition);
4077                 }
4078         }
4079
4080         /* Name */
4081         replaceToken("NAME", position, m_name.c_str(), definition);
4082
4083         /* Array size */
4084         if (0 == m_n_array_elements)
4085         {
4086                 replaceToken("ARRAY", position, "", definition);
4087         }
4088         else
4089         {
4090                 char buffer[16];
4091                 sprintf(buffer, "[%d]", m_n_array_elements);
4092
4093                 replaceToken("ARRAY", position, buffer, definition);
4094         }
4095
4096         /* Done */
4097         return definition;
4098 }
4099
4100 /** Get definitions for variables collected in vector
4101  *
4102  * @param vector  Collection of variables
4103  * @param flavour Flavour of variables
4104  *
4105  * @return Code with definitions
4106  **/
4107 std::string GetDefinitions(const Variable::PtrVector& vector, Variable::FLAVOUR flavour)
4108 {
4109         std::string list         = Utils::g_list;
4110         size_t          position = 0;
4111
4112         for (GLuint i = 0; i < vector.size(); ++i)
4113         {
4114                 Utils::insertElementOfList(vector[i]->GetDefinition(flavour).c_str(), "\n", position, list);
4115         }
4116
4117         Utils::endList("", position, list);
4118
4119         return list;
4120 }
4121
4122 /** Get definitions for interfaces collected in vector
4123  *
4124  * @param vector Collection of interfaces
4125  *
4126  * @return Code with definitions
4127  **/
4128 std::string GetDefinitions(const Interface::PtrVector& vector)
4129 {
4130         std::string list         = Utils::g_list;
4131         size_t          position = 0;
4132
4133         for (GLuint i = 0; i < vector.size(); ++i)
4134         {
4135                 Utils::insertElementOfList(vector[i]->GetDefinition().c_str(), "\n", position, list);
4136         }
4137
4138         Utils::endList("", position, list);
4139
4140         return list;
4141 }
4142
4143 /** Constructor
4144  *
4145  * @param name Name
4146  * @param type Type of interface
4147  **/
4148 Interface::Interface(const GLchar* name, Interface::TYPE type) : m_name(name), m_type(type)
4149 {
4150 }
4151
4152 /** Adds member to interface
4153  *
4154  * @param member Descriptor of new member
4155  *
4156  * @return Pointer to just created member
4157  **/
4158 Variable::Descriptor* Interface::AddMember(const Variable::Descriptor& member)
4159 {
4160         m_members.push_back(member);
4161
4162         return &m_members.back();
4163 }
4164
4165 /** Get definition of interface
4166  *
4167  * @param Code with definition
4168  **/
4169 std::string Interface::GetDefinition() const
4170 {
4171         std::string definition;
4172         size_t          position = 0;
4173
4174         const GLchar* member_list = "    MEMBER_DEFINITION\nMEMBER_LIST";
4175
4176         if (STRUCT == m_type)
4177         {
4178                 definition = "struct NAME {\nMEMBER_LIST};";
4179         }
4180         else
4181         {
4182                 definition = "NAME {\nMEMBER_LIST}";
4183         }
4184
4185         /* Name */
4186         replaceToken("NAME", position, m_name.c_str(), definition);
4187
4188         /* Member list */
4189         for (GLuint i = 0; i < m_members.size(); ++i)
4190         {
4191                 const size_t       start_position       = position;
4192                 const std::string& member_definition = m_members[i].GetDefinition(Variable::BASIC, Variable::MEMBER);
4193
4194                 /* Member list */
4195                 replaceToken("MEMBER_LIST", position, member_list, definition);
4196
4197                 /* Move back position */
4198                 position = start_position;
4199
4200                 /* Member definition */
4201                 replaceToken("MEMBER_DEFINITION", position, member_definition.c_str(), definition);
4202         }
4203
4204         /* Remove last member list */
4205         replaceToken("MEMBER_LIST", position, "", definition);
4206
4207         /* Done */
4208         return definition;
4209 }
4210
4211 /** Adds member of built-in type to interface
4212  *
4213  * @param name                       Name
4214  * @param qualifiers                 Qualifiers
4215  * @param expected_component         Expected component of variable
4216  * @param expected_location          Expected location
4217  * @param type                       Type
4218  * @param normalized                 Selects if data should be normalized
4219  * @param n_array_elements           Length of array
4220  * @param expected_stride_of_element Expected stride of element
4221  * @param offset                     Offset
4222  *
4223  * @return Pointer to just created member
4224  **/
4225 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4226                                                                                 GLint expected_location, const Type& type, GLboolean normalized,
4227                                                                                 GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
4228 {
4229         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, type, normalized,
4230                                                                                   n_array_elements, expected_stride_of_element, offset));
4231 }
4232
4233 /** Adds member of interface type to interface
4234  *
4235  * @param name                       Name
4236  * @param qualifiers                 Qualifiers
4237  * @param expected_component         Expected component of variable
4238  * @param expected_location          Expected location
4239  * @param type                       Type
4240  * @param normalized                 Selects if data should be normalized
4241  * @param n_array_elements           Length of array
4242  * @param expected_stride_of_element Expected stride of element
4243  * @param offset                     Offset
4244  *
4245  * @return Pointer to just created member
4246  **/
4247 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4248                                                                                 GLint expected_location, Interface* nterface, GLuint n_array_elements,
4249                                                                                 GLint expected_stride_of_element, GLuint offset)
4250 {
4251         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, nterface,
4252                                                                                   n_array_elements, expected_stride_of_element, offset));
4253 }
4254
4255 /** Clears contents of vector of pointers
4256  *
4257  * @tparam T Type of elements
4258  *
4259  * @param vector Collection to be cleared
4260  **/
4261 template <typename T>
4262 void clearPtrVector(std::vector<T*>& vector)
4263 {
4264         for (size_t i = 0; i < vector.size(); ++i)
4265         {
4266                 T* t = vector[i];
4267
4268                 vector[i] = 0;
4269
4270                 if (0 != t)
4271                 {
4272                         delete t;
4273                 }
4274         }
4275
4276         vector.clear();
4277 }
4278
4279 /** Constructor
4280  *
4281  * @param stage Stage described by that interface
4282  **/
4283 ShaderInterface::ShaderInterface(Shader::STAGES stage) : m_stage(stage)
4284 {
4285         /* Nothing to be done */
4286 }
4287
4288 /** Get definitions of globals
4289  *
4290  * @return Code with definitions
4291  **/
4292 std::string ShaderInterface::GetDefinitionsGlobals() const
4293 {
4294         return m_globals;
4295 }
4296
4297 /** Get definitions of inputs
4298  *
4299  * @return Code with definitions
4300  **/
4301 std::string ShaderInterface::GetDefinitionsInputs() const
4302 {
4303         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::INPUT);
4304
4305         return GetDefinitions(m_inputs, flavour);
4306 }
4307
4308 /** Get definitions of outputs
4309  *
4310  * @return Code with definitions
4311  **/
4312 std::string ShaderInterface::GetDefinitionsOutputs() const
4313 {
4314         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::OUTPUT);
4315
4316         return GetDefinitions(m_outputs, flavour);
4317 }
4318
4319 /** Get definitions of buffers
4320  *
4321  * @return Code with definitions
4322  **/
4323 std::string ShaderInterface::GetDefinitionsSSBs() const
4324 {
4325         return GetDefinitions(m_ssb_blocks, Variable::BASIC);
4326 }
4327
4328 /** Get definitions of uniforms
4329  *
4330  * @return Code with definitions
4331  **/
4332 std::string ShaderInterface::GetDefinitionsUniforms() const
4333 {
4334         return GetDefinitions(m_uniforms, Variable::BASIC);
4335 }
4336
4337 /** Constructor
4338  *
4339  * @param in  Input variable
4340  * @param out Output variable
4341  **/
4342 VaryingConnection::VaryingConnection(Variable* in, Variable* out) : m_in(in), m_out(out)
4343 {
4344         /* NBothing to be done here */
4345 }
4346
4347 /** Adds new varying connection to given stage
4348  *
4349  * @param stage Shader stage
4350  * @param in    In varying
4351  * @param out   Out varying
4352  **/
4353 void VaryingPassthrough::Add(Shader::STAGES stage, Variable* in, Variable* out)
4354 {
4355         VaryingConnection::Vector& vector = Get(stage);
4356
4357         vector.push_back(VaryingConnection(in, out));
4358 }
4359
4360 /** Get all passthrough connections for given stage
4361  *
4362  * @param stage Shader stage
4363  *
4364  * @return Vector of connections
4365  **/
4366 VaryingConnection::Vector& VaryingPassthrough::Get(Shader::STAGES stage)
4367 {
4368         VaryingConnection::Vector* result = 0;
4369
4370         switch (stage)
4371         {
4372         case Shader::FRAGMENT:
4373                 result = &m_fragment;
4374                 break;
4375         case Shader::GEOMETRY:
4376                 result = &m_geometry;
4377                 break;
4378         case Shader::TESS_CTRL:
4379                 result = &m_tess_ctrl;
4380                 break;
4381         case Shader::TESS_EVAL:
4382                 result = &m_tess_eval;
4383                 break;
4384         case Shader::VERTEX:
4385                 result = &m_vertex;
4386                 break;
4387         default:
4388                 TCU_FAIL("Invalid enum");
4389         }
4390
4391         return *result;
4392 }
4393
4394 /** Constructor
4395  *
4396  **/
4397 ProgramInterface::ProgramInterface()
4398         : m_compute(Shader::COMPUTE)
4399         , m_vertex(Shader::VERTEX)
4400         , m_tess_ctrl(Shader::TESS_CTRL)
4401         , m_tess_eval(Shader::TESS_EVAL)
4402         , m_geometry(Shader::GEOMETRY)
4403         , m_fragment(Shader::FRAGMENT)
4404 {
4405 }
4406
4407 /** Destructor
4408  *
4409  **/
4410 ProgramInterface::~ProgramInterface()
4411 {
4412         clearPtrVector(m_blocks);
4413         clearPtrVector(m_structures);
4414 }
4415
4416 /** Adds new interface
4417  *
4418  * @param name
4419  * @param type
4420  *
4421  * @return Pointer to created interface
4422  **/
4423 Interface* ProgramInterface::AddInterface(const GLchar* name, Interface::TYPE type)
4424 {
4425         Interface* interface = 0;
4426
4427         if (Interface::STRUCT == type)
4428         {
4429                 interface = new Interface(name, type);
4430
4431                 m_structures.push_back(interface);
4432         }
4433         else
4434         {
4435                 interface = new Interface(name, type);
4436
4437                 m_blocks.push_back(interface);
4438         }
4439
4440         return interface;
4441 }
4442
4443 /** Adds new block interface
4444  *
4445  * @param name
4446  *
4447  * @return Pointer to created interface
4448  **/
4449 Interface* ProgramInterface::Block(const GLchar* name)
4450 {
4451         return AddInterface(name, Interface::BLOCK);
4452 }
4453
4454 /** Get interface of given shader stage
4455  *
4456  * @param stage Shader stage
4457  *
4458  * @return Reference to stage interface
4459  **/
4460 ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage)
4461 {
4462         ShaderInterface* interface = 0;
4463
4464         switch (stage)
4465         {
4466         case Shader::COMPUTE:
4467                 interface = &m_compute;
4468                 break;
4469         case Shader::FRAGMENT:
4470                 interface = &m_fragment;
4471                 break;
4472         case Shader::GEOMETRY:
4473                 interface = &m_geometry;
4474                 break;
4475         case Shader::TESS_CTRL:
4476                 interface = &m_tess_ctrl;
4477                 break;
4478         case Shader::TESS_EVAL:
4479                 interface = &m_tess_eval;
4480                 break;
4481         case Shader::VERTEX:
4482                 interface = &m_vertex;
4483                 break;
4484         default:
4485                 TCU_FAIL("Invalid enum");
4486         }
4487
4488         return *interface;
4489 }
4490
4491 /** Get interface of given shader stage
4492  *
4493  * @param stage Shader stage
4494  *
4495  * @return Reference to stage interface
4496  **/
4497 const ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage) const
4498 {
4499         const ShaderInterface* interface = 0;
4500
4501         switch (stage)
4502         {
4503         case Shader::COMPUTE:
4504                 interface = &m_compute;
4505                 break;
4506         case Shader::FRAGMENT:
4507                 interface = &m_fragment;
4508                 break;
4509         case Shader::GEOMETRY:
4510                 interface = &m_geometry;
4511                 break;
4512         case Shader::TESS_CTRL:
4513                 interface = &m_tess_ctrl;
4514                 break;
4515         case Shader::TESS_EVAL:
4516                 interface = &m_tess_eval;
4517                 break;
4518         case Shader::VERTEX:
4519                 interface = &m_vertex;
4520                 break;
4521         default:
4522                 TCU_FAIL("Invalid enum");
4523         }
4524
4525         return *interface;
4526 }
4527
4528 /** Clone interface of Vertex shader stage to other stages
4529  * It creates matching inputs, outputs, uniforms and buffers in other stages.
4530  * There are no additional outputs for FRAGMENT shader generated.
4531  *
4532  * @param varying_passthrough Collection of varyings connections
4533  **/
4534 void ProgramInterface::CloneVertexInterface(VaryingPassthrough& varying_passthrough)
4535 {
4536         /* VS outputs >> TCS inputs >> TCS outputs >> ..  >> FS inputs */
4537         for (size_t i = 0; i < m_vertex.m_outputs.size(); ++i)
4538         {
4539                 const Variable& vs_var = *m_vertex.m_outputs[i];
4540                 const GLchar*   prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4541
4542                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4543                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4544                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4545                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4546         }
4547
4548         /* Copy uniforms from VS to other stages */
4549         for (size_t i = 0; i < m_vertex.m_uniforms.size(); ++i)
4550         {
4551                 Variable&        vs_var = *m_vertex.m_uniforms[i];
4552                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4553
4554                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4555                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4556                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4557                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4558                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4559
4560                 /* Uniform blocks needs unique binding */
4561                 if (true == vs_var.IsBlock())
4562                 {
4563                         replaceBinding(vs_var, Shader::VERTEX);
4564                 }
4565         }
4566
4567         /* Copy SSBs from VS to other stages */
4568         for (size_t i = 0; i < m_vertex.m_ssb_blocks.size(); ++i)
4569         {
4570                 Variable&        vs_var = *m_vertex.m_ssb_blocks[i];
4571                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4572
4573                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4574                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4575                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4576                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4577                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4578
4579                 /* SSBs blocks needs unique binding */
4580                 if (true == vs_var.IsBlock())
4581                 {
4582                         replaceBinding(vs_var, Shader::VERTEX);
4583                 }
4584         }
4585
4586         m_compute.m_globals   = m_vertex.m_globals;
4587         m_fragment.m_globals  = m_vertex.m_globals;
4588         m_geometry.m_globals  = m_vertex.m_globals;
4589         m_tess_ctrl.m_globals = m_vertex.m_globals;
4590         m_tess_eval.m_globals = m_vertex.m_globals;
4591 }
4592
4593 /** Clone variable for specific stage
4594  *
4595  * @param variable            Variable
4596  * @param stage               Requested stage
4597  * @param prefix              Prefix used in variable name that is specific for original stage
4598  * @param varying_passthrough Collection of varyings connections
4599  **/
4600 void ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage, const GLchar* prefix,
4601                                                                                          VaryingPassthrough& varying_passthrough)
4602 {
4603         switch (variable.m_storage)
4604         {
4605         case Variable::VARYING_OUTPUT:
4606         {
4607                 Variable* in = cloneVariableForStage(variable, stage, Variable::VARYING_INPUT, prefix);
4608
4609                 if (Shader::FRAGMENT != stage)
4610                 {
4611                         Variable* out = cloneVariableForStage(variable, stage, Variable::VARYING_OUTPUT, prefix);
4612                         varying_passthrough.Add(stage, in, out);
4613                 }
4614         }
4615         break;
4616         case Variable::UNIFORM:
4617         case Variable::SSB:
4618                 cloneVariableForStage(variable, stage, variable.m_storage, prefix);
4619                 break;
4620         default:
4621                 TCU_FAIL("Invalid enum");
4622                 break;
4623         }
4624 }
4625
4626 /** Clone variable for specific stage
4627  *
4628  * @param variable Variable
4629  * @param stage    Requested stage
4630  * @param storage  Storage used by variable
4631  * @param prefix   Prefix used in variable name that is specific for original stage
4632  *
4633  * @return New variable
4634  **/
4635 Variable* ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage,
4636                                                                                                   Variable::STORAGE storage, const GLchar* prefix)
4637 {
4638         /* Initialize with original variable */
4639         Variable* var = new Variable(variable);
4640         if (0 == var)
4641         {
4642                 TCU_FAIL("Memory allocation");
4643         }
4644
4645         /* Set up storage */
4646         var->m_storage = storage;
4647
4648         /* Get name */
4649         std::string name = variable.m_descriptor.m_name;
4650
4651         /* Prefix name with stage ID, empty means default block */
4652         if (false == name.empty())
4653         {
4654                 size_t            position       = 0;
4655                 const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4656                 Utils::replaceToken(prefix, position, stage_prefix, name);
4657         }
4658         var->m_descriptor.m_name = name;
4659
4660         /* Clone block */
4661         const bool is_block = variable.IsBlock();
4662         if (true == is_block)
4663         {
4664                 const Interface* interface = variable.m_descriptor.m_interface;
4665
4666                 Interface* block = CloneBlockForStage(*interface, stage, storage, prefix);
4667
4668                 var->m_descriptor.m_interface = block;
4669         }
4670
4671         /* Store variable */
4672         ShaderInterface& si             = GetShaderInterface(stage);
4673         Variable*                result = 0;
4674
4675         switch (storage)
4676         {
4677         case Variable::VARYING_INPUT:
4678                 si.m_inputs.push_back(var);
4679                 result = si.m_inputs.back();
4680                 break;
4681         case Variable::VARYING_OUTPUT:
4682                 si.m_outputs.push_back(var);
4683                 result = si.m_outputs.back();
4684                 break;
4685         case Variable::UNIFORM:
4686                 /* Uniform blocks needs unique binding */
4687                 if (true == is_block)
4688                 {
4689                         replaceBinding(*var, stage);
4690                 }
4691
4692                 si.m_uniforms.push_back(var);
4693                 result = si.m_uniforms.back();
4694                 break;
4695         case Variable::SSB:
4696                 /* SSBs needs unique binding */
4697                 if (true == is_block)
4698                 {
4699                         replaceBinding(*var, stage);
4700                 }
4701
4702                 si.m_ssb_blocks.push_back(var);
4703                 result = si.m_ssb_blocks.back();
4704                 break;
4705         default:
4706                 TCU_FAIL("Invalid enum");
4707                 break;
4708         }
4709
4710         return result;
4711 }
4712
4713 /** clone block to specific stage
4714  *
4715  * @param block   Block to be copied
4716  * @param stage   Specific stage
4717  * @param storage Storage used by block
4718  * @param prefix  Prefix used in block name
4719  *
4720  * @return New interface
4721  **/
4722 Interface* ProgramInterface::CloneBlockForStage(const Interface& block, Shader::STAGES stage, Variable::STORAGE storage,
4723                                                                                                 const GLchar* prefix)
4724 {
4725         /* Get name */
4726         std::string name = block.m_name;
4727
4728         /* Prefix name with stage ID */
4729         size_t            position       = 0;
4730         const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4731         Utils::replaceToken(prefix, position, stage_prefix, name);
4732
4733         Interface* ptr = GetBlock(name.c_str());
4734
4735         if (0 == ptr)
4736         {
4737                 ptr = AddInterface(name.c_str(), Interface::BLOCK);
4738         }
4739
4740         ptr->m_members = block.m_members;
4741
4742         return ptr;
4743 }
4744
4745 /** Get stage specific prefix used in names
4746  *
4747  * @param stage   Stage
4748  * @param storage Storage class
4749  *
4750  * @return String
4751  **/
4752 const GLchar* ProgramInterface::GetStagePrefix(Shader::STAGES stage, Variable::STORAGE storage)
4753 {
4754         static const GLchar* lut[Shader::STAGE_MAX][Variable::STORAGE_MAX] = {
4755                 /*          IN          OUT         UNIFORM     SSB        MEMBER       */
4756                 /* CS  */ { 0, 0, "cs_uni_", "cs_buf_", "" },
4757                 /* VS  */ { "in_vs_", "vs_tcs_", "vs_uni_", "vs_buf_", "" },
4758                 /* TCS */ { "vs_tcs_", "tcs_tes_", "tcs_uni_", "tcs_buf_", "" },
4759                 /* TES */ { "tcs_tes_", "tes_gs_", "tes_uni_", "tes_buf_", "" },
4760                 /* GS  */ { "tes_gs_", "gs_fs_", "gs_uni_", "gs_buf_", "" },
4761                 /* FS  */ { "gs_fs_", "fs_out_", "fs_uni_", "fs_buf_", "" },
4762         };
4763
4764         const GLchar* result = 0;
4765
4766         result = lut[stage][storage];
4767
4768         return result;
4769 }
4770
4771 /** Get definitions of all structures used in program interface
4772  *
4773  * @return String with code
4774  **/
4775 std::string ProgramInterface::GetDefinitionsStructures() const
4776 {
4777         return GetDefinitions(m_structures);
4778 }
4779
4780 /** Get interface code for stage
4781  *
4782  * @param stage Specific stage
4783  *
4784  * @return String with code
4785  **/
4786 std::string ProgramInterface::GetInterfaceForStage(Shader::STAGES stage) const
4787 {
4788         size_t          position  = 0;
4789         std::string interface = "/* Globals */\n"
4790                                                         "GLOBALS\n"
4791                                                         "\n"
4792                                                         "/* Structures */\n"
4793                                                         "STRUCTURES\n"
4794                                                         "\n"
4795                                                         "/* Uniforms */\n"
4796                                                         "UNIFORMS\n"
4797                                                         "\n"
4798                                                         "/* Inputs */\n"
4799                                                         "INPUTS\n"
4800                                                         "\n"
4801                                                         "/* Outputs */\n"
4802                                                         "OUTPUTS\n"
4803                                                         "\n"
4804                                                         "/* Storage */\n"
4805                                                         "STORAGE\n";
4806
4807         const ShaderInterface& si = GetShaderInterface(stage);
4808
4809         const std::string& structures = GetDefinitionsStructures();
4810
4811         const std::string& globals  = si.GetDefinitionsGlobals();
4812         const std::string& inputs   = si.GetDefinitionsInputs();
4813         const std::string& outputs  = si.GetDefinitionsOutputs();
4814         const std::string& uniforms = si.GetDefinitionsUniforms();
4815         const std::string& ssbs         = si.GetDefinitionsSSBs();
4816
4817         replaceToken("GLOBALS", position, globals.c_str(), interface);
4818         replaceToken("STRUCTURES", position, structures.c_str(), interface);
4819         replaceToken("UNIFORMS", position, uniforms.c_str(), interface);
4820         replaceToken("INPUTS", position, inputs.c_str(), interface);
4821         replaceToken("OUTPUTS", position, outputs.c_str(), interface);
4822         replaceToken("STORAGE", position, ssbs.c_str(), interface);
4823
4824         return interface;
4825 }
4826
4827 /** Functional object used in find_if algorithm, in search for interface of given name
4828  *
4829  **/
4830 struct matchInterfaceName
4831 {
4832         matchInterfaceName(const GLchar* name) : m_name(name)
4833         {
4834         }
4835
4836         bool operator()(const Interface* interface)
4837         {
4838                 return 0 == interface->m_name.compare(m_name);
4839         }
4840
4841         const GLchar* m_name;
4842 };
4843
4844 /** Finds interface of given name in given vector of interfaces
4845  *
4846  * @param vector Collection of interfaces
4847  * @param name   Requested name
4848  *
4849  * @return Pointer to interface if available, 0 otherwise
4850  **/
4851 static Interface* findInterfaceByName(Interface::PtrVector& vector, const GLchar* name)
4852 {
4853         Interface::PtrVector::iterator it = std::find_if(vector.begin(), vector.end(), matchInterfaceName(name));
4854
4855         if (vector.end() != it)
4856         {
4857                 return *it;
4858         }
4859         else
4860         {
4861                 return 0;
4862         }
4863 }
4864
4865 /** Search for block of given name
4866  *
4867  * @param name Name of block
4868  *
4869  * @return Pointer to block or 0
4870  **/
4871 Interface* ProgramInterface::GetBlock(const GLchar* name)
4872 {
4873         return findInterfaceByName(m_blocks, name);
4874 }
4875
4876 /** Search for structure of given name
4877  *
4878  * @param name Name of structure
4879  *
4880  * @return Pointer to structure or 0
4881  **/
4882 Interface* ProgramInterface::GetStructure(const GLchar* name)
4883 {
4884         return findInterfaceByName(m_structures, name);
4885 }
4886
4887 /** Adds new sturcture to interface
4888  *
4889  * @param name Name of structure
4890  *
4891  * @return Created structure
4892  **/
4893 Interface* ProgramInterface::Structure(const GLchar* name)
4894 {
4895         return AddInterface(name, Interface::STRUCT);
4896 }
4897
4898 /** Replace "BINDING" token in qualifiers string to value specific for given stage
4899  *
4900  * @param variable Variable to modify
4901  * @param stage    Requested stage
4902  **/
4903 void ProgramInterface::replaceBinding(Variable& variable, Shader::STAGES stage)
4904 {
4905         GLchar binding[16];
4906         sprintf(binding, "%d", stage);
4907         replaceAllTokens("BINDING", binding, variable.m_descriptor.m_qualifiers);
4908 }
4909 } /* Utils namespace */
4910
4911 /** Debuging procedure. Logs parameters.
4912  *
4913  * @param source   As specified in GL spec.
4914  * @param type     As specified in GL spec.
4915  * @param id       As specified in GL spec.
4916  * @param severity As specified in GL spec.
4917  * @param ignored
4918  * @param message  As specified in GL spec.
4919  * @param info     Pointer to instance of Context used by test.
4920  */
4921 void GLW_APIENTRY debug_proc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /* length */,
4922                                                          const GLchar* message, void* info)
4923 {
4924         deqp::Context* ctx = (deqp::Context*)info;
4925
4926         const GLchar* source_str   = "Unknown";
4927         const GLchar* type_str   = "Unknown";
4928         const GLchar* severity_str = "Unknown";
4929
4930         switch (source)
4931         {
4932         case GL_DEBUG_SOURCE_API:
4933                 source_str = "API";
4934                 break;
4935         case GL_DEBUG_SOURCE_APPLICATION:
4936                 source_str = "APP";
4937                 break;
4938         case GL_DEBUG_SOURCE_OTHER:
4939                 source_str = "OTR";
4940                 break;
4941         case GL_DEBUG_SOURCE_SHADER_COMPILER:
4942                 source_str = "COM";
4943                 break;
4944         case GL_DEBUG_SOURCE_THIRD_PARTY:
4945                 source_str = "3RD";
4946                 break;
4947         case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
4948                 source_str = "WS";
4949                 break;
4950         default:
4951                 break;
4952         }
4953
4954         switch (type)
4955         {
4956         case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
4957                 type_str = "DEPRECATED_BEHAVIOR";
4958                 break;
4959         case GL_DEBUG_TYPE_ERROR:
4960                 type_str = "ERROR";
4961                 break;
4962         case GL_DEBUG_TYPE_MARKER:
4963                 type_str = "MARKER";
4964                 break;
4965         case GL_DEBUG_TYPE_OTHER:
4966                 type_str = "OTHER";
4967                 break;
4968         case GL_DEBUG_TYPE_PERFORMANCE:
4969                 type_str = "PERFORMANCE";
4970                 break;
4971         case GL_DEBUG_TYPE_POP_GROUP:
4972                 type_str = "POP_GROUP";
4973                 break;
4974         case GL_DEBUG_TYPE_PORTABILITY:
4975                 type_str = "PORTABILITY";
4976                 break;
4977         case GL_DEBUG_TYPE_PUSH_GROUP:
4978                 type_str = "PUSH_GROUP";
4979                 break;
4980         case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
4981                 type_str = "UNDEFINED_BEHAVIOR";
4982                 break;
4983         default:
4984                 break;
4985         }
4986
4987         switch (severity)
4988         {
4989         case GL_DEBUG_SEVERITY_HIGH:
4990                 severity_str = "H";
4991                 break;
4992         case GL_DEBUG_SEVERITY_LOW:
4993                 severity_str = "L";
4994                 break;
4995         case GL_DEBUG_SEVERITY_MEDIUM:
4996                 severity_str = "M";
4997                 break;
4998         case GL_DEBUG_SEVERITY_NOTIFICATION:
4999                 severity_str = "N";
5000                 break;
5001         default:
5002                 break;
5003         }
5004
5005         ctx->getTestContext().getLog() << tcu::TestLog::Message << "DEBUG_INFO: " << std::setw(3) << source_str << "|"
5006                                                                    << severity_str << "|" << std::setw(18) << type_str << "|" << std::setw(12) << id
5007                                                                    << ": " << message << tcu::TestLog::EndMessage;
5008 }
5009
5010 /** Constructor
5011  *
5012  * @param context          Test context
5013  * @param test_name        Test name
5014  * @param test_description Test description
5015  **/
5016 TestBase::TestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5017         : TestCase(context, test_name, test_description)
5018 {
5019         /* Nothing to be done here */
5020 }
5021
5022 /** Execute test
5023  *
5024  * @return tcu::TestNode::STOP otherwise
5025  **/
5026 tcu::TestNode::IterateResult TestBase::iterate()
5027 {
5028         bool test_result;
5029
5030 #if DEBUG_ENBALE_MESSAGE_CALLBACK
5031         const Functions& gl = m_context.getRenderContext().getFunctions();
5032
5033         gl.debugMessageCallback(debug_proc, &m_context);
5034         GLU_EXPECT_NO_ERROR(gl.getError(), "DebugMessageCallback");
5035 #endif /* DEBUG_ENBALE_MESSAGE_CALLBACK */
5036
5037         try
5038         {
5039                 /* Execute test */
5040                 test_result = test();
5041         }
5042         catch (std::exception& exc)
5043         {
5044                 TCU_FAIL(exc.what());
5045         }
5046
5047         /* Set result */
5048         if (true == test_result)
5049         {
5050                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
5051         }
5052         else
5053         {
5054                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5055         }
5056
5057         /* Done */
5058         return tcu::TestNode::STOP;
5059 }
5060
5061 /** Get last input location available for given type at specific stage
5062  *
5063  * @param stage        Shader stage
5064  * @param type         Input type
5065  * @param array_length Length of input array
5066  *
5067  * @return Last location index
5068  **/
5069 GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5070 {
5071         GLint  divide = 4; /* 4 components per location */
5072         GLint  param  = 0;
5073         GLenum pname  = 0;
5074
5075         /* Select pnmae */
5076         switch (stage)
5077         {
5078         case Utils::Shader::FRAGMENT:
5079                 pname = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
5080                 break;
5081         case Utils::Shader::GEOMETRY:
5082                 pname = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
5083                 break;
5084         case Utils::Shader::TESS_CTRL:
5085                 pname = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
5086                 break;
5087         case Utils::Shader::TESS_EVAL:
5088                 pname = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
5089                 break;
5090         case Utils::Shader::VERTEX:
5091                 pname  = GL_MAX_VERTEX_ATTRIBS;
5092                 divide = 1;
5093                 break;
5094         default:
5095                 TCU_FAIL("Invalid enum");
5096                 break;
5097         }
5098
5099         /* Zero means no array, but 1 slot is required */
5100         if (0 == array_length)
5101         {
5102                 array_length += 1;
5103         }
5104
5105         /* Get MAX */
5106         const Functions& gl = m_context.getRenderContext().getFunctions();
5107
5108         gl.getIntegerv(pname, &param);
5109         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5110
5111 /* Calculate */
5112 #if WRKARD_VARYINGLOCATIONSTEST
5113
5114         const GLint n_avl_locations = 16;
5115
5116 #else
5117
5118         const GLint n_avl_locations = param / divide;
5119
5120 #endif
5121
5122         const GLuint n_req_location = type.GetLocations() * array_length;
5123
5124         return n_avl_locations - n_req_location; /* last is max - 1 */
5125 }
5126
5127 /** Get last input location available for given type at specific stage
5128  *
5129  * @param stage        Shader stage
5130  * @param type         Input type
5131  * @param array_length Length of input array
5132  *
5133  * @return Last location index
5134  **/
5135 GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5136 {
5137         GLint  param = 0;
5138         GLenum pname = 0;
5139
5140         /* Select pnmae */
5141         switch (stage)
5142         {
5143         case Utils::Shader::GEOMETRY:
5144                 pname = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
5145                 break;
5146         case Utils::Shader::TESS_CTRL:
5147                 pname = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
5148                 break;
5149         case Utils::Shader::TESS_EVAL:
5150                 pname = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
5151                 break;
5152         case Utils::Shader::VERTEX:
5153                 pname = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
5154                 break;
5155         default:
5156                 TCU_FAIL("Invalid enum");
5157                 break;
5158         }
5159
5160         /* Zero means no array, but 1 slot is required */
5161         if (0 == array_length)
5162         {
5163                 array_length += 1;
5164         }
5165
5166         /* Get MAX */
5167         const Functions& gl = m_context.getRenderContext().getFunctions();
5168
5169         gl.getIntegerv(pname, &param);
5170         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5171
5172 /* Calculate */
5173 #if WRKARD_VARYINGLOCATIONSTEST
5174
5175         const GLint n_avl_locations = 16;
5176
5177 #else
5178
5179         const GLint n_avl_locations = param / 4; /* 4 components per location */
5180
5181 #endif
5182
5183         const GLuint n_req_location = type.GetLocations() * array_length;
5184
5185         return n_avl_locations - n_req_location; /* last is max - 1 */
5186 }
5187
5188 /** Basic implementation
5189  *
5190  * @param ignored
5191  *
5192  * @return Empty string
5193  **/
5194 std::string TestBase::getTestCaseName(GLuint /* test_case_index */)
5195 {
5196         std::string result;
5197
5198         return result;
5199 }
5200
5201 /** Basic implementation
5202  *
5203  * @return 1
5204  **/
5205 GLuint TestBase::getTestCaseNumber()
5206 {
5207         return 1;
5208 }
5209
5210 /** Check if flat qualifier is required for given type, stage and storage
5211  *
5212  * @param stage        Shader stage
5213  * @param type         Input type
5214  * @param storage      Storage of variable
5215  *
5216  * @return Last location index
5217  **/
5218 bool TestBase::isFlatRequired(Utils::Shader::STAGES stage, const Utils::Type& type,
5219                                                           Utils::Variable::STORAGE storage) const
5220 {
5221         /* Float types do not need flat at all */
5222         if (Utils::Type::Float == type.m_basic_type)
5223         {
5224                 return false;
5225         }
5226
5227         /* Inputs to fragment shader */
5228         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_INPUT == storage))
5229         {
5230                 return true;
5231         }
5232
5233         /* Outputs from geometry shader */
5234         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_OUTPUT == storage))
5235         {
5236                 return true;
5237         }
5238
5239         return false;
5240 }
5241
5242 /** Basic implementation of testInit method
5243  *
5244  **/
5245 void TestBase::testInit()
5246 {
5247 }
5248
5249 /** Calculate stride for interface
5250  *
5251  * @param interface Interface
5252  *
5253  * @return Calculated value
5254  **/
5255 GLuint TestBase::calculateStride(const Utils::Interface& interface) const
5256 {
5257         const size_t n_members = interface.m_members.size();
5258
5259         GLuint stride = 0;
5260
5261         for (size_t i = 0; i < n_members; ++i)
5262         {
5263                 const Utils::Variable::Descriptor& member                 = interface.m_members[i];
5264                 const GLuint                                       member_offset  = member.m_offset;
5265                 const GLuint                                       member_stride  = member.m_expected_stride_of_element;
5266                 const GLuint                                       member_ends_at = member_offset + member_stride;
5267
5268                 stride = std::max(stride, member_ends_at);
5269         }
5270
5271         return stride;
5272 }
5273
5274 /** Generate data for interface. This routine is recursive
5275  *
5276  * @param interface Interface
5277  * @param offset    Offset in out_data
5278  * @param out_data  Buffer to be filled
5279  **/
5280 void TestBase::generateData(const Utils::Interface& interface, GLuint offset, std::vector<GLubyte>& out_data) const
5281 {
5282         const size_t n_members = interface.m_members.size();
5283         GLubyte*         ptr       = &out_data[offset];
5284
5285         for (size_t i = 0; i < n_members; ++i)
5286         {
5287                 const Utils::Variable::Descriptor& member                = interface.m_members[i];
5288                 const GLuint                                       member_offset = member.m_offset;
5289                 const GLuint n_elements = (0 == member.m_n_array_elements) ? 1 : member.m_n_array_elements;
5290
5291                 for (GLuint element = 0; element < n_elements; ++element)
5292                 {
5293                         const GLuint element_offset = element * member.m_expected_stride_of_element;
5294                         const GLuint data_offfset   = member_offset + element_offset;
5295
5296                         if (Utils::Variable::BUILTIN == member.m_type)
5297                         {
5298                                 const std::vector<GLubyte>& data = member.m_builtin.GenerateData();
5299
5300                                 memcpy(ptr + data_offfset, &data[0], data.size());
5301                         }
5302                         else
5303                         {
5304                                 generateData(*member.m_interface, offset + data_offfset, out_data);
5305                         }
5306                 }
5307         }
5308 }
5309
5310 /** Get type at index
5311  *
5312  * @param index Index of requested type
5313  *
5314  * @return Type
5315  **/
5316 Utils::Type TestBase::getType(GLuint index) const
5317 {
5318         Utils::Type type;
5319
5320         switch (index)
5321         {
5322         case 0:
5323                 type = Utils::Type::_double;
5324                 break;
5325         case 1:
5326                 type = Utils::Type::dmat2;
5327                 break;
5328         case 2:
5329                 type = Utils::Type::dmat2x3;
5330                 break;
5331         case 3:
5332                 type = Utils::Type::dmat2x4;
5333                 break;
5334         case 4:
5335                 type = Utils::Type::dmat3;
5336                 break;
5337         case 5:
5338                 type = Utils::Type::dmat3x2;
5339                 break;
5340         case 6:
5341                 type = Utils::Type::dmat3x4;
5342                 break;
5343         case 7:
5344                 type = Utils::Type::dmat4;
5345                 break;
5346         case 8:
5347                 type = Utils::Type::dmat4x2;
5348                 break;
5349         case 9:
5350                 type = Utils::Type::dmat4x3;
5351                 break;
5352         case 10:
5353                 type = Utils::Type::dvec2;
5354                 break;
5355         case 11:
5356                 type = Utils::Type::dvec3;
5357                 break;
5358         case 12:
5359                 type = Utils::Type::dvec4;
5360                 break;
5361         case 13:
5362                 type = Utils::Type::_float;
5363                 break;
5364         case 14:
5365                 type = Utils::Type::mat2;
5366                 break;
5367         case 15:
5368                 type = Utils::Type::mat2x3;
5369                 break;
5370         case 16:
5371                 type = Utils::Type::mat2x4;
5372                 break;
5373         case 17:
5374                 type = Utils::Type::mat3;
5375                 break;
5376         case 18:
5377                 type = Utils::Type::mat3x2;
5378                 break;
5379         case 19:
5380                 type = Utils::Type::mat3x4;
5381                 break;
5382         case 20:
5383                 type = Utils::Type::mat4;
5384                 break;
5385         case 21:
5386                 type = Utils::Type::mat4x2;
5387                 break;
5388         case 22:
5389                 type = Utils::Type::mat4x3;
5390                 break;
5391         case 23:
5392                 type = Utils::Type::vec2;
5393                 break;
5394         case 24:
5395                 type = Utils::Type::vec3;
5396                 break;
5397         case 25:
5398                 type = Utils::Type::vec4;
5399                 break;
5400         case 26:
5401                 type = Utils::Type::_int;
5402                 break;
5403         case 27:
5404                 type = Utils::Type::ivec2;
5405                 break;
5406         case 28:
5407                 type = Utils::Type::ivec3;
5408                 break;
5409         case 29:
5410                 type = Utils::Type::ivec4;
5411                 break;
5412         case 30:
5413                 type = Utils::Type::uint;
5414                 break;
5415         case 31:
5416                 type = Utils::Type::uvec2;
5417                 break;
5418         case 32:
5419                 type = Utils::Type::uvec3;
5420                 break;
5421         case 33:
5422                 type = Utils::Type::uvec4;
5423                 break;
5424         default:
5425                 TCU_FAIL("invalid enum");
5426         }
5427
5428         return type;
5429 }
5430
5431 /** Get name of type at index
5432  *
5433  * @param index Index of type
5434  *
5435  * @return Name
5436  **/
5437 std::string TestBase::getTypeName(GLuint index) const
5438 {
5439         std::string name = getType(index).GetGLSLTypeName();
5440
5441         return name;
5442 }
5443
5444 /** Get number of types
5445  *
5446  * @return 34
5447  **/
5448 glw::GLuint TestBase::getTypesNumber() const
5449 {
5450         return 34;
5451 }
5452
5453 /** Execute test
5454  *
5455  * @return true if test pass, false otherwise
5456  **/
5457 bool TestBase::test()
5458 {
5459         bool   result           = true;
5460         GLuint n_test_cases = 0;
5461
5462         /* Prepare test */
5463         testInit();
5464
5465         /* GL entry points */
5466         const Functions& gl = m_context.getRenderContext().getFunctions();
5467
5468         /* Tessellation patch set up */
5469         gl.patchParameteri(GL_PATCH_VERTICES, 1);
5470         GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
5471
5472         /* Get number of test cases */
5473         n_test_cases = getTestCaseNumber();
5474
5475 #if DEBUG_REPEAT_TEST_CASE
5476
5477         while (1)
5478         {
5479                 GLuint test_case = DEBUG_REPEATED_TEST_CASE;
5480
5481 #else /* DEBUG_REPEAT_TEST_CASE */
5482
5483         for (GLuint test_case = 0; test_case < n_test_cases; ++test_case)
5484         {
5485
5486 #endif /* DEBUG_REPEAT_TEST_CASE */
5487
5488                 bool case_result = true;
5489
5490                 /* Execute case */
5491                 if (false == testCase(test_case))
5492                 {
5493                         case_result = false;
5494                 }
5495
5496                 /* Log failure */
5497                 if (false == case_result)
5498                 {
5499                         const std::string& test_case_name = getTestCaseName(test_case);
5500
5501                         if (false == test_case_name.empty())
5502                         {
5503                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case_name
5504                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5505                         }
5506                         else
5507                         {
5508                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case
5509                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5510                         }
5511
5512                         result = false;
5513                 }
5514         }
5515
5516         /* Done */
5517         return result;
5518 }
5519
5520 /* Constants used by BufferTestBase */
5521 const GLuint BufferTestBase::bufferDescriptor::m_non_indexed = -1;
5522
5523 /** Constructor
5524  *
5525  * @param context          Test context
5526  * @param test_name        Name of test
5527  * @param test_description Description of test
5528  **/
5529 BufferTestBase::BufferTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5530         : TestBase(context, test_name, test_description)
5531 {
5532 }
5533
5534 /** Execute drawArrays for single vertex
5535  *
5536  * @param ignored
5537  *
5538  * @return true
5539  **/
5540 bool BufferTestBase::executeDrawCall(bool tesEnabled, GLuint /* test_case_index */)
5541 {
5542         const Functions& gl = m_context.getRenderContext().getFunctions();
5543
5544         gl.disable(GL_RASTERIZER_DISCARD);
5545         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
5546
5547         gl.beginTransformFeedback(GL_POINTS);
5548         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
5549
5550         // Only TES is existed, glDrawArray can use the parameter GL_PATCHES
5551         if (tesEnabled == false)
5552         {
5553                 gl.drawArrays(GL_POINTS, 0 /* first */, 1 /* count */);
5554         }
5555         else
5556         {
5557                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
5558         }
5559
5560         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
5561
5562         gl.endTransformFeedback();
5563         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
5564
5565         return true;
5566 }
5567
5568 /** Get descriptors of buffers necessary for test
5569  *
5570  * @param ignored
5571  * @param ignored
5572  **/
5573 void BufferTestBase::getBufferDescriptors(glw::GLuint /* test_case_index */,
5574                                                                                   bufferDescriptor::Vector& /* out_descriptors */)
5575 {
5576         /* Nothhing to be done */
5577 }
5578
5579 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
5580  *
5581  * @param ignored
5582  * @param ignored
5583  **/
5584 void BufferTestBase::getCapturedVaryings(glw::GLuint /* test_case_index */,
5585                                                                                  Utils::Program::NameVector& /* captured_varyings */)
5586 {
5587         /* Nothing to be done */
5588 }
5589
5590 /** Get body of main function for given shader stage
5591  *
5592  * @param ignored
5593  * @param ignored
5594  * @param out_assignments  Set to empty
5595  * @param out_calculations Set to empty
5596  **/
5597 void BufferTestBase::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5598                                                                    std::string& out_assignments, std::string& out_calculations)
5599 {
5600         out_assignments  = "";
5601         out_calculations = "";
5602 }
5603
5604 /** Get interface of shader
5605  *
5606  * @param ignored
5607  * @param ignored
5608  * @param out_interface Set to ""
5609  **/
5610 void BufferTestBase::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5611                                                                                 std::string& out_interface)
5612 {
5613         out_interface = "";
5614 }
5615
5616 /** Get source code of shader
5617  *
5618  * @param test_case_index Index of test case
5619  * @param stage           Shader stage
5620  *
5621  * @return Source
5622  **/
5623 std::string BufferTestBase::getShaderSource(glw::GLuint test_case_index, Utils::Shader::STAGES stage)
5624 {
5625         std::string assignments;
5626         std::string calculations;
5627         std::string interface;
5628
5629         /* */
5630         getShaderBody(test_case_index, stage, assignments, calculations);
5631         getShaderInterface(test_case_index, stage, interface);
5632
5633         /* */
5634         std::string source = getShaderTemplate(stage);
5635
5636         /* */
5637         size_t position = 0;
5638         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
5639         Utils::replaceToken("CALCULATIONS", position, calculations.c_str(), source);
5640         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
5641
5642         /* */
5643         return source;
5644 }
5645
5646 /** Inspects program to check if all resources are as expected
5647  *
5648  * @param ignored
5649  * @param ignored
5650  * @param ignored
5651  *
5652  * @return true
5653  **/
5654 bool BufferTestBase::inspectProgram(GLuint /* test_case_index */, Utils::Program& /* program */,
5655                                                                         std::stringstream& /* out_stream */)
5656 {
5657         return true;
5658 }
5659
5660 /** Runs test case
5661  *
5662  * @param test_case_index Id of test case
5663  *
5664  * @return true if test case pass, false otherwise
5665  **/
5666 bool BufferTestBase::testCase(GLuint test_case_index)
5667 {
5668         try
5669         {
5670                 bufferCollection                   buffers;
5671                 Utils::Program::NameVector captured_varyings;
5672                 bufferDescriptor::Vector   descriptors;
5673                 Utils::Program                     program(m_context);
5674                 Utils::VertexArray                 vao(m_context);
5675
5676                 /* Get captured varyings */
5677                 getCapturedVaryings(test_case_index, captured_varyings);
5678
5679                 /* Get shader sources */
5680                 const std::string& fragment_shader  = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
5681                 const std::string& geometry_shader  = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
5682                 const std::string& tess_ctrl_shader = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
5683                 const std::string& tess_eval_shader = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
5684                 const std::string& vertex_shader        = getShaderSource(test_case_index, Utils::Shader::VERTEX);
5685
5686                 /* Set up program */
5687                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
5688                                          vertex_shader, captured_varyings, true, false /* is_separable */);
5689
5690                 /* Inspection */
5691                 {
5692                         std::stringstream stream;
5693                         if (false == inspectProgram(test_case_index, program, stream))
5694                         {
5695                                 m_context.getTestContext().getLog()
5696                                         << tcu::TestLog::Message
5697                                         << "Program inspection failed. Test case: " << getTestCaseName(test_case_index)
5698                                         << ". Reason: " << stream.str() << tcu::TestLog::EndMessage
5699                                         << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5700                                         << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5701                                         << tcu::TestLog::KernelSource(fragment_shader);
5702
5703                                 return false;
5704                         }
5705                 }
5706
5707                 program.Use();
5708
5709                 /* Set up buffers */
5710                 getBufferDescriptors(test_case_index, descriptors);
5711                 cleanBuffers();
5712                 prepareBuffers(descriptors, buffers);
5713
5714                 /* Set up vao */
5715                 vao.Init();
5716                 vao.Bind();
5717
5718                 /* Draw */
5719                 bool result = executeDrawCall((program.m_tess_eval.m_id != 0), test_case_index);
5720
5721 #if USE_NSIGHT
5722                 m_context.getRenderContext().postIterate();
5723 #endif
5724
5725                 if (false == result)
5726                 {
5727                         m_context.getTestContext().getLog()
5728                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5729                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5730                                 << tcu::TestLog::KernelSource(fragment_shader);
5731
5732                         return false;
5733                 }
5734
5735                 /* Verify result */
5736                 if (false == verifyBuffers(buffers))
5737                 {
5738                         m_context.getTestContext().getLog()
5739                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5740                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5741                                 << tcu::TestLog::KernelSource(fragment_shader);
5742
5743                         return false;
5744                 }
5745         }
5746         catch (Utils::Shader::InvalidSourceException& exc)
5747         {
5748                 exc.log(m_context);
5749                 TCU_FAIL(exc.what());
5750         }
5751         catch (Utils::Program::BuildException& exc)
5752         {
5753                 exc.log(m_context);
5754                 TCU_FAIL(exc.what());
5755         }
5756
5757         /* Done */
5758         return true;
5759 }
5760
5761 /** Verify contents of buffers
5762  *
5763  * @param buffers Collection of buffers to be verified
5764  *
5765  * @return true if everything is as expected, false otherwise
5766  **/
5767 bool BufferTestBase::verifyBuffers(bufferCollection& buffers)
5768 {
5769         bool result = true;
5770
5771         for (bufferCollection::Vector::iterator it = buffers.m_vector.begin(), end = buffers.m_vector.end(); end != it;
5772                  ++it)
5773         {
5774                 bufferCollection::pair& pair       = *it;
5775                 Utils::Buffer*                  buffer   = pair.m_buffer;
5776                 bufferDescriptor*               descriptor = pair.m_descriptor;
5777                 size_t                                  size       = descriptor->m_expected_data.size();
5778
5779                 /* Skip buffers that have no expected data */
5780                 if (0 == size)
5781                 {
5782                         continue;
5783                 }
5784
5785                 /* Get pointer to contents of buffer */
5786                 buffer->Bind();
5787                 GLvoid* buffer_data = buffer->Map(Utils::Buffer::ReadOnly);
5788
5789                 /* Get pointer to expected data */
5790                 GLvoid* expected_data = &descriptor->m_expected_data[0];
5791
5792                 /* Compare */
5793                 int res = memcmp(buffer_data, expected_data, size);
5794
5795                 if (0 != res)
5796                 {
5797                         m_context.getTestContext().getLog()
5798                                 << tcu::TestLog::Message
5799                                 << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
5800                                 << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
5801
5802                         result = false;
5803                 }
5804
5805                 /* Release buffer mapping */
5806                 buffer->UnMap();
5807         }
5808
5809         return result;
5810 }
5811
5812 /** Unbinds all uniforms and xfb
5813  *
5814  **/
5815 void BufferTestBase::cleanBuffers()
5816 {
5817         const Functions& gl = m_context.getRenderContext().getFunctions();
5818
5819         GLint max_uni = 0;
5820         GLint max_xfb = 0;
5821
5822         gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_uni);
5823         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
5824         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5825
5826         for (GLint i = 0; i < max_uni; ++i)
5827         {
5828                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Uniform, i);
5829         }
5830
5831         for (GLint i = 0; i < max_xfb; ++i)
5832         {
5833                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Transform_feedback, i);
5834         }
5835 }
5836
5837 /** Get template of shader for given stage
5838  *
5839  * @param stage Stage
5840  *
5841  * @return Template of shader source
5842  **/
5843 std::string BufferTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
5844 {
5845         static const GLchar* compute_shader_template = "#version 430 core\n"
5846                                                                                                    "#extension GL_ARB_enhanced_layouts : require\n"
5847                                                                                                    "\n"
5848                                                                                                    "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5849                                                                                                    "\n"
5850                                                                                                    "writeonly uniform uimage2D uni_image;\n"
5851                                                                                                    "\n"
5852                                                                                                    "INTERFACE"
5853                                                                                                    "\n"
5854                                                                                                    "void main()\n"
5855                                                                                                    "{\n"
5856                                                                                                    "CALCULATIONS"
5857                                                                                                    "\n"
5858                                                                                                    "ASSIGNMENTS"
5859                                                                                                    "}\n"
5860                                                                                                    "\n";
5861
5862         static const GLchar* fragment_shader_template = "#version 430 core\n"
5863                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5864                                                                                                         "\n"
5865                                                                                                         "INTERFACE"
5866                                                                                                         "\n"
5867                                                                                                         "void main()\n"
5868                                                                                                         "{\n"
5869                                                                                                         "CALCULATIONS"
5870                                                                                                         "\n"
5871                                                                                                         "ASSIGNMENTS"
5872                                                                                                         "}\n"
5873                                                                                                         "\n";
5874
5875         // max_vertices is set to 3 for the test case "xfb_vertex_streams" declares 3 streams in geometry shader,
5876         // according to spec, max_vertices should be no less than 3 if there are 3 streams in GS.
5877         static const GLchar* geometry_shader_template = "#version 430 core\n"
5878                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5879                                                                                                         "\n"
5880                                                                                                         "layout(points)                   in;\n"
5881                                                                                                         "layout(points, max_vertices = 3) out;\n"
5882                                                                                                         "\n"
5883                                                                                                         "INTERFACE"
5884                                                                                                         "\n"
5885                                                                                                         "void main()\n"
5886                                                                                                         "{\n"
5887                                                                                                         "CALCULATIONS"
5888                                                                                                         "\n"
5889                                                                                                         "\n"
5890                                                                                                         "ASSIGNMENTS"
5891                                                                                                         "    gl_Position  = vec4(0, 0, 0, 1);\n"
5892                                                                                                         "    EmitVertex();\n"
5893                                                                                                         "}\n"
5894                                                                                                         "\n";
5895
5896         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
5897                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5898                                                                                                          "\n"
5899                                                                                                          "layout(vertices = 1) out;\n"
5900                                                                                                          "\n"
5901                                                                                                          "INTERFACE"
5902                                                                                                          "\n"
5903                                                                                                          "void main()\n"
5904                                                                                                          "{\n"
5905                                                                                                          "CALCULATIONS"
5906                                                                                                          "\n"
5907                                                                                                          "ASSIGNMENTS"
5908                                                                                                          "\n"
5909                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
5910                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
5911                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
5912                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
5913                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
5914                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
5915                                                                                                          "}\n"
5916                                                                                                          "\n";
5917
5918         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
5919                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5920                                                                                                          "\n"
5921                                                                                                          "layout(isolines, point_mode) in;\n"
5922                                                                                                          "\n"
5923                                                                                                          "INTERFACE"
5924                                                                                                          "\n"
5925                                                                                                          "void main()\n"
5926                                                                                                          "{\n"
5927                                                                                                          "CALCULATIONS"
5928                                                                                                          "\n"
5929                                                                                                          "ASSIGNMENTS"
5930                                                                                                          "}\n"
5931                                                                                                          "\n";
5932
5933         static const GLchar* vertex_shader_template = "#version 430 core\n"
5934                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
5935                                                                                                   "\n"
5936                                                                                                   "INTERFACE"
5937                                                                                                   "\n"
5938                                                                                                   "void main()\n"
5939                                                                                                   "{\n"
5940                                                                                                   "CALCULATIONS"
5941                                                                                                   "\n"
5942                                                                                                   "ASSIGNMENTS"
5943                                                                                                   "}\n"
5944                                                                                                   "\n";
5945
5946         const GLchar* result = 0;
5947
5948         switch (stage)
5949         {
5950         case Utils::Shader::COMPUTE:
5951                 result = compute_shader_template;
5952                 break;
5953         case Utils::Shader::FRAGMENT:
5954                 result = fragment_shader_template;
5955                 break;
5956         case Utils::Shader::GEOMETRY:
5957                 result = geometry_shader_template;
5958                 break;
5959         case Utils::Shader::TESS_CTRL:
5960                 result = tess_ctrl_shader_template;
5961                 break;
5962         case Utils::Shader::TESS_EVAL:
5963                 result = tess_eval_shader_template;
5964                 break;
5965         case Utils::Shader::VERTEX:
5966                 result = vertex_shader_template;
5967                 break;
5968         default:
5969                 TCU_FAIL("Invalid enum");
5970         }
5971
5972         return result;
5973 }
5974
5975 /** Prepare buffer according to descriptor
5976  *
5977  * @param buffer Buffer to prepare
5978  * @param desc   Descriptor
5979  **/
5980 void BufferTestBase::prepareBuffer(Utils::Buffer& buffer, bufferDescriptor& desc)
5981 {
5982         GLsizeiptr size = 0;
5983         GLvoid* data = 0;
5984
5985         if (false == desc.m_initial_data.empty())
5986         {
5987                 size = desc.m_initial_data.size();
5988                 data = &desc.m_initial_data[0];
5989         }
5990         else if (false == desc.m_expected_data.empty())
5991         {
5992                 size = desc.m_expected_data.size();
5993         }
5994
5995         buffer.Init(desc.m_target, Utils::Buffer::StaticDraw, size, data);
5996
5997         if (bufferDescriptor::m_non_indexed != desc.m_index)
5998         {
5999                 buffer.BindBase(desc.m_index);
6000         }
6001         else
6002         {
6003                 buffer.Bind();
6004         }
6005 }
6006
6007 /** Prepare collection of buffer
6008  *
6009  * @param descriptors Collection of descriptors
6010  * @param out_buffers Collection of buffers
6011  **/
6012 void BufferTestBase::prepareBuffers(bufferDescriptor::Vector& descriptors, bufferCollection& out_buffers)
6013 {
6014         for (bufferDescriptor::Vector::iterator it = descriptors.begin(), end = descriptors.end(); end != it; ++it)
6015         {
6016                 bufferCollection::pair pair;
6017
6018                 pair.m_buffer = new Utils::Buffer(m_context);
6019                 if (0 == pair.m_buffer)
6020                 {
6021                         TCU_FAIL("Memory allocation failed");
6022                 }
6023
6024                 pair.m_descriptor = &(*it);
6025
6026                 prepareBuffer(*pair.m_buffer, *pair.m_descriptor);
6027
6028                 out_buffers.m_vector.push_back(pair);
6029         }
6030 }
6031
6032 /** Destructor
6033  *
6034  **/
6035 BufferTestBase::bufferCollection::~bufferCollection()
6036 {
6037         for (Vector::iterator it = m_vector.begin(), end = m_vector.end(); end != it; ++it)
6038         {
6039                 if (0 != it->m_buffer)
6040                 {
6041                         delete it->m_buffer;
6042                         it->m_buffer = 0;
6043                 }
6044         }
6045 }
6046
6047 /** Constructor
6048  *
6049  * @param context          Test context
6050  * @param test_name        Name of test
6051  * @param test_description Description of test
6052  **/
6053 NegativeTestBase::NegativeTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6054         : TestBase(context, test_name, test_description)
6055 {
6056 }
6057
6058 /** Selects if "compute" stage is relevant for test
6059  *
6060  * @param ignored
6061  *
6062  * @return true
6063  **/
6064 bool NegativeTestBase::isComputeRelevant(GLuint /* test_case_index */)
6065 {
6066         return true;
6067 }
6068
6069 /** Selects if compilation failure is expected result
6070  *
6071  * @param ignored
6072  *
6073  * @return true
6074  **/
6075 bool NegativeTestBase::isFailureExpected(GLuint /* test_case_index */)
6076 {
6077         return true;
6078 }
6079
6080 /** Runs test case
6081  *
6082  * @param test_case_index Id of test case
6083  *
6084  * @return true if test case pass, false otherwise
6085  **/
6086 bool NegativeTestBase::testCase(GLuint test_case_index)
6087 {
6088         bool test_case_result = true;
6089
6090         /* Compute */
6091         if (true == isComputeRelevant(test_case_index))
6092         {
6093                 const std::string& cs_source               = getShaderSource(test_case_index, Utils::Shader::COMPUTE);
6094                 bool                       is_build_error         = false;
6095                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6096                 Utils::Program   program(m_context);
6097
6098                 try
6099                 {
6100                         program.Init(cs_source, "" /* fs */, "" /* gs */, "" /* tcs */, "" /* tes */, "" /* vs */,
6101                                                  false /* separable */);
6102                 }
6103                 catch (Utils::Shader::InvalidSourceException& exc)
6104                 {
6105                         if (false == is_failure_expected)
6106                         {
6107                                 m_context.getTestContext().getLog()
6108                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6109                                 exc.log(m_context);
6110                         }
6111
6112 #if DEBUG_NEG_LOG_ERROR
6113
6114                         else
6115                         {
6116                                 m_context.getTestContext().getLog()
6117                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6118                                         << tcu::TestLog::EndMessage;
6119                                 exc.log(m_context);
6120                         }
6121
6122 #endif /* DEBUG_NEG_LOG_ERROR */
6123
6124                         is_build_error = true;
6125                 }
6126                 catch (Utils::Program::BuildException& exc)
6127                 {
6128                         if (false == is_failure_expected)
6129                         {
6130                                 m_context.getTestContext().getLog()
6131                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6132                                 exc.log(m_context);
6133                         }
6134
6135 #if DEBUG_NEG_LOG_ERROR
6136
6137                         else
6138                         {
6139                                 m_context.getTestContext().getLog()
6140                                         << tcu::TestLog::Message
6141                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6142                                 exc.log(m_context);
6143                         }
6144
6145 #endif /* DEBUG_NEG_LOG_ERROR */
6146
6147                         is_build_error = true;
6148                 }
6149
6150                 if (is_build_error != is_failure_expected)
6151                 {
6152                         if (!is_build_error)
6153                         {
6154                                 m_context.getTestContext().getLog()
6155                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6156                                 Utils::Shader::LogSource(m_context, cs_source, Utils::Shader::COMPUTE);
6157                         }
6158                         test_case_result = false;
6159                 }
6160         }
6161         else /* Draw */
6162         {
6163                 const std::string& fs_source               = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
6164                 const std::string& gs_source               = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
6165                 bool                       is_build_error         = false;
6166                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6167                 Utils::Program   program(m_context);
6168                 const std::string& tcs_source = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
6169                 const std::string& tes_source = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
6170                 const std::string& vs_source  = getShaderSource(test_case_index, Utils::Shader::VERTEX);
6171
6172                 try
6173                 {
6174                         program.Init("" /* cs */, fs_source, gs_source, tcs_source, tes_source, vs_source, false /* separable */);
6175                 }
6176                 catch (Utils::Shader::InvalidSourceException& exc)
6177                 {
6178                         if (false == is_failure_expected)
6179                         {
6180                                 m_context.getTestContext().getLog()
6181                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6182                                 exc.log(m_context);
6183                         }
6184
6185 #if DEBUG_NEG_LOG_ERROR
6186
6187                         else
6188                         {
6189                                 m_context.getTestContext().getLog()
6190                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6191                                         << tcu::TestLog::EndMessage;
6192                                 exc.log(m_context);
6193                         }
6194
6195 #endif /* DEBUG_NEG_LOG_ERROR */
6196
6197                         is_build_error = true;
6198                 }
6199                 catch (Utils::Program::BuildException& exc)
6200                 {
6201                         if (false == is_failure_expected)
6202                         {
6203                                 m_context.getTestContext().getLog()
6204                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6205                                 exc.log(m_context);
6206                         }
6207
6208 #if DEBUG_NEG_LOG_ERROR
6209
6210                         else
6211                         {
6212                                 m_context.getTestContext().getLog()
6213                                         << tcu::TestLog::Message
6214                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6215                                 exc.log(m_context);
6216                         }
6217
6218 #endif /* DEBUG_NEG_LOG_ERROR */
6219
6220                         is_build_error = true;
6221                 }
6222
6223                 if (is_build_error != is_failure_expected)
6224                 {
6225                         if (!is_build_error)
6226                         {
6227                                 m_context.getTestContext().getLog()
6228                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6229                                 Utils::Shader::LogSource(m_context, vs_source, Utils::Shader::VERTEX);
6230                                 Utils::Shader::LogSource(m_context, tcs_source, Utils::Shader::TESS_CTRL);
6231                                 Utils::Shader::LogSource(m_context, tes_source, Utils::Shader::TESS_EVAL);
6232                                 Utils::Shader::LogSource(m_context, gs_source, Utils::Shader::GEOMETRY);
6233                                 Utils::Shader::LogSource(m_context, fs_source, Utils::Shader::FRAGMENT);
6234                         }
6235                         test_case_result = false;
6236                 }
6237         }
6238
6239         return test_case_result;
6240 }
6241
6242 /* Constants used by TextureTestBase */
6243 const glw::GLuint TextureTestBase::m_width  = 16;
6244 const glw::GLuint TextureTestBase::m_height = 16;
6245
6246 /** Constructor
6247  *
6248  * @param context          Test context
6249  * @param test_name        Name of test
6250  * @param test_description Description of test
6251  **/
6252 TextureTestBase::TextureTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6253         : TestBase(context, test_name, test_description)
6254 {
6255 }
6256
6257 /** Get locations for all inputs with automatic_location
6258  *
6259  * @param program           Program object
6260  * @param program_interface Interface of program
6261  **/
6262 void TextureTestBase::prepareAttribLocation(Utils::Program& program, Utils::ProgramInterface& program_interface)
6263 {
6264         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6265
6266         Utils::Variable::PtrVector& inputs = si.m_inputs;
6267
6268         for (Utils::Variable::PtrVector::iterator it = inputs.begin(); inputs.end() != it; ++it)
6269         {
6270                 /* Test does not specify location, query value and set */
6271                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6272                 {
6273                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_INPUT);
6274                         GLint  location = 0;
6275
6276                         program.GetResource(GL_PROGRAM_INPUT, index, GL_LOCATION, 1 /* size */, &location);
6277
6278                         (*it)->m_descriptor.m_expected_location = location;
6279                 }
6280         }
6281 }
6282
6283 /** Verifies contents of drawn image
6284  *
6285  * @param ignored
6286  * @param color_0 Verified image
6287  *
6288  * @return true if image is filled with 1, false otherwise
6289  **/
6290 bool TextureTestBase::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& color_0)
6291 {
6292         static const GLuint size                   = m_width * m_height;
6293         static const GLuint expected_color = 1;
6294
6295         std::vector<GLuint> data;
6296         data.resize(size);
6297
6298         color_0.Get(GL_RED_INTEGER, GL_UNSIGNED_INT, &data[0]);
6299
6300         for (GLuint i = 0; i < size; ++i)
6301         {
6302                 const GLuint color = data[i];
6303
6304                 if (expected_color != color)
6305                 {
6306                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "R32UI[" << i << "]:" << color
6307                                                                                                 << tcu::TestLog::EndMessage;
6308                         return false;
6309                 }
6310         }
6311
6312         return true;
6313 }
6314
6315 /** Execute dispatch compute for 16x16x1
6316  *
6317  * @param ignored
6318  **/
6319 void TextureTestBase::executeDispatchCall(GLuint /* test_case_index */)
6320 {
6321         const Functions& gl = m_context.getRenderContext().getFunctions();
6322
6323         gl.dispatchCompute(16 /* x */, 16 /* y */, 1 /* z */);
6324         GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
6325 }
6326
6327 /** Execute drawArrays for single vertex
6328  *
6329  * @param ignored
6330  **/
6331 void TextureTestBase::executeDrawCall(GLuint /* test_case_index */)
6332 {
6333         const Functions& gl = m_context.getRenderContext().getFunctions();
6334
6335         gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
6336         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
6337 }
6338
6339 /** Prepare code snippet that will pass in variables to out variables
6340  *
6341  * @param ignored
6342  * @param varying_passthrough Collection of connections between in and out variables
6343  * @param stage               Shader stage
6344  *
6345  * @return Code that pass in variables to next stage
6346  **/
6347 std::string TextureTestBase::getPassSnippet(GLuint /* test_case_index */,
6348                                                                                         Utils::VaryingPassthrough& varying_passthrough, Utils::Shader::STAGES stage)
6349 {
6350         static const GLchar* separator = "\n    ";
6351
6352         /* Skip for compute shader */
6353         if (Utils::Shader::COMPUTE == stage)
6354         {
6355                 return "";
6356         }
6357
6358         Utils::VaryingConnection::Vector& vector = varying_passthrough.Get(stage);
6359
6360         std::string result   = Utils::g_list;
6361         size_t          position = 0;
6362
6363         for (GLuint i = 0; i < vector.size(); ++i)
6364         {
6365
6366                 Utils::VaryingConnection& connection = vector[i];
6367
6368                 Utils::Variable* in  = connection.m_in;
6369                 Utils::Variable* out = connection.m_out;
6370
6371                 Utils::Variable::FLAVOUR in_flavour  = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6372                 Utils::Variable::FLAVOUR out_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::OUTPUT);
6373
6374                 const std::string passthrough =
6375                         getVariablePassthrough("", in->m_descriptor, in_flavour, "", out->m_descriptor, out_flavour);
6376
6377                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6378         }
6379
6380         Utils::endList("", position, result);
6381
6382         return result;
6383 }
6384
6385 /** Basic implementation of method getProgramInterface
6386  *
6387  * @param ignored
6388  * @param ignored
6389  * @param ignored
6390  **/
6391 void TextureTestBase::getProgramInterface(GLuint /* test_case_index */,
6392                                                                                   Utils::ProgramInterface& /* program_interface */,
6393                                                                                   Utils::VaryingPassthrough& /* varying_passthrough */)
6394 {
6395 }
6396
6397 /** Prepare code snippet that will verify in and uniform variables
6398  *
6399  * @param ignored
6400  * @param program_interface Interface of program
6401  * @param stage             Shader stage
6402  *
6403  * @return Code that verify variables
6404  **/
6405 std::string TextureTestBase::getVerificationSnippet(GLuint /* test_case_index */,
6406                                                                                                         Utils::ProgramInterface& program_interface,
6407                                                                                                         Utils::Shader::STAGES   stage)
6408 {
6409         static const GLchar* separator = " ||\n        ";
6410
6411         std::string verification = "if (LIST)\n"
6412                                                            "    {\n"
6413                                                            "        result = 0u;\n"
6414                                                            "    }\n";
6415
6416         /* Get flavour of in and out variables */
6417         Utils::Variable::FLAVOUR in_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6418
6419         /* Get interface for shader stage */
6420         Utils::ShaderInterface& si = program_interface.GetShaderInterface(stage);
6421
6422         /* There are no varialbes to verify */
6423         if ((0 == si.m_inputs.size()) && (0 == si.m_uniforms.size()) && (0 == si.m_ssb_blocks.size()))
6424         {
6425                 return "";
6426         }
6427
6428         /* For each in variable insert verification code */
6429         size_t position = 0;
6430
6431         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6432         {
6433                 const Utils::Variable& var                              = *si.m_inputs[i];
6434                 const std::string&       var_verification = getVariableVerifcation("", var.m_data, var.m_descriptor, in_flavour);
6435
6436                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6437         }
6438
6439         /* For each unifrom variable insert verification code */
6440         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6441         {
6442                 const Utils::Variable& var = *si.m_uniforms[i];
6443                 const std::string&       var_verification =
6444                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6445
6446                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6447         }
6448
6449         /* For each ssb variable insert verification code */
6450         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6451         {
6452                 const Utils::Variable& var = *si.m_ssb_blocks[i];
6453                 const std::string&       var_verification =
6454                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6455
6456                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6457         }
6458
6459         Utils::endList("", position, verification);
6460
6461 #if DEBUG_TTB_VERIFICATION_SNIPPET_STAGE
6462
6463         {
6464                 GLchar buffer[16];
6465                 sprintf(buffer, "%d", stage + 10);
6466                 Utils::replaceToken("0u", position, buffer, verification);
6467         }
6468
6469 #elif DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE
6470
6471         if (Utils::Shader::VERTEX == stage)
6472         {
6473                 Utils::replaceToken("0u", position, "in_vs_first.x", verification);
6474         }
6475         else
6476         {
6477                 Utils::replaceToken("0u", position, "31u", verification);
6478         }
6479
6480 #endif
6481
6482         /* Done */
6483         return verification;
6484 }
6485
6486 /** Selects if "compute" stage is relevant for test
6487  *
6488  * @param ignored
6489  *
6490  * @return true
6491  **/
6492 bool TextureTestBase::isComputeRelevant(GLuint /* test_case_index */)
6493 {
6494         return true;
6495 }
6496
6497 /** Selects if "draw" stages are relevant for test
6498  *
6499  * @param ignored
6500  *
6501  * @return true
6502  **/
6503 bool TextureTestBase::isDrawRelevant(GLuint /* test_case_index */)
6504 {
6505         return true;
6506 }
6507
6508 /** Prepare code that will do assignment of single in to single out
6509  *
6510  * @param in_parent_name  Name of parent in variable
6511  * @param in_variable     Descriptor of in variable
6512  * @param in_flavour      Flavoud of in variable
6513  * @param out_parent_name Name of parent out variable
6514  * @param out_variable    Descriptor of out variable
6515  * @param out_flavour     Flavoud of out variable
6516  *
6517  * @return Code that does OUT = IN
6518  **/
6519 std::string TextureTestBase::getVariablePassthrough(const std::string&                             in_parent_name,
6520                                                                                                         const Utils::Variable::Descriptor& in_variable,
6521                                                                                                         Utils::Variable::FLAVOUR                   in_flavour,
6522                                                                                                         const std::string&                                 out_parent_name,
6523                                                                                                         const Utils::Variable::Descriptor& out_variable,
6524                                                                                                         Utils::Variable::FLAVOUR                   out_flavour)
6525 {
6526         bool                             done             = false;
6527         GLuint                           index            = 0;
6528         GLuint                           member_index = 0;
6529         size_t                           position        = 0;
6530         std::string                      result           = Utils::g_list;
6531         static const GLchar* separator  = ";\n    ";
6532
6533         /* For each member of each array element */
6534         do
6535         {
6536                 const std::string in_name  = Utils::Variable::GetReference(in_parent_name, in_variable, in_flavour, index);
6537                 const std::string out_name = Utils::Variable::GetReference(out_parent_name, out_variable, out_flavour, index);
6538                 std::string               passthrough;
6539
6540                 /* Prepare verification */
6541                 if (Utils::Variable::BUILTIN == in_variable.m_type)
6542                 {
6543                         size_t pass_position = 0;
6544
6545                         passthrough = "OUT = IN;";
6546
6547                         Utils::replaceToken("OUT", pass_position, out_name.c_str(), passthrough);
6548                         Utils::replaceToken("IN", pass_position, in_name.c_str(), passthrough);
6549
6550                         /* Increment index */
6551                         ++index;
6552                 }
6553                 else
6554                 {
6555                         const Utils::Interface* in_interface  = in_variable.m_interface;
6556                         const Utils::Interface* out_interface = out_variable.m_interface;
6557
6558                         if ((0 == in_interface) || (0 == out_interface))
6559                         {
6560                                 TCU_FAIL("Nullptr");
6561                         }
6562
6563                         const Utils::Variable::Descriptor& in_member  = in_interface->m_members[member_index];
6564                         const Utils::Variable::Descriptor& out_member = out_interface->m_members[member_index];
6565
6566                         passthrough = getVariablePassthrough(in_name, in_member, Utils::Variable::BASIC, out_name, out_member,
6567                                                                                                  Utils::Variable::BASIC);
6568
6569                         /* Increment member_index */
6570                         ++member_index;
6571
6572                         /* Increment index and reset member_index if all members were processed */
6573                         if (in_interface->m_members.size() == member_index)
6574                         {
6575                                 ++index;
6576                                 member_index = 0;
6577                         }
6578                 }
6579
6580                 /* Check if loop should end */
6581                 if ((index >= in_variable.m_n_array_elements) && (0 == member_index))
6582                 {
6583                         done = true;
6584                 }
6585
6586                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6587
6588         } while (true != done);
6589
6590         Utils::endList("", position, result);
6591
6592         /* Done */
6593         return result;
6594 }
6595
6596 /** Get verification of single variable
6597  *
6598  * @param parent_name Name of parent variable
6599  * @param data        Data that should be used as EXPECTED
6600  * @param variable    Descriptor of variable
6601  * @param flavour     Flavour of variable
6602  *
6603  * @return Code that does (EXPECTED != VALUE) ||
6604  **/
6605 std::string TextureTestBase::getVariableVerifcation(const std::string& parent_name, const GLvoid* data,
6606                                                                                                         const Utils::Variable::Descriptor& variable,
6607                                                                                                         Utils::Variable::FLAVOUR                   flavour)
6608 {
6609         static const GLchar* logic_op   = " ||\n        ";
6610         const GLuint             n_elements = (0 == variable.m_n_array_elements) ? 1 : variable.m_n_array_elements;
6611         size_t                           position   = 0;
6612         std::string                      result         = Utils::g_list;
6613         GLint                            stride         = variable.m_expected_stride_of_element;
6614
6615         /* For each each array element */
6616         for (GLuint element = 0; element < n_elements; ++element)
6617         {
6618                 const std::string name = Utils::Variable::GetReference(parent_name, variable, flavour, element);
6619
6620                 /* Calculate data pointer */
6621                 GLvoid* data_ptr = (GLvoid*)((GLubyte*)data + element * stride);
6622
6623                 /* Prepare verification */
6624                 if (Utils::Variable::BUILTIN == variable.m_type)
6625                 {
6626                         const std::string& expected = variable.m_builtin.GetGLSLConstructor(data_ptr);
6627                         std::string                verification;
6628                         size_t                     verification_position = 0;
6629
6630                         verification = "(EXPECTED != NAME)";
6631
6632                         Utils::replaceToken("EXPECTED", verification_position, expected.c_str(), verification);
6633                         Utils::replaceToken("NAME", verification_position, name.c_str(), verification);
6634
6635                         Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6636                 }
6637                 else
6638                 {
6639                         const Utils::Interface* interface = variable.m_interface;
6640
6641                         if (0 == interface)
6642                         {
6643                                 TCU_FAIL("Nullptr");
6644                         }
6645
6646                         const GLuint n_members = static_cast<GLuint>(interface->m_members.size());
6647
6648                         /* for each member */
6649                         for (GLuint member_index = 0; member_index < n_members; ++member_index)
6650                         {
6651                                 const Utils::Variable::Descriptor& member = interface->m_members[member_index];
6652
6653                                 /* Get verification of member */
6654                                 const std::string& verification =
6655                                         getVariableVerifcation(name, (GLubyte*)data_ptr + member.m_offset, member, Utils::Variable::BASIC);
6656
6657                                 Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6658                         }
6659                 }
6660         }
6661
6662         Utils::endList("", position, result);
6663
6664         return result;
6665 }
6666
6667 /** Prepare attributes, vertex array object and array buffer
6668  *
6669  * @param test_case_index   Index of test case
6670  * @param program_interface Interface of program
6671  * @param buffer            Array buffer
6672  * @param vao               Vertex array object
6673  **/
6674 void TextureTestBase::prepareAttributes(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6675                                                                                 Utils::Buffer& buffer, Utils::VertexArray& vao)
6676 {
6677         bool use_component_qualifier = useComponentQualifier(test_case_index);
6678
6679         /* Get shader interface */
6680         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6681
6682         /* Bind vao and buffer */
6683         vao.Bind();
6684         buffer.Bind();
6685
6686         /* Skip if there are no input variables in vertex shader */
6687         if (0 == si.m_inputs.size())
6688         {
6689                 return;
6690         }
6691
6692         /* Calculate vertex stride and check */
6693         GLint vertex_stride = 0;
6694
6695         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6696         {
6697                 Utils::Variable& variable = *si.m_inputs[i];
6698
6699                 GLint variable_size = static_cast<GLuint>(variable.m_data_size);
6700
6701                 GLint ends_at = variable_size + variable.m_descriptor.m_offset;
6702
6703                 vertex_stride = std::max(vertex_stride, ends_at);
6704         }
6705
6706         /* Prepare buffer data and set up vao */
6707         std::vector<GLubyte> buffer_data;
6708         buffer_data.resize(vertex_stride);
6709
6710         GLubyte* ptr = &buffer_data[0];
6711
6712         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6713         {
6714                 Utils::Variable& variable = *si.m_inputs[i];
6715
6716                 memcpy(ptr + variable.m_descriptor.m_offset, variable.m_data, variable.m_data_size);
6717
6718                 if (false == use_component_qualifier)
6719                 {
6720                         vao.Attribute(variable.m_descriptor.m_expected_location, variable.m_descriptor.m_builtin,
6721                                                   variable.m_descriptor.m_n_array_elements, variable.m_descriptor.m_normalized,
6722                                                   variable.GetStride(), (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6723                 }
6724                 else if (0 == variable.m_descriptor.m_expected_component)
6725                 {
6726                         /* Components can only be applied to vectors.
6727                          Assumption that test use all 4 components */
6728                         const Utils::Type& type =
6729                                 Utils::Type::GetType(variable.m_descriptor.m_builtin.m_basic_type, 1 /* n_columns */, 4 /* n_rows */);
6730
6731                         vao.Attribute(variable.m_descriptor.m_expected_location, type, variable.m_descriptor.m_n_array_elements,
6732                                                   variable.m_descriptor.m_normalized, variable.GetStride(),
6733                                                   (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6734                 }
6735         }
6736
6737         /* Update buffer */
6738         buffer.Data(Utils::Buffer::StaticDraw, vertex_stride, ptr);
6739 }
6740
6741 /** Get locations for all outputs with automatic_location
6742  *
6743  * @param program           Program object
6744  * @param program_interface Interface of program
6745  **/
6746 void TextureTestBase::prepareFragmentDataLoc(Utils::Program& program, Utils::ProgramInterface& program_interface)
6747 {
6748         Utils::ShaderInterface&         si              = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6749         Utils::Variable::PtrVector& outputs = si.m_outputs;
6750
6751         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
6752         {
6753                 /* Test does not specify location, query value and set */
6754                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6755                 {
6756                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_OUTPUT);
6757                         GLint  location = 0;
6758
6759                         program.GetResource(GL_PROGRAM_OUTPUT, index, GL_LOCATION, 1 /* size */, &location);
6760
6761                         (*it)->m_descriptor.m_expected_location = location;
6762                 }
6763         }
6764 }
6765
6766 /** Prepare framebuffer with single texture as color attachment
6767  *
6768  * @param framebuffer     Framebuffer
6769  * @param color_0_texture Texture that will used as color attachment
6770  **/
6771 void TextureTestBase::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
6772 {
6773         /* Prepare data */
6774         std::vector<GLuint> texture_data;
6775         texture_data.resize(m_width * m_height);
6776
6777         for (GLuint i = 0; i < texture_data.size(); ++i)
6778         {
6779                 texture_data[i] = 0x20406080;
6780         }
6781
6782         /* Prepare texture */
6783         color_0_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6784                                                  &texture_data[0]);
6785
6786         /* Prepare framebuffer */
6787         framebuffer.Init();
6788         framebuffer.Bind();
6789         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0, color_0_texture.m_id, m_width, m_height);
6790
6791         framebuffer.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
6792         framebuffer.Clear(GL_COLOR_BUFFER_BIT);
6793 }
6794
6795 /** Prepare iamge unit for compute shader
6796  *
6797  * @param location      Uniform location
6798  * @param image_texture Texture that will used as color attachment
6799  **/
6800 void TextureTestBase::prepareImage(GLint location, Utils::Texture& image_texture) const
6801 {
6802         static const GLuint image_unit = 0;
6803
6804         std::vector<GLuint> texture_data;
6805         texture_data.resize(m_width * m_height);
6806
6807         for (GLuint i = 0; i < texture_data.size(); ++i)
6808         {
6809                 texture_data[i] = 0x20406080;
6810         }
6811
6812         image_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6813                                            &texture_data[0]);
6814
6815         const Functions& gl = m_context.getRenderContext().getFunctions();
6816
6817         gl.bindImageTexture(image_unit, image_texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* Layer */,
6818                                                 GL_WRITE_ONLY, GL_R32UI);
6819         GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
6820
6821         Utils::Program::Uniform(gl, Utils::Type::_int, 1 /* count */, location, &image_unit);
6822 }
6823
6824 /** Basic implementation
6825  *
6826  * @param ignored
6827  * @param si        Shader interface
6828  * @param program   Program
6829  * @param cs_buffer Buffer for ssb blocks
6830  **/
6831 void TextureTestBase::prepareSSBs(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6832                                                                   Utils::Buffer& buffer)
6833 {
6834         /* Skip if there are no input variables in vertex shader */
6835         if (0 == si.m_ssb_blocks.size())
6836         {
6837                 return;
6838         }
6839
6840         /* Calculate vertex stride */
6841         GLint ssbs_stride = 0;
6842
6843         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6844         {
6845                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6846
6847                 if (false == variable.IsBlock())
6848                 {
6849                         continue;
6850                 }
6851
6852                 GLint variable_stride = variable.GetStride();
6853
6854                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6855
6856                 ssbs_stride = std::max(ssbs_stride, ends_at);
6857         }
6858
6859         /* Set active program */
6860         program.Use();
6861
6862         /* Allocate */
6863         buffer.Bind();
6864         buffer.Data(Utils::Buffer::StaticDraw, ssbs_stride, 0);
6865
6866         /* Set up uniforms */
6867         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6868         {
6869                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6870
6871                 /* prepareUnifor should work fine for ssb blocks */
6872                 prepareUniform(program, variable, buffer);
6873         }
6874 }
6875
6876 /** Basic implementation
6877  *
6878  * @param test_case_index   Test case index
6879  * @param program_interface Program interface
6880  * @param program           Program
6881  * @param cs_buffer         Buffer for compute shader stage
6882  **/
6883 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6884                                                                   Utils::Program& program, Utils::Buffer& cs_buffer)
6885 {
6886         cs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6887
6888         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
6889
6890         prepareSSBs(test_case_index, cs, program, cs_buffer);
6891
6892         cs_buffer.BindBase(Utils::Shader::COMPUTE);
6893 }
6894
6895 /** Basic implementation
6896  *
6897  * @param test_case_index   Test case index
6898  * @param program_interface Program interface
6899  * @param program           Program
6900  * @param fs_buffer         Buffer for fragment shader stage
6901  * @param gs_buffer         Buffer for geometry shader stage
6902  * @param tcs_buffer        Buffer for tessellation control shader stage
6903  * @param tes_buffer        Buffer for tessellation evaluation shader stage
6904  * @param vs_buffer         Buffer for vertex shader stage
6905  **/
6906 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6907                                                                   Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
6908                                                                   Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
6909 {
6910         fs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6911         gs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6912         tcs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6913         tes_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6914         vs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6915
6916         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6917         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
6918         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
6919         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
6920         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6921
6922         prepareSSBs(test_case_index, fs, program, fs_buffer);
6923         prepareSSBs(test_case_index, gs, program, gs_buffer);
6924         prepareSSBs(test_case_index, tcs, program, tcs_buffer);
6925         prepareSSBs(test_case_index, tes, program, tes_buffer);
6926         prepareSSBs(test_case_index, vs, program, vs_buffer);
6927
6928         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
6929         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
6930         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
6931         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
6932         vs_buffer.BindBase(Utils::Shader::VERTEX);
6933 }
6934
6935 /** Updates buffer data with variable
6936  *
6937  * @param program  Program object
6938  * @param variable Variable
6939  * @param buffer   Buffer
6940  **/
6941 void TextureTestBase::prepareUniform(Utils::Program& program, Utils::Variable& variable, Utils::Buffer& buffer)
6942 {
6943         const Functions& gl = m_context.getRenderContext().getFunctions();
6944
6945         GLsizei count = variable.m_descriptor.m_n_array_elements;
6946         if (0 == count)
6947         {
6948                 count = 1;
6949         }
6950
6951         if (Utils::Variable::BUILTIN == variable.m_descriptor.m_type)
6952         {
6953                 program.Uniform(gl, variable.m_descriptor.m_builtin, count, variable.m_descriptor.m_expected_location,
6954                                                 variable.m_data);
6955         }
6956         else
6957         {
6958                 const bool is_block = variable.IsBlock();
6959
6960                 if (false == is_block)
6961                 {
6962                         TCU_FAIL("Not implemented");
6963                 }
6964                 else
6965                 {
6966                         buffer.SubData(variable.m_descriptor.m_offset, variable.m_descriptor.m_expected_stride_of_element * count,
6967                                                    variable.m_data);
6968                 }
6969         }
6970 }
6971
6972 /** Basic implementation
6973  *
6974  * @param ignored
6975  * @param si        Shader interface
6976  * @param program   Program
6977  * @param cs_buffer Buffer for uniform blocks
6978  **/
6979 void TextureTestBase::prepareUniforms(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6980                                                                           Utils::Buffer& buffer)
6981 {
6982         /* Skip if there are no input variables in vertex shader */
6983         if (0 == si.m_uniforms.size())
6984         {
6985                 return;
6986         }
6987
6988         /* Calculate vertex stride */
6989         GLint uniforms_stride = 0;
6990
6991         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6992         {
6993                 Utils::Variable& variable = *si.m_uniforms[i];
6994
6995                 if (false == variable.IsBlock())
6996                 {
6997                         continue;
6998                 }
6999
7000                 GLint variable_stride = variable.GetStride();
7001
7002                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
7003
7004                 uniforms_stride = std::max(uniforms_stride, ends_at);
7005         }
7006
7007         /* Set active program */
7008         program.Use();
7009
7010         /* Allocate */
7011         buffer.Bind();
7012         buffer.Data(Utils::Buffer::StaticDraw, uniforms_stride, 0);
7013
7014         /* Set up uniforms */
7015         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
7016         {
7017                 Utils::Variable& variable = *si.m_uniforms[i];
7018
7019                 prepareUniform(program, variable, buffer);
7020         }
7021 }
7022
7023 /** Basic implementation
7024  *
7025  * @param test_case_index   Test case index
7026  * @param program_interface Program interface
7027  * @param program           Program
7028  * @param cs_buffer         Buffer for compute shader stage
7029  **/
7030 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7031                                                                           Utils::Program& program, Utils::Buffer& cs_buffer)
7032 {
7033         cs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7034
7035         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
7036
7037         prepareUniforms(test_case_index, cs, program, cs_buffer);
7038
7039         cs_buffer.BindBase(Utils::Shader::COMPUTE);
7040 }
7041
7042 /** Basic implementation
7043  *
7044  * @param test_case_index   Test case index
7045  * @param program_interface Program interface
7046  * @param program           Program
7047  * @param fs_buffer         Buffer for fragment shader stage
7048  * @param gs_buffer         Buffer for geometry shader stage
7049  * @param tcs_buffer        Buffer for tessellation control shader stage
7050  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7051  * @param vs_buffer         Buffer for vertex shader stage
7052  **/
7053 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7054                                                                           Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7055                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7056 {
7057         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7058         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7059         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7060         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7061         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7062
7063         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7064         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7065         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7066         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7067         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7068
7069         prepareUniforms(test_case_index, fs, program, fs_buffer);
7070         prepareUniforms(test_case_index, gs, program, gs_buffer);
7071         prepareUniforms(test_case_index, tcs, program, tcs_buffer);
7072         prepareUniforms(test_case_index, tes, program, tes_buffer);
7073         prepareUniforms(test_case_index, vs, program, vs_buffer);
7074
7075         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7076         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7077         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7078         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7079         vs_buffer.BindBase(Utils::Shader::VERTEX);
7080 }
7081
7082 /** Basic implementation
7083  *
7084  * @param test_case_index   Test case index
7085  * @param program_interface Program interface
7086  * @param program           Program
7087  * @param fs_buffer         Buffer for fragment shader stage
7088  * @param gs_buffer         Buffer for geometry shader stage
7089  * @param tcs_buffer        Buffer for tessellation control shader stage
7090  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7091  * @param vs_buffer         Buffer for vertex shader stage
7092  **/
7093 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7094                                                                           Utils::Program& fs_program, Utils::Program& gs_program,
7095                                                                           Utils::Program& tcs_program, Utils::Program& tes_program,
7096                                                                           Utils::Program& vs_program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7097                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7098 {
7099         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7100         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7101         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7102         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7103         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7104
7105         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7106         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7107         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7108         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7109         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7110
7111         prepareUniforms(test_case_index, fs, fs_program, fs_buffer);
7112         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7113
7114         prepareUniforms(test_case_index, gs, gs_program, gs_buffer);
7115         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7116
7117         prepareUniforms(test_case_index, tcs, tcs_program, tcs_buffer);
7118         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7119
7120         prepareUniforms(test_case_index, tes, tes_program, tes_buffer);
7121         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7122
7123         prepareUniforms(test_case_index, vs, vs_program, vs_buffer);
7124         vs_buffer.BindBase(Utils::Shader::VERTEX);
7125 }
7126
7127 /** Prepare source for shader
7128  *
7129  * @param test_case_index     Index of test case
7130  * @param program_interface   Interface of program
7131  * @param varying_passthrough Collection of connection between in and out variables
7132  * @param stage               Shader stage
7133  *
7134  * @return Source of shader
7135  **/
7136 std::string TextureTestBase::getShaderSource(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7137                                                                                          Utils::VaryingPassthrough& varying_passthrough,
7138                                                                                          Utils::Shader::STAGES          stage)
7139 {
7140         /* Get strings */
7141         const GLchar*     shader_template  = getShaderTemplate(stage);
7142         const std::string& shader_interface = program_interface.GetInterfaceForStage(stage);
7143
7144         const std::string& verification = getVerificationSnippet(test_case_index, program_interface, stage);
7145
7146         const std::string& passthrough = getPassSnippet(test_case_index, varying_passthrough, stage);
7147
7148         const GLchar* per_vertex = "";
7149
7150         std::string source   = shader_template;
7151         size_t          position = 0;
7152
7153         /* Replace tokens in template */
7154         if (Utils::Shader::GEOMETRY == stage)
7155         {
7156                 if (false == useMonolithicProgram(test_case_index))
7157                 {
7158                         per_vertex = "out gl_PerVertex {\n"
7159                                                  "vec4 gl_Position;\n"
7160                                                  "};\n"
7161                                                  "\n";
7162                 }
7163
7164                 Utils::replaceToken("PERVERTEX", position, per_vertex, source);
7165         }
7166
7167         Utils::replaceToken("INTERFACE", position, shader_interface.c_str(), source);
7168         Utils::replaceToken("VERIFICATION", position, verification.c_str(), source);
7169
7170         if (false == verification.empty())
7171         {
7172                 Utils::replaceAllTokens("ELSE", "    else ", source);
7173         }
7174         else
7175         {
7176                 Utils::replaceAllTokens("ELSE", "", source);
7177         }
7178
7179         Utils::replaceAllTokens("PASSTHROUGH", passthrough.c_str(), source);
7180
7181         /* Done */
7182         return source;
7183 }
7184
7185 /** Returns template of shader for given stage
7186  *
7187  * @param stage Shade stage
7188  *
7189  * @return Proper template
7190  **/
7191 const GLchar* TextureTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
7192 {
7193
7194         static const GLchar* compute_shader_template =
7195                 "#version 430 core\n"
7196                 "#extension GL_ARB_enhanced_layouts : require\n"
7197                 "\n"
7198                 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7199                 "\n"
7200                 "writeonly uniform uimage2D uni_image;\n"
7201                 "\n"
7202                 "INTERFACE"
7203                 "\n"
7204                 "void main()\n"
7205                 "{\n"
7206                 "    uint result = 1u;\n"
7207                 "\n"
7208                 "    VERIFICATION"
7209                 "\n"
7210                 "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
7211                 "}\n"
7212                 "\n";
7213
7214         static const GLchar* fragment_shader_template = "#version 430 core\n"
7215                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
7216                                                                                                         "\n"
7217                                                                                                         "flat in  uint gs_fs_result;\n"
7218                                                                                                         "     out uint fs_out_result;\n"
7219                                                                                                         "\n"
7220                                                                                                         "INTERFACE"
7221                                                                                                         "\n"
7222                                                                                                         "void main()\n"
7223                                                                                                         "{\n"
7224                                                                                                         "    uint result = 1u;\n"
7225                                                                                                         "\n"
7226                                                                                                         "    if (1u != gs_fs_result)\n"
7227                                                                                                         "    {\n"
7228                                                                                                         "         result = gs_fs_result;\n"
7229                                                                                                         "    }\n"
7230                                                                                                         "ELSEVERIFICATION"
7231                                                                                                         "\n"
7232                                                                                                         "    fs_out_result = result;\n"
7233                                                                                                         "    PASSTHROUGH\n"
7234                                                                                                         "}\n"
7235                                                                                                         "\n";
7236
7237         static const GLchar* geometry_shader_template =
7238                 "#version 430 core\n"
7239                 "#extension GL_ARB_enhanced_layouts : require\n"
7240                 "\n"
7241                 "layout(points)                           in;\n"
7242                 "layout(triangle_strip, max_vertices = 4) out;\n"
7243                 "\n"
7244                 "     in  uint tes_gs_result[];\n"
7245                 "flat out uint gs_fs_result;\n"
7246                 "\n"
7247                 "PERVERTEX" /* Separable programs require explicit declaration of gl_PerVertex */
7248                 "INTERFACE"
7249                 "\n"
7250                 "void main()\n"
7251                 "{\n"
7252                 "    uint result = 1u;\n"
7253                 "\n"
7254                 "    if (1u != tes_gs_result[0])\n"
7255                 "    {\n"
7256                 "         result = tes_gs_result[0];\n"
7257                 "    }\n"
7258                 "ELSEVERIFICATION"
7259                 "\n"
7260                 "    gs_fs_result = result;\n"
7261                 "    PASSTHROUGH\n"
7262                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
7263                 "    EmitVertex();\n"
7264                 "    gs_fs_result = result;\n"
7265                 "    PASSTHROUGH\n"
7266                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
7267                 "    EmitVertex();\n"
7268                 "    gs_fs_result = result;\n"
7269                 "    PASSTHROUGH\n"
7270                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
7271                 "    EmitVertex();\n"
7272                 "    gs_fs_result = result;\n"
7273                 "    PASSTHROUGH\n"
7274                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
7275                 "    EmitVertex();\n"
7276                 "}\n"
7277                 "\n";
7278
7279         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
7280                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7281                                                                                                          "\n"
7282                                                                                                          "layout(vertices = 1) out;\n"
7283                                                                                                          "\n"
7284                                                                                                          "in  uint vs_tcs_result[];\n"
7285                                                                                                          "out uint tcs_tes_result[];\n"
7286                                                                                                          "\n"
7287                                                                                                          "INTERFACE"
7288                                                                                                          "\n"
7289                                                                                                          "void main()\n"
7290                                                                                                          "{\n"
7291                                                                                                          "    uint result = 1u;\n"
7292                                                                                                          "\n"
7293                                                                                                          "    if (1u != vs_tcs_result[gl_InvocationID])\n"
7294                                                                                                          "    {\n"
7295                                                                                                          "         result = vs_tcs_result[gl_InvocationID];\n"
7296                                                                                                          "    }\n"
7297                                                                                                          "ELSEVERIFICATION"
7298                                                                                                          "\n"
7299                                                                                                          "    tcs_tes_result[gl_InvocationID] = result;\n"
7300                                                                                                          "\n"
7301                                                                                                          "    PASSTHROUGH\n"
7302                                                                                                          "\n"
7303                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
7304                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
7305                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
7306                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
7307                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
7308                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
7309                                                                                                          "}\n"
7310                                                                                                          "\n";
7311
7312         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
7313                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7314                                                                                                          "\n"
7315                                                                                                          "layout(isolines, point_mode) in;\n"
7316                                                                                                          "\n"
7317                                                                                                          "in  uint tcs_tes_result[];\n"
7318                                                                                                          "out uint tes_gs_result;\n"
7319                                                                                                          "\n"
7320                                                                                                          "INTERFACE"
7321                                                                                                          "\n"
7322                                                                                                          "void main()\n"
7323                                                                                                          "{\n"
7324                                                                                                          "    uint result = 1u;\n"
7325                                                                                                          "\n"
7326                                                                                                          "    if (1 != tcs_tes_result[0])\n"
7327                                                                                                          "    {\n"
7328                                                                                                          "         result = tcs_tes_result[0];\n"
7329                                                                                                          "    }\n"
7330                                                                                                          "ELSEVERIFICATION"
7331                                                                                                          "\n"
7332                                                                                                          "    tes_gs_result = result;\n"
7333                                                                                                          "\n"
7334                                                                                                          "    PASSTHROUGH\n"
7335                                                                                                          "}\n"
7336                                                                                                          "\n";
7337
7338         static const GLchar* vertex_shader_template = "#version 430 core\n"
7339                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7340                                                                                                   "\n"
7341                                                                                                   "out uint vs_tcs_result;\n"
7342                                                                                                   "\n"
7343                                                                                                   "INTERFACE"
7344                                                                                                   "\n"
7345                                                                                                   "void main()\n"
7346                                                                                                   "{\n"
7347                                                                                                   "    uint result = 1u;\n"
7348                                                                                                   "\n"
7349                                                                                                   "    VERIFICATION\n"
7350                                                                                                   "\n"
7351                                                                                                   "    vs_tcs_result = result;\n"
7352                                                                                                   "\n"
7353                                                                                                   "    PASSTHROUGH\n"
7354                                                                                                   "}\n"
7355                                                                                                   "\n";
7356
7357         const GLchar* result = 0;
7358
7359         switch (stage)
7360         {
7361         case Utils::Shader::COMPUTE:
7362                 result = compute_shader_template;
7363                 break;
7364         case Utils::Shader::FRAGMENT:
7365                 result = fragment_shader_template;
7366                 break;
7367         case Utils::Shader::GEOMETRY:
7368                 result = geometry_shader_template;
7369                 break;
7370         case Utils::Shader::TESS_CTRL:
7371                 result = tess_ctrl_shader_template;
7372                 break;
7373         case Utils::Shader::TESS_EVAL:
7374                 result = tess_eval_shader_template;
7375                 break;
7376         case Utils::Shader::VERTEX:
7377                 result = vertex_shader_template;
7378                 break;
7379         default:
7380                 TCU_FAIL("Invalid enum");
7381         }
7382
7383         return result;
7384 }
7385
7386 /** Runs test case
7387  *
7388  * @param test_case_index Id of test case
7389  *
7390  * @return true if test case pass, false otherwise
7391  **/
7392 bool TextureTestBase::testCase(GLuint test_case_index)
7393 {
7394         try
7395         {
7396                 if (true == useMonolithicProgram(test_case_index))
7397                 {
7398                         return testMonolithic(test_case_index);
7399                 }
7400                 else
7401                 {
7402                         return testSeparable(test_case_index);
7403                 }
7404         }
7405         catch (Utils::Shader::InvalidSourceException& exc)
7406         {
7407                 exc.log(m_context);
7408                 TCU_FAIL(exc.what());
7409         }
7410         catch (Utils::Program::BuildException& exc)
7411         {
7412                 TCU_FAIL(exc.what());
7413         }
7414 }
7415
7416 /** Runs "draw" test with monolithic program
7417  *
7418  * @param test_case_index Id of test case
7419  **/
7420 bool TextureTestBase::testMonolithic(GLuint test_case_index)
7421 {
7422         Utils::ProgramInterface   program_interface;
7423         Utils::VaryingPassthrough varying_passthrough;
7424
7425         /* */
7426         const std::string& test_name = getTestCaseName(test_case_index);
7427
7428         /* */
7429         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7430
7431         bool result = true;
7432         /* Draw */
7433         if (true == isDrawRelevant(test_case_index))
7434         {
7435                 Utils::Buffer     buffer_attr(m_context);
7436                 Utils::Buffer     buffer_ssb_fs(m_context);
7437                 Utils::Buffer     buffer_ssb_gs(m_context);
7438                 Utils::Buffer     buffer_ssb_tcs(m_context);
7439                 Utils::Buffer     buffer_ssb_tes(m_context);
7440                 Utils::Buffer     buffer_ssb_vs(m_context);
7441                 Utils::Buffer     buffer_u_fs(m_context);
7442                 Utils::Buffer     buffer_u_gs(m_context);
7443                 Utils::Buffer     buffer_u_tcs(m_context);
7444                 Utils::Buffer     buffer_u_tes(m_context);
7445                 Utils::Buffer     buffer_u_vs(m_context);
7446                 Utils::Framebuffer framebuffer(m_context);
7447                 Utils::Program   program(m_context);
7448                 Utils::Texture   texture_fb(m_context);
7449                 Utils::VertexArray vao(m_context);
7450
7451                 /* */
7452                 const std::string& fragment_shader =
7453                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7454                 const std::string& geometry_shader =
7455                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7456                 const std::string& tess_ctrl_shader =
7457                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7458                 const std::string& tess_eval_shader =
7459                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7460                 const std::string& vertex_shader =
7461                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7462
7463                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
7464                                          vertex_shader, false /* is_separable */);
7465
7466                 /* */
7467                 prepareAttribLocation(program, program_interface);
7468                 prepareFragmentDataLoc(program, program_interface);
7469
7470                 /* */
7471                 std::stringstream stream;
7472                 if (false == Utils::checkMonolithicDrawProgramInterface(program, program_interface, stream))
7473                 {
7474                         m_context.getTestContext().getLog()
7475                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7476                                 << ". Inspection of draw program interface failed:\n"
7477                                 << stream.str() << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7478                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7479                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7480
7481                         return false;
7482                 }
7483
7484                 /* */
7485                 program.Use();
7486
7487                 /* */
7488                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7489                 vao.Init();
7490                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7491
7492                 /* */
7493                 prepareUniforms(test_case_index, program_interface, program, buffer_u_fs, buffer_u_gs, buffer_u_tcs,
7494                                                 buffer_u_tes, buffer_u_vs);
7495
7496                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_fs, buffer_ssb_gs, buffer_ssb_tcs,
7497                                         buffer_ssb_tes, buffer_ssb_vs);
7498
7499                 /* */
7500                 prepareFramebuffer(framebuffer, texture_fb);
7501
7502                 /* Draw */
7503                 executeDrawCall(test_case_index);
7504
7505 #if USE_NSIGHT
7506                 m_context.getRenderContext().postIterate();
7507 #endif
7508
7509                 /* Check results */
7510                 if (false == checkResults(test_case_index, texture_fb))
7511                 {
7512                         m_context.getTestContext().getLog()
7513                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7514                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7515                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7516                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7517
7518                         result = false;
7519                 }
7520         }
7521
7522         /* Compute */
7523         if (true == isComputeRelevant(test_case_index))
7524         {
7525                 Utils::Buffer     buffer_ssb_cs(m_context);
7526                 Utils::Buffer     buffer_u_cs(m_context);
7527                 Utils::Program   program(m_context);
7528                 Utils::Texture   texture_im(m_context);
7529                 Utils::VertexArray vao(m_context);
7530
7531                 /* */
7532                 const std::string& compute_shader =
7533                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7534
7535                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7536                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7537
7538                 /* */
7539                 {
7540                         std::stringstream stream;
7541
7542                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7543                         {
7544                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7545                                                                                                         << ". Inspection of compute program interface failed:\n"
7546                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7547
7548                                 return false;
7549                         }
7550                 }
7551
7552                 /* */
7553                 program.Use();
7554
7555                 /* */
7556                 vao.Init();
7557                 vao.Bind();
7558
7559                 /* */
7560                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7561
7562                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_cs);
7563
7564                 /* */
7565                 GLint image_location = program.GetUniformLocation("uni_image");
7566                 prepareImage(image_location, texture_im);
7567
7568                 /* Draw */
7569                 executeDispatchCall(test_case_index);
7570
7571 #if USE_NSIGHT
7572                 m_context.getRenderContext().postIterate();
7573 #endif
7574
7575                 /* Check results */
7576                 if (false == checkResults(test_case_index, texture_im))
7577                 {
7578                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7579                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7580                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7581
7582                         result = false;
7583                 }
7584         }
7585
7586         return result;
7587 }
7588
7589 /** Runs "draw" test with separable program
7590  *
7591  * @param test_case_index Id of test case
7592  **/
7593 bool TextureTestBase::testSeparable(GLuint test_case_index)
7594 {
7595         Utils::ProgramInterface   program_interface;
7596         Utils::VaryingPassthrough varying_passthrough;
7597
7598         /* */
7599         const std::string& test_name = getTestCaseName(test_case_index);
7600
7601         /* */
7602         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7603
7604         bool result = true;
7605         /* Draw */
7606         if (true == isDrawRelevant(test_case_index))
7607         {
7608                 Utils::Buffer     buffer_attr(m_context);
7609                 Utils::Buffer     buffer_u_fs(m_context);
7610                 Utils::Buffer     buffer_u_gs(m_context);
7611                 Utils::Buffer     buffer_u_tcs(m_context);
7612                 Utils::Buffer     buffer_u_tes(m_context);
7613                 Utils::Buffer     buffer_u_vs(m_context);
7614                 Utils::Framebuffer framebuffer(m_context);
7615                 Utils::Pipeline pipeline(m_context);
7616                 Utils::Program   program_fs(m_context);
7617                 Utils::Program   program_gs(m_context);
7618                 Utils::Program   program_tcs(m_context);
7619                 Utils::Program   program_tes(m_context);
7620                 Utils::Program   program_vs(m_context);
7621                 Utils::Texture   texture_fb(m_context);
7622                 Utils::VertexArray vao(m_context);
7623
7624                 /* */
7625                 const std::string& fs =
7626                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7627                 const std::string& gs =
7628                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7629                 const std::string& tcs =
7630                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7631                 const std::string& tes =
7632                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7633                 const std::string& vs =
7634                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7635
7636                 program_fs.Init("" /*cs*/, fs, "" /*gs*/, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7637                 program_gs.Init("" /*cs*/, "" /*fs*/, gs, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7638                 program_tcs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, tcs, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7639                 program_tes.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, tes, "" /*vs*/, true /* is_separable */);
7640                 program_vs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, "" /*tes*/, vs, true /* is_separable */);
7641
7642                 /* */
7643                 prepareAttribLocation(program_vs, program_interface);
7644                 prepareFragmentDataLoc(program_vs, program_interface);
7645
7646                 /* */
7647                 std::stringstream stream;
7648                 if ((false ==
7649                          Utils::checkSeparableDrawProgramInterface(program_vs, program_interface, Utils::Shader::VERTEX, stream)) ||
7650                         (false == Utils::checkSeparableDrawProgramInterface(program_fs, program_interface, Utils::Shader::FRAGMENT,
7651                                                                                                                                 stream)) ||
7652                         (false == Utils::checkSeparableDrawProgramInterface(program_gs, program_interface, Utils::Shader::GEOMETRY,
7653                                                                                                                                 stream)) ||
7654                         (false == Utils::checkSeparableDrawProgramInterface(program_tcs, program_interface,
7655                                                                                                                                 Utils::Shader::TESS_CTRL, stream)) ||
7656                         (false == Utils::checkSeparableDrawProgramInterface(program_tes, program_interface,
7657                                                                                                                                 Utils::Shader::TESS_EVAL, stream)))
7658                 {
7659                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7660                                                                                                 << ". Inspection of separable draw program interface failed:\n"
7661                                                                                                 << stream.str() << tcu::TestLog::EndMessage
7662                                                                                                 << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7663                                                                                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs)
7664                                                                                                 << tcu::TestLog::KernelSource(fs);
7665
7666                         return false;
7667                 }
7668
7669                 /* */
7670                 pipeline.Init();
7671                 pipeline.UseProgramStages(program_fs.m_id, GL_FRAGMENT_SHADER_BIT);
7672                 pipeline.UseProgramStages(program_gs.m_id, GL_GEOMETRY_SHADER_BIT);
7673                 pipeline.UseProgramStages(program_tcs.m_id, GL_TESS_CONTROL_SHADER_BIT);
7674                 pipeline.UseProgramStages(program_tes.m_id, GL_TESS_EVALUATION_SHADER_BIT);
7675                 pipeline.UseProgramStages(program_vs.m_id, GL_VERTEX_SHADER_BIT);
7676                 pipeline.Bind();
7677
7678                 /* */
7679
7680                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7681                 vao.Init();
7682                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7683
7684                 /* */
7685                 prepareUniforms(test_case_index, program_interface, program_fs, program_gs, program_tcs, program_tes,
7686                                                 program_vs, buffer_u_fs, buffer_u_gs, buffer_u_tcs, buffer_u_tes, buffer_u_vs);
7687
7688                 Utils::Program::Use(m_context.getRenderContext().getFunctions(), Utils::Program::m_invalid_id);
7689
7690                 /* */
7691                 prepareFramebuffer(framebuffer, texture_fb);
7692
7693                 /* Draw */
7694                 executeDrawCall(test_case_index);
7695
7696 #if USE_NSIGHT
7697                 m_context.getRenderContext().postIterate();
7698 #endif
7699
7700                 /* Check results */
7701                 if (false == checkResults(test_case_index, texture_fb))
7702                 {
7703                         m_context.getTestContext().getLog()
7704                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7705                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7706                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs) << tcu::TestLog::KernelSource(fs);
7707
7708                         result = false;
7709                 }
7710         }
7711
7712         /* Compute */
7713         if (true == isComputeRelevant(test_case_index))
7714         {
7715                 Utils::Buffer     buffer_u_cs(m_context);
7716                 Utils::Program   program(m_context);
7717                 Utils::Texture   texture_im(m_context);
7718                 Utils::VertexArray vao(m_context);
7719
7720                 /* */
7721                 const std::string& compute_shader =
7722                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7723
7724                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7725                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7726
7727                 /* */
7728                 {
7729                         std::stringstream stream;
7730
7731                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7732                         {
7733                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7734                                                                                                         << ". Inspection of compute program interface failed:\n"
7735                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7736
7737                                 return false;
7738                         }
7739                 }
7740
7741                 /* */
7742                 program.Use();
7743
7744                 /* */
7745                 vao.Init();
7746                 vao.Bind();
7747
7748                 /* */
7749                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7750
7751                 /* */
7752                 GLint image_location = program.GetUniformLocation("uni_image");
7753                 prepareImage(image_location, texture_im);
7754
7755                 /* Draw */
7756                 executeDispatchCall(test_case_index);
7757
7758 #if USE_NSIGHT
7759                 m_context.getRenderContext().postIterate();
7760 #endif
7761
7762                 /* Check results */
7763                 if (false == checkResults(test_case_index, texture_im))
7764                 {
7765                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7766                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7767                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7768
7769                         result = false;
7770                 }
7771         }
7772
7773         return result;
7774 }
7775
7776 /** Basic implementation
7777  *
7778  * @param ignored
7779  *
7780  * @return false
7781  **/
7782 bool TextureTestBase::useComponentQualifier(glw::GLuint /* test_case_index */)
7783 {
7784         return false;
7785 }
7786
7787 /** Basic implementation
7788  *
7789  * @param ignored
7790  *
7791  * @return true
7792  **/
7793 bool TextureTestBase::useMonolithicProgram(GLuint /* test_case_index */)
7794 {
7795         return true;
7796 }
7797
7798 /** Constructor
7799  *
7800  * @param context Test framework context
7801  **/
7802 APIConstantValuesTest::APIConstantValuesTest(deqp::Context& context)
7803         : TestCase(context, "api_constant_values", "Test verifies values of api constants")
7804 {
7805         /* Nothing to be done here */
7806 }
7807
7808 /** Execute test
7809  *
7810  * @return tcu::TestNode::STOP otherwise
7811  **/
7812 tcu::TestNode::IterateResult APIConstantValuesTest::iterate()
7813 {
7814         static const GLuint expected_comp = 64;
7815         static const GLuint expected_xfb  = 4;
7816         static const GLuint expected_sep  = 4;
7817         GLint                           max_comp          = 0;
7818         GLint                           max_xfb           = 0;
7819         GLint                           max_sep           = 0;
7820         bool                            test_result   = true;
7821
7822         const Functions& gl = m_context.getRenderContext().getFunctions();
7823
7824         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
7825         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7826         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_comp);
7827         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7828         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_sep);
7829         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7830
7831         if (expected_xfb > (GLuint)max_xfb)
7832         {
7833                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7834                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_BUFFERS. Got " << max_xfb
7835                                                                                         << " Expected at least " << expected_xfb << tcu::TestLog::EndMessage;
7836
7837                 test_result = false;
7838         }
7839
7840         if (expected_comp > (GLuint)max_comp)
7841         {
7842                 m_context.getTestContext().getLog()
7843                         << tcu::TestLog::Message << "Invalid GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS. Got " << max_comp
7844                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7845
7846                 test_result = false;
7847         }
7848
7849         if (expected_sep > (GLuint)max_sep)
7850         {
7851                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7852                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS. Got " << max_comp
7853                                                                                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7854
7855                 test_result = false;
7856         }
7857
7858         /* Set result */
7859         if (true == test_result)
7860         {
7861                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7862         }
7863         else
7864         {
7865                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7866         }
7867
7868         /* Done */
7869         return tcu::TestNode::STOP;
7870 }
7871
7872 /** Constructor
7873  *
7874  * @param context Test framework context
7875  **/
7876 APIErrorsTest::APIErrorsTest(deqp::Context& context)
7877         : TestCase(context, "api_errors", "Test verifies errors reeturned by api")
7878 {
7879         /* Nothing to be done here */
7880 }
7881
7882 /** Execute test
7883  *
7884  * @return tcu::TestNode::STOP otherwise
7885  **/
7886 tcu::TestNode::IterateResult APIErrorsTest::iterate()
7887 {
7888         GLint              length = 0;
7889         GLchar             name[64];
7890         GLint              param = 0;
7891         Utils::Program program(m_context);
7892         bool               test_result = true;
7893
7894         const Functions& gl = m_context.getRenderContext().getFunctions();
7895
7896         try
7897         {
7898                 program.Init("" /* cs */, "#version 430 core\n"
7899                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7900                                                                   "\n"
7901                                                                   "in  vec4 vs_fs;\n"
7902                                                                   "out vec4 fs_out;\n"
7903                                                                   "\n"
7904                                                                   "void main()\n"
7905                                                                   "{\n"
7906                                                                   "    fs_out = vs_fs;\n"
7907                                                                   "}\n"
7908                                                                   "\n" /* fs */,
7909                                          "" /* gs */, "" /* tcs */, "" /* tes */, "#version 430 core\n"
7910                                                                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7911                                                                                                                           "\n"
7912                                                                                                                           "in  vec4 in_vs;\n"
7913                                                                                                                           "layout (xfb_offset = 16) out vec4 vs_fs;\n"
7914                                                                                                                           "\n"
7915                                                                                                                           "void main()\n"
7916                                                                                                                           "{\n"
7917                                                                                                                           "    vs_fs = in_vs;\n"
7918                                                                                                                           "}\n"
7919                                                                                                                           "\n" /* vs */,
7920                                          false /* separable */);
7921         }
7922         catch (Utils::Shader::InvalidSourceException& exc)
7923         {
7924                 exc.log(m_context);
7925                 TCU_FAIL(exc.what());
7926         }
7927         catch (Utils::Program::BuildException& exc)
7928         {
7929                 TCU_FAIL(exc.what());
7930         }
7931
7932         /*
7933          * - GetProgramInterfaceiv should generate INVALID_OPERATION when
7934          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER and <pname> is one of the
7935          * following:
7936          *   * MAX_NAME_LENGTH,
7937          *   * MAX_NUM_ACTIVE_VARIABLES;
7938          */
7939         gl.getProgramInterfaceiv(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH, &param);
7940         checkError(GL_INVALID_OPERATION, "GetProgramInterfaceiv(GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH)",
7941                            test_result);
7942
7943         /*
7944          * - GetProgramResourceIndex should generate INVALID_ENUM when
7945          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7946          */
7947         gl.getProgramResourceIndex(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, "0");
7948         checkError(GL_INVALID_ENUM, "GetProgramResourceIndex(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7949         /*
7950          * - GetProgramResourceName should generate INVALID_ENUM when
7951          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7952          */
7953         gl.getProgramResourceName(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, 64 /* bufSize */, &length,
7954                                                           name);
7955         checkError(GL_INVALID_ENUM, "GetProgramResourceName(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7956
7957         /* Set result */
7958         if (true == test_result)
7959         {
7960                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7961         }
7962         else
7963         {
7964                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7965         }
7966
7967         /* Done */
7968         return tcu::TestNode::STOP;
7969 }
7970
7971 /** Check if error is the expected one.
7972  *
7973  * @param expected_error Expected error
7974  * @param message        Message to log in case of error
7975  * @param test_result    Test result, set to false in case of invalid error
7976  **/
7977 void APIErrorsTest::checkError(GLenum expected_error, const GLchar* message, bool& test_result)
7978 {
7979         const Functions& gl = m_context.getRenderContext().getFunctions();
7980
7981         GLenum error = gl.getError();
7982
7983         if (error != expected_error)
7984         {
7985                 m_context.getTestContext().getLog()
7986                         << tcu::TestLog::Message << "Failure. Invalid error. Got " << glu::getErrorStr(error) << " expected "
7987                         << glu::getErrorStr(expected_error) << " Msg: " << message << tcu::TestLog::EndMessage;
7988
7989                 test_result = false;
7990         }
7991 }
7992
7993 /** Constructor
7994  *
7995  * @param context Test framework context
7996  **/
7997 GLSLContantImmutablityTest::GLSLContantImmutablityTest(deqp::Context& context)
7998         : NegativeTestBase(context, "glsl_contant_immutablity", "Test verifies that glsl constants cannot be modified")
7999 {
8000         /* Nothing to be done here */
8001 }
8002
8003 /** Source for given test case and stage
8004  *
8005  * @param test_case_index Index of test case
8006  * @param stage           Shader stage
8007  *
8008  * @return Shader source
8009  **/
8010 std::string GLSLContantImmutablityTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
8011 {
8012         static const GLchar* cs = "#version 430 core\n"
8013                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8014                                                           "\n"
8015                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8016                                                           "\n"
8017                                                           "writeonly uniform uimage2D uni_image;\n"
8018                                                           "\n"
8019                                                           "void main()\n"
8020                                                           "{\n"
8021                                                           "    uint result = 1u;\n"
8022                                                           "    CONSTANT = 3;\n"
8023                                                           "\n"
8024                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
8025                                                           "}\n"
8026                                                           "\n";
8027         static const GLchar* fs = "#version 430 core\n"
8028                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8029                                                           "\n"
8030                                                           "in  vec4 gs_fs;\n"
8031                                                           "out vec4 fs_out;\n"
8032                                                           "\n"
8033                                                           "void main()\n"
8034                                                           "{\n"
8035                                                           "ASSIGNMENT"
8036                                                           "    fs_out = gs_fs;\n"
8037                                                           "}\n"
8038                                                           "\n";
8039         static const GLchar* gs = "#version 430 core\n"
8040                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8041                                                           "\n"
8042                                                           "layout(points)                           in;\n"
8043                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8044                                                           "\n"
8045                                                           "in  vec4 tes_gs[];\n"
8046                                                           "out vec4 gs_fs;\n"
8047                                                           "\n"
8048                                                           "void main()\n"
8049                                                           "{\n"
8050                                                           "ASSIGNMENT"
8051                                                           "    gs_fs = tes_gs[0];\n"
8052                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8053                                                           "    EmitVertex();\n"
8054                                                           "    gs_fs = tes_gs[0];\n"
8055                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8056                                                           "    EmitVertex();\n"
8057                                                           "    gs_fs = tes_gs[0];\n"
8058                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8059                                                           "    EmitVertex();\n"
8060                                                           "    gs_fs = tes_gs[0];\n"
8061                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8062                                                           "    EmitVertex();\n"
8063                                                           "}\n"
8064                                                           "\n";
8065         static const GLchar* tcs = "#version 430 core\n"
8066                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8067                                                            "\n"
8068                                                            "layout(vertices = 1) out;\n"
8069                                                            "\n"
8070                                                            "in  vec4 vs_tcs[];\n"
8071                                                            "out vec4 tcs_tes[];\n"
8072                                                            "\n"
8073                                                            "void main()\n"
8074                                                            "{\n"
8075                                                            "\n"
8076                                                            "ASSIGNMENT"
8077                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
8078                                                            "\n"
8079                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
8080                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
8081                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
8082                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
8083                                                            "    gl_TessLevelInner[0] = 1.0;\n"
8084                                                            "    gl_TessLevelInner[1] = 1.0;\n"
8085                                                            "}\n"
8086                                                            "\n";
8087         static const GLchar* tes = "#version 430 core\n"
8088                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8089                                                            "\n"
8090                                                            "layout(isolines, point_mode) in;\n"
8091                                                            "\n"
8092                                                            "in  vec4 tcs_tes[];\n"
8093                                                            "out vec4 tes_gs;\n"
8094                                                            "\n"
8095                                                            "void main()\n"
8096                                                            "{\n"
8097                                                            "ASSIGNMENT"
8098                                                            "    tes_gs = tcs_tes[0];\n"
8099                                                            "}\n"
8100                                                            "\n";
8101         static const GLchar* vs = "#version 430 core\n"
8102                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8103                                                           "\n"
8104                                                           "in  vec4 in_vs;\n"
8105                                                           "out vec4 vs_tcs;\n"
8106                                                           "\n"
8107                                                           "void main()\n"
8108                                                           "{\n"
8109                                                           "ASSIGNMENT"
8110                                                           "    vs_tcs = in_vs;\n"
8111                                                           "}\n"
8112                                                           "\n";
8113
8114         std::string source;
8115         testCase&   test_case = m_test_cases[test_case_index];
8116
8117         if (Utils::Shader::COMPUTE == test_case.m_stage)
8118         {
8119                 size_t position = 0;
8120
8121                 source = cs;
8122
8123                 Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), source);
8124         }
8125         else
8126         {
8127                 std::string assignment = "    CONSTANT = 3;\n";
8128                 size_t          position   = 0;
8129
8130                 switch (stage)
8131                 {
8132                 case Utils::Shader::FRAGMENT:
8133                         source = fs;
8134                         break;
8135                 case Utils::Shader::GEOMETRY:
8136                         source = gs;
8137                         break;
8138                 case Utils::Shader::TESS_CTRL:
8139                         source = tcs;
8140                         break;
8141                 case Utils::Shader::TESS_EVAL:
8142                         source = tes;
8143                         break;
8144                 case Utils::Shader::VERTEX:
8145                         source = vs;
8146                         break;
8147                 default:
8148                         TCU_FAIL("Invalid enum");
8149                 }
8150
8151                 if (test_case.m_stage == stage)
8152                 {
8153                         Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), assignment);
8154                 }
8155                 else
8156                 {
8157                         assignment = "";
8158                 }
8159
8160                 position = 0;
8161                 Utils::replaceToken("ASSIGNMENT", position, assignment.c_str(), source);
8162         }
8163
8164         return source;
8165 }
8166
8167 /** Get description of test case
8168  *
8169  * @param test_case_index Index of test case
8170  *
8171  * @return Constant name
8172  **/
8173 std::string GLSLContantImmutablityTest::getTestCaseName(GLuint test_case_index)
8174 {
8175         std::string result = getConstantName(m_test_cases[test_case_index].m_constant);
8176
8177         return result;
8178 }
8179
8180 /** Get number of test cases
8181  *
8182  * @return Number of test cases
8183  **/
8184 GLuint GLSLContantImmutablityTest::getTestCaseNumber()
8185 {
8186         return static_cast<GLuint>(m_test_cases.size());
8187 }
8188
8189 /** Selects if "compute" stage is relevant for test
8190  *
8191  * @param test_case_index Index of test case
8192  *
8193  * @return true when tested stage is compute
8194  **/
8195 bool GLSLContantImmutablityTest::isComputeRelevant(GLuint test_case_index)
8196 {
8197         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8198 }
8199
8200 /** Prepare all test cases
8201  *
8202  **/
8203 void GLSLContantImmutablityTest::testInit()
8204 {
8205         for (GLuint constant = 0; constant < CONSTANTS_MAX; ++constant)
8206         {
8207                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8208                 {
8209                         testCase test_case = { (CONSTANTS)constant, (Utils::Shader::STAGES)stage };
8210
8211                         m_test_cases.push_back(test_case);
8212                 }
8213         }
8214 }
8215
8216 /** Get name of glsl constant
8217  *
8218  * @param Constant id
8219  *
8220  * @return Name of constant used in GLSL
8221  **/
8222 const GLchar* GLSLContantImmutablityTest::getConstantName(CONSTANTS constant)
8223 {
8224         const GLchar* name = "";
8225
8226         switch (constant)
8227         {
8228         case GL_ARB_ENHANCED_LAYOUTS:
8229                 name = "GL_ARB_enhanced_layouts";
8230                 break;
8231         case GL_MAX_XFB:
8232                 name = "gl_MaxTransformFeedbackBuffers";
8233                 break;
8234         case GL_MAX_XFB_INT_COMP:
8235                 name = "gl_MaxTransformFeedbackInterleavedComponents";
8236                 break;
8237         default:
8238                 TCU_FAIL("Invalid enum");
8239         }
8240
8241         return name;
8242 }
8243
8244 /** Constructor
8245  *
8246  * @param context Test framework context
8247  **/
8248 GLSLContantValuesTest::GLSLContantValuesTest(deqp::Context& context)
8249         : TextureTestBase(context, "glsl_contant_values", "Test verifies values of constant symbols")
8250 {
8251 }
8252
8253 /** Selects if "compute" stage is relevant for test
8254  *
8255  * @param ignored
8256  *
8257  * @return false
8258  **/
8259 bool GLSLContantValuesTest::isComputeRelevant(GLuint /* test_case_index */)
8260 {
8261         return false;
8262 }
8263
8264 /** Prepare code snippet that will verify in and uniform variables
8265  *
8266  * @param ignored
8267  * @param ignored
8268  * @param stage   Shader stage
8269  *
8270  * @return Code that verify variables
8271  **/
8272 std::string GLSLContantValuesTest::getVerificationSnippet(GLuint /* test_case_index */,
8273                                                                                                                   Utils::ProgramInterface& /* program_interface */,
8274                                                                                                                   Utils::Shader::STAGES stage)
8275 {
8276         /* Get constants */
8277         const Functions& gl = m_context.getRenderContext().getFunctions();
8278
8279         GLint max_transform_feedback_buffers                            = 0;
8280         GLint max_transform_feedback_interleaved_components = 0;
8281
8282         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8283         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8284         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8285         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8286
8287         std::string verification;
8288
8289         if (Utils::Shader::VERTEX == stage)
8290         {
8291                 verification = "if (1 != GL_ARB_enhanced_layouts)\n"
8292                                            "    {\n"
8293                                            "        result = 0;\n"
8294                                            "    }\n"
8295                                            "    else if (MAX_TRANSFORM_FEEDBACK_BUFFERS\n"
8296                                            "        != gl_MaxTransformFeedbackBuffers)\n"
8297                                            "    {\n"
8298                                            "        result = 0;\n"
8299                                            "    }\n"
8300                                            "    else if (MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS \n"
8301                                            "        != gl_MaxTransformFeedbackInterleavedComponents)\n"
8302                                            "    {\n"
8303                                            "        result = 0;\n"
8304                                            "    }\n";
8305
8306                 size_t position = 0;
8307                 GLchar buffer[16];
8308
8309                 sprintf(buffer, "%d", max_transform_feedback_buffers);
8310                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_BUFFERS", position, buffer, verification);
8311
8312                 sprintf(buffer, "%d", max_transform_feedback_interleaved_components);
8313                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", position, buffer, verification);
8314         }
8315         else
8316         {
8317                 verification = "";
8318         }
8319
8320         return verification;
8321 }
8322
8323 /** Constructor
8324  *
8325  * @param context Test framework context
8326  **/
8327 GLSLConstantIntegralExpressionTest::GLSLConstantIntegralExpressionTest(deqp::Context& context)
8328         : TextureTestBase(context, "glsl_constant_integral_expression",
8329                                           "Test verifies that symbols can be used as constant integral expressions")
8330 {
8331 }
8332
8333 /** Get interface of program
8334  *
8335  * @param ignored
8336  * @param program_interface Interface of program
8337  * @param ignored
8338  **/
8339 void GLSLConstantIntegralExpressionTest::getProgramInterface(GLuint /* test_case_index */,
8340                                                                                                                          Utils::ProgramInterface& program_interface,
8341                                                                                                                          Utils::VaryingPassthrough& /* varying_passthrough */)
8342 {
8343         /* Get constants */
8344         const Functions& gl = m_context.getRenderContext().getFunctions();
8345
8346         GLint max_transform_feedback_buffers                            = 0;
8347         GLint max_transform_feedback_interleaved_components = 0;
8348
8349         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8350         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8351         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8352         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8353
8354         GLuint gohan_div = std::max(1, max_transform_feedback_buffers / 16);
8355         GLuint goten_div = std::max(1, max_transform_feedback_interleaved_components / 16);
8356
8357         m_gohan_length = max_transform_feedback_buffers / gohan_div;
8358         m_goten_length = max_transform_feedback_interleaved_components / goten_div;
8359
8360         /* Globals */
8361         std::string globals = "uniform uint goku [GL_ARB_enhanced_layouts / 1];\n"
8362                                                   "uniform uint gohan[gl_MaxTransformFeedbackBuffers / GOHAN_DIV];\n"
8363                                                   "uniform uint goten[gl_MaxTransformFeedbackInterleavedComponents / GOTEN_DIV];\n";
8364
8365         size_t position = 0;
8366         GLchar buffer[16];
8367
8368         sprintf(buffer, "%d", gohan_div);
8369         Utils::replaceToken("GOHAN_DIV", position, buffer, globals);
8370
8371         sprintf(buffer, "%d", goten_div);
8372         Utils::replaceToken("GOTEN_DIV", position, buffer, globals);
8373
8374         program_interface.m_vertex.m_globals    = globals;
8375         program_interface.m_tess_ctrl.m_globals = globals;
8376         program_interface.m_tess_eval.m_globals = globals;
8377         program_interface.m_geometry.m_globals  = globals;
8378         program_interface.m_fragment.m_globals  = globals;
8379         program_interface.m_compute.m_globals   = globals;
8380 }
8381
8382 /** Prepare code snippet that will verify in and uniform variables
8383  *
8384  * @param ignored
8385  * @param ignored
8386  * @param ignored
8387  *
8388  * @return Code that verify variables
8389  **/
8390 std::string GLSLConstantIntegralExpressionTest::getVerificationSnippet(GLuint /* test_case_index */,
8391                                                                                                                                            Utils::ProgramInterface& /* program_interface */,
8392                                                                                                                                            Utils::Shader::STAGES /* stage */)
8393 {
8394         std::string verification = "{\n"
8395                                                            "        uint goku_sum = 0;\n"
8396                                                            "        uint gohan_sum = 0;\n"
8397                                                            "        uint goten_sum = 0;\n"
8398                                                            "\n"
8399                                                            "        for (uint i = 0u; i < goku.length(); ++i)\n"
8400                                                            "        {\n"
8401                                                            "            goku_sum += goku[i];\n"
8402                                                            "        }\n"
8403                                                            "\n"
8404                                                            "        for (uint i = 0u; i < gohan.length(); ++i)\n"
8405                                                            "        {\n"
8406                                                            "            gohan_sum += gohan[i];\n"
8407                                                            "        }\n"
8408                                                            "\n"
8409                                                            "        for (uint i = 0u; i < goten.length(); ++i)\n"
8410                                                            "        {\n"
8411                                                            "            goten_sum += goten[i];\n"
8412                                                            "        }\n"
8413                                                            "\n"
8414                                                            "        if ( (1u != goku_sum)  &&\n"
8415                                                            "             (EXPECTED_GOHAN_SUMu != gohan_sum) ||\n"
8416                                                            "             (EXPECTED_GOTEN_SUMu != goten_sum) )\n"
8417                                                            "        {\n"
8418                                                            "            result = 0u;\n"
8419                                                            "        }\n"
8420                                                            "    }\n";
8421
8422         size_t position = 0;
8423         GLchar buffer[16];
8424
8425         sprintf(buffer, "%d", m_gohan_length);
8426         Utils::replaceToken("EXPECTED_GOHAN_SUM", position, buffer, verification);
8427
8428         sprintf(buffer, "%d", m_goten_length);
8429         Utils::replaceToken("EXPECTED_GOTEN_SUM", position, buffer, verification);
8430
8431         return verification;
8432 }
8433
8434 /** Prepare unifroms
8435  *
8436  * @param ignored
8437  * @param ignored
8438  * @param program Program object
8439  * @param ignored
8440  **/
8441 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint /* test_case_index */,
8442                                                                                                                  Utils::ProgramInterface& /* program_interface */,
8443                                                                                                                  Utils::Program& program, Utils::Buffer& /* cs_buffer */)
8444 {
8445         static const GLuint uniform_data[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
8446
8447         const Functions& gl = m_context.getRenderContext().getFunctions();
8448
8449         GLint goku_location  = program.GetUniformLocation("goku");
8450         GLint gohan_location = program.GetUniformLocation("gohan");
8451         GLint goten_location = program.GetUniformLocation("goten");
8452
8453         program.Uniform(gl, Utils::Type::uint, 1 /* count */, goku_location, uniform_data);
8454         program.Uniform(gl, Utils::Type::uint, m_gohan_length, gohan_location, uniform_data);
8455         program.Uniform(gl, Utils::Type::uint, m_goten_length, goten_location, uniform_data);
8456 }
8457
8458 /** Prepare unifroms
8459  *
8460  * @param test_case_index   Pass as param to first implemetnation
8461  * @param program_interface Pass as param to first implemetnation
8462  * @param program           Pass as param to first implemetnation
8463  * @param ignored
8464  * @param ignored
8465  * @param ignored
8466  * @param ignored
8467  * @param vs_buffer         Pass as param to first implemetnation
8468  **/
8469 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint                                   test_case_index,
8470                                                                                                                  Utils::ProgramInterface& program_interface,
8471                                                                                                                  Utils::Program& program, Utils::Buffer& /* fs_buffer */,
8472                                                                                                                  Utils::Buffer& /* gs_buffer */,
8473                                                                                                                  Utils::Buffer& /* tcs_buffer */,
8474                                                                                                                  Utils::Buffer& /* tes_buffer */, Utils::Buffer& vs_buffer)
8475 {
8476         /* Call first implementation */
8477         prepareUniforms(test_case_index, program_interface, program, vs_buffer);
8478 }
8479
8480 /** Constructor
8481  *
8482  * @param context Test framework context
8483  **/
8484 UniformBlockMemberOffsetAndAlignTest::UniformBlockMemberOffsetAndAlignTest(deqp::Context& context)
8485         : TextureTestBase(context, "uniform_block_member_offset_and_align",
8486                                           "Test verifies offsets and alignment of uniform buffer members")
8487 {
8488 }
8489
8490 /** Get interface of program
8491  *
8492  * @param test_case_index     Test case index
8493  * @param program_interface   Interface of program
8494  * @param varying_passthrough Collection of connections between in and out variables
8495  **/
8496 void UniformBlockMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
8497                                                                                                                            Utils::ProgramInterface&   program_interface,
8498                                                                                                                            Utils::VaryingPassthrough& varying_passthrough)
8499 {
8500         std::string globals = "const int basic_size = BASIC_SIZE;\n"
8501                                                   "const int type_align = TYPE_ALIGN;\n"
8502                                                   "const int type_size  = TYPE_SIZE;\n";
8503
8504         Utils::Type  type                = getType(test_case_index);
8505         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
8506         const GLuint base_align  = type.GetBaseAlignment(false);
8507         const GLuint array_align = type.GetBaseAlignment(true);
8508         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
8509         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
8510
8511         /* Calculate offsets */
8512         const GLuint first_offset  = 0;
8513         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
8514
8515 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
8516
8517         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
8518         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
8519         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8520         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8521         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8522         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
8523
8524 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8525
8526         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
8527         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
8528         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8529         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8530         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8531         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
8532
8533 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8534
8535         /* Prepare data */
8536         const std::vector<GLubyte>& first  = type.GenerateData();
8537         const std::vector<GLubyte>& second = type.GenerateData();
8538         const std::vector<GLubyte>& third  = type.GenerateData();
8539         const std::vector<GLubyte>& fourth = type.GenerateData();
8540
8541         m_data.resize(eigth_offset + base_stride);
8542         GLubyte* ptr = &m_data[0];
8543         memcpy(ptr + first_offset, &first[0], first.size());
8544         memcpy(ptr + second_offset, &second[0], second.size());
8545         memcpy(ptr + third_offset, &third[0], third.size());
8546         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
8547         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
8548         memcpy(ptr + sixth_offset, &third[0], third.size());
8549         memcpy(ptr + seventh_offset, &second[0], second.size());
8550         memcpy(ptr + eigth_offset, &first[0], first.size());
8551
8552         /* Prepare globals */
8553         size_t position = 0;
8554         GLchar buffer[16];
8555
8556         sprintf(buffer, "%d", basic_size);
8557         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
8558
8559         sprintf(buffer, "%d", type_align);
8560         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
8561
8562         sprintf(buffer, "%d", base_stride);
8563         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
8564
8565         /* Prepare Block */
8566         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
8567
8568         vs_uni_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
8569                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8570                                                  first_offset);
8571
8572         vs_uni_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
8573                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
8574                                                  0 /* n_array_elements */, base_stride, second_offset);
8575
8576         vs_uni_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
8577                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8578                                                  third_offset);
8579
8580         vs_uni_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
8581                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8582                                                  fourth_offset);
8583
8584         vs_uni_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8585                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
8586
8587         vs_uni_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8588                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
8589
8590         vs_uni_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
8591                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8592                                                  eigth_offset);
8593
8594         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
8595
8596         /* Add globals */
8597         vs_si.m_globals = globals;
8598
8599         /* Add uniform BLOCK */
8600         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
8601                                   static_cast<glw::GLint>(m_data.size()), 0, &m_data[0], m_data.size());
8602
8603         /* */
8604         program_interface.CloneVertexInterface(varying_passthrough);
8605 }
8606
8607 /** Get type name
8608  *
8609  * @param test_case_index Index of test case
8610  *
8611  * @return Name of type test in test_case_index
8612  **/
8613 std::string UniformBlockMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
8614 {
8615         return getTypeName(test_case_index);
8616 }
8617
8618 /** Returns number of types to test
8619  *
8620  * @return Number of types, 34
8621  **/
8622 glw::GLuint UniformBlockMemberOffsetAndAlignTest::getTestCaseNumber()
8623 {
8624         return getTypesNumber();
8625 }
8626
8627 /** Prepare code snippet that will verify in and uniform variables
8628  *
8629  * @param ignored
8630  * @param ignored
8631  * @param stage   Shader stage
8632  *
8633  * @return Code that verify variables
8634  **/
8635 std::string UniformBlockMemberOffsetAndAlignTest::getVerificationSnippet(
8636         GLuint /* test_case_index */, Utils::ProgramInterface& /* program_interface */, Utils::Shader::STAGES stage)
8637 {
8638         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
8639                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
8640                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
8641                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
8642                                                            "    {\n"
8643                                                            "        result = 0;\n"
8644                                                            "    }";
8645
8646         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::UNIFORM);
8647
8648         Utils::replaceAllTokens("PREFIX", prefix, verification);
8649
8650         return verification;
8651 }
8652
8653 /** Constructor
8654  *
8655  * @param context Test framework context
8656  **/
8657 UniformBlockLayoutQualifierConflictTest::UniformBlockLayoutQualifierConflictTest(deqp::Context& context)
8658         : NegativeTestBase(
8659                   context, "uniform_block_layout_qualifier_conflict",
8660                   "Test verifies that std140 is required when offset and/or align qualifiers are used with uniform block")
8661 {
8662         /* Nothing to be done here */
8663 }
8664
8665 /** Source for given test case and stage
8666  *
8667  * @param test_case_index Index of test case
8668  * @param stage           Shader stage
8669  *
8670  * @return Shader source
8671  **/
8672 std::string UniformBlockLayoutQualifierConflictTest::getShaderSource(GLuint                                test_case_index,
8673                                                                                                                                          Utils::Shader::STAGES stage)
8674 {
8675         static const GLchar* cs = "#version 430 core\n"
8676                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8677                                                           "\n"
8678                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8679                                                           "\n"
8680                                                           "LAYOUTuniform Block {\n"
8681                                                           "    layout(offset = 16) vec4 boy;\n"
8682                                                           "    layout(align  = 64) vec4 man;\n"
8683                                                           "} uni_block;\n"
8684                                                           "\n"
8685                                                           "writeonly uniform image2D uni_image;\n"
8686                                                           "\n"
8687                                                           "void main()\n"
8688                                                           "{\n"
8689                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
8690                                                           "\n"
8691                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8692                                                           "}\n"
8693                                                           "\n";
8694         static const GLchar* fs = "#version 430 core\n"
8695                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8696                                                           "\n"
8697                                                           "LAYOUTuniform Block {\n"
8698                                                           "    layout(offset = 16) vec4 boy;\n"
8699                                                           "    layout(align  = 64) vec4 man;\n"
8700                                                           "} uni_block;\n"
8701                                                           "\n"
8702                                                           "in  vec4 gs_fs;\n"
8703                                                           "out vec4 fs_out;\n"
8704                                                           "\n"
8705                                                           "void main()\n"
8706                                                           "{\n"
8707                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
8708                                                           "}\n"
8709                                                           "\n";
8710         static const GLchar* gs = "#version 430 core\n"
8711                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8712                                                           "\n"
8713                                                           "layout(points)                           in;\n"
8714                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8715                                                           "\n"
8716                                                           "LAYOUTuniform Block {\n"
8717                                                           "    layout(offset = 16) vec4 boy;\n"
8718                                                           "    layout(align  = 64) vec4 man;\n"
8719                                                           "} uni_block;\n"
8720                                                           "\n"
8721                                                           "in  vec4 tes_gs[];\n"
8722                                                           "out vec4 gs_fs;\n"
8723                                                           "\n"
8724                                                           "void main()\n"
8725                                                           "{\n"
8726                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8727                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8728                                                           "    EmitVertex();\n"
8729                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8730                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8731                                                           "    EmitVertex();\n"
8732                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8733                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8734                                                           "    EmitVertex();\n"
8735                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8736                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8737                                                           "    EmitVertex();\n"
8738                                                           "}\n"
8739                                                           "\n";
8740         static const GLchar* tcs =
8741                 "#version 430 core\n"
8742                 "#extension GL_ARB_enhanced_layouts : require\n"
8743                 "\n"
8744                 "layout(vertices = 1) out;\n"
8745                 "\n"
8746                 "LAYOUTuniform Block {\n"
8747                 "    layout(offset = 16) vec4 boy;\n"
8748                 "    layout(align  = 64) vec4 man;\n"
8749                 "} uni_block;\n"
8750                 "\n"
8751                 "in  vec4 vs_tcs[];\n"
8752                 "out vec4 tcs_tes[];\n"
8753                 "\n"
8754                 "void main()\n"
8755                 "{\n"
8756                 "\n"
8757                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
8758                 "\n"
8759                 "    gl_TessLevelOuter[0] = 1.0;\n"
8760                 "    gl_TessLevelOuter[1] = 1.0;\n"
8761                 "    gl_TessLevelOuter[2] = 1.0;\n"
8762                 "    gl_TessLevelOuter[3] = 1.0;\n"
8763                 "    gl_TessLevelInner[0] = 1.0;\n"
8764                 "    gl_TessLevelInner[1] = 1.0;\n"
8765                 "}\n"
8766                 "\n";
8767         static const GLchar* tes = "#version 430 core\n"
8768                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8769                                                            "\n"
8770                                                            "layout(isolines, point_mode) in;\n"
8771                                                            "\n"
8772                                                            "LAYOUTuniform Block {\n"
8773                                                            "    layout(offset = 16) vec4 boy;\n"
8774                                                            "    layout(align  = 64) vec4 man;\n"
8775                                                            "} uni_block;\n"
8776                                                            "\n"
8777                                                            "in  vec4 tcs_tes[];\n"
8778                                                            "out vec4 tes_gs;\n"
8779                                                            "\n"
8780                                                            "void main()\n"
8781                                                            "{\n"
8782                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
8783                                                            "}\n"
8784                                                            "\n";
8785         static const GLchar* vs = "#version 430 core\n"
8786                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8787                                                           "\n"
8788                                                           "LAYOUTuniform Block {\n"
8789                                                           "    layout(offset = 16) vec4 boy;\n"
8790                                                           "    layout(align  = 64) vec4 man;\n"
8791                                                           "} uni_block;\n"
8792                                                           "\n"
8793                                                           "in  vec4 in_vs;\n"
8794                                                           "out vec4 vs_tcs;\n"
8795                                                           "\n"
8796                                                           "void main()\n"
8797                                                           "{\n"
8798                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
8799                                                           "}\n"
8800                                                           "\n";
8801
8802         std::string   layout    = "";
8803         size_t            position  = 0;
8804         testCase&        test_case = m_test_cases[test_case_index];
8805         const GLchar* qualifier = getQualifierName(test_case.m_qualifier);
8806         std::string   source;
8807
8808         if (0 != qualifier[0])
8809         {
8810                 size_t layout_position = 0;
8811
8812                 layout = "layout (QUALIFIER) ";
8813
8814                 Utils::replaceToken("QUALIFIER", layout_position, qualifier, layout);
8815         }
8816
8817         switch (stage)
8818         {
8819         case Utils::Shader::COMPUTE:
8820                 source = cs;
8821                 break;
8822         case Utils::Shader::FRAGMENT:
8823                 source = fs;
8824                 break;
8825         case Utils::Shader::GEOMETRY:
8826                 source = gs;
8827                 break;
8828         case Utils::Shader::TESS_CTRL:
8829                 source = tcs;
8830                 break;
8831         case Utils::Shader::TESS_EVAL:
8832                 source = tes;
8833                 break;
8834         case Utils::Shader::VERTEX:
8835                 source = vs;
8836                 break;
8837         default:
8838                 TCU_FAIL("Invalid enum");
8839         }
8840
8841         if (test_case.m_stage == stage)
8842         {
8843                 Utils::replaceToken("LAYOUT", position, layout.c_str(), source);
8844         }
8845         else
8846         {
8847                 Utils::replaceToken("LAYOUT", position, "layout (std140) ", source);
8848         }
8849
8850         return source;
8851 }
8852
8853 /** Get description of test case
8854  *
8855  * @param test_case_index Index of test case
8856  *
8857  * @return Qualifier name
8858  **/
8859 std::string UniformBlockLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
8860 {
8861         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
8862
8863         return result;
8864 }
8865
8866 /** Get number of test cases
8867  *
8868  * @return Number of test cases
8869  **/
8870 GLuint UniformBlockLayoutQualifierConflictTest::getTestCaseNumber()
8871 {
8872         return static_cast<GLuint>(m_test_cases.size());
8873 }
8874
8875 /** Selects if "compute" stage is relevant for test
8876  *
8877  * @param test_case_index Index of test case
8878  *
8879  * @return true when tested stage is compute
8880  **/
8881 bool UniformBlockLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
8882 {
8883         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8884 }
8885
8886 /** Selects if compilation failure is expected result
8887  *
8888  * @param test_case_index Index of test case
8889  *
8890  * @return false for STD140 cases, true otherwise
8891  **/
8892 bool UniformBlockLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
8893 {
8894         return (STD140 != m_test_cases[test_case_index].m_qualifier);
8895 }
8896
8897 /** Prepare all test cases
8898  *
8899  **/
8900 void UniformBlockLayoutQualifierConflictTest::testInit()
8901 {
8902         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
8903         {
8904                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8905                 {
8906                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
8907
8908                         m_test_cases.push_back(test_case);
8909                 }
8910         }
8911 }
8912
8913 /** Get name of glsl constant
8914  *
8915  * @param Constant id
8916  *
8917  * @return Name of constant used in GLSL
8918  **/
8919 const GLchar* UniformBlockLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
8920 {
8921         const GLchar* name = "";
8922
8923         switch (qualifier)
8924         {
8925         case DEFAULT:
8926                 name = "";
8927                 break;
8928         case STD140:
8929                 name = "std140";
8930                 break;
8931         case SHARED:
8932                 name = "shared";
8933                 break;
8934         case PACKED:
8935                 name = "packed";
8936                 break;
8937         default:
8938                 TCU_FAIL("Invalid enum");
8939         }
8940
8941         return name;
8942 }
8943
8944 /** Constructor
8945  *
8946  * @param context Test framework context
8947  **/
8948 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(deqp::Context& context)
8949         : NegativeTestBase(context, "uniform_block_member_invalid_offset_alignment",
8950                                            "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
8951 {
8952         /* Nothing to be done here */
8953 }
8954
8955 /** Constructor
8956  *
8957  * @param context     Test framework context
8958  * @param name        Test name
8959  * @param description Test description
8960  **/
8961 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(
8962         deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description)
8963         : NegativeTestBase(context, name, description)
8964 {
8965         /* Nothing to be done here */
8966 }
8967
8968 /** Source for given test case and stage
8969  *
8970  * @param test_case_index Index of test case
8971  * @param stage           Shader stage
8972  *
8973  * @return Shader source
8974  **/
8975 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint                                test_case_index,
8976                                                                                                                                                   Utils::Shader::STAGES stage)
8977 {
8978         static const GLchar* cs = "#version 430 core\n"
8979                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8980                                                           "\n"
8981                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8982                                                           "\n"
8983                                                           "layout (std140) uniform Block {\n"
8984                                                           "    layout (offset = OFFSET) TYPE member;\n"
8985                                                           "} block;\n"
8986                                                           "\n"
8987                                                           "writeonly uniform image2D uni_image;\n"
8988                                                           "\n"
8989                                                           "void main()\n"
8990                                                           "{\n"
8991                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
8992                                                           "\n"
8993                                                           "    if (TYPE(1) == block.member)\n"
8994                                                           "    {\n"
8995                                                           "        result = vec4(1, 1, 1, 1);\n"
8996                                                           "    }\n"
8997                                                           "\n"
8998                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8999                                                           "}\n"
9000                                                           "\n";
9001         static const GLchar* fs = "#version 430 core\n"
9002                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9003                                                           "\n"
9004                                                           "in  vec4 gs_fs;\n"
9005                                                           "out vec4 fs_out;\n"
9006                                                           "\n"
9007                                                           "void main()\n"
9008                                                           "{\n"
9009                                                           "    fs_out = gs_fs;\n"
9010                                                           "}\n"
9011                                                           "\n";
9012         static const GLchar* fs_tested = "#version 430 core\n"
9013                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9014                                                                          "\n"
9015                                                                          "layout (std140) uniform Block {\n"
9016                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9017                                                                          "} block;\n"
9018                                                                          "\n"
9019                                                                          "in  vec4 gs_fs;\n"
9020                                                                          "out vec4 fs_out;\n"
9021                                                                          "\n"
9022                                                                          "void main()\n"
9023                                                                          "{\n"
9024                                                                          "    if (TYPE(1) == block.member)\n"
9025                                                                          "    {\n"
9026                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9027                                                                          "    }\n"
9028                                                                          "\n"
9029                                                                          "    fs_out += gs_fs;\n"
9030                                                                          "}\n"
9031                                                                          "\n";
9032         static const GLchar* gs = "#version 430 core\n"
9033                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9034                                                           "\n"
9035                                                           "layout(points)                           in;\n"
9036                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9037                                                           "\n"
9038                                                           "in  vec4 tes_gs[];\n"
9039                                                           "out vec4 gs_fs;\n"
9040                                                           "\n"
9041                                                           "void main()\n"
9042                                                           "{\n"
9043                                                           "    gs_fs = tes_gs[0];\n"
9044                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9045                                                           "    EmitVertex();\n"
9046                                                           "    gs_fs = tes_gs[0];\n"
9047                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9048                                                           "    EmitVertex();\n"
9049                                                           "    gs_fs = tes_gs[0];\n"
9050                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9051                                                           "    EmitVertex();\n"
9052                                                           "    gs_fs = tes_gs[0];\n"
9053                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9054                                                           "    EmitVertex();\n"
9055                                                           "}\n"
9056                                                           "\n";
9057         static const GLchar* gs_tested = "#version 430 core\n"
9058                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9059                                                                          "\n"
9060                                                                          "layout(points)                           in;\n"
9061                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9062                                                                          "\n"
9063                                                                          "layout (std140) uniform Block {\n"
9064                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9065                                                                          "} block;\n"
9066                                                                          "\n"
9067                                                                          "in  vec4 tes_gs[];\n"
9068                                                                          "out vec4 gs_fs;\n"
9069                                                                          "\n"
9070                                                                          "void main()\n"
9071                                                                          "{\n"
9072                                                                          "    if (TYPE(1) == block.member)\n"
9073                                                                          "    {\n"
9074                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9075                                                                          "    }\n"
9076                                                                          "\n"
9077                                                                          "    gs_fs += tes_gs[0];\n"
9078                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9079                                                                          "    EmitVertex();\n"
9080                                                                          "    gs_fs += tes_gs[0];\n"
9081                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9082                                                                          "    EmitVertex();\n"
9083                                                                          "    gs_fs += tes_gs[0];\n"
9084                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9085                                                                          "    EmitVertex();\n"
9086                                                                          "    gs_fs += tes_gs[0];\n"
9087                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9088                                                                          "    EmitVertex();\n"
9089                                                                          "}\n"
9090                                                                          "\n";
9091         static const GLchar* tcs = "#version 430 core\n"
9092                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9093                                                            "\n"
9094                                                            "layout(vertices = 1) out;\n"
9095                                                            "\n"
9096                                                            "in  vec4 vs_tcs[];\n"
9097                                                            "out vec4 tcs_tes[];\n"
9098                                                            "\n"
9099                                                            "void main()\n"
9100                                                            "{\n"
9101                                                            "\n"
9102                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9103                                                            "\n"
9104                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9105                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9106                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9107                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9108                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9109                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9110                                                            "}\n"
9111                                                            "\n";
9112         static const GLchar* tcs_tested = "#version 430 core\n"
9113                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9114                                                                           "\n"
9115                                                                           "layout(vertices = 1) out;\n"
9116                                                                           "\n"
9117                                                                           "layout (std140) uniform Block {\n"
9118                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9119                                                                           "} block;\n"
9120                                                                           "\n"
9121                                                                           "in  vec4 vs_tcs[];\n"
9122                                                                           "out vec4 tcs_tes[];\n"
9123                                                                           "\n"
9124                                                                           "void main()\n"
9125                                                                           "{\n"
9126                                                                           "    if (TYPE(1) == block.member)\n"
9127                                                                           "    {\n"
9128                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9129                                                                           "    }\n"
9130                                                                           "\n"
9131                                                                           "\n"
9132                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9133                                                                           "\n"
9134                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9135                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9136                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9137                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9138                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9139                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9140                                                                           "}\n"
9141                                                                           "\n";
9142         static const GLchar* tes = "#version 430 core\n"
9143                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9144                                                            "\n"
9145                                                            "layout(isolines, point_mode) in;\n"
9146                                                            "\n"
9147                                                            "in  vec4 tcs_tes[];\n"
9148                                                            "out vec4 tes_gs;\n"
9149                                                            "\n"
9150                                                            "void main()\n"
9151                                                            "{\n"
9152                                                            "    tes_gs = tcs_tes[0];\n"
9153                                                            "}\n"
9154                                                            "\n";
9155         static const GLchar* tes_tested = "#version 430 core\n"
9156                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9157                                                                           "\n"
9158                                                                           "layout(isolines, point_mode) in;\n"
9159                                                                           "\n"
9160                                                                           "layout (std140) uniform Block {\n"
9161                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9162                                                                           "} block;\n"
9163                                                                           "\n"
9164                                                                           "in  vec4 tcs_tes[];\n"
9165                                                                           "out vec4 tes_gs;\n"
9166                                                                           "\n"
9167                                                                           "void main()\n"
9168                                                                           "{\n"
9169                                                                           "    if (TYPE(1) == block.member)\n"
9170                                                                           "    {\n"
9171                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9172                                                                           "    }\n"
9173                                                                           "\n"
9174                                                                           "    tes_gs += tcs_tes[0];\n"
9175                                                                           "}\n"
9176                                                                           "\n";
9177         static const GLchar* vs = "#version 430 core\n"
9178                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9179                                                           "\n"
9180                                                           "in  vec4 in_vs;\n"
9181                                                           "out vec4 vs_tcs;\n"
9182                                                           "\n"
9183                                                           "void main()\n"
9184                                                           "{\n"
9185                                                           "    vs_tcs = in_vs;\n"
9186                                                           "}\n"
9187                                                           "\n";
9188         static const GLchar* vs_tested = "#version 430 core\n"
9189                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9190                                                                          "\n"
9191                                                                          "layout (std140) uniform Block {\n"
9192                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9193                                                                          "} block;\n"
9194                                                                          "\n"
9195                                                                          "in  vec4 in_vs;\n"
9196                                                                          "out vec4 vs_tcs;\n"
9197                                                                          "\n"
9198                                                                          "void main()\n"
9199                                                                          "{\n"
9200                                                                          "    if (TYPE(1) == block.member)\n"
9201                                                                          "    {\n"
9202                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9203                                                                          "    }\n"
9204                                                                          "\n"
9205                                                                          "    vs_tcs += in_vs;\n"
9206                                                                          "}\n"
9207                                                                          "\n";
9208
9209         std::string source;
9210         testCase&   test_case = m_test_cases[test_case_index];
9211
9212         if (test_case.m_stage == stage)
9213         {
9214                 GLchar                     buffer[16];
9215                 const GLuint       offset       = test_case.m_offset;
9216                 size_t                     position  = 0;
9217                 const Utils::Type& type          = test_case.m_type;
9218                 const GLchar*     type_name = type.GetGLSLTypeName();
9219
9220                 sprintf(buffer, "%d", offset);
9221
9222                 switch (stage)
9223                 {
9224                 case Utils::Shader::COMPUTE:
9225                         source = cs;
9226                         break;
9227                 case Utils::Shader::FRAGMENT:
9228                         source = fs_tested;
9229                         break;
9230                 case Utils::Shader::GEOMETRY:
9231                         source = gs_tested;
9232                         break;
9233                 case Utils::Shader::TESS_CTRL:
9234                         source = tcs_tested;
9235                         break;
9236                 case Utils::Shader::TESS_EVAL:
9237                         source = tes_tested;
9238                         break;
9239                 case Utils::Shader::VERTEX:
9240                         source = vs_tested;
9241                         break;
9242                 default:
9243                         TCU_FAIL("Invalid enum");
9244                 }
9245
9246                 Utils::replaceToken("OFFSET", position, buffer, source);
9247                 Utils::replaceToken("TYPE", position, type_name, source);
9248                 Utils::replaceToken("TYPE", position, type_name, source);
9249         }
9250         else
9251         {
9252                 switch (stage)
9253                 {
9254                 case Utils::Shader::FRAGMENT:
9255                         source = fs;
9256                         break;
9257                 case Utils::Shader::GEOMETRY:
9258                         source = gs;
9259                         break;
9260                 case Utils::Shader::TESS_CTRL:
9261                         source = tcs;
9262                         break;
9263                 case Utils::Shader::TESS_EVAL:
9264                         source = tes;
9265                         break;
9266                 case Utils::Shader::VERTEX:
9267                         source = vs;
9268                         break;
9269                 default:
9270                         TCU_FAIL("Invalid enum");
9271                 }
9272         }
9273
9274         return source;
9275 }
9276
9277 /** Get description of test case
9278  *
9279  * @param test_case_index Index of test case
9280  *
9281  * @return Type name and offset
9282  **/
9283 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
9284 {
9285         std::stringstream stream;
9286         testCase&                 test_case = m_test_cases[test_case_index];
9287
9288         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
9289
9290         return stream.str();
9291 }
9292
9293 /** Get number of test cases
9294  *
9295  * @return Number of test cases
9296  **/
9297 GLuint UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseNumber()
9298 {
9299         return static_cast<GLuint>(m_test_cases.size());
9300 }
9301
9302 /** Selects if "compute" stage is relevant for test
9303  *
9304  * @param test_case_index Index of test case
9305  *
9306  * @return true when tested stage is compute
9307  **/
9308 bool UniformBlockMemberInvalidOffsetAlignmentTest::isComputeRelevant(GLuint test_case_index)
9309 {
9310         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9311 }
9312
9313 /** Selects if compilation failure is expected result
9314  *
9315  * @param test_case_index Index of test case
9316  *
9317  * @return should_fail field from testCase
9318  **/
9319 bool UniformBlockMemberInvalidOffsetAlignmentTest::isFailureExpected(GLuint test_case_index)
9320 {
9321         return m_test_cases[test_case_index].m_should_fail;
9322 }
9323
9324 /** Checks if stage is supported
9325  *
9326  * @param stage ignored
9327  *
9328  * @return true
9329  **/
9330 bool UniformBlockMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9331 {
9332         return true;
9333 }
9334
9335 /** Prepare all test cases
9336  *
9337  **/
9338 void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
9339 {
9340         const Functions& gl               = m_context.getRenderContext().getFunctions();
9341         GLint                    max_size = 0;
9342         const GLuint     n_types  = getTypesNumber();
9343         bool                     stage_support[Utils::Shader::STAGE_MAX];
9344
9345         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9346         {
9347                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9348         }
9349
9350         gl.getIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
9351         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
9352
9353         for (GLuint i = 0; i < n_types; ++i)
9354         {
9355                 const Utils::Type& type           = getType(i);
9356                 const GLuint       alignment  = type.GetBaseAlignment(false);
9357                 const GLuint       type_size  = type.GetSize(true);
9358                 const GLuint       sec_to_end = max_size - 2 * type_size;
9359
9360                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9361                 {
9362                         if (false == stage_support[stage])
9363                         {
9364                                 continue;
9365                         }
9366
9367                         for (GLuint offset = 0; offset <= type_size; ++offset)
9368                         {
9369                                 const GLuint modulo              = offset % alignment;
9370                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9371                                 const bool   should_fail = !is_aligned;
9372
9373                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9374
9375                                 m_test_cases.push_back(test_case);
9376                         }
9377
9378                         for (GLuint offset = sec_to_end; offset <= sec_to_end + type_size; ++offset)
9379                         {
9380                                 const GLuint modulo              = offset % alignment;
9381                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9382                                 const bool   should_fail = !is_aligned;
9383
9384                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9385
9386                                 m_test_cases.push_back(test_case);
9387                         }
9388                 }
9389         }
9390 }
9391
9392 /** Constructor
9393  *
9394  * @param context Test framework context
9395  **/
9396 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context& context)
9397         : NegativeTestBase(context, "uniform_block_member_overlapping_offsets",
9398                                            "Test verifies that overlapping offsets qualifiers cause compilation failure")
9399 {
9400         /* Nothing to be done here */
9401 }
9402
9403 /** Constructor
9404  *
9405  * @param context Test framework context
9406  * @param name        Test name
9407  * @param description Test description
9408  **/
9409 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context&        context,
9410                                                                                                                                                                    const glw::GLchar* name,
9411                                                                                                                                                                    const glw::GLchar* description)
9412         : NegativeTestBase(context, name, description)
9413 {
9414         /* Nothing to be done here */
9415 }
9416
9417 /** Source for given test case and stage
9418  *
9419  * @param test_case_index Index of test case
9420  * @param stage           Shader stage
9421  *
9422  * @return Shader source
9423  **/
9424 std::string UniformBlockMemberOverlappingOffsetsTest::getShaderSource(GLuint                            test_case_index,
9425                                                                                                                                           Utils::Shader::STAGES stage)
9426 {
9427         static const GLchar* cs = "#version 430 core\n"
9428                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9429                                                           "\n"
9430                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9431                                                           "\n"
9432                                                           "layout (std140) uniform Block {\n"
9433                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9434                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9435                                                           "} block;\n"
9436                                                           "\n"
9437                                                           "writeonly uniform image2D uni_image;\n"
9438                                                           "\n"
9439                                                           "void main()\n"
9440                                                           "{\n"
9441                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9442                                                           "\n"
9443                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9444                                                           "        (MAN_TYPE(0) == block.man) )\n"
9445                                                           "    {\n"
9446                                                           "        result = vec4(1, 1, 1, 1);\n"
9447                                                           "    }\n"
9448                                                           "\n"
9449                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9450                                                           "}\n"
9451                                                           "\n";
9452         static const GLchar* fs = "#version 430 core\n"
9453                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9454                                                           "\n"
9455                                                           "in  vec4 gs_fs;\n"
9456                                                           "out vec4 fs_out;\n"
9457                                                           "\n"
9458                                                           "void main()\n"
9459                                                           "{\n"
9460                                                           "    fs_out = gs_fs;\n"
9461                                                           "}\n"
9462                                                           "\n";
9463         static const GLchar* fs_tested = "#version 430 core\n"
9464                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9465                                                                          "\n"
9466                                                                          "layout (std140) uniform Block {\n"
9467                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9468                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9469                                                                          "} block;\n"
9470                                                                          "\n"
9471                                                                          "in  vec4 gs_fs;\n"
9472                                                                          "out vec4 fs_out;\n"
9473                                                                          "\n"
9474                                                                          "void main()\n"
9475                                                                          "{\n"
9476                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9477                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9478                                                                          "    {\n"
9479                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9480                                                                          "    }\n"
9481                                                                          "\n"
9482                                                                          "    fs_out += gs_fs;\n"
9483                                                                          "}\n"
9484                                                                          "\n";
9485         static const GLchar* gs = "#version 430 core\n"
9486                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9487                                                           "\n"
9488                                                           "layout(points)                           in;\n"
9489                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9490                                                           "\n"
9491                                                           "in  vec4 tes_gs[];\n"
9492                                                           "out vec4 gs_fs;\n"
9493                                                           "\n"
9494                                                           "void main()\n"
9495                                                           "{\n"
9496                                                           "    gs_fs = tes_gs[0];\n"
9497                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9498                                                           "    EmitVertex();\n"
9499                                                           "    gs_fs = tes_gs[0];\n"
9500                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9501                                                           "    EmitVertex();\n"
9502                                                           "    gs_fs = tes_gs[0];\n"
9503                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9504                                                           "    EmitVertex();\n"
9505                                                           "    gs_fs = tes_gs[0];\n"
9506                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9507                                                           "    EmitVertex();\n"
9508                                                           "}\n"
9509                                                           "\n";
9510         static const GLchar* gs_tested = "#version 430 core\n"
9511                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9512                                                                          "\n"
9513                                                                          "layout(points)                           in;\n"
9514                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9515                                                                          "\n"
9516                                                                          "layout (std140) uniform Block {\n"
9517                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9518                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9519                                                                          "} block;\n"
9520                                                                          "\n"
9521                                                                          "in  vec4 tes_gs[];\n"
9522                                                                          "out vec4 gs_fs;\n"
9523                                                                          "\n"
9524                                                                          "void main()\n"
9525                                                                          "{\n"
9526                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9527                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9528                                                                          "    {\n"
9529                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9530                                                                          "    }\n"
9531                                                                          "\n"
9532                                                                          "    gs_fs += tes_gs[0];\n"
9533                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9534                                                                          "    EmitVertex();\n"
9535                                                                          "    gs_fs += tes_gs[0];\n"
9536                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9537                                                                          "    EmitVertex();\n"
9538                                                                          "    gs_fs += tes_gs[0];\n"
9539                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9540                                                                          "    EmitVertex();\n"
9541                                                                          "    gs_fs += tes_gs[0];\n"
9542                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9543                                                                          "    EmitVertex();\n"
9544                                                                          "}\n"
9545                                                                          "\n";
9546         static const GLchar* tcs = "#version 430 core\n"
9547                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9548                                                            "\n"
9549                                                            "layout(vertices = 1) out;\n"
9550                                                            "\n"
9551                                                            "in  vec4 vs_tcs[];\n"
9552                                                            "out vec4 tcs_tes[];\n"
9553                                                            "\n"
9554                                                            "void main()\n"
9555                                                            "{\n"
9556                                                            "\n"
9557                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9558                                                            "\n"
9559                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9560                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9561                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9562                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9563                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9564                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9565                                                            "}\n"
9566                                                            "\n";
9567         static const GLchar* tcs_tested = "#version 430 core\n"
9568                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9569                                                                           "\n"
9570                                                                           "layout(vertices = 1) out;\n"
9571                                                                           "\n"
9572                                                                           "layout (std140) uniform Block {\n"
9573                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9574                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9575                                                                           "} block;\n"
9576                                                                           "\n"
9577                                                                           "in  vec4 vs_tcs[];\n"
9578                                                                           "out vec4 tcs_tes[];\n"
9579                                                                           "\n"
9580                                                                           "void main()\n"
9581                                                                           "{\n"
9582                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9583                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9584                                                                           "    {\n"
9585                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9586                                                                           "    }\n"
9587                                                                           "\n"
9588                                                                           "\n"
9589                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9590                                                                           "\n"
9591                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9592                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9593                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9594                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9595                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9596                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9597                                                                           "}\n"
9598                                                                           "\n";
9599         static const GLchar* tes = "#version 430 core\n"
9600                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9601                                                            "\n"
9602                                                            "layout(isolines, point_mode) in;\n"
9603                                                            "\n"
9604                                                            "in  vec4 tcs_tes[];\n"
9605                                                            "out vec4 tes_gs;\n"
9606                                                            "\n"
9607                                                            "void main()\n"
9608                                                            "{\n"
9609                                                            "    tes_gs = tcs_tes[0];\n"
9610                                                            "}\n"
9611                                                            "\n";
9612         static const GLchar* tes_tested = "#version 430 core\n"
9613                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9614                                                                           "\n"
9615                                                                           "layout(isolines, point_mode) in;\n"
9616                                                                           "\n"
9617                                                                           "layout (std140) uniform Block {\n"
9618                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9619                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9620                                                                           "} block;\n"
9621                                                                           "\n"
9622                                                                           "in  vec4 tcs_tes[];\n"
9623                                                                           "out vec4 tes_gs;\n"
9624                                                                           "\n"
9625                                                                           "void main()\n"
9626                                                                           "{\n"
9627                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9628                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9629                                                                           "    {\n"
9630                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9631                                                                           "    }\n"
9632                                                                           "\n"
9633                                                                           "    tes_gs += tcs_tes[0];\n"
9634                                                                           "}\n"
9635                                                                           "\n";
9636         static const GLchar* vs = "#version 430 core\n"
9637                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9638                                                           "\n"
9639                                                           "in  vec4 in_vs;\n"
9640                                                           "out vec4 vs_tcs;\n"
9641                                                           "\n"
9642                                                           "void main()\n"
9643                                                           "{\n"
9644                                                           "    vs_tcs = in_vs;\n"
9645                                                           "}\n"
9646                                                           "\n";
9647         static const GLchar* vs_tested = "#version 430 core\n"
9648                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9649                                                                          "\n"
9650                                                                          "layout (std140) uniform Block {\n"
9651                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9652                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9653                                                                          "} block;\n"
9654                                                                          "\n"
9655                                                                          "in  vec4 in_vs;\n"
9656                                                                          "out vec4 vs_tcs;\n"
9657                                                                          "\n"
9658                                                                          "void main()\n"
9659                                                                          "{\n"
9660                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9661                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9662                                                                          "    {\n"
9663                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9664                                                                          "    }\n"
9665                                                                          "\n"
9666                                                                          "    vs_tcs += in_vs;\n"
9667                                                                          "}\n"
9668                                                                          "\n";
9669
9670         std::string source;
9671         testCase&   test_case = m_test_cases[test_case_index];
9672
9673         if (test_case.m_stage == stage)
9674         {
9675                 GLchar                     buffer[16];
9676                 const GLuint       boy_offset   = test_case.m_boy_offset;
9677                 const Utils::Type& boy_type              = test_case.m_boy_type;
9678                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
9679                 const GLuint       man_offset   = test_case.m_man_offset;
9680                 const Utils::Type& man_type              = test_case.m_man_type;
9681                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
9682                 size_t                     position              = 0;
9683
9684                 switch (stage)
9685                 {
9686                 case Utils::Shader::COMPUTE:
9687                         source = cs;
9688                         break;
9689                 case Utils::Shader::FRAGMENT:
9690                         source = fs_tested;
9691                         break;
9692                 case Utils::Shader::GEOMETRY:
9693                         source = gs_tested;
9694                         break;
9695                 case Utils::Shader::TESS_CTRL:
9696                         source = tcs_tested;
9697                         break;
9698                 case Utils::Shader::TESS_EVAL:
9699                         source = tes_tested;
9700                         break;
9701                 case Utils::Shader::VERTEX:
9702                         source = vs_tested;
9703                         break;
9704                 default:
9705                         TCU_FAIL("Invalid enum");
9706                 }
9707
9708                 sprintf(buffer, "%d", boy_offset);
9709                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
9710                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9711                 sprintf(buffer, "%d", man_offset);
9712                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
9713                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9714                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9715                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9716         }
9717         else
9718         {
9719                 switch (stage)
9720                 {
9721                 case Utils::Shader::FRAGMENT:
9722                         source = fs;
9723                         break;
9724                 case Utils::Shader::GEOMETRY:
9725                         source = gs;
9726                         break;
9727                 case Utils::Shader::TESS_CTRL:
9728                         source = tcs;
9729                         break;
9730                 case Utils::Shader::TESS_EVAL:
9731                         source = tes;
9732                         break;
9733                 case Utils::Shader::VERTEX:
9734                         source = vs;
9735                         break;
9736                 default:
9737                         TCU_FAIL("Invalid enum");
9738                 }
9739         }
9740
9741         return source;
9742 }
9743
9744 /** Get description of test case
9745  *
9746  * @param test_case_index Index of test case
9747  *
9748  * @return Type name and offset
9749  **/
9750 std::string UniformBlockMemberOverlappingOffsetsTest::getTestCaseName(GLuint test_case_index)
9751 {
9752         std::stringstream stream;
9753         testCase&                 test_case = m_test_cases[test_case_index];
9754
9755         stream << "Type: " << test_case.m_boy_type.GetGLSLTypeName() << ", offset: " << test_case.m_boy_offset
9756                    << ". Type: " << test_case.m_man_type.GetGLSLTypeName() << ", offset: " << test_case.m_man_offset;
9757
9758         return stream.str();
9759 }
9760
9761 /** Get number of test cases
9762  *
9763  * @return Number of test cases
9764  **/
9765 GLuint UniformBlockMemberOverlappingOffsetsTest::getTestCaseNumber()
9766 {
9767         return static_cast<GLuint>(m_test_cases.size());
9768 }
9769
9770 /** Selects if "compute" stage is relevant for test
9771  *
9772  * @param test_case_index Index of test case
9773  *
9774  * @return true when tested stage is compute
9775  **/
9776 bool UniformBlockMemberOverlappingOffsetsTest::isComputeRelevant(GLuint test_case_index)
9777 {
9778         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9779 }
9780
9781 /** Checks if stage is supported
9782  *
9783  * @param stage ignored
9784  *
9785  * @return true
9786  **/
9787 bool UniformBlockMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9788 {
9789         return true;
9790 }
9791
9792 /** Prepare all test cases
9793  *
9794  **/
9795 void UniformBlockMemberOverlappingOffsetsTest::testInit()
9796 {
9797         const GLuint n_types = getTypesNumber();
9798         bool             stage_support[Utils::Shader::STAGE_MAX];
9799
9800         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9801         {
9802                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9803         }
9804
9805         for (GLuint i = 0; i < n_types; ++i)
9806         {
9807                 const Utils::Type& boy_type = getType(i);
9808                 const GLuint       boy_size = boy_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9809
9810                 for (GLuint j = 0; j < n_types; ++j)
9811                 {
9812                         const Utils::Type& man_type  = getType(j);
9813                         const GLuint       man_align = man_type.GetBaseAlignment(false);
9814                         const GLuint       man_size  = man_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9815
9816                         const GLuint boy_offset           = lcm(boy_size, man_size);
9817                         const GLuint man_after_start  = boy_offset + 1;
9818                         const GLuint man_after_off      = man_type.GetActualOffset(man_after_start, man_size);
9819                         const GLuint man_before_start = boy_offset - man_align;
9820                         const GLuint man_before_off   = man_type.GetActualOffset(man_before_start, man_size);
9821
9822                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9823                         {
9824                                 if (false == stage_support[stage])
9825                                 {
9826                                         continue;
9827                                 }
9828
9829                                 if ((boy_offset > man_before_off) && (boy_offset < man_before_off + man_size))
9830                                 {
9831                                         testCase test_case = { boy_offset, boy_type, man_before_off, man_type,
9832                                                                                    (Utils::Shader::STAGES)stage };
9833
9834                                         m_test_cases.push_back(test_case);
9835                                 }
9836
9837                                 if ((boy_offset < man_after_off) && (boy_offset + boy_size > man_after_off))
9838                                 {
9839                                         testCase test_case = { boy_offset, boy_type, man_after_off, man_type,
9840                                                                                    (Utils::Shader::STAGES)stage };
9841
9842                                         m_test_cases.push_back(test_case);
9843                                 }
9844
9845                                 /* Boy offset, should be fine for both types */
9846                                 testCase test_case = { boy_offset, boy_type, boy_offset, man_type, (Utils::Shader::STAGES)stage };
9847
9848                                 m_test_cases.push_back(test_case);
9849                         }
9850                 }
9851         }
9852 }
9853
9854 /** Find greatest common divisor for a and b
9855  *
9856  * @param a A argument
9857  * @param b B argument
9858  *
9859  * @return Found gcd value
9860  **/
9861 GLuint UniformBlockMemberOverlappingOffsetsTest::gcd(GLuint a, GLuint b)
9862 {
9863         if ((0 != a) && (0 == b))
9864         {
9865                 return a;
9866         }
9867         else
9868         {
9869                 GLuint greater = std::max(a, b);
9870                 GLuint lesser  = std::min(a, b);
9871
9872                 return gcd(lesser, greater % lesser);
9873         }
9874 }
9875
9876 /** Find lowest common multiple for a and b
9877  *
9878  * @param a A argument
9879  * @param b B argument
9880  *
9881  * @return Found gcd value
9882  **/
9883 GLuint UniformBlockMemberOverlappingOffsetsTest::lcm(GLuint a, GLuint b)
9884 {
9885         return (a * b) / gcd(a, b);
9886 }
9887
9888 /** Constructor
9889  *
9890  * @param context Test framework context
9891  **/
9892 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context& context)
9893         : NegativeTestBase(context, "uniform_block_member_align_non_power_of_2",
9894                                            "Test verifies that align qualifier requires value that is a power of 2")
9895 {
9896         /* Nothing to be done here */
9897 }
9898
9899 /** Constructor
9900  *
9901  * @param context Test framework context
9902  * @param name        Test name
9903  * @param description Test description
9904  **/
9905 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context&    context,
9906                                                                                                                                                            const glw::GLchar* name,
9907                                                                                                                                                            const glw::GLchar* description)
9908         : NegativeTestBase(context, name, description)
9909 {
9910         /* Nothing to be done here */
9911 }
9912
9913 /** Source for given test case and stage
9914  *
9915  * @param test_case_index Index of test case
9916  * @param stage           Shader stage
9917  *
9918  * @return Shader source
9919  **/
9920 std::string UniformBlockMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
9921 {
9922         static const GLchar* cs = "#version 430 core\n"
9923                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9924                                                           "\n"
9925                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9926                                                           "\n"
9927                                                           "layout (std140) uniform Block {\n"
9928                                                           "    vec4 boy;\n"
9929                                                           "    layout (align = ALIGN) TYPE man;\n"
9930                                                           "} block;\n"
9931                                                           "\n"
9932                                                           "writeonly uniform image2D uni_image;\n"
9933                                                           "\n"
9934                                                           "void main()\n"
9935                                                           "{\n"
9936                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9937                                                           "\n"
9938                                                           "    if (TYPE(0) == block.man)\n"
9939                                                           "    {\n"
9940                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
9941                                                           "    }\n"
9942                                                           "\n"
9943                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9944                                                           "}\n"
9945                                                           "\n";
9946         static const GLchar* fs = "#version 430 core\n"
9947                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9948                                                           "\n"
9949                                                           "in  vec4 gs_fs;\n"
9950                                                           "out vec4 fs_out;\n"
9951                                                           "\n"
9952                                                           "void main()\n"
9953                                                           "{\n"
9954                                                           "    fs_out = gs_fs;\n"
9955                                                           "}\n"
9956                                                           "\n";
9957         static const GLchar* fs_tested = "#version 430 core\n"
9958                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9959                                                                          "\n"
9960                                                                          "layout (std140) uniform Block {\n"
9961                                                                          "    vec4 boy;\n"
9962                                                                          "    layout (align = ALIGN) TYPE man;\n"
9963                                                                          "} block;\n"
9964                                                                          "\n"
9965                                                                          "in  vec4 gs_fs;\n"
9966                                                                          "out vec4 fs_out;\n"
9967                                                                          "\n"
9968                                                                          "void main()\n"
9969                                                                          "{\n"
9970                                                                          "    if (TYPE(0) == block.man)\n"
9971                                                                          "    {\n"
9972                                                                          "        fs_out = block.boy;\n"
9973                                                                          "    }\n"
9974                                                                          "\n"
9975                                                                          "    fs_out += gs_fs;\n"
9976                                                                          "}\n"
9977                                                                          "\n";
9978         static const GLchar* gs = "#version 430 core\n"
9979                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9980                                                           "\n"
9981                                                           "layout(points)                           in;\n"
9982                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9983                                                           "\n"
9984                                                           "in  vec4 tes_gs[];\n"
9985                                                           "out vec4 gs_fs;\n"
9986                                                           "\n"
9987                                                           "void main()\n"
9988                                                           "{\n"
9989                                                           "    gs_fs = tes_gs[0];\n"
9990                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9991                                                           "    EmitVertex();\n"
9992                                                           "    gs_fs = tes_gs[0];\n"
9993                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9994                                                           "    EmitVertex();\n"
9995                                                           "    gs_fs = tes_gs[0];\n"
9996                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9997                                                           "    EmitVertex();\n"
9998                                                           "    gs_fs = tes_gs[0];\n"
9999                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10000                                                           "    EmitVertex();\n"
10001                                                           "}\n"
10002                                                           "\n";
10003         static const GLchar* gs_tested = "#version 430 core\n"
10004                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10005                                                                          "\n"
10006                                                                          "layout(points)                           in;\n"
10007                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
10008                                                                          "\n"
10009                                                                          "layout (std140) uniform Block {\n"
10010                                                                          "    vec4 boy;\n"
10011                                                                          "    layout (align = ALIGN) TYPE man;\n"
10012                                                                          "} block;\n"
10013                                                                          "\n"
10014                                                                          "in  vec4 tes_gs[];\n"
10015                                                                          "out vec4 gs_fs;\n"
10016                                                                          "\n"
10017                                                                          "void main()\n"
10018                                                                          "{\n"
10019                                                                          "    if (TYPE(0) == block.man)\n"
10020                                                                          "    {\n"
10021                                                                          "        gs_fs = block.boy;\n"
10022                                                                          "    }\n"
10023                                                                          "\n"
10024                                                                          "    gs_fs += tes_gs[0];\n"
10025                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10026                                                                          "    EmitVertex();\n"
10027                                                                          "    gs_fs += tes_gs[0];\n"
10028                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10029                                                                          "    EmitVertex();\n"
10030                                                                          "    gs_fs += tes_gs[0];\n"
10031                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
10032                                                                          "    EmitVertex();\n"
10033                                                                          "    gs_fs += tes_gs[0];\n"
10034                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
10035                                                                          "    EmitVertex();\n"
10036                                                                          "}\n"
10037                                                                          "\n";
10038         static const GLchar* tcs = "#version 430 core\n"
10039                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10040                                                            "\n"
10041                                                            "layout(vertices = 1) out;\n"
10042                                                            "\n"
10043                                                            "in  vec4 vs_tcs[];\n"
10044                                                            "out vec4 tcs_tes[];\n"
10045                                                            "\n"
10046                                                            "void main()\n"
10047                                                            "{\n"
10048                                                            "\n"
10049                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
10050                                                            "\n"
10051                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
10052                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
10053                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
10054                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
10055                                                            "    gl_TessLevelInner[0] = 1.0;\n"
10056                                                            "    gl_TessLevelInner[1] = 1.0;\n"
10057                                                            "}\n"
10058                                                            "\n";
10059         static const GLchar* tcs_tested = "#version 430 core\n"
10060                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10061                                                                           "\n"
10062                                                                           "layout(vertices = 1) out;\n"
10063                                                                           "\n"
10064                                                                           "layout (std140) uniform Block {\n"
10065                                                                           "    vec4 boy;\n"
10066                                                                           "    layout (align = ALIGN) TYPE man;\n"
10067                                                                           "} block;\n"
10068                                                                           "\n"
10069                                                                           "in  vec4 vs_tcs[];\n"
10070                                                                           "out vec4 tcs_tes[];\n"
10071                                                                           "\n"
10072                                                                           "void main()\n"
10073                                                                           "{\n"
10074                                                                           "    if (TYPE(0) == block.man)\n"
10075                                                                           "    {\n"
10076                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
10077                                                                           "    }\n"
10078                                                                           "\n"
10079                                                                           "\n"
10080                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
10081                                                                           "\n"
10082                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
10083                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
10084                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
10085                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
10086                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
10087                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
10088                                                                           "}\n"
10089                                                                           "\n";
10090         static const GLchar* tes = "#version 430 core\n"
10091                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10092                                                            "\n"
10093                                                            "layout(isolines, point_mode) in;\n"
10094                                                            "\n"
10095                                                            "in  vec4 tcs_tes[];\n"
10096                                                            "out vec4 tes_gs;\n"
10097                                                            "\n"
10098                                                            "void main()\n"
10099                                                            "{\n"
10100                                                            "    tes_gs = tcs_tes[0];\n"
10101                                                            "}\n"
10102                                                            "\n";
10103         static const GLchar* tes_tested = "#version 430 core\n"
10104                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10105                                                                           "\n"
10106                                                                           "layout(isolines, point_mode) in;\n"
10107                                                                           "\n"
10108                                                                           "layout (std140) uniform Block {\n"
10109                                                                           "    vec4 boy;\n"
10110                                                                           "    layout (align = ALIGN) TYPE man;\n"
10111                                                                           "} block;\n"
10112                                                                           "\n"
10113                                                                           "in  vec4 tcs_tes[];\n"
10114                                                                           "out vec4 tes_gs;\n"
10115                                                                           "\n"
10116                                                                           "void main()\n"
10117                                                                           "{\n"
10118                                                                           "    if (TYPE(0) == block.man)\n"
10119                                                                           "    {\n"
10120                                                                           "        tes_gs = block.boy;\n"
10121                                                                           "    }\n"
10122                                                                           "\n"
10123                                                                           "    tes_gs += tcs_tes[0];\n"
10124                                                                           "}\n"
10125                                                                           "\n";
10126         static const GLchar* vs = "#version 430 core\n"
10127                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10128                                                           "\n"
10129                                                           "in  vec4 in_vs;\n"
10130                                                           "out vec4 vs_tcs;\n"
10131                                                           "\n"
10132                                                           "void main()\n"
10133                                                           "{\n"
10134                                                           "    vs_tcs = in_vs;\n"
10135                                                           "}\n"
10136                                                           "\n";
10137         static const GLchar* vs_tested = "#version 430 core\n"
10138                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10139                                                                          "\n"
10140                                                                          "layout (std140) uniform Block {\n"
10141                                                                          "    vec4 boy;\n"
10142                                                                          "    layout (align = ALIGN) TYPE man;\n"
10143                                                                          "} block;\n"
10144                                                                          "\n"
10145                                                                          "in  vec4 in_vs;\n"
10146                                                                          "out vec4 vs_tcs;\n"
10147                                                                          "\n"
10148                                                                          "void main()\n"
10149                                                                          "{\n"
10150                                                                          "    if (TYPE(0) == block.man)\n"
10151                                                                          "    {\n"
10152                                                                          "        vs_tcs = block.boy;\n"
10153                                                                          "    }\n"
10154                                                                          "\n"
10155                                                                          "    vs_tcs += in_vs;\n"
10156                                                                          "}\n"
10157                                                                          "\n";
10158
10159         std::string source;
10160         testCase&   test_case = m_test_cases[test_case_index];
10161
10162         if (test_case.m_stage == stage)
10163         {
10164                 GLchar                     buffer[16];
10165                 const GLuint       alignment = test_case.m_alignment;
10166                 const Utils::Type& type          = test_case.m_type;
10167                 const GLchar*     type_name = type.GetGLSLTypeName();
10168                 size_t                     position  = 0;
10169
10170                 switch (stage)
10171                 {
10172                 case Utils::Shader::COMPUTE:
10173                         source = cs;
10174                         break;
10175                 case Utils::Shader::FRAGMENT:
10176                         source = fs_tested;
10177                         break;
10178                 case Utils::Shader::GEOMETRY:
10179                         source = gs_tested;
10180                         break;
10181                 case Utils::Shader::TESS_CTRL:
10182                         source = tcs_tested;
10183                         break;
10184                 case Utils::Shader::TESS_EVAL:
10185                         source = tes_tested;
10186                         break;
10187                 case Utils::Shader::VERTEX:
10188                         source = vs_tested;
10189                         break;
10190                 default:
10191                         TCU_FAIL("Invalid enum");
10192                 }
10193
10194                 sprintf(buffer, "%d", alignment);
10195                 Utils::replaceToken("ALIGN", position, buffer, source);
10196                 Utils::replaceToken("TYPE", position, type_name, source);
10197                 Utils::replaceToken("TYPE", position, type_name, source);
10198         }
10199         else
10200         {
10201                 switch (stage)
10202                 {
10203                 case Utils::Shader::FRAGMENT:
10204                         source = fs;
10205                         break;
10206                 case Utils::Shader::GEOMETRY:
10207                         source = gs;
10208                         break;
10209                 case Utils::Shader::TESS_CTRL:
10210                         source = tcs;
10211                         break;
10212                 case Utils::Shader::TESS_EVAL:
10213                         source = tes;
10214                         break;
10215                 case Utils::Shader::VERTEX:
10216                         source = vs;
10217                         break;
10218                 default:
10219                         TCU_FAIL("Invalid enum");
10220                 }
10221         }
10222
10223         return source;
10224 }
10225
10226 /** Get description of test case
10227  *
10228  * @param test_case_index Index of test case
10229  *
10230  * @return Type name and offset
10231  **/
10232 std::string UniformBlockMemberAlignNonPowerOf2Test::getTestCaseName(GLuint test_case_index)
10233 {
10234         std::stringstream stream;
10235         testCase&                 test_case = m_test_cases[test_case_index];
10236
10237         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", align: " << test_case.m_alignment;
10238
10239         return stream.str();
10240 }
10241
10242 /** Get number of test cases
10243  *
10244  * @return Number of test cases
10245  **/
10246 GLuint UniformBlockMemberAlignNonPowerOf2Test::getTestCaseNumber()
10247 {
10248         return static_cast<GLuint>(m_test_cases.size());
10249 }
10250
10251 /** Selects if "compute" stage is relevant for test
10252  *
10253  * @param test_case_index Index of test case
10254  *
10255  * @return true when tested stage is compute
10256  **/
10257 bool UniformBlockMemberAlignNonPowerOf2Test::isComputeRelevant(GLuint test_case_index)
10258 {
10259         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10260 }
10261
10262 /** Checks if stage is supported
10263  *
10264  * @param ignored
10265  *
10266  * @return true
10267  **/
10268 bool UniformBlockMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES /* stage */)
10269 {
10270         return true;
10271 }
10272
10273 /** Selects if compilation failure is expected result
10274  *
10275  * @param test_case_index Index of test case
10276  *
10277  * @return should_fail field from testCase
10278  **/
10279 bool UniformBlockMemberAlignNonPowerOf2Test::isFailureExpected(GLuint test_case_index)
10280 {
10281         return m_test_cases[test_case_index].m_should_fail;
10282 }
10283
10284 /** Prepare all test cases
10285  *
10286  **/
10287 void UniformBlockMemberAlignNonPowerOf2Test::testInit()
10288 {
10289         static const GLuint dmat4_size = 128;
10290         const GLuint            n_types = getTypesNumber();
10291         bool                            stage_support[Utils::Shader::STAGE_MAX];
10292
10293         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10294         {
10295                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10296         }
10297
10298         for (GLuint j = 0; j < n_types; ++j)
10299         {
10300                 const Utils::Type& type = getType(j);
10301
10302                 for (GLuint align = 0; align <= dmat4_size; ++align)
10303                 {
10304
10305 #if WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST
10306
10307                         const bool should_fail = (0 == align) ? false : !isPowerOf2(align);
10308
10309 #else /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10310
10311                         const bool should_fail = !isPowerOf2(align);
10312
10313 #endif /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10314
10315                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10316                         {
10317                                 if (false == stage_support[stage])
10318                                 {
10319                                         continue;
10320                                 }
10321
10322                                 testCase test_case = { align, type, should_fail, (Utils::Shader::STAGES)stage };
10323
10324                                 m_test_cases.push_back(test_case);
10325                         }
10326                 }
10327         }
10328 }
10329
10330 /** Check if value is power of 2
10331  *
10332  * @param val Tested value
10333  *
10334  * @return true if val is power of 2, false otherwise
10335  **/
10336 bool UniformBlockMemberAlignNonPowerOf2Test::isPowerOf2(GLuint val)
10337 {
10338         if (0 == val)
10339         {
10340                 return false;
10341         }
10342
10343         return (0 == (val & (val - 1)));
10344 }
10345
10346 /** Constructor
10347  *
10348  * @param context Test framework context
10349  **/
10350 UniformBlockAlignmentTest::UniformBlockAlignmentTest(deqp::Context& context)
10351         : TextureTestBase(context, "uniform_block_alignment", "Test verifies offset and alignment of uniform buffer")
10352 {
10353 }
10354
10355 /** Get interface of program
10356  *
10357  * @param ignored
10358  * @param program_interface Interface of program
10359  * @param varying_passthrough Collection of connections between in and out variables
10360  **/
10361 void UniformBlockAlignmentTest::getProgramInterface(GLuint /* test_case_index */,
10362                                                                                                         Utils::ProgramInterface&   program_interface,
10363                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
10364 {
10365         static const Utils::Type vec4 = Utils::Type::vec4;
10366
10367 #if WRKARD_UNIFORMBLOCKALIGNMENT
10368
10369         static const GLuint block_align = 16;
10370
10371 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
10372
10373         static const GLuint block_align = 64;
10374
10375 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10376
10377         static const GLuint vec4_stride = 16;
10378         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
10379
10380         /*Fixed a test issue, the fifth_offset should be calculated by block_align, instead of fifth_align, according to spec, the actual
10381          alignment of a member will be the greater of the specified alignment and the base aligment for the member type
10382          */
10383         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
10384         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
10385         const GLuint third_offset =
10386                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
10387         const GLuint fourth_offset =
10388                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
10389         const GLuint fifth_offset =
10390                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, block_align); /* vec4[2] at 160 */
10391         const GLuint sixth_offset =
10392                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
10393
10394         Utils::Interface* structure = program_interface.Structure("Data");
10395
10396         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10397                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
10398
10399         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
10400                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
10401                                           Utils::Type::vec4.GetSize() /* offset */);
10402
10403         /* Prepare Block */
10404         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
10405
10406         vs_uni_block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10407                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
10408
10409         vs_uni_block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10410                                                  0 /* n_array_elements */, data_stride, second_offset);
10411
10412         vs_uni_block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10413                                                  2 /* n_array_elements */, data_stride, third_offset);
10414
10415         vs_uni_block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
10416                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
10417
10418         vs_uni_block->Member("fifth", "layout(align = 64)", 0 /* expected_component */, 0 /* expected_location */, vec4,
10419                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
10420
10421         vs_uni_block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10422                                                  0 /* n_array_elements */, data_stride, sixth_offset);
10423
10424         const GLuint stride = calculateStride(*vs_uni_block);
10425         m_data.resize(stride);
10426         generateData(*vs_uni_block, 0, m_data);
10427
10428         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10429
10430 /* Add uniform BLOCK */
10431 #if WRKARD_UNIFORMBLOCKALIGNMENT
10432         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
10433                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10434 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
10435         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_uni_block, 0,
10436                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10437 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10438
10439         program_interface.CloneVertexInterface(varying_passthrough);
10440 }
10441
10442 /** Constructor
10443  *
10444  * @param context Test framework context
10445  **/
10446 SSBMemberOffsetAndAlignTest::SSBMemberOffsetAndAlignTest(deqp::Context& context)
10447         : TextureTestBase(context, "ssb_member_offset_and_align",
10448                                           "Test verifies offsets and alignment of storage buffer members")
10449 {
10450 }
10451
10452 /** Get interface of program
10453  *
10454  * @param test_case_index     Test case index
10455  * @param program_interface   Interface of program
10456  * @param varying_passthrough Collection of connections between in and out variables
10457  **/
10458 void SSBMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
10459                                                                                                           Utils::ProgramInterface&   program_interface,
10460                                                                                                           Utils::VaryingPassthrough& varying_passthrough)
10461 {
10462         std::string globals = "const int basic_size = BASIC_SIZE;\n"
10463                                                   "const int type_align = TYPE_ALIGN;\n"
10464                                                   "const int type_size  = TYPE_SIZE;\n";
10465
10466         Utils::Type  type                = getType(test_case_index);
10467         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
10468         const GLuint base_align  = type.GetBaseAlignment(false);
10469         const GLuint array_align = type.GetBaseAlignment(true);
10470         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
10471         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
10472
10473         /* Calculate offsets */
10474         const GLuint first_offset  = 0;
10475         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
10476
10477 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
10478
10479         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
10480         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
10481         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10482         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10483         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10484         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
10485
10486 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10487
10488         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
10489         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + base_stride, base_align);
10490         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10491         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10492         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10493         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, 8 * basic_size);
10494
10495 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10496
10497         /* Prepare data */
10498         const std::vector<GLubyte>& first  = type.GenerateData();
10499         const std::vector<GLubyte>& second = type.GenerateData();
10500         const std::vector<GLubyte>& third  = type.GenerateData();
10501         const std::vector<GLubyte>& fourth = type.GenerateData();
10502
10503         m_data.resize(eigth_offset + base_stride);
10504         GLubyte* ptr = &m_data[0];
10505         memcpy(ptr + first_offset, &first[0], first.size());
10506         memcpy(ptr + second_offset, &second[0], second.size());
10507         memcpy(ptr + third_offset, &third[0], third.size());
10508         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
10509         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
10510         memcpy(ptr + sixth_offset, &third[0], third.size());
10511         memcpy(ptr + seventh_offset, &second[0], second.size());
10512         memcpy(ptr + eigth_offset, &first[0], first.size());
10513
10514         /* Prepare globals */
10515         size_t position = 0;
10516         GLchar buffer[16];
10517
10518         sprintf(buffer, "%d", basic_size);
10519         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
10520
10521         sprintf(buffer, "%d", type_align);
10522         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
10523
10524         sprintf(buffer, "%d", base_stride);
10525         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
10526
10527         /* Prepare Block */
10528         Utils::Interface* vs_buf_block = program_interface.Block("vs_buf_Block");
10529
10530         vs_buf_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
10531                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10532                                                  first_offset);
10533
10534         vs_buf_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
10535                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
10536                                                  0 /* n_array_elements */, base_stride, second_offset);
10537
10538         vs_buf_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
10539                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10540                                                  third_offset);
10541
10542         vs_buf_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
10543                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10544                                                  fourth_offset);
10545
10546         vs_buf_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10547                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
10548
10549         vs_buf_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10550                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
10551
10552         vs_buf_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
10553                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10554                                                  eigth_offset);
10555
10556         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10557
10558         /* Add globals */
10559         vs_si.m_globals = globals;
10560
10561         /* Add uniform BLOCK */
10562         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_block, 0,
10563                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10564
10565         /* */
10566         program_interface.CloneVertexInterface(varying_passthrough);
10567 }
10568
10569 /** Get type name
10570  *
10571  * @param test_case_index Index of test case
10572  *
10573  * @return Name of type test in test_case_index
10574  **/
10575 std::string SSBMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
10576 {
10577         return getTypeName(test_case_index);
10578 }
10579
10580 /** Returns number of types to test
10581  *
10582  * @return Number of types, 34
10583  **/
10584 glw::GLuint SSBMemberOffsetAndAlignTest::getTestCaseNumber()
10585 {
10586         return getTypesNumber();
10587 }
10588
10589 /** Prepare code snippet that will verify in and uniform variables
10590  *
10591  * @param ignored
10592  * @param ignored
10593  * @param stage   Shader stage
10594  *
10595  * @return Code that verify variables
10596  **/
10597 std::string SSBMemberOffsetAndAlignTest::getVerificationSnippet(GLuint /* test_case_index */,
10598                                                                                                                                 Utils::ProgramInterface& /* program_interface */,
10599                                                                                                                                 Utils::Shader::STAGES stage)
10600 {
10601         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
10602                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
10603                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
10604                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
10605                                                            "    {\n"
10606                                                            "        result = 0;\n"
10607                                                            "    }";
10608
10609         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::SSB);
10610
10611         Utils::replaceAllTokens("PREFIX", prefix, verification);
10612
10613         return verification;
10614 }
10615
10616 /** Selects if "draw" stages are relevant for test
10617  *
10618  * @param ignored
10619  *
10620  * @return true if all stages support shader storage buffers, false otherwise
10621  **/
10622 bool SSBMemberOffsetAndAlignTest::isDrawRelevant(GLuint /* test_case_index */)
10623 {
10624         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10625         GLint                    gs_supported_buffers  = 0;
10626         GLint                    tcs_supported_buffers = 0;
10627         GLint                    tes_supported_buffers = 0;
10628         GLint                    vs_supported_buffers  = 0;
10629
10630         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
10631         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
10632         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
10633         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
10634
10635         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10636
10637         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
10638                         (1 <= vs_supported_buffers));
10639 }
10640
10641 /** Constructor
10642  *
10643  * @param context Test framework context
10644  **/
10645 SSBLayoutQualifierConflictTest::SSBLayoutQualifierConflictTest(deqp::Context& context)
10646         : NegativeTestBase(context, "ssb_layout_qualifier_conflict", "Test verifies that std140 or std430 is required when "
10647                                                                                                                                  "offset and/or align qualifiers are used with storage "
10648                                                                                                                                  "block")
10649 {
10650         /* Nothing to be done here */
10651 }
10652
10653 /** Source for given test case and stage
10654  *
10655  * @param test_case_index Index of test case
10656  * @param stage           Shader stage
10657  *
10658  * @return Shader source
10659  **/
10660 std::string SSBLayoutQualifierConflictTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10661 {
10662         static const GLchar* cs = "#version 430 core\n"
10663                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10664                                                           "\n"
10665                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10666                                                           "\n"
10667                                                           "layout (QUALIFIERbinding = BINDING) buffer cs_Block {\n"
10668                                                           "    layout(offset = 16) vec4 boy;\n"
10669                                                           "    layout(align  = 64) vec4 man;\n"
10670                                                           "} uni_block;\n"
10671                                                           "\n"
10672                                                           "writeonly uniform image2D uni_image;\n"
10673                                                           "\n"
10674                                                           "void main()\n"
10675                                                           "{\n"
10676                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
10677                                                           "\n"
10678                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10679                                                           "}\n"
10680                                                           "\n";
10681         static const GLchar* fs = "#version 430 core\n"
10682                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10683                                                           "\n"
10684                                                           "layout (QUALIFIERbinding = BINDING) buffer Block {\n"
10685                                                           "    layout(offset = 16) vec4 boy;\n"
10686                                                           "    layout(align  = 64) vec4 man;\n"
10687                                                           "} uni_block;\n"
10688                                                           "\n"
10689                                                           "in  vec4 gs_fs;\n"
10690                                                           "out vec4 fs_out;\n"
10691                                                           "\n"
10692                                                           "void main()\n"
10693                                                           "{\n"
10694                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
10695                                                           "}\n"
10696                                                           "\n";
10697         static const GLchar* gs = "#version 430 core\n"
10698                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10699                                                           "\n"
10700                                                           "layout(points)                           in;\n"
10701                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10702                                                           "\n"
10703                                                           "layout (QUALIFIERbinding = BINDING) buffer gs_Block {\n"
10704                                                           "    layout(offset = 16) vec4 boy;\n"
10705                                                           "    layout(align  = 64) vec4 man;\n"
10706                                                           "} uni_block;\n"
10707                                                           "\n"
10708                                                           "in  vec4 tes_gs[];\n"
10709                                                           "out vec4 gs_fs;\n"
10710                                                           "\n"
10711                                                           "void main()\n"
10712                                                           "{\n"
10713                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10714                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10715                                                           "    EmitVertex();\n"
10716                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10717                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10718                                                           "    EmitVertex();\n"
10719                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10720                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10721                                                           "    EmitVertex();\n"
10722                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10723                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
10724                                                           "    EmitVertex();\n"
10725                                                           "}\n"
10726                                                           "\n";
10727         static const GLchar* tcs =
10728                 "#version 430 core\n"
10729                 "#extension GL_ARB_enhanced_layouts : require\n"
10730                 "\n"
10731                 "layout(vertices = 1) out;\n"
10732                 "\n"
10733                 "layout (QUALIFIERbinding = BINDING) buffer tcs_Block {\n"
10734                 "    layout(offset = 16) vec4 boy;\n"
10735                 "    layout(align  = 64) vec4 man;\n"
10736                 "} uni_block;\n"
10737                 "\n"
10738                 "in  vec4 vs_tcs[];\n"
10739                 "out vec4 tcs_tes[];\n"
10740                 "\n"
10741                 "void main()\n"
10742                 "{\n"
10743                 "\n"
10744                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
10745                 "\n"
10746                 "    gl_TessLevelOuter[0] = 1.0;\n"
10747                 "    gl_TessLevelOuter[1] = 1.0;\n"
10748                 "    gl_TessLevelOuter[2] = 1.0;\n"
10749                 "    gl_TessLevelOuter[3] = 1.0;\n"
10750                 "    gl_TessLevelInner[0] = 1.0;\n"
10751                 "    gl_TessLevelInner[1] = 1.0;\n"
10752                 "}\n"
10753                 "\n";
10754         static const GLchar* tes = "#version 430 core\n"
10755                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10756                                                            "\n"
10757                                                            "layout(isolines, point_mode) in;\n"
10758                                                            "\n"
10759                                                            "layout (QUALIFIERbinding = BINDING) buffer tes_Block {\n"
10760                                                            "    layout(offset = 16) vec4 boy;\n"
10761                                                            "    layout(align  = 64) vec4 man;\n"
10762                                                            "} uni_block;\n"
10763                                                            "\n"
10764                                                            "in  vec4 tcs_tes[];\n"
10765                                                            "out vec4 tes_gs;\n"
10766                                                            "\n"
10767                                                            "void main()\n"
10768                                                            "{\n"
10769                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
10770                                                            "}\n"
10771                                                            "\n";
10772         static const GLchar* vs = "#version 430 core\n"
10773                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10774                                                           "\n"
10775                                                           "layout (QUALIFIERbinding = BINDING) buffer vs_Block {\n"
10776                                                           "    layout(offset = 16) vec4 boy;\n"
10777                                                           "    layout(align  = 64) vec4 man;\n"
10778                                                           "} uni_block;\n"
10779                                                           "\n"
10780                                                           "in  vec4 in_vs;\n"
10781                                                           "out vec4 vs_tcs;\n"
10782                                                           "\n"
10783                                                           "void main()\n"
10784                                                           "{\n"
10785                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
10786                                                           "}\n"
10787                                                           "\n";
10788
10789         GLchar          buffer[16];
10790         size_t          position = 0;
10791         std::string source;
10792         testCase&   test_case = m_test_cases[test_case_index];
10793         std::string qualifier = getQualifierName(test_case.m_qualifier);
10794
10795         if (false == qualifier.empty())
10796         {
10797                 qualifier.append(", ");
10798         }
10799
10800         sprintf(buffer, "%d", stage);
10801
10802         switch (stage)
10803         {
10804         case Utils::Shader::COMPUTE:
10805                 source = cs;
10806                 break;
10807         case Utils::Shader::FRAGMENT:
10808                 source = fs;
10809                 break;
10810         case Utils::Shader::GEOMETRY:
10811                 source = gs;
10812                 break;
10813         case Utils::Shader::TESS_CTRL:
10814                 source = tcs;
10815                 break;
10816         case Utils::Shader::TESS_EVAL:
10817                 source = tes;
10818                 break;
10819         case Utils::Shader::VERTEX:
10820                 source = vs;
10821                 break;
10822         default:
10823                 TCU_FAIL("Invalid enum");
10824         }
10825
10826         if (test_case.m_stage == stage)
10827         {
10828                 Utils::replaceToken("QUALIFIER", position, qualifier.c_str(), source);
10829         }
10830         else
10831         {
10832                 Utils::replaceToken("QUALIFIER", position, "std140, ", source);
10833         }
10834
10835         Utils::replaceToken("BINDING", position, buffer, source);
10836
10837         return source;
10838 }
10839
10840 /** Get description of test case
10841  *
10842  * @param test_case_index Index of test case
10843  *
10844  * @return Qualifier name
10845  **/
10846 std::string SSBLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
10847 {
10848         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
10849
10850         return result;
10851 }
10852
10853 /** Get number of test cases
10854  *
10855  * @return Number of test cases
10856  **/
10857 GLuint SSBLayoutQualifierConflictTest::getTestCaseNumber()
10858 {
10859         return static_cast<GLuint>(m_test_cases.size());
10860 }
10861
10862 /** Selects if "compute" stage is relevant for test
10863  *
10864  * @param test_case_index Index of test case
10865  *
10866  * @return true when tested stage is compute
10867  **/
10868 bool SSBLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
10869 {
10870         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10871 }
10872
10873 /** Selects if compilation failure is expected result
10874  *
10875  * @param test_case_index Index of test case
10876  *
10877  * @return false for STD140 and STD430 cases, true otherwise
10878  **/
10879 bool SSBLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
10880 {
10881         const QUALIFIERS qualifier = m_test_cases[test_case_index].m_qualifier;
10882
10883         return !((STD140 == qualifier) || (STD430 == qualifier));
10884 }
10885
10886 /** Checks if stage is supported
10887  *
10888  * @param stage Shader stage
10889  *
10890  * @return true if supported, false otherwise
10891  **/
10892 bool SSBLayoutQualifierConflictTest::isStageSupported(Utils::Shader::STAGES stage)
10893 {
10894         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10895         GLint                    max_supported_buffers = 0;
10896         GLenum                   pname                             = 0;
10897
10898         switch (stage)
10899         {
10900         case Utils::Shader::COMPUTE:
10901                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
10902                 break;
10903         case Utils::Shader::FRAGMENT:
10904                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
10905                 break;
10906         case Utils::Shader::GEOMETRY:
10907                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
10908                 break;
10909         case Utils::Shader::TESS_CTRL:
10910                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
10911                 break;
10912         case Utils::Shader::TESS_EVAL:
10913                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
10914                 break;
10915         case Utils::Shader::VERTEX:
10916                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
10917                 break;
10918         default:
10919                 TCU_FAIL("Invalid enum");
10920         }
10921
10922         gl.getIntegerv(pname, &max_supported_buffers);
10923         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10924
10925         return 1 <= max_supported_buffers;
10926 }
10927
10928 /** Prepare all test cases
10929  *
10930  **/
10931 void SSBLayoutQualifierConflictTest::testInit()
10932 {
10933         bool stage_support[Utils::Shader::STAGE_MAX];
10934
10935         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10936         {
10937                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10938         }
10939
10940         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
10941         {
10942                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10943                 {
10944                         if (false == stage_support[stage])
10945                         {
10946                                 continue;
10947                         }
10948
10949                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
10950
10951                         m_test_cases.push_back(test_case);
10952                 }
10953         }
10954 }
10955
10956 /** Get name of glsl constant
10957  *
10958  * @param Constant id
10959  *
10960  * @return Name of constant used in GLSL
10961  **/
10962 const GLchar* SSBLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
10963 {
10964         const GLchar* name = "";
10965
10966         switch (qualifier)
10967         {
10968         case DEFAULT:
10969                 name = "";
10970                 break;
10971         case STD140:
10972                 name = "std140";
10973                 break;
10974         case STD430:
10975                 name = "std430";
10976                 break;
10977         case SHARED:
10978                 name = "shared";
10979                 break;
10980         case PACKED:
10981                 name = "packed";
10982                 break;
10983         default:
10984                 TCU_FAIL("Invalid enum");
10985         }
10986
10987         return name;
10988 }
10989
10990 /** Constructor
10991  *
10992  * @param context Test framework context
10993  **/
10994 SSBMemberInvalidOffsetAlignmentTest::SSBMemberInvalidOffsetAlignmentTest(deqp::Context& context)
10995         : UniformBlockMemberInvalidOffsetAlignmentTest(
10996                   context, "ssb_member_invalid_offset_alignment",
10997                   "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
10998 {
10999         /* Nothing to be done here */
11000 }
11001
11002 /** Source for given test case and stage
11003  *
11004  * @param test_case_index Index of test case
11005  * @param stage           Shader stage
11006  *
11007  * @return Shader source
11008  **/
11009 std::string SSBMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11010 {
11011         static const GLchar* cs = "#version 430 core\n"
11012                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11013                                                           "\n"
11014                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11015                                                           "\n"
11016                                                           "layout (std140) buffer Block {\n"
11017                                                           "    layout (offset = OFFSET) TYPE member;\n"
11018                                                           "} block;\n"
11019                                                           "\n"
11020                                                           "writeonly uniform image2D uni_image;\n"
11021                                                           "\n"
11022                                                           "void main()\n"
11023                                                           "{\n"
11024                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11025                                                           "\n"
11026                                                           "    if (TYPE(1) == block.member)\n"
11027                                                           "    {\n"
11028                                                           "        result = vec4(1, 1, 1, 1);\n"
11029                                                           "    }\n"
11030                                                           "\n"
11031                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11032                                                           "}\n"
11033                                                           "\n";
11034         static const GLchar* fs = "#version 430 core\n"
11035                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11036                                                           "\n"
11037                                                           "in  vec4 gs_fs;\n"
11038                                                           "out vec4 fs_out;\n"
11039                                                           "\n"
11040                                                           "void main()\n"
11041                                                           "{\n"
11042                                                           "    fs_out = gs_fs;\n"
11043                                                           "}\n"
11044                                                           "\n";
11045         static const GLchar* fs_tested = "#version 430 core\n"
11046                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11047                                                                          "\n"
11048                                                                          "layout (std140) buffer Block {\n"
11049                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11050                                                                          "} block;\n"
11051                                                                          "\n"
11052                                                                          "in  vec4 gs_fs;\n"
11053                                                                          "out vec4 fs_out;\n"
11054                                                                          "\n"
11055                                                                          "void main()\n"
11056                                                                          "{\n"
11057                                                                          "    if (TYPE(1) == block.member)\n"
11058                                                                          "    {\n"
11059                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11060                                                                          "    }\n"
11061                                                                          "\n"
11062                                                                          "    fs_out += gs_fs;\n"
11063                                                                          "}\n"
11064                                                                          "\n";
11065         static const GLchar* gs = "#version 430 core\n"
11066                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11067                                                           "\n"
11068                                                           "layout(points)                           in;\n"
11069                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11070                                                           "\n"
11071                                                           "in  vec4 tes_gs[];\n"
11072                                                           "out vec4 gs_fs;\n"
11073                                                           "\n"
11074                                                           "void main()\n"
11075                                                           "{\n"
11076                                                           "    gs_fs = tes_gs[0];\n"
11077                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11078                                                           "    EmitVertex();\n"
11079                                                           "    gs_fs = tes_gs[0];\n"
11080                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11081                                                           "    EmitVertex();\n"
11082                                                           "    gs_fs = tes_gs[0];\n"
11083                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11084                                                           "    EmitVertex();\n"
11085                                                           "    gs_fs = tes_gs[0];\n"
11086                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11087                                                           "    EmitVertex();\n"
11088                                                           "}\n"
11089                                                           "\n";
11090         static const GLchar* gs_tested = "#version 430 core\n"
11091                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11092                                                                          "\n"
11093                                                                          "layout(points)                           in;\n"
11094                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11095                                                                          "\n"
11096                                                                          "layout (std140) buffer Block {\n"
11097                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11098                                                                          "} block;\n"
11099                                                                          "\n"
11100                                                                          "in  vec4 tes_gs[];\n"
11101                                                                          "out vec4 gs_fs;\n"
11102                                                                          "\n"
11103                                                                          "void main()\n"
11104                                                                          "{\n"
11105                                                                          "    if (TYPE(1) == block.member)\n"
11106                                                                          "    {\n"
11107                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11108                                                                          "    }\n"
11109                                                                          "\n"
11110                                                                          "    gs_fs += tes_gs[0];\n"
11111                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11112                                                                          "    EmitVertex();\n"
11113                                                                          "    gs_fs += tes_gs[0];\n"
11114                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11115                                                                          "    EmitVertex();\n"
11116                                                                          "    gs_fs += tes_gs[0];\n"
11117                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11118                                                                          "    EmitVertex();\n"
11119                                                                          "    gs_fs += tes_gs[0];\n"
11120                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11121                                                                          "    EmitVertex();\n"
11122                                                                          "}\n"
11123                                                                          "\n";
11124         static const GLchar* tcs = "#version 430 core\n"
11125                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11126                                                            "\n"
11127                                                            "layout(vertices = 1) out;\n"
11128                                                            "\n"
11129                                                            "in  vec4 vs_tcs[];\n"
11130                                                            "out vec4 tcs_tes[];\n"
11131                                                            "\n"
11132                                                            "void main()\n"
11133                                                            "{\n"
11134                                                            "\n"
11135                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11136                                                            "\n"
11137                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11138                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11139                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11140                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11141                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11142                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11143                                                            "}\n"
11144                                                            "\n";
11145         static const GLchar* tcs_tested = "#version 430 core\n"
11146                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11147                                                                           "\n"
11148                                                                           "layout(vertices = 1) out;\n"
11149                                                                           "\n"
11150                                                                           "layout (std140) buffer Block {\n"
11151                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11152                                                                           "} block;\n"
11153                                                                           "\n"
11154                                                                           "in  vec4 vs_tcs[];\n"
11155                                                                           "out vec4 tcs_tes[];\n"
11156                                                                           "\n"
11157                                                                           "void main()\n"
11158                                                                           "{\n"
11159                                                                           "    if (TYPE(1) == block.member)\n"
11160                                                                           "    {\n"
11161                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11162                                                                           "    }\n"
11163                                                                           "\n"
11164                                                                           "\n"
11165                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11166                                                                           "\n"
11167                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11168                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11169                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11170                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11171                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11172                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11173                                                                           "}\n"
11174                                                                           "\n";
11175         static const GLchar* tes = "#version 430 core\n"
11176                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11177                                                            "\n"
11178                                                            "layout(isolines, point_mode) in;\n"
11179                                                            "\n"
11180                                                            "in  vec4 tcs_tes[];\n"
11181                                                            "out vec4 tes_gs;\n"
11182                                                            "\n"
11183                                                            "void main()\n"
11184                                                            "{\n"
11185                                                            "    tes_gs = tcs_tes[0];\n"
11186                                                            "}\n"
11187                                                            "\n";
11188         static const GLchar* tes_tested = "#version 430 core\n"
11189                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11190                                                                           "\n"
11191                                                                           "layout(isolines, point_mode) in;\n"
11192                                                                           "\n"
11193                                                                           "layout (std140) buffer Block {\n"
11194                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11195                                                                           "} block;\n"
11196                                                                           "\n"
11197                                                                           "in  vec4 tcs_tes[];\n"
11198                                                                           "out vec4 tes_gs;\n"
11199                                                                           "\n"
11200                                                                           "void main()\n"
11201                                                                           "{\n"
11202                                                                           "    if (TYPE(1) == block.member)\n"
11203                                                                           "    {\n"
11204                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11205                                                                           "    }\n"
11206                                                                           "\n"
11207                                                                           "    tes_gs += tcs_tes[0];\n"
11208                                                                           "}\n"
11209                                                                           "\n";
11210         static const GLchar* vs = "#version 430 core\n"
11211                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11212                                                           "\n"
11213                                                           "in  vec4 in_vs;\n"
11214                                                           "out vec4 vs_tcs;\n"
11215                                                           "\n"
11216                                                           "void main()\n"
11217                                                           "{\n"
11218                                                           "    vs_tcs = in_vs;\n"
11219                                                           "}\n"
11220                                                           "\n";
11221         static const GLchar* vs_tested = "#version 430 core\n"
11222                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11223                                                                          "\n"
11224                                                                          "layout (std140) buffer Block {\n"
11225                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11226                                                                          "} block;\n"
11227                                                                          "\n"
11228                                                                          "in  vec4 in_vs;\n"
11229                                                                          "out vec4 vs_tcs;\n"
11230                                                                          "\n"
11231                                                                          "void main()\n"
11232                                                                          "{\n"
11233                                                                          "    if (TYPE(1) == block.member)\n"
11234                                                                          "    {\n"
11235                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11236                                                                          "    }\n"
11237                                                                          "\n"
11238                                                                          "    vs_tcs += in_vs;\n"
11239                                                                          "}\n"
11240                                                                          "\n";
11241
11242         std::string source;
11243         testCase&   test_case = m_test_cases[test_case_index];
11244
11245         if (test_case.m_stage == stage)
11246         {
11247                 GLchar                     buffer[16];
11248                 const GLuint       offset       = test_case.m_offset;
11249                 size_t                     position  = 0;
11250                 const Utils::Type& type          = test_case.m_type;
11251                 const GLchar*     type_name = type.GetGLSLTypeName();
11252
11253                 sprintf(buffer, "%d", offset);
11254
11255                 switch (stage)
11256                 {
11257                 case Utils::Shader::COMPUTE:
11258                         source = cs;
11259                         break;
11260                 case Utils::Shader::FRAGMENT:
11261                         source = fs_tested;
11262                         break;
11263                 case Utils::Shader::GEOMETRY:
11264                         source = gs_tested;
11265                         break;
11266                 case Utils::Shader::TESS_CTRL:
11267                         source = tcs_tested;
11268                         break;
11269                 case Utils::Shader::TESS_EVAL:
11270                         source = tes_tested;
11271                         break;
11272                 case Utils::Shader::VERTEX:
11273                         source = vs_tested;
11274                         break;
11275                 default:
11276                         TCU_FAIL("Invalid enum");
11277                 }
11278
11279                 Utils::replaceToken("OFFSET", position, buffer, source);
11280                 Utils::replaceToken("TYPE", position, type_name, source);
11281                 Utils::replaceToken("TYPE", position, type_name, source);
11282         }
11283         else
11284         {
11285                 switch (stage)
11286                 {
11287                 case Utils::Shader::FRAGMENT:
11288                         source = fs;
11289                         break;
11290                 case Utils::Shader::GEOMETRY:
11291                         source = gs;
11292                         break;
11293                 case Utils::Shader::TESS_CTRL:
11294                         source = tcs;
11295                         break;
11296                 case Utils::Shader::TESS_EVAL:
11297                         source = tes;
11298                         break;
11299                 case Utils::Shader::VERTEX:
11300                         source = vs;
11301                         break;
11302                 default:
11303                         TCU_FAIL("Invalid enum");
11304                 }
11305         }
11306
11307         return source;
11308 }
11309
11310 /** Checks if stage is supported
11311  *
11312  * @param stage Shader stage
11313  *
11314  * @return true if supported, false otherwise
11315  **/
11316 bool SSBMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES stage)
11317 {
11318         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11319         GLint                    max_supported_buffers = 0;
11320         GLenum                   pname                             = 0;
11321
11322         switch (stage)
11323         {
11324         case Utils::Shader::COMPUTE:
11325                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11326                 break;
11327         case Utils::Shader::FRAGMENT:
11328                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11329                 break;
11330         case Utils::Shader::GEOMETRY:
11331                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11332                 break;
11333         case Utils::Shader::TESS_CTRL:
11334                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11335                 break;
11336         case Utils::Shader::TESS_EVAL:
11337                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11338                 break;
11339         case Utils::Shader::VERTEX:
11340                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11341                 break;
11342         default:
11343                 TCU_FAIL("Invalid enum");
11344         }
11345
11346         gl.getIntegerv(pname, &max_supported_buffers);
11347         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11348
11349         return 1 <= max_supported_buffers;
11350 }
11351
11352 /** Constructor
11353  *
11354  * @param context Test framework context
11355  **/
11356 SSBMemberOverlappingOffsetsTest::SSBMemberOverlappingOffsetsTest(deqp::Context& context)
11357         : UniformBlockMemberOverlappingOffsetsTest(
11358                   context, "ssb_member_overlapping_offsets",
11359                   "Test verifies that overlapping offsets qualifiers cause compilation failure")
11360 {
11361         /* Nothing to be done here */
11362 }
11363
11364 /** Source for given test case and stage
11365  *
11366  * @param test_case_index Index of test case
11367  * @param stage           Shader stage
11368  *
11369  * @return Shader source
11370  **/
11371 std::string SSBMemberOverlappingOffsetsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11372 {
11373         static const GLchar* cs = "#version 430 core\n"
11374                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11375                                                           "\n"
11376                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11377                                                           "\n"
11378                                                           "layout (std140) buffer Block {\n"
11379                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11380                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11381                                                           "} block;\n"
11382                                                           "\n"
11383                                                           "writeonly uniform image2D uni_image;\n"
11384                                                           "\n"
11385                                                           "void main()\n"
11386                                                           "{\n"
11387                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11388                                                           "\n"
11389                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11390                                                           "        (MAN_TYPE(0) == block.man) )\n"
11391                                                           "    {\n"
11392                                                           "        result = vec4(1, 1, 1, 1);\n"
11393                                                           "    }\n"
11394                                                           "\n"
11395                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11396                                                           "}\n"
11397                                                           "\n";
11398         static const GLchar* fs = "#version 430 core\n"
11399                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11400                                                           "\n"
11401                                                           "in  vec4 gs_fs;\n"
11402                                                           "out vec4 fs_out;\n"
11403                                                           "\n"
11404                                                           "void main()\n"
11405                                                           "{\n"
11406                                                           "    fs_out = gs_fs;\n"
11407                                                           "}\n"
11408                                                           "\n";
11409         static const GLchar* fs_tested = "#version 430 core\n"
11410                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11411                                                                          "\n"
11412                                                                          "layout (std140) buffer Block {\n"
11413                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11414                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11415                                                                          "} block;\n"
11416                                                                          "\n"
11417                                                                          "in  vec4 gs_fs;\n"
11418                                                                          "out vec4 fs_out;\n"
11419                                                                          "\n"
11420                                                                          "void main()\n"
11421                                                                          "{\n"
11422                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11423                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11424                                                                          "    {\n"
11425                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11426                                                                          "    }\n"
11427                                                                          "\n"
11428                                                                          "    fs_out += gs_fs;\n"
11429                                                                          "}\n"
11430                                                                          "\n";
11431         static const GLchar* gs = "#version 430 core\n"
11432                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11433                                                           "\n"
11434                                                           "layout(points)                           in;\n"
11435                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11436                                                           "\n"
11437                                                           "in  vec4 tes_gs[];\n"
11438                                                           "out vec4 gs_fs;\n"
11439                                                           "\n"
11440                                                           "void main()\n"
11441                                                           "{\n"
11442                                                           "    gs_fs = tes_gs[0];\n"
11443                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11444                                                           "    EmitVertex();\n"
11445                                                           "    gs_fs = tes_gs[0];\n"
11446                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11447                                                           "    EmitVertex();\n"
11448                                                           "    gs_fs = tes_gs[0];\n"
11449                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11450                                                           "    EmitVertex();\n"
11451                                                           "    gs_fs = tes_gs[0];\n"
11452                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11453                                                           "    EmitVertex();\n"
11454                                                           "}\n"
11455                                                           "\n";
11456         static const GLchar* gs_tested = "#version 430 core\n"
11457                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11458                                                                          "\n"
11459                                                                          "layout(points)                           in;\n"
11460                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11461                                                                          "\n"
11462                                                                          "layout (std140) buffer Block {\n"
11463                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11464                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11465                                                                          "} block;\n"
11466                                                                          "\n"
11467                                                                          "in  vec4 tes_gs[];\n"
11468                                                                          "out vec4 gs_fs;\n"
11469                                                                          "\n"
11470                                                                          "void main()\n"
11471                                                                          "{\n"
11472                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11473                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11474                                                                          "    {\n"
11475                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11476                                                                          "    }\n"
11477                                                                          "\n"
11478                                                                          "    gs_fs += tes_gs[0];\n"
11479                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11480                                                                          "    EmitVertex();\n"
11481                                                                          "    gs_fs += tes_gs[0];\n"
11482                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11483                                                                          "    EmitVertex();\n"
11484                                                                          "    gs_fs += tes_gs[0];\n"
11485                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11486                                                                          "    EmitVertex();\n"
11487                                                                          "    gs_fs += tes_gs[0];\n"
11488                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11489                                                                          "    EmitVertex();\n"
11490                                                                          "}\n"
11491                                                                          "\n";
11492         static const GLchar* tcs = "#version 430 core\n"
11493                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11494                                                            "\n"
11495                                                            "layout(vertices = 1) out;\n"
11496                                                            "\n"
11497                                                            "in  vec4 vs_tcs[];\n"
11498                                                            "out vec4 tcs_tes[];\n"
11499                                                            "\n"
11500                                                            "void main()\n"
11501                                                            "{\n"
11502                                                            "\n"
11503                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11504                                                            "\n"
11505                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11506                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11507                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11508                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11509                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11510                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11511                                                            "}\n"
11512                                                            "\n";
11513         static const GLchar* tcs_tested = "#version 430 core\n"
11514                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11515                                                                           "\n"
11516                                                                           "layout(vertices = 1) out;\n"
11517                                                                           "\n"
11518                                                                           "layout (std140) buffer Block {\n"
11519                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11520                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11521                                                                           "} block;\n"
11522                                                                           "\n"
11523                                                                           "in  vec4 vs_tcs[];\n"
11524                                                                           "out vec4 tcs_tes[];\n"
11525                                                                           "\n"
11526                                                                           "void main()\n"
11527                                                                           "{\n"
11528                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11529                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11530                                                                           "    {\n"
11531                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11532                                                                           "    }\n"
11533                                                                           "\n"
11534                                                                           "\n"
11535                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11536                                                                           "\n"
11537                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11538                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11539                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11540                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11541                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11542                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11543                                                                           "}\n"
11544                                                                           "\n";
11545         static const GLchar* tes = "#version 430 core\n"
11546                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11547                                                            "\n"
11548                                                            "layout(isolines, point_mode) in;\n"
11549                                                            "\n"
11550                                                            "in  vec4 tcs_tes[];\n"
11551                                                            "out vec4 tes_gs;\n"
11552                                                            "\n"
11553                                                            "void main()\n"
11554                                                            "{\n"
11555                                                            "    tes_gs = tcs_tes[0];\n"
11556                                                            "}\n"
11557                                                            "\n";
11558         static const GLchar* tes_tested = "#version 430 core\n"
11559                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11560                                                                           "\n"
11561                                                                           "layout(isolines, point_mode) in;\n"
11562                                                                           "\n"
11563                                                                           "layout (std140) buffer Block {\n"
11564                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11565                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11566                                                                           "} block;\n"
11567                                                                           "\n"
11568                                                                           "in  vec4 tcs_tes[];\n"
11569                                                                           "out vec4 tes_gs;\n"
11570                                                                           "\n"
11571                                                                           "void main()\n"
11572                                                                           "{\n"
11573                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11574                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11575                                                                           "    {\n"
11576                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11577                                                                           "    }\n"
11578                                                                           "\n"
11579                                                                           "    tes_gs += tcs_tes[0];\n"
11580                                                                           "}\n"
11581                                                                           "\n";
11582         static const GLchar* vs = "#version 430 core\n"
11583                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11584                                                           "\n"
11585                                                           "in  vec4 in_vs;\n"
11586                                                           "out vec4 vs_tcs;\n"
11587                                                           "\n"
11588                                                           "void main()\n"
11589                                                           "{\n"
11590                                                           "    vs_tcs = in_vs;\n"
11591                                                           "}\n"
11592                                                           "\n";
11593         static const GLchar* vs_tested = "#version 430 core\n"
11594                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11595                                                                          "\n"
11596                                                                          "layout (std140) buffer Block {\n"
11597                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11598                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11599                                                                          "} block;\n"
11600                                                                          "\n"
11601                                                                          "in  vec4 in_vs;\n"
11602                                                                          "out vec4 vs_tcs;\n"
11603                                                                          "\n"
11604                                                                          "void main()\n"
11605                                                                          "{\n"
11606                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11607                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11608                                                                          "    {\n"
11609                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11610                                                                          "    }\n"
11611                                                                          "\n"
11612                                                                          "    vs_tcs += in_vs;\n"
11613                                                                          "}\n"
11614                                                                          "\n";
11615
11616         std::string source;
11617         testCase&   test_case = m_test_cases[test_case_index];
11618
11619         if (test_case.m_stage == stage)
11620         {
11621                 GLchar                     buffer[16];
11622                 const GLuint       boy_offset   = test_case.m_boy_offset;
11623                 const Utils::Type& boy_type              = test_case.m_boy_type;
11624                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
11625                 const GLuint       man_offset   = test_case.m_man_offset;
11626                 const Utils::Type& man_type              = test_case.m_man_type;
11627                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
11628                 size_t                     position              = 0;
11629
11630                 switch (stage)
11631                 {
11632                 case Utils::Shader::COMPUTE:
11633                         source = cs;
11634                         break;
11635                 case Utils::Shader::FRAGMENT:
11636                         source = fs_tested;
11637                         break;
11638                 case Utils::Shader::GEOMETRY:
11639                         source = gs_tested;
11640                         break;
11641                 case Utils::Shader::TESS_CTRL:
11642                         source = tcs_tested;
11643                         break;
11644                 case Utils::Shader::TESS_EVAL:
11645                         source = tes_tested;
11646                         break;
11647                 case Utils::Shader::VERTEX:
11648                         source = vs_tested;
11649                         break;
11650                 default:
11651                         TCU_FAIL("Invalid enum");
11652                 }
11653
11654                 sprintf(buffer, "%d", boy_offset);
11655                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
11656                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11657                 sprintf(buffer, "%d", man_offset);
11658                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
11659                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11660                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11661                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11662         }
11663         else
11664         {
11665                 switch (stage)
11666                 {
11667                 case Utils::Shader::FRAGMENT:
11668                         source = fs;
11669                         break;
11670                 case Utils::Shader::GEOMETRY:
11671                         source = gs;
11672                         break;
11673                 case Utils::Shader::TESS_CTRL:
11674                         source = tcs;
11675                         break;
11676                 case Utils::Shader::TESS_EVAL:
11677                         source = tes;
11678                         break;
11679                 case Utils::Shader::VERTEX:
11680                         source = vs;
11681                         break;
11682                 default:
11683                         TCU_FAIL("Invalid enum");
11684                 }
11685         }
11686
11687         return source;
11688 }
11689
11690 /** Checks if stage is supported
11691  *
11692  * @param stage Shader stage
11693  *
11694  * @return true if supported, false otherwise
11695  **/
11696 bool SSBMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES stage)
11697 {
11698         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11699         GLint                    max_supported_buffers = 0;
11700         GLenum                   pname                             = 0;
11701
11702         switch (stage)
11703         {
11704         case Utils::Shader::COMPUTE:
11705                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11706                 break;
11707         case Utils::Shader::FRAGMENT:
11708                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11709                 break;
11710         case Utils::Shader::GEOMETRY:
11711                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11712                 break;
11713         case Utils::Shader::TESS_CTRL:
11714                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11715                 break;
11716         case Utils::Shader::TESS_EVAL:
11717                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11718                 break;
11719         case Utils::Shader::VERTEX:
11720                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11721                 break;
11722         default:
11723                 TCU_FAIL("Invalid enum");
11724         }
11725
11726         gl.getIntegerv(pname, &max_supported_buffers);
11727         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11728
11729         return 1 <= max_supported_buffers;
11730 }
11731
11732 /** Constructor
11733  *
11734  * @param context Test framework context
11735  **/
11736 SSBMemberAlignNonPowerOf2Test::SSBMemberAlignNonPowerOf2Test(deqp::Context& context)
11737         : UniformBlockMemberAlignNonPowerOf2Test(context, "ssb_member_align_non_power_of_2",
11738                                                                                          "Test verifies that align qualifier requires value that is a power of 2")
11739 {
11740         /* Nothing to be done here */
11741 }
11742
11743 /** Source for given test case and stage
11744  *
11745  * @param test_case_index Index of test case
11746  * @param stage           Shader stage
11747  *
11748  * @return Shader source
11749  **/
11750 std::string SSBMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11751 {
11752         static const GLchar* cs = "#version 430 core\n"
11753                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11754                                                           "\n"
11755                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11756                                                           "\n"
11757                                                           "layout (std140) buffer Block {\n"
11758                                                           "    vec4 boy;\n"
11759                                                           "    layout (align = ALIGN) TYPE man;\n"
11760                                                           "} block;\n"
11761                                                           "\n"
11762                                                           "writeonly uniform image2D uni_image;\n"
11763                                                           "\n"
11764                                                           "void main()\n"
11765                                                           "{\n"
11766                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11767                                                           "\n"
11768                                                           "    if (TYPE(0) == block.man)\n"
11769                                                           "    {\n"
11770                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
11771                                                           "    }\n"
11772                                                           "\n"
11773                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11774                                                           "}\n"
11775                                                           "\n";
11776         static const GLchar* fs = "#version 430 core\n"
11777                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11778                                                           "\n"
11779                                                           "in  vec4 gs_fs;\n"
11780                                                           "out vec4 fs_out;\n"
11781                                                           "\n"
11782                                                           "void main()\n"
11783                                                           "{\n"
11784                                                           "    fs_out = gs_fs;\n"
11785                                                           "}\n"
11786                                                           "\n";
11787         static const GLchar* fs_tested = "#version 430 core\n"
11788                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11789                                                                          "\n"
11790                                                                          "layout (std140) buffer Block {\n"
11791                                                                          "    vec4 boy;\n"
11792                                                                          "    layout (align = ALIGN) TYPE man;\n"
11793                                                                          "} block;\n"
11794                                                                          "\n"
11795                                                                          "in  vec4 gs_fs;\n"
11796                                                                          "out vec4 fs_out;\n"
11797                                                                          "\n"
11798                                                                          "void main()\n"
11799                                                                          "{\n"
11800                                                                          "    if (TYPE(0) == block.man)\n"
11801                                                                          "    {\n"
11802                                                                          "        fs_out = block.boy;\n"
11803                                                                          "    }\n"
11804                                                                          "\n"
11805                                                                          "    fs_out += gs_fs;\n"
11806                                                                          "}\n"
11807                                                                          "\n";
11808         static const GLchar* gs = "#version 430 core\n"
11809                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11810                                                           "\n"
11811                                                           "layout(points)                           in;\n"
11812                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11813                                                           "\n"
11814                                                           "in  vec4 tes_gs[];\n"
11815                                                           "out vec4 gs_fs;\n"
11816                                                           "\n"
11817                                                           "void main()\n"
11818                                                           "{\n"
11819                                                           "    gs_fs = tes_gs[0];\n"
11820                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11821                                                           "    EmitVertex();\n"
11822                                                           "    gs_fs = tes_gs[0];\n"
11823                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11824                                                           "    EmitVertex();\n"
11825                                                           "    gs_fs = tes_gs[0];\n"
11826                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11827                                                           "    EmitVertex();\n"
11828                                                           "    gs_fs = tes_gs[0];\n"
11829                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11830                                                           "    EmitVertex();\n"
11831                                                           "}\n"
11832                                                           "\n";
11833         static const GLchar* gs_tested = "#version 430 core\n"
11834                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11835                                                                          "\n"
11836                                                                          "layout(points)                           in;\n"
11837                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11838                                                                          "\n"
11839                                                                          "layout (std140) buffer Block {\n"
11840                                                                          "    vec4 boy;\n"
11841                                                                          "    layout (align = ALIGN) TYPE man;\n"
11842                                                                          "} block;\n"
11843                                                                          "\n"
11844                                                                          "in  vec4 tes_gs[];\n"
11845                                                                          "out vec4 gs_fs;\n"
11846                                                                          "\n"
11847                                                                          "void main()\n"
11848                                                                          "{\n"
11849                                                                          "    if (TYPE(0) == block.man)\n"
11850                                                                          "    {\n"
11851                                                                          "        gs_fs = block.boy;\n"
11852                                                                          "    }\n"
11853                                                                          "\n"
11854                                                                          "    gs_fs += tes_gs[0];\n"
11855                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11856                                                                          "    EmitVertex();\n"
11857                                                                          "    gs_fs += tes_gs[0];\n"
11858                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11859                                                                          "    EmitVertex();\n"
11860                                                                          "    gs_fs += tes_gs[0];\n"
11861                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11862                                                                          "    EmitVertex();\n"
11863                                                                          "    gs_fs += tes_gs[0];\n"
11864                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11865                                                                          "    EmitVertex();\n"
11866                                                                          "}\n"
11867                                                                          "\n";
11868         static const GLchar* tcs = "#version 430 core\n"
11869                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11870                                                            "\n"
11871                                                            "layout(vertices = 1) out;\n"
11872                                                            "\n"
11873                                                            "in  vec4 vs_tcs[];\n"
11874                                                            "out vec4 tcs_tes[];\n"
11875                                                            "\n"
11876                                                            "void main()\n"
11877                                                            "{\n"
11878                                                            "\n"
11879                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11880                                                            "\n"
11881                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11882                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11883                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11884                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11885                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11886                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11887                                                            "}\n"
11888                                                            "\n";
11889         static const GLchar* tcs_tested = "#version 430 core\n"
11890                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11891                                                                           "\n"
11892                                                                           "layout(vertices = 1) out;\n"
11893                                                                           "\n"
11894                                                                           "layout (std140) buffer Block {\n"
11895                                                                           "    vec4 boy;\n"
11896                                                                           "    layout (align = ALIGN) TYPE man;\n"
11897                                                                           "} block;\n"
11898                                                                           "\n"
11899                                                                           "in  vec4 vs_tcs[];\n"
11900                                                                           "out vec4 tcs_tes[];\n"
11901                                                                           "\n"
11902                                                                           "void main()\n"
11903                                                                           "{\n"
11904                                                                           "    if (TYPE(0) == block.man)\n"
11905                                                                           "    {\n"
11906                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
11907                                                                           "    }\n"
11908                                                                           "\n"
11909                                                                           "\n"
11910                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11911                                                                           "\n"
11912                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11913                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11914                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11915                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11916                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11917                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11918                                                                           "}\n"
11919                                                                           "\n";
11920         static const GLchar* tes = "#version 430 core\n"
11921                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11922                                                            "\n"
11923                                                            "layout(isolines, point_mode) in;\n"
11924                                                            "\n"
11925                                                            "in  vec4 tcs_tes[];\n"
11926                                                            "out vec4 tes_gs;\n"
11927                                                            "\n"
11928                                                            "void main()\n"
11929                                                            "{\n"
11930                                                            "    tes_gs = tcs_tes[0];\n"
11931                                                            "}\n"
11932                                                            "\n";
11933         static const GLchar* tes_tested = "#version 430 core\n"
11934                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11935                                                                           "\n"
11936                                                                           "layout(isolines, point_mode) in;\n"
11937                                                                           "\n"
11938                                                                           "layout (std140) buffer Block {\n"
11939                                                                           "    vec4 boy;\n"
11940                                                                           "    layout (align = ALIGN) TYPE man;\n"
11941                                                                           "} block;\n"
11942                                                                           "\n"
11943                                                                           "in  vec4 tcs_tes[];\n"
11944                                                                           "out vec4 tes_gs;\n"
11945                                                                           "\n"
11946                                                                           "void main()\n"
11947                                                                           "{\n"
11948                                                                           "    if (TYPE(0) == block.man)\n"
11949                                                                           "    {\n"
11950                                                                           "        tes_gs = block.boy;\n"
11951                                                                           "    }\n"
11952                                                                           "\n"
11953                                                                           "    tes_gs += tcs_tes[0];\n"
11954                                                                           "}\n"
11955                                                                           "\n";
11956         static const GLchar* vs = "#version 430 core\n"
11957                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11958                                                           "\n"
11959                                                           "in  vec4 in_vs;\n"
11960                                                           "out vec4 vs_tcs;\n"
11961                                                           "\n"
11962                                                           "void main()\n"
11963                                                           "{\n"
11964                                                           "    vs_tcs = in_vs;\n"
11965                                                           "}\n"
11966                                                           "\n";
11967         static const GLchar* vs_tested = "#version 430 core\n"
11968                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11969                                                                          "\n"
11970                                                                          "layout (std140) buffer Block {\n"
11971                                                                          "    vec4 boy;\n"
11972                                                                          "    layout (align = ALIGN) TYPE man;\n"
11973                                                                          "} block;\n"
11974                                                                          "\n"
11975                                                                          "in  vec4 in_vs;\n"
11976                                                                          "out vec4 vs_tcs;\n"
11977                                                                          "\n"
11978                                                                          "void main()\n"
11979                                                                          "{\n"
11980                                                                          "    if (TYPE(0) == block.man)\n"
11981                                                                          "    {\n"
11982                                                                          "        vs_tcs = block.boy;\n"
11983                                                                          "    }\n"
11984                                                                          "\n"
11985                                                                          "    vs_tcs += in_vs;\n"
11986                                                                          "}\n"
11987                                                                          "\n";
11988
11989         std::string source;
11990         testCase&   test_case = m_test_cases[test_case_index];
11991
11992         if (test_case.m_stage == stage)
11993         {
11994                 GLchar                     buffer[16];
11995                 const GLuint       alignment = test_case.m_alignment;
11996                 const Utils::Type& type          = test_case.m_type;
11997                 const GLchar*     type_name = type.GetGLSLTypeName();
11998                 size_t                     position  = 0;
11999
12000                 switch (stage)
12001                 {
12002                 case Utils::Shader::COMPUTE:
12003                         source = cs;
12004                         break;
12005                 case Utils::Shader::FRAGMENT:
12006                         source = fs_tested;
12007                         break;
12008                 case Utils::Shader::GEOMETRY:
12009                         source = gs_tested;
12010                         break;
12011                 case Utils::Shader::TESS_CTRL:
12012                         source = tcs_tested;
12013                         break;
12014                 case Utils::Shader::TESS_EVAL:
12015                         source = tes_tested;
12016                         break;
12017                 case Utils::Shader::VERTEX:
12018                         source = vs_tested;
12019                         break;
12020                 default:
12021                         TCU_FAIL("Invalid enum");
12022                 }
12023
12024                 sprintf(buffer, "%d", alignment);
12025                 Utils::replaceToken("ALIGN", position, buffer, source);
12026                 Utils::replaceToken("TYPE", position, type_name, source);
12027                 Utils::replaceToken("TYPE", position, type_name, source);
12028         }
12029         else
12030         {
12031                 switch (stage)
12032                 {
12033                 case Utils::Shader::FRAGMENT:
12034                         source = fs;
12035                         break;
12036                 case Utils::Shader::GEOMETRY:
12037                         source = gs;
12038                         break;
12039                 case Utils::Shader::TESS_CTRL:
12040                         source = tcs;
12041                         break;
12042                 case Utils::Shader::TESS_EVAL:
12043                         source = tes;
12044                         break;
12045                 case Utils::Shader::VERTEX:
12046                         source = vs;
12047                         break;
12048                 default:
12049                         TCU_FAIL("Invalid enum");
12050                 }
12051         }
12052
12053         return source;
12054 }
12055
12056 /** Checks if stage is supported
12057  *
12058  * @param stage Shader stage
12059  *
12060  * @return true if supported, false otherwise
12061  **/
12062 bool SSBMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES stage)
12063 {
12064         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12065         GLint                    max_supported_buffers = 0;
12066         GLenum                   pname                             = 0;
12067
12068         switch (stage)
12069         {
12070         case Utils::Shader::COMPUTE:
12071                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
12072                 break;
12073         case Utils::Shader::FRAGMENT:
12074                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
12075                 break;
12076         case Utils::Shader::GEOMETRY:
12077                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
12078                 break;
12079         case Utils::Shader::TESS_CTRL:
12080                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
12081                 break;
12082         case Utils::Shader::TESS_EVAL:
12083                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
12084                 break;
12085         case Utils::Shader::VERTEX:
12086                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
12087                 break;
12088         default:
12089                 TCU_FAIL("Invalid enum");
12090         }
12091
12092         gl.getIntegerv(pname, &max_supported_buffers);
12093         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12094
12095         return 1 <= max_supported_buffers;
12096 }
12097
12098 /** Constructor
12099  *
12100  * @param context Test framework context
12101  **/
12102 SSBAlignmentTest::SSBAlignmentTest(deqp::Context& context)
12103         : TextureTestBase(context, "ssb_alignment", "Test verifies offset and alignment of ssb buffer")
12104 {
12105 }
12106
12107 /** Get interface of program
12108  *
12109  * @param ignored
12110  * @param program_interface Interface of program
12111  * @param varying_passthrough Collection of connections between in and out variables
12112  **/
12113 void SSBAlignmentTest::getProgramInterface(GLuint /* test_case_index */, Utils::ProgramInterface& program_interface,
12114                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12115 {
12116         static const Utils::Type vec4 = Utils::Type::vec4;
12117
12118 #if WRKARD_UNIFORMBLOCKALIGNMENT
12119
12120         static const GLuint block_align = 16;
12121
12122 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
12123
12124         static const GLuint block_align = 64;
12125
12126 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12127
12128         static const GLuint fifth_align = 16;
12129         static const GLuint vec4_stride = 16;
12130         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
12131
12132         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
12133         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
12134         const GLuint third_offset =
12135                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
12136         const GLuint fourth_offset =
12137                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
12138         const GLuint fifth_offset =
12139                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, fifth_align); /* vec4[2] at 160 */
12140         const GLuint sixth_offset =
12141                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
12142
12143         Utils::Interface* structure = program_interface.Structure("Data");
12144
12145         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12146                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
12147
12148         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
12149                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
12150                                           Utils::Type::vec4.GetSize() /* offset */);
12151
12152         /* Prepare Block */
12153         Utils::Interface* vs_buf_Block = program_interface.Block("vs_buf_Block");
12154
12155         vs_buf_Block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12156                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
12157
12158         vs_buf_Block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12159                                                  0 /* n_array_elements */, data_stride, second_offset);
12160
12161         vs_buf_Block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12162                                                  2 /* n_array_elements */, data_stride, third_offset);
12163
12164         vs_buf_Block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
12165                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
12166
12167         vs_buf_Block->Member("fifth", "layout(align = 16)", 0 /* expected_component */, 0 /* expected_location */, vec4,
12168                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
12169
12170         vs_buf_Block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12171                                                  0 /* n_array_elements */, data_stride, sixth_offset);
12172
12173         const GLuint stride = calculateStride(*vs_buf_Block);
12174         m_data.resize(stride);
12175         generateData(*vs_buf_Block, 0, m_data);
12176
12177         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12178
12179 /* Add uniform BLOCK */
12180 #if WRKARD_UNIFORMBLOCKALIGNMENT
12181         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_Block, 0,
12182                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12183 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
12184         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_buf_Block, 0,
12185                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12186 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12187
12188         program_interface.CloneVertexInterface(varying_passthrough);
12189 }
12190
12191 /** Selects if "draw" stages are relevant for test
12192  *
12193  * @param ignored
12194  *
12195  * @return true if all stages support shader storage buffers, false otherwise
12196  **/
12197 bool SSBAlignmentTest::isDrawRelevant(GLuint /* test_case_index */)
12198 {
12199         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12200         GLint                    gs_supported_buffers  = 0;
12201         GLint                    tcs_supported_buffers = 0;
12202         GLint                    tes_supported_buffers = 0;
12203         GLint                    vs_supported_buffers  = 0;
12204
12205         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
12206         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
12207         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
12208         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
12209
12210         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12211
12212         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
12213                         (1 <= vs_supported_buffers));
12214 }
12215
12216 /** Constructor
12217  *
12218  * @param context Test framework context
12219  **/
12220 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context)
12221         : TextureTestBase(context, "varying_locations", "Test verifies that input and output locations are respected")
12222 {
12223 }
12224
12225 /** Constructor
12226  *
12227  * @param context          Test context
12228  * @param test_name        Name of test
12229  * @param test_description Description of test
12230  **/
12231 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context, const glw::GLchar* test_name,
12232                                                                                    const glw::GLchar* test_description)
12233         : TextureTestBase(context, test_name, test_description)
12234 {
12235 }
12236
12237 /** Get interface of program
12238  *
12239  * @param test_case_index     Test case
12240  * @param program_interface   Interface of program
12241  * @param varying_passthrough Collection of connections between in and out variables
12242  **/
12243 void VaryingLocationsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
12244                                                                                            Utils::VaryingPassthrough& varying_passthrough)
12245 {
12246         const Utils::Type type = getType(test_case_index);
12247
12248         m_first_data = type.GenerateDataPacked();
12249         m_last_data  = type.GenerateDataPacked();
12250
12251         prepareShaderStage(Utils::Shader::FRAGMENT, type, program_interface, varying_passthrough);
12252         prepareShaderStage(Utils::Shader::GEOMETRY, type, program_interface, varying_passthrough);
12253         prepareShaderStage(Utils::Shader::TESS_CTRL, type, program_interface, varying_passthrough);
12254         prepareShaderStage(Utils::Shader::TESS_EVAL, type, program_interface, varying_passthrough);
12255         prepareShaderStage(Utils::Shader::VERTEX, type, program_interface, varying_passthrough);
12256 }
12257
12258 /** Get type name
12259  *
12260  * @param test_case_index Index of test case
12261  *
12262  * @return Name of type test in test_case_index
12263  **/
12264 std::string VaryingLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12265 {
12266         return getTypeName(test_case_index);
12267 }
12268
12269 /** Returns number of types to test
12270  *
12271  * @return Number of types, 34
12272  **/
12273 glw::GLuint VaryingLocationsTest::getTestCaseNumber()
12274 {
12275         return getTypesNumber();
12276 }
12277
12278 /** Selects if "compute" stage is relevant for test
12279  *
12280  * @param ignored
12281  *
12282  * @return false
12283  **/
12284 bool VaryingLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12285 {
12286         return false;
12287 }
12288
12289 /**
12290  *
12291  *
12292  **/
12293 std::string VaryingLocationsTest::prepareGlobals(GLint last_in_loc, GLint last_out_loc)
12294 {
12295         GLchar          buffer[16];
12296         std::string globals = "const uint first_input_location  = 0u;\n"
12297                                                   "const uint first_output_location = 0u;\n"
12298                                                   "const uint last_input_location   = LAST_INPUTu;\n"
12299                                                   "const uint last_output_location  = LAST_OUTPUTu;\n";
12300         size_t position = 100; /* Skip first part */
12301
12302         sprintf(buffer, "%d", last_in_loc);
12303         Utils::replaceToken("LAST_INPUT", position, buffer, globals);
12304
12305         sprintf(buffer, "%d", last_out_loc);
12306         Utils::replaceToken("LAST_OUTPUT", position, buffer, globals);
12307
12308         return globals;
12309 }
12310
12311 /**
12312  *
12313  **/
12314 void VaryingLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12315                                                                                           Utils::ProgramInterface&   program_interface,
12316                                                                                           Utils::VaryingPassthrough& varying_passthrough)
12317 {
12318         const GLuint array_length  = 1;
12319         const GLuint first_in_loc  = 0;
12320         const GLuint first_out_loc = 0;
12321         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12322         size_t           position         = 0;
12323
12324         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12325
12326         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12327
12328         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12329         const GLchar* qual_first_out = "layout (location = first_output_location)";
12330         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12331         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12332
12333         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12334         const GLuint                    type_size = type.GetSize();
12335
12336         std::string first_in_name  = "PREFIXfirst";
12337         std::string first_out_name = "PREFIXfirst";
12338         std::string last_in_name   = "PREFIXlast";
12339         std::string last_out_name  = "PREFIXlast";
12340
12341         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12342         position = 0;
12343         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12344         position = 0;
12345         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12346         position = 0;
12347         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12348
12349         if (Utils::Shader::FRAGMENT == stage)
12350         {
12351                 qual_first_in = "layout (location = first_input_location) flat";
12352                 qual_last_in  = "layout (location = last_input_location)  flat";
12353         }
12354         if (Utils::Shader::GEOMETRY == stage)
12355         {
12356                 qual_first_out = "layout (location = first_output_location) flat";
12357                 qual_last_out  = "layout (location = last_output_location)  flat";
12358         }
12359
12360         Utils::Variable* first_in = si.Input(
12361                 first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12362                 first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12363                 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12364
12365         Utils::Variable* last_in =
12366                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12367                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12368                                  0u /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12369                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12370
12371         if (Utils::Shader::FRAGMENT != stage)
12372         {
12373                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12374
12375                 Utils::Variable* first_out =
12376                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12377                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12378                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */,
12379                                           m_first_data.size() /* data_size */);
12380
12381                 Utils::Variable* last_out = si.Output(
12382                         last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12383                         last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12384                         0u /* stride */, 0u /* offset */, (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12385
12386                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12387
12388                 varying_passthrough.Add(stage, first_in, first_out);
12389                 varying_passthrough.Add(stage, last_in, last_out);
12390         }
12391         else
12392         {
12393                 /* No outputs for fragment shader, so last_output_location can be 0 */
12394                 si.m_globals = prepareGlobals(last_in_loc, 0);
12395         }
12396 }
12397
12398 /** This test should be run with separable programs
12399  *
12400  * @param ignored
12401  *
12402  * @return true
12403  **/
12404 bool VaryingLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12405 {
12406         return false;
12407 }
12408
12409 /* Constants used by VertexAttribLocationsTest */
12410 const GLuint VertexAttribLocationsTest::m_base_vertex   = 4;
12411 const GLuint VertexAttribLocationsTest::m_base_instance = 2;
12412 const GLuint VertexAttribLocationsTest::m_loc_vertex    = 2;
12413 const GLuint VertexAttribLocationsTest::m_loc_instance  = 5;
12414 const GLuint VertexAttribLocationsTest::m_n_instances   = 4;
12415
12416 /** Constructor
12417  *
12418  * @param context Test framework context
12419  **/
12420 VertexAttribLocationsTest::VertexAttribLocationsTest(deqp::Context& context)
12421         : TextureTestBase(context, "vertex_attrib_locations",
12422                                           "Test verifies that attribute locations are respected by drawing operations")
12423 {
12424 }
12425
12426 /** Execute proper draw command for test case
12427  *
12428  * @param test_case_index Index of test case
12429  **/
12430 void VertexAttribLocationsTest::executeDrawCall(GLuint test_case_index)
12431 {
12432         const Functions& gl = m_context.getRenderContext().getFunctions();
12433
12434         switch (test_case_index)
12435         {
12436         case DRAWARRAYS:
12437                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
12438                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
12439                 break;
12440         case DRAWARRAYSINSTANCED:
12441                 gl.drawArraysInstanced(GL_PATCHES, 0 /* first */, 1 /* count */, m_n_instances);
12442                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArraysInstanced");
12443                 break;
12444         case DRAWELEMENTS:
12445                 gl.drawElements(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL);
12446                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElements");
12447                 break;
12448         case DRAWELEMENTSBASEVERTEX:
12449                 gl.drawElementsBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_base_vertex);
12450                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsBaseVertex");
12451                 break;
12452         case DRAWELEMENTSINSTANCED:
12453                 gl.drawElementsInstanced(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances);
12454                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstanced");
12455                 break;
12456         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12457                 gl.drawElementsInstancedBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12458                                                                                          m_base_instance);
12459                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseInstance");
12460                 break;
12461         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12462                 gl.drawElementsInstancedBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12463                                                                                    m_base_vertex);
12464                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertex");
12465                 break;
12466         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12467                 gl.drawElementsInstancedBaseVertexBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL,
12468                                                                                                            m_n_instances, m_base_vertex, m_base_instance);
12469                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertexBaseInstance");
12470                 break;
12471         default:
12472                 TCU_FAIL("Invalid enum");
12473         }
12474 }
12475
12476 /** Get interface of program
12477  *
12478  * @param ignored
12479  * @param program_interface   Interface of program
12480  * @param ignored
12481  **/
12482 void VertexAttribLocationsTest::getProgramInterface(GLuint /* test_case_index */,
12483                                                                                                         Utils::ProgramInterface& program_interface,
12484                                                                                                         Utils::VaryingPassthrough& /* varying_passthrough */)
12485 {
12486         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12487
12488         /* Globals */
12489         si.m_globals = "const uint vertex_index_location   = 2;\n"
12490                                    "const uint instance_index_location = 5;\n";
12491
12492         /* Attributes */
12493         si.Input("vertex_index" /* name */, "layout (location = vertex_index_location)" /* qualifiers */,
12494                          0 /* expected_componenet */, m_loc_vertex /* expected_location */, Utils::Type::uint /* type */,
12495                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 0u /* offset */,
12496                          (GLvoid*)0 /* data */, 0 /* data_size */);
12497         si.Input("instance_index" /* name */, "layout (location = instance_index_location)" /* qualifiers */,
12498                          0 /* expected_componenet */, m_loc_instance /* expected_location */, Utils::Type::uint /* type */,
12499                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 16u /* offset */,
12500                          (GLvoid*)0 /* data */, 0 /* data_size */);
12501 }
12502
12503 /** Get name of test case
12504  *
12505  * @param test_case_index Index of test case
12506  *
12507  * @return Name of test case
12508  **/
12509 std::string VertexAttribLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12510 {
12511         std::string result;
12512
12513         switch (test_case_index)
12514         {
12515         case DRAWARRAYS:
12516                 result = "DrawArrays";
12517                 break;
12518         case DRAWARRAYSINSTANCED:
12519                 result = "DrawArraysInstanced";
12520                 break;
12521         case DRAWELEMENTS:
12522                 result = "DrawElements";
12523                 break;
12524         case DRAWELEMENTSBASEVERTEX:
12525                 result = "DrawElementsBaseVertex";
12526                 break;
12527         case DRAWELEMENTSINSTANCED:
12528                 result = "DrawElementsInstanced";
12529                 break;
12530         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12531                 result = "DrawElementsInstancedBaseInstance";
12532                 break;
12533         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12534                 result = "DrawElementsInstancedBaseVertex";
12535                 break;
12536         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12537                 result = "DrawElementsInstancedBaseVertexBaseInstance";
12538                 break;
12539         default:
12540                 TCU_FAIL("Invalid enum");
12541         }
12542
12543         return result;
12544 }
12545
12546 /** Get number of test cases
12547  *
12548  * @return Number of test cases
12549  **/
12550 GLuint VertexAttribLocationsTest::getTestCaseNumber()
12551 {
12552         return TESTCASES_MAX;
12553 }
12554
12555 /** Prepare code snippet that will verify in and uniform variables
12556  *
12557  * @param ignored
12558  * @param ignored
12559  * @param stage   Shader stage
12560  *
12561  * @return Code that verify variables
12562  **/
12563 std::string VertexAttribLocationsTest::getVerificationSnippet(GLuint /* test_case_index */,
12564                                                                                                                           Utils::ProgramInterface& /* program_interface */,
12565                                                                                                                           Utils::Shader::STAGES stage)
12566 {
12567         std::string verification;
12568
12569         if (Utils::Shader::VERTEX == stage)
12570         {
12571
12572 #if DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE
12573
12574                 verification = "if (gl_InstanceID != instance_index)\n"
12575                                            "    {\n"
12576                                            "        result = 12u;\n"
12577                                            "    }\n"
12578                                            "    else if (gl_VertexID != vertex_index)\n"
12579                                            "    {\n"
12580                                            "        result = 11u;\n"
12581                                            "    }\n";
12582
12583 #else
12584
12585                 verification = "if ((gl_VertexID   != vertex_index)  ||\n"
12586                                            "        (gl_InstanceID != instance_index) )\n"
12587                                            "    {\n"
12588                                            "        result = 0u;\n"
12589                                            "    }\n";
12590
12591 #endif
12592         }
12593         else
12594         {
12595                 verification = "";
12596         }
12597
12598         return verification;
12599 }
12600
12601 /** Selects if "compute" stage is relevant for test
12602  *
12603  * @param ignored
12604  *
12605  * @return false
12606  **/
12607 bool VertexAttribLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12608 {
12609         return false;
12610 }
12611
12612 /** Prepare attributes, vertex array object and array buffer
12613  *
12614  * @param ignored
12615  * @param ignored Interface of program
12616  * @param buffer  Array buffer
12617  * @param vao     Vertex array object
12618  **/
12619 void VertexAttribLocationsTest::prepareAttributes(GLuint test_case_index /* test_case_index */,
12620                                                                                                   Utils::ProgramInterface& /* program_interface */,
12621                                                                                                   Utils::Buffer& buffer, Utils::VertexArray& vao)
12622 {
12623         static const GLuint vertex_index_data[8]   = { 0, 1, 2, 3, 4, 5, 6, 7 };
12624         static const GLuint instance_index_data[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
12625
12626         std::vector<GLuint> buffer_data;
12627         buffer_data.resize(8 + 8); /* vertex_index_data + instance_index_data */
12628
12629         GLubyte* ptr = (GLubyte*)&buffer_data[0];
12630
12631         /*
12632          When case index >=2, the test calls glDrawElement*(), such as glDrawElementsBaseVertex(), glDrawElementsInstanced(), glDrawElementsInstancedBaseInstance() and so on,
12633          So we need to change the buffer type as GL_ELEMENT_ARRAY_BUFFER
12634          */
12635         if (test_case_index >= 2)
12636         {
12637                 buffer.m_buffer = Utils::Buffer::Element;
12638         }
12639         vao.Bind();
12640         buffer.Bind();
12641
12642         vao.Attribute(m_loc_vertex /* vertex_index */, Utils::Type::uint, 0 /* array_elements */, false /* normalized */,
12643                                   0 /* stride */, 0 /* offset */);
12644
12645         vao.Attribute(m_loc_instance /* instance_index */, Utils::Type::uint, 0 /* array_elements */,
12646                                   false /* normalized */, 0 /* stride */, (GLvoid*)sizeof(vertex_index_data) /* offset */);
12647         // when test_case_index is 5 or 7, the draw call is glDrawElementsInstancedBaseInstance, glDrawElementsInstancedBaseVertexBaseInstance
12648         // the instancecount is 4, the baseinstance is 2, the divisor should be set 2
12649         bool isBaseInstanced = (test_case_index == DRAWELEMENTSINSTANCEDBASEINSTANCE ||
12650                                                         test_case_index == DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE);
12651         vao.Divisor(m_context.getRenderContext().getFunctions() /* gl */, m_loc_instance /* instance_index */,
12652                                 isBaseInstanced ? 2 : 1 /* divisor. 1 - advance once per instance */);
12653
12654         memcpy(ptr + 0, vertex_index_data, sizeof(vertex_index_data));
12655         memcpy(ptr + sizeof(vertex_index_data), instance_index_data, sizeof(instance_index_data));
12656
12657         buffer.Data(Utils::Buffer::StaticDraw, buffer_data.size() * sizeof(GLuint), ptr);
12658 }
12659
12660 /** This test should be run with separable programs
12661  *
12662  * @param ignored
12663  *
12664  * @return true
12665  **/
12666 bool VertexAttribLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12667 {
12668         return false;
12669 }
12670
12671 /** Constructor
12672  *
12673  * @param context Test framework context
12674  **/
12675 VaryingArrayLocationsTest::VaryingArrayLocationsTest(deqp::Context& context)
12676         : VaryingLocationsTest(context, "varying_array_locations",
12677                                                    "Test verifies that input and output locations are respected for arrays")
12678 {
12679 }
12680
12681 /**
12682  *
12683  **/
12684 void VaryingArrayLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12685                                                                                                    Utils::ProgramInterface&   program_interface,
12686                                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12687 {
12688         const GLuint array_length  = 1u;
12689         const GLuint first_in_loc  = 0;
12690         const GLuint first_out_loc = 0;
12691         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12692         size_t           position         = 0;
12693
12694         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12695
12696         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12697
12698         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12699         const GLchar* qual_first_out = "layout (location = first_output_location)";
12700         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12701         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12702
12703         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12704         const GLuint                    type_size = type.GetSize();
12705
12706         std::string first_in_name  = "PREFIXfirst";
12707         std::string first_out_name = "PREFIXfirst";
12708         std::string last_in_name   = "PREFIXlast";
12709         std::string last_out_name  = "PREFIXlast";
12710
12711         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12712         position = 0;
12713         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12714         position = 0;
12715         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12716         position = 0;
12717         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12718
12719         if (Utils::Shader::FRAGMENT == stage)
12720         {
12721                 qual_first_in = "layout (location = first_input_location) flat";
12722                 qual_last_in  = "layout (location = last_input_location)  flat";
12723         }
12724         if (Utils::Shader::GEOMETRY == stage)
12725         {
12726                 qual_first_out = "layout (location = first_output_location) flat";
12727                 qual_last_out  = "layout (location = last_output_location)  flat";
12728         }
12729
12730         Utils::Variable* first_in =
12731                 si.Input(first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12732                                  first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12733                                  array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12734                                  (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12735
12736         Utils::Variable* last_in =
12737                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12738                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12739                                  array_length /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12740                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12741
12742         if (Utils::Shader::FRAGMENT != stage)
12743         {
12744                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12745
12746                 Utils::Variable* first_out =
12747                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12748                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12749                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12750                                           (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12751
12752                 Utils::Variable* last_out =
12753                         si.Output(last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12754                                           last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12755                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12756                                           (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12757
12758                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12759
12760                 varying_passthrough.Add(stage, first_in, first_out);
12761                 varying_passthrough.Add(stage, last_in, last_out);
12762         }
12763         else
12764         {
12765                 /* No outputs for fragment shader, so last_output_location can be 0 */
12766                 si.m_globals = prepareGlobals(last_in_loc, 0);
12767         }
12768 }
12769
12770 /** Constructor
12771  *
12772  * @param context Test framework context
12773  **/
12774 VaryingStructureLocationsTest::VaryingStructureLocationsTest(deqp::Context& context)
12775         : TextureTestBase(context, "varying_structure_locations",
12776                                           "Test verifies that locations are respected when structures are used as in and out ")
12777 {
12778 }
12779
12780 /** Prepare code snippet that will pass in variables to out variables
12781  *
12782  * @param ignored
12783  * @param varying_passthrough Collection of connections between in and out variables
12784  * @param stage               Shader stage
12785  *
12786  * @return Code that pass in variables to next stage
12787  **/
12788 std::string VaryingStructureLocationsTest::getPassSnippet(GLuint /* test_case_index */,
12789                                                                                                                   Utils::VaryingPassthrough& varying_passthrough,
12790                                                                                                                   Utils::Shader::STAGES          stage)
12791 {
12792         std::string result;
12793
12794         if (Utils::Shader::VERTEX != stage)
12795         {
12796                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
12797         }
12798         else
12799         {
12800                 result = "    vs_tcs_output[0].single   = vs_in_single[0];\n"
12801                                  "    vs_tcs_output[0].array[0] = vs_in_array[0];\n";
12802         }
12803
12804         return result;
12805 }
12806
12807 /** Get interface of program
12808  *
12809  * @param test_case_index     Test case
12810  * @param program_interface   Interface of program
12811  * @param varying_passthrough Collection of connections between in and out variables
12812  **/
12813 void VaryingStructureLocationsTest::getProgramInterface(GLuint                                     test_case_index,
12814                                                                                                                 Utils::ProgramInterface&   program_interface,
12815                                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
12816 {
12817         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12818         const Utils::Type               type = getType(test_case_index);
12819
12820         /* Prepare data */
12821         // We should call GenerateDataPacked() to generate data, which can make sure the data in shader is correct
12822         m_single_data = type.GenerateDataPacked();
12823         m_array_data  = type.GenerateDataPacked();
12824
12825         m_data.resize(m_single_data.size() + m_array_data.size());
12826         GLubyte* ptr = (GLubyte*)&m_data[0];
12827         memcpy(ptr, &m_single_data[0], m_single_data.size());
12828         memcpy(ptr + m_single_data.size(), &m_array_data[0], m_array_data.size());
12829
12830         Utils::Interface* structure = program_interface.Structure("Data");
12831
12832         structure->Member("single", "" /* qualifiers */, 0 /* component */, 0 /* location */, type, false /* normalized */,
12833                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */);
12834
12835         // the second struct member 's location should not be 0, it is based on by how many the locations the first struct member consumed.
12836         structure->Member("array", "" /* qualifiers */, 0 /* component */, type.GetLocations() /* location */, type,
12837                                           false /* normalized */, 1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */);
12838
12839         si.Input("vs_in_single", "layout (location = 0)", 0 /* component */, 0 /* location */, type, false /* normalized */,
12840                          1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_single_data[0] /* data */,
12841                          m_single_data.size() /* data_size */);
12842
12843         si.Input("vs_in_array", "layout (location = 8)", 0 /* component */, 8 /* location */, type, false /* normalized */,
12844                          1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */,
12845                          (GLvoid*)&m_array_data[0] /* data */, m_array_data.size() /* data_size */);
12846
12847         si.Output("vs_tcs_output", "layout (location = 0)", 0 /* component */, 0 /* location */, structure,
12848                           1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
12849                           m_data.size() /* data_size */);
12850
12851         program_interface.CloneVertexInterface(varying_passthrough);
12852 }
12853
12854 /** Get type name
12855  *
12856  * @param test_case_index Index of test case
12857  *
12858  * @return Name of type test in test_case_index
12859  **/
12860 std::string VaryingStructureLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12861 {
12862         return getTypeName(test_case_index);
12863 }
12864
12865 /** Returns number of types to test
12866  *
12867  * @return Number of types, 34
12868  **/
12869 glw::GLuint VaryingStructureLocationsTest::getTestCaseNumber()
12870 {
12871         return getTypesNumber();
12872 }
12873
12874 /** Selects if "compute" stage is relevant for test
12875  *
12876  * @param ignored
12877  *
12878  * @return false
12879  **/
12880 bool VaryingStructureLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12881 {
12882         return false;
12883 }
12884
12885 /** This test should be run with separable programs
12886  *
12887  * @param ignored
12888  *
12889  * @return true
12890  **/
12891 bool VaryingStructureLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12892 {
12893         return false;
12894 }
12895
12896 /** Constructor
12897  *
12898  * @param context          Test context
12899  * @param test_name        Name of test
12900  * @param test_description Description of test
12901  **/
12902 VaryingStructureMemberLocationTest::VaryingStructureMemberLocationTest(deqp::Context& context)
12903         : NegativeTestBase(context, "varying_structure_member_location",
12904                                            "Test verifies that compiler does not allow location qualifier on member of strucure")
12905 {
12906 }
12907
12908 /** Source for given test case and stage
12909  *
12910  * @param test_case_index Index of test case
12911  * @param stage           Shader stage
12912  *
12913  * @return Shader source
12914  **/
12915 std::string VaryingStructureMemberLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
12916 {
12917         static const GLchar* struct_definition = "struct Data {\n"
12918                                                                                          "    vec4 gohan;\n"
12919                                                                                          "    layout (location = 4) vec4 goten;\n"
12920                                                                                          "};\n";
12921         static const GLchar* input_var  = "in Data data;\n";
12922         static const GLchar* output_var = "out Data data;\n";
12923         static const GLchar* input_use  = "    result += data.gohan + data.goten;\n";
12924         static const GLchar* output_use = "    data.gohan = result / 2;\n"
12925                                                                           "    data.goten = result / 4 - data.gohan;\n";
12926         static const GLchar* fs = "#version 430 core\n"
12927                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12928                                                           "\n"
12929                                                           "in  vec4 gs_fs;\n"
12930                                                           "out vec4 fs_out;\n"
12931                                                           "\n"
12932                                                           "void main()\n"
12933                                                           "{\n"
12934                                                           "    fs_out = gs_fs;\n"
12935                                                           "}\n"
12936                                                           "\n";
12937         static const GLchar* fs_tested = "#version 430 core\n"
12938                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12939                                                                          "\n"
12940                                                                          "STRUCT_DEFINITION"
12941                                                                          "\n"
12942                                                                          "VARIABLE_DEFINITION"
12943                                                                          "\n"
12944                                                                          "in  vec4 gs_fs;\n"
12945                                                                          "out vec4 fs_out;\n"
12946                                                                          "\n"
12947                                                                          "void main()\n"
12948                                                                          "{\n"
12949                                                                          "    vec4 result = gs_fs;\n"
12950                                                                          "\n"
12951                                                                          "VARIABLE_USE"
12952                                                                          "\n"
12953                                                                          "    fs_out += result;\n"
12954                                                                          "}\n"
12955                                                                          "\n";
12956         static const GLchar* gs = "#version 430 core\n"
12957                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12958                                                           "\n"
12959                                                           "layout(points)                           in;\n"
12960                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
12961                                                           "\n"
12962                                                           "in  vec4 tes_gs[];\n"
12963                                                           "out vec4 gs_fs;\n"
12964                                                           "\n"
12965                                                           "void main()\n"
12966                                                           "{\n"
12967                                                           "    gs_fs = tes_gs[0];\n"
12968                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12969                                                           "    EmitVertex();\n"
12970                                                           "    gs_fs = tes_gs[0];\n"
12971                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12972                                                           "    EmitVertex();\n"
12973                                                           "    gs_fs = tes_gs[0];\n"
12974                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
12975                                                           "    EmitVertex();\n"
12976                                                           "    gs_fs = tes_gs[0];\n"
12977                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
12978                                                           "    EmitVertex();\n"
12979                                                           "}\n"
12980                                                           "\n";
12981         static const GLchar* gs_tested = "#version 430 core\n"
12982                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12983                                                                          "\n"
12984                                                                          "layout(points)                           in;\n"
12985                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
12986                                                                          "\n"
12987                                                                          "STRUCT_DEFINITION"
12988                                                                          "\n"
12989                                                                          "VARIABLE_DEFINITION"
12990                                                                          "\n"
12991                                                                          "in  vec4 tes_gs[];\n"
12992                                                                          "out vec4 gs_fs;\n"
12993                                                                          "\n"
12994                                                                          "void main()\n"
12995                                                                          "{\n"
12996                                                                          "    vec4 result = tes_gs[0];\n"
12997                                                                          "\n"
12998                                                                          "VARIABLE_USE"
12999                                                                          "\n"
13000                                                                          "    gs_fs = result;\n"
13001                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13002                                                                          "    EmitVertex();\n"
13003                                                                          "    gs_fs = result;\n"
13004                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13005                                                                          "    EmitVertex();\n"
13006                                                                          "    gs_fs = result;\n"
13007                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13008                                                                          "    EmitVertex();\n"
13009                                                                          "    gs_fs = result;\n"
13010                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13011                                                                          "    EmitVertex();\n"
13012                                                                          "}\n"
13013                                                                          "\n";
13014         static const GLchar* tcs = "#version 430 core\n"
13015                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13016                                                            "\n"
13017                                                            "layout(vertices = 1) out;\n"
13018                                                            "\n"
13019                                                            "in  vec4 vs_tcs[];\n"
13020                                                            "out vec4 tcs_tes[];\n"
13021                                                            "\n"
13022                                                            "void main()\n"
13023                                                            "{\n"
13024                                                            "\n"
13025                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13026                                                            "\n"
13027                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13028                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13029                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13030                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13031                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13032                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13033                                                            "}\n"
13034                                                            "\n";
13035         static const GLchar* tcs_tested = "#version 430 core\n"
13036                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13037                                                                           "\n"
13038                                                                           "layout(vertices = 1) out;\n"
13039                                                                           "\n"
13040                                                                           "STRUCT_DEFINITION"
13041                                                                           "\n"
13042                                                                           "VARIABLE_DEFINITION"
13043                                                                           "\n"
13044                                                                           "in  vec4 vs_tcs[];\n"
13045                                                                           "out vec4 tcs_tes[];\n"
13046                                                                           "\n"
13047                                                                           "void main()\n"
13048                                                                           "{\n"
13049                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13050                                                                           "\n"
13051                                                                           "VARIABLE_USE"
13052                                                                           "\n"
13053                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13054                                                                           "\n"
13055                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13056                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13057                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13058                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13059                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13060                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13061                                                                           "}\n"
13062                                                                           "\n";
13063         static const GLchar* tes = "#version 430 core\n"
13064                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13065                                                            "\n"
13066                                                            "layout(isolines, point_mode) in;\n"
13067                                                            "\n"
13068                                                            "in  vec4 tcs_tes[];\n"
13069                                                            "out vec4 tes_gs;\n"
13070                                                            "\n"
13071                                                            "void main()\n"
13072                                                            "{\n"
13073                                                            "    tes_gs = tcs_tes[0];\n"
13074                                                            "}\n"
13075                                                            "\n";
13076         static const GLchar* tes_tested = "#version 430 core\n"
13077                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13078                                                                           "\n"
13079                                                                           "layout(isolines, point_mode) in;\n"
13080                                                                           "\n"
13081                                                                           "STRUCT_DEFINITION"
13082                                                                           "\n"
13083                                                                           "VARIABLE_DEFINITION"
13084                                                                           "\n"
13085                                                                           "in  vec4 tcs_tes[];\n"
13086                                                                           "out vec4 tes_gs;\n"
13087                                                                           "\n"
13088                                                                           "void main()\n"
13089                                                                           "{\n"
13090                                                                           "    vec4 result = tcs_tes[0];\n"
13091                                                                           "\n"
13092                                                                           "VARIABLE_USE"
13093                                                                           "\n"
13094                                                                           "    tes_gs += result;\n"
13095                                                                           "}\n"
13096                                                                           "\n";
13097         static const GLchar* vs = "#version 430 core\n"
13098                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13099                                                           "\n"
13100                                                           "in  vec4 in_vs;\n"
13101                                                           "out vec4 vs_tcs;\n"
13102                                                           "\n"
13103                                                           "void main()\n"
13104                                                           "{\n"
13105                                                           "    vs_tcs = in_vs;\n"
13106                                                           "}\n"
13107                                                           "\n";
13108         static const GLchar* vs_tested = "#version 430 core\n"
13109                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13110                                                                          "\n"
13111                                                                          "STRUCT_DEFINITION"
13112                                                                          "\n"
13113                                                                          "VARIABLE_DEFINITION"
13114                                                                          "\n"
13115                                                                          "in  vec4 in_vs;\n"
13116                                                                          "out vec4 vs_tcs;\n"
13117                                                                          "\n"
13118                                                                          "void main()\n"
13119                                                                          "{\n"
13120                                                                          "    vec4 result = in_vs;\n"
13121                                                                          "\n"
13122                                                                          "VARIABLE_USE"
13123                                                                          "\n"
13124                                                                          "    vs_tcs += result;\n"
13125                                                                          "}\n"
13126                                                                          "\n";
13127
13128         std::string   source;
13129         testCase&        test_case               = m_test_cases[test_case_index];
13130         const GLchar* var_definition = 0;
13131         const GLchar* var_use            = 0;
13132
13133         if (true == test_case.m_is_input)
13134         {
13135                 var_definition = input_var;
13136                 var_use            = input_use;
13137         }
13138         else
13139         {
13140                 var_definition = output_var;
13141                 var_use            = output_use;
13142         }
13143
13144         if (test_case.m_stage == stage)
13145         {
13146                 size_t position = 0;
13147
13148                 switch (stage)
13149                 {
13150                 case Utils::Shader::FRAGMENT:
13151                         source = fs_tested;
13152                         break;
13153                 case Utils::Shader::GEOMETRY:
13154                         source = gs_tested;
13155                         break;
13156                 case Utils::Shader::TESS_CTRL:
13157                         source = tcs_tested;
13158                         break;
13159                 case Utils::Shader::TESS_EVAL:
13160                         source = tes_tested;
13161                         break;
13162                 case Utils::Shader::VERTEX:
13163                         source = vs_tested;
13164                         break;
13165                 default:
13166                         TCU_FAIL("Invalid enum");
13167                 }
13168
13169                 Utils::replaceToken("STRUCT_DEFINITION", position, struct_definition, source);
13170                 Utils::replaceToken("VARIABLE_DEFINITION", position, var_definition, source);
13171                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13172         }
13173         else
13174         {
13175                 switch (stage)
13176                 {
13177                 case Utils::Shader::FRAGMENT:
13178                         source = fs;
13179                         break;
13180                 case Utils::Shader::GEOMETRY:
13181                         source = gs;
13182                         break;
13183                 case Utils::Shader::TESS_CTRL:
13184                         source = tcs;
13185                         break;
13186                 case Utils::Shader::TESS_EVAL:
13187                         source = tes;
13188                         break;
13189                 case Utils::Shader::VERTEX:
13190                         source = vs;
13191                         break;
13192                 default:
13193                         TCU_FAIL("Invalid enum");
13194                 }
13195         }
13196
13197         return source;
13198 }
13199
13200 /** Get description of test case
13201  *
13202  * @param test_case_index Index of test case
13203  *
13204  * @return Test case description
13205  **/
13206 std::string VaryingStructureMemberLocationTest::getTestCaseName(GLuint test_case_index)
13207 {
13208         std::stringstream stream;
13209         testCase&                 test_case = m_test_cases[test_case_index];
13210
13211         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13212
13213         if (true == test_case.m_is_input)
13214         {
13215                 stream << "input";
13216         }
13217         else
13218         {
13219                 stream << "output";
13220         }
13221
13222         return stream.str();
13223 }
13224
13225 /** Get number of test cases
13226  *
13227  * @return Number of test cases
13228  **/
13229 GLuint VaryingStructureMemberLocationTest::getTestCaseNumber()
13230 {
13231         return static_cast<GLuint>(m_test_cases.size());
13232 }
13233
13234 /** Selects if "compute" stage is relevant for test
13235  *
13236  * @param ignored
13237  *
13238  * @return false
13239  **/
13240 bool VaryingStructureMemberLocationTest::isComputeRelevant(GLuint /* test_case_index */)
13241 {
13242         return false;
13243 }
13244
13245 /** Prepare all test cases
13246  *
13247  **/
13248 void VaryingStructureMemberLocationTest::testInit()
13249 {
13250         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13251         {
13252                 if (Utils::Shader::COMPUTE == stage)
13253                 {
13254                         continue;
13255                 }
13256
13257                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
13258                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
13259
13260                 m_test_cases.push_back(test_case_in);
13261
13262                 if (Utils::Shader::FRAGMENT != stage)
13263                 {
13264                         m_test_cases.push_back(test_case_out);
13265                 }
13266         }
13267 }
13268
13269 /** Constructor
13270  *
13271  * @param context Test framework context
13272  **/
13273 VaryingBlockLocationsTest::VaryingBlockLocationsTest(deqp::Context& context)
13274         : TextureTestBase(context, "varying_block_locations",
13275                                           "Test verifies that locations are respected when blocks are used as in and out ")
13276 {
13277 }
13278
13279 /** Prepare code snippet that will pass in variables to out variables
13280  *
13281  * @param ignored
13282  * @param varying_passthrough Collection of connections between in and out variables
13283  * @param stage               Shader stage
13284  *
13285  * @return Code that pass in variables to next stage
13286  **/
13287 std::string VaryingBlockLocationsTest::getPassSnippet(GLuint /* test_case_index */,
13288                                                                                                           Utils::VaryingPassthrough& varying_passthrough,
13289                                                                                                           Utils::Shader::STAGES          stage)
13290 {
13291         std::string result;
13292
13293         if (Utils::Shader::VERTEX != stage)
13294         {
13295                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
13296         }
13297         else
13298         {
13299                 result = "vs_tcs_block.third  = vs_in_third;\n"
13300                                  "    vs_tcs_block.fourth = vs_in_fourth;\n"
13301                                  "    vs_tcs_block.fifth  = vs_in_fifth;\n";
13302         }
13303
13304         return result;
13305 }
13306
13307 /** Get interface of program
13308  *
13309  * @param ignored
13310  * @param program_interface   Interface of program
13311  * @param varying_passthrough Collection of connections between in and out variables
13312  **/
13313 void VaryingBlockLocationsTest::getProgramInterface(GLuint /* test_case_index */,
13314                                                                                                         Utils::ProgramInterface&   program_interface,
13315                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
13316 {
13317         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
13318         const Utils::Type               vec4 = Utils::Type::vec4;
13319
13320         /* Prepare data */
13321         m_third_data  = vec4.GenerateData();
13322         m_fourth_data = vec4.GenerateData();
13323         m_fifth_data  = vec4.GenerateData();
13324
13325         /* Memory layout is different from location layout */
13326         const GLuint fifth_offset  = 0u;
13327         const GLuint third_offset  = static_cast<GLuint>(fifth_offset + m_fifth_data.size());
13328         const GLuint fourth_offset = static_cast<GLuint>(third_offset + m_fourth_data.size());
13329
13330         m_data.resize(fourth_offset + m_fourth_data.size());
13331         GLubyte* ptr = (GLubyte*)&m_data[0];
13332         memcpy(ptr + third_offset, &m_third_data[0], m_third_data.size());
13333         memcpy(ptr + fourth_offset, &m_fourth_data[0], m_fourth_data.size());
13334         memcpy(ptr + fifth_offset, &m_fifth_data[0], m_fifth_data.size());
13335
13336         Utils::Interface* block = program_interface.Block("vs_tcs_Block");
13337
13338         block->Member("fifth", "" /* qualifiers */, 0 /* component */, 4 /* location */, vec4, false /* normalized */,
13339                                   0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */);
13340
13341         block->Member("third", "layout (location = 2)" /* qualifiers */, 0 /* component */, 2 /* location */, vec4,
13342                                   false /* normalized */, 0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */);
13343
13344         block->Member("fourth", "" /* qualifiers */, 0 /* component */, 3 /* location */, vec4, false /* normalized */,
13345                                   0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */);
13346
13347         si.Output("vs_tcs_block", "layout (location = 4)", 0 /* component */, 4 /* location */, block,
13348                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
13349                           m_data.size() /* data_size */);
13350
13351         si.Input("vs_in_third", "layout (location = 0)", 0 /* component */, 0 /* location */, vec4, false /* normalized */,
13352                          0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */,
13353                          (GLvoid*)&m_third_data[0] /* data */, m_third_data.size() /* data_size */);
13354
13355         si.Input("vs_in_fourth", "layout (location = 1)", 0 /* component */, 1 /* location */, vec4, false /* normalized */,
13356                          0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */,
13357                          (GLvoid*)&m_fourth_data[0] /* data */, m_fourth_data.size() /* data_size */);
13358
13359         si.Input("vs_in_fifth", "layout (location = 2)", 0 /* component */, 2 /* location */, vec4, false /* normalized */,
13360                          0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */,
13361                          (GLvoid*)&m_fifth_data[0] /* data */, m_fifth_data.size() /* data_size */);
13362
13363         program_interface.CloneVertexInterface(varying_passthrough);
13364 }
13365
13366 /** Selects if "compute" stage is relevant for test
13367  *
13368  * @param ignored
13369  *
13370  * @return false
13371  **/
13372 bool VaryingBlockLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13373 {
13374         return false;
13375 }
13376
13377 /** This test should be run with separable programs
13378  *
13379  * @param ignored
13380  *
13381  * @return true
13382  **/
13383 bool VaryingBlockLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
13384 {
13385         return false;
13386 }
13387
13388 /** Constructor
13389  *
13390  * @param context Test framework context
13391  **/
13392 VaryingBlockMemberLocationsTest::VaryingBlockMemberLocationsTest(deqp::Context& context)
13393         : NegativeTestBase(
13394                   context, "varying_block_member_locations",
13395                   "Test verifies that compilation error is reported when not all members of block are qualified with location")
13396 {
13397 }
13398
13399 /** Source for given test case and stage
13400  *
13401  * @param test_case_index Index of test case
13402  * @param stage           Shader stage
13403  *
13404  * @return Shader source
13405  **/
13406 std::string VaryingBlockMemberLocationsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13407 {
13408         static const GLchar* block_definition_all = "Goku {\n"
13409                                                                                                 "    layout (location = 2) vec4 gohan;\n"
13410                                                                                                 "    layout (location = 4) vec4 goten;\n"
13411                                                                                                 "    layout (location = 6) vec4 chichi;\n"
13412                                                                                                 "} gokuARRAY;\n";
13413         static const GLchar* block_definition_default = "Goku {\n"
13414                                                                                                         "    vec4 gohan;\n"
13415                                                                                                         "    vec4 goten;\n"
13416                                                                                                         "    vec4 chichi;\n"
13417                                                                                                         "} gokuARRAY;\n";
13418         static const GLchar* block_definition_one = "Goku {\n"
13419                                                                                                 "    vec4 gohan;\n"
13420                                                                                                 "    layout (location = 4) vec4 goten;\n"
13421                                                                                                 "    vec4 chichi;\n"
13422                                                                                                 "} gokuARRAY;\n";
13423         static const GLchar* input_use  = "    result += gokuINDEX.gohan + gokuINDEX.goten + gokuINDEX.chichi;\n";
13424         static const GLchar* output_use = "    gokuINDEX.gohan  = result / 2;\n"
13425                                                                           "    gokuINDEX.goten  = result / 4 - gokuINDEX.gohan;\n"
13426                                                                           "    gokuINDEX.chichi = result / 8 - gokuINDEX.goten;\n";
13427         static const GLchar* fs = "#version 430 core\n"
13428                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13429                                                           "\n"
13430                                                           "in  vec4 gs_fs;\n"
13431                                                           "out vec4 fs_out;\n"
13432                                                           "\n"
13433                                                           "void main()\n"
13434                                                           "{\n"
13435                                                           "    fs_out = gs_fs;\n"
13436                                                           "}\n"
13437                                                           "\n";
13438         static const GLchar* fs_tested = "#version 430 core\n"
13439                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13440                                                                          "\n"
13441                                                                          "DIRECTION BLOCK_DEFINITION"
13442                                                                          "\n"
13443                                                                          "in  vec4 gs_fs;\n"
13444                                                                          "out vec4 fs_out;\n"
13445                                                                          "\n"
13446                                                                          "void main()\n"
13447                                                                          "{\n"
13448                                                                          "    vec4 result = gs_fs;\n"
13449                                                                          "\n"
13450                                                                          "VARIABLE_USE"
13451                                                                          "\n"
13452                                                                          "    fs_out = result;\n"
13453                                                                          "}\n"
13454                                                                          "\n";
13455         static const GLchar* gs = "#version 430 core\n"
13456                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13457                                                           "\n"
13458                                                           "layout(points)                           in;\n"
13459                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13460                                                           "\n"
13461                                                           "in  vec4 tes_gs[];\n"
13462                                                           "out vec4 gs_fs;\n"
13463                                                           "\n"
13464                                                           "void main()\n"
13465                                                           "{\n"
13466                                                           "    gs_fs = tes_gs[0];\n"
13467                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13468                                                           "    EmitVertex();\n"
13469                                                           "    gs_fs = tes_gs[0];\n"
13470                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13471                                                           "    EmitVertex();\n"
13472                                                           "    gs_fs = tes_gs[0];\n"
13473                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13474                                                           "    EmitVertex();\n"
13475                                                           "    gs_fs = tes_gs[0];\n"
13476                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13477                                                           "    EmitVertex();\n"
13478                                                           "}\n"
13479                                                           "\n";
13480         static const GLchar* gs_tested = "#version 430 core\n"
13481                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13482                                                                          "\n"
13483                                                                          "layout(points)                           in;\n"
13484                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13485                                                                          "\n"
13486                                                                          "DIRECTION BLOCK_DEFINITION"
13487                                                                          "\n"
13488                                                                          "in  vec4 tes_gs[];\n"
13489                                                                          "out vec4 gs_fs;\n"
13490                                                                          "\n"
13491                                                                          "void main()\n"
13492                                                                          "{\n"
13493                                                                          "    vec4 result = tes_gs[0];\n"
13494                                                                          "\n"
13495                                                                          "VARIABLE_USE"
13496                                                                          "\n"
13497                                                                          "    gs_fs = result;\n"
13498                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13499                                                                          "    EmitVertex();\n"
13500                                                                          "    gs_fs = result;\n"
13501                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13502                                                                          "    EmitVertex();\n"
13503                                                                          "    gs_fs = result;\n"
13504                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13505                                                                          "    EmitVertex();\n"
13506                                                                          "    gs_fs = result;\n"
13507                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13508                                                                          "    EmitVertex();\n"
13509                                                                          "}\n"
13510                                                                          "\n";
13511         static const GLchar* tcs = "#version 430 core\n"
13512                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13513                                                            "\n"
13514                                                            "layout(vertices = 1) out;\n"
13515                                                            "\n"
13516                                                            "in  vec4 vs_tcs[];\n"
13517                                                            "out vec4 tcs_tes[];\n"
13518                                                            "\n"
13519                                                            "void main()\n"
13520                                                            "{\n"
13521                                                            "\n"
13522                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13523                                                            "\n"
13524                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13525                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13526                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13527                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13528                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13529                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13530                                                            "}\n"
13531                                                            "\n";
13532         static const GLchar* tcs_tested = "#version 430 core\n"
13533                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13534                                                                           "\n"
13535                                                                           "layout(vertices = 1) out;\n"
13536                                                                           "\n"
13537                                                                           "DIRECTION BLOCK_DEFINITION"
13538                                                                           "\n"
13539                                                                           "in  vec4 vs_tcs[];\n"
13540                                                                           "out vec4 tcs_tes[];\n"
13541                                                                           "\n"
13542                                                                           "void main()\n"
13543                                                                           "{\n"
13544                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13545                                                                           "\n"
13546                                                                           "VARIABLE_USE"
13547                                                                           "\n"
13548                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13549                                                                           "\n"
13550                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13551                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13552                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13553                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13554                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13555                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13556                                                                           "}\n"
13557                                                                           "\n";
13558         static const GLchar* tes = "#version 430 core\n"
13559                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13560                                                            "\n"
13561                                                            "layout(isolines, point_mode) in;\n"
13562                                                            "\n"
13563                                                            "in  vec4 tcs_tes[];\n"
13564                                                            "out vec4 tes_gs;\n"
13565                                                            "\n"
13566                                                            "void main()\n"
13567                                                            "{\n"
13568                                                            "    tes_gs = tcs_tes[0];\n"
13569                                                            "}\n"
13570                                                            "\n";
13571         static const GLchar* tes_tested = "#version 430 core\n"
13572                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13573                                                                           "\n"
13574                                                                           "layout(isolines, point_mode) in;\n"
13575                                                                           "\n"
13576                                                                           "DIRECTION BLOCK_DEFINITION"
13577                                                                           "\n"
13578                                                                           "in  vec4 tcs_tes[];\n"
13579                                                                           "out vec4 tes_gs;\n"
13580                                                                           "\n"
13581                                                                           "void main()\n"
13582                                                                           "{\n"
13583                                                                           "    vec4 result = tcs_tes[0];\n"
13584                                                                           "\n"
13585                                                                           "VARIABLE_USE"
13586                                                                           "\n"
13587                                                                           "    tes_gs = result;\n"
13588                                                                           "}\n"
13589                                                                           "\n";
13590         static const GLchar* vs = "#version 430 core\n"
13591                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13592                                                           "\n"
13593                                                           "in  vec4 in_vs;\n"
13594                                                           "out vec4 vs_tcs;\n"
13595                                                           "\n"
13596                                                           "void main()\n"
13597                                                           "{\n"
13598                                                           "    vs_tcs = in_vs;\n"
13599                                                           "}\n"
13600                                                           "\n";
13601         static const GLchar* vs_tested = "#version 430 core\n"
13602                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13603                                                                          "\n"
13604                                                                          "DIRECTION BLOCK_DEFINITION"
13605                                                                          "\n"
13606                                                                          "in  vec4 in_vs;\n"
13607                                                                          "out vec4 vs_tcs;\n"
13608                                                                          "\n"
13609                                                                          "void main()\n"
13610                                                                          "{\n"
13611                                                                          "    vec4 result = in_vs;\n"
13612                                                                          "\n"
13613                                                                          "VARIABLE_USE"
13614                                                                          "\n"
13615                                                                          "    vs_tcs = result;\n"
13616                                                                          "}\n"
13617                                                                          "\n";
13618
13619         static const GLchar* shaders_in[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13620                                                                                           /* vs  */ { 0, vs_tested, tcs, tes, gs, fs },
13621                                                                                           /* tcs */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13622                                                                                           /* tes */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13623                                                                                           /* gs  */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13624                                                                                           /* fs  */ { 0, vs, tcs, tes, gs_tested, fs_tested } };
13625
13626         static const GLchar* shaders_out[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13627                                                                                            /* vs  */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13628                                                                                            /* tcs */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13629                                                                                            /* tes */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13630                                                                                            /* gs  */ { 0, vs, tcs, tes, gs_tested, fs_tested },
13631                                                                                            /* fs  */ { 0, 0, 0, 0, 0, 0 } };
13632
13633         static const bool require_modifications_in[6][6] = {
13634                 /* cs  */ { false, false, false, false, false, false },
13635                 /* vs  */ { false, true, false, false, false, false },
13636                 /* tcs */ { false, true, true, false, false, false },
13637                 /* tes */ { false, false, true, true, false, false },
13638                 /* gs  */ { false, false, false, true, true, false },
13639                 /* fs  */ { false, false, false, false, true, true }
13640         };
13641
13642         static const bool require_modifications_out[6][6] = {
13643                 /* cs  */ { false, false, false, false, false, false },
13644                 /* vs  */ { false, true, true, false, false, false },
13645                 /* tcs */ { false, false, true, true, false, false },
13646                 /* tes */ { false, false, false, true, true, false },
13647                 /* gs  */ { false, false, false, false, true, true },
13648                 /* fs  */ { false, false, false, false, false, false }
13649         };
13650
13651         const GLchar* array                                     = "";
13652         const GLchar* definition                        = block_definition_default;
13653         const GLchar* direction                         = "out";
13654         const GLchar* index                                     = "";
13655         bool              require_modifications = false;
13656         std::string   source;
13657         testCase&        test_case = m_test_cases[test_case_index];
13658         const GLchar* var_use   = output_use;
13659
13660         if (true == test_case.m_is_input)
13661         {
13662                 require_modifications = require_modifications_in[test_case.m_stage][stage];
13663                 source                            = shaders_in[test_case.m_stage][stage];
13664
13665                 if (test_case.m_stage == stage)
13666                 {
13667                         direction = "in";
13668                         var_use   = input_use;
13669                 }
13670         }
13671         else
13672         {
13673                 require_modifications = require_modifications_out[test_case.m_stage][stage];
13674                 source                            = shaders_out[test_case.m_stage][stage];
13675
13676                 if (test_case.m_stage != stage)
13677                 {
13678                         direction = "in";
13679                         var_use   = input_use;
13680                 }
13681         }
13682
13683         if (test_case.m_stage == stage)
13684         {
13685                 if (true == test_case.m_qualify_all)
13686                 {
13687                         definition = block_definition_all;
13688                 }
13689                 else
13690                 {
13691                         definition = block_definition_one;
13692                 }
13693         }
13694
13695         switch (stage)
13696         {
13697         case Utils::Shader::FRAGMENT:
13698                 break;
13699         case Utils::Shader::GEOMETRY:
13700                 array = "[]";
13701                 index = "[0]";
13702                 break;
13703         case Utils::Shader::TESS_CTRL:
13704                 array = "[]";
13705                 index = "[gl_InvocationID]";
13706                 break;
13707         // geometry shader's input must have one more dimension than tessellation evaluation shader's output,
13708         // the GS input block is an array, so the DS output can't be declared as an array
13709         case Utils::Shader::TESS_EVAL:
13710         {
13711                 if (std::string(direction) == std::string("in")) // match HS output and DS input
13712                 {
13713                         array = "[]";
13714                         index = "[0]";
13715                 }
13716                 else // match DS output and GS input
13717                 {
13718                         array = "";
13719                         index = "";
13720                 }
13721         }
13722         break;
13723         case Utils::Shader::VERTEX:
13724                 break;
13725         default:
13726                 TCU_FAIL("Invalid enum");
13727         }
13728
13729         if (true == require_modifications)
13730         {
13731                 size_t position = 0;
13732                 size_t temp;
13733
13734                 Utils::replaceToken("DIRECTION", position, direction, source);
13735                 temp = position;
13736                 Utils::replaceToken("BLOCK_DEFINITION", position, definition, source);
13737                 position = temp;
13738                 Utils::replaceToken("ARRAY", position, array, source);
13739                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13740
13741                 Utils::replaceAllTokens("INDEX", index, source);
13742         }
13743         else
13744         {
13745                 switch (stage)
13746                 {
13747                 case Utils::Shader::FRAGMENT:
13748                         source = fs;
13749                         break;
13750                 case Utils::Shader::GEOMETRY:
13751                         source = gs;
13752                         break;
13753                 case Utils::Shader::TESS_CTRL:
13754                         source = tcs;
13755                         break;
13756                 case Utils::Shader::TESS_EVAL:
13757                         source = tes;
13758                         break;
13759                 case Utils::Shader::VERTEX:
13760                         source = vs;
13761                         break;
13762                 default:
13763                         TCU_FAIL("Invalid enum");
13764                 }
13765         }
13766
13767         return source;
13768 }
13769
13770 /** Get description of test case
13771  *
13772  * @param test_case_index Index of test case
13773  *
13774  * @return Test case description
13775  **/
13776 std::string VaryingBlockMemberLocationsTest::getTestCaseName(GLuint test_case_index)
13777 {
13778         std::stringstream stream;
13779         testCase&                 test_case = m_test_cases[test_case_index];
13780
13781         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13782
13783         if (true == test_case.m_is_input)
13784         {
13785                 stream << "input";
13786         }
13787         else
13788         {
13789                 stream << "output";
13790         }
13791
13792         if (true == test_case.m_qualify_all)
13793         {
13794                 stream << ", all members qualified";
13795         }
13796         else
13797         {
13798                 stream << ", not all members qualified";
13799         }
13800
13801         return stream.str();
13802 }
13803
13804 /** Get number of test cases
13805  *
13806  * @return Number of test cases
13807  **/
13808 GLuint VaryingBlockMemberLocationsTest::getTestCaseNumber()
13809 {
13810         return static_cast<GLuint>(m_test_cases.size());
13811 }
13812
13813 /** Selects if "compute" stage is relevant for test
13814  *
13815  * @param ignored
13816  *
13817  * @return false
13818  **/
13819 bool VaryingBlockMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13820 {
13821         return false;
13822 }
13823
13824 /** Selects if compilation failure is expected result
13825  *
13826  * @param test_case_index Index of test case
13827  *
13828  * @return false when all members are qualified, true otherwise
13829  **/
13830 bool VaryingBlockMemberLocationsTest::isFailureExpected(GLuint test_case_index)
13831 {
13832         return (true != m_test_cases[test_case_index].m_qualify_all);
13833 }
13834
13835 /** Prepare all test cases
13836  *
13837  **/
13838 void VaryingBlockMemberLocationsTest::testInit()
13839 {
13840         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13841         {
13842                 if (Utils::Shader::COMPUTE == stage)
13843                 {
13844                         continue;
13845                 }
13846
13847                 testCase test_case_in_all  = { true, true, (Utils::Shader::STAGES)stage };
13848                 testCase test_case_in_one  = { true, false, (Utils::Shader::STAGES)stage };
13849                 testCase test_case_out_all = { false, true, (Utils::Shader::STAGES)stage };
13850                 testCase test_case_out_one = { false, false, (Utils::Shader::STAGES)stage };
13851
13852                 if (Utils::Shader::VERTEX != stage)
13853                 {
13854                         m_test_cases.push_back(test_case_in_all);
13855                         m_test_cases.push_back(test_case_in_one);
13856                 }
13857
13858                 if (Utils::Shader::FRAGMENT != stage)
13859                 {
13860                         m_test_cases.push_back(test_case_out_all);
13861                         m_test_cases.push_back(test_case_out_one);
13862                 }
13863         }
13864 }
13865
13866 /** Constructor
13867  *
13868  * @param context Test framework context
13869  **/
13870 VaryingBlockAutomaticMemberLocationsTest::VaryingBlockAutomaticMemberLocationsTest(deqp::Context& context)
13871         : NegativeTestBase(
13872                   context, "varying_block_automatic_member_locations",
13873                   "Test verifies that compiler assigns subsequent locations to block members, even if this causes errors")
13874 {
13875 }
13876
13877 /** Source for given test case and stage
13878  *
13879  * @param test_case_index Index of test case
13880  * @param stage           Shader stage
13881  *
13882  * @return Shader source
13883  **/
13884 std::string VaryingBlockAutomaticMemberLocationsTest::getShaderSource(GLuint                            test_case_index,
13885                                                                                                                                           Utils::Shader::STAGES stage)
13886 {
13887         static const GLchar* block_definition = "layout (location = 2) DIRECTION DBZ {\n"
13888                                                                                         "    vec4 goku;\n"
13889                                                                                         "    vec4 gohan[4];\n"
13890                                                                                         "    vec4 goten;\n"
13891                                                                                         "    layout (location = 1) vec4 chichi;\n"
13892                                                                                         "    vec4 pan;\n"
13893                                                                                         "} dbzARRAY;\n";
13894         static const GLchar* input_use = "    result += dbzINDEX.goku + dbzINDEX.gohan[0] + dbzINDEX.gohan[1] + "
13895                                                                          "dbzINDEX.gohan[3] + dbzINDEX.gohan[2] + dbzINDEX.goten + dbzINDEX.chichi + "
13896                                                                          "dbzINDEX.pan;\n";
13897         static const GLchar* output_use = "    dbzINDEX.goku     = result;\n"
13898                                                                           "    dbzINDEX.gohan[0] = result / 2;\n"
13899                                                                           "    dbzINDEX.gohan[1] = result / 2.25;\n"
13900                                                                           "    dbzINDEX.gohan[2] = result / 2.5;\n"
13901                                                                           "    dbzINDEX.gohan[3] = result / 2.75;\n"
13902                                                                           "    dbzINDEX.goten    = result / 4  - dbzINDEX.gohan[0] - dbzINDEX.gohan[1] - "
13903                                                                           "dbzINDEX.gohan[2] - dbzINDEX.gohan[3];\n"
13904                                                                           "    dbzINDEX.chichi   = result / 8  - dbzINDEX.goten;\n"
13905                                                                           "    dbzINDEX.pan      = result / 16 - dbzINDEX.chichi;\n";
13906         static const GLchar* fs = "#version 430 core\n"
13907                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13908                                                           "\n"
13909                                                           "in  vec4 gs_fs;\n"
13910                                                           "out vec4 fs_out;\n"
13911                                                           "\n"
13912                                                           "void main()\n"
13913                                                           "{\n"
13914                                                           "    fs_out = gs_fs;\n"
13915                                                           "}\n"
13916                                                           "\n";
13917         static const GLchar* fs_tested = "#version 430 core\n"
13918                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13919                                                                          "\n"
13920                                                                          "BLOCK_DEFINITION"
13921                                                                          "\n"
13922                                                                          "in  vec4 gs_fs;\n"
13923                                                                          "out vec4 fs_out;\n"
13924                                                                          "\n"
13925                                                                          "void main()\n"
13926                                                                          "{\n"
13927                                                                          "    vec4 result = gs_fs;\n"
13928                                                                          "\n"
13929                                                                          "VARIABLE_USE"
13930                                                                          "\n"
13931                                                                          "    fs_out += result;\n"
13932                                                                          "}\n"
13933                                                                          "\n";
13934         static const GLchar* gs = "#version 430 core\n"
13935                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13936                                                           "\n"
13937                                                           "layout(points)                           in;\n"
13938                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13939                                                           "\n"
13940                                                           "in  vec4 tes_gs[];\n"
13941                                                           "out vec4 gs_fs;\n"
13942                                                           "\n"
13943                                                           "void main()\n"
13944                                                           "{\n"
13945                                                           "    gs_fs = tes_gs[0];\n"
13946                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13947                                                           "    EmitVertex();\n"
13948                                                           "    gs_fs = tes_gs[0];\n"
13949                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13950                                                           "    EmitVertex();\n"
13951                                                           "    gs_fs = tes_gs[0];\n"
13952                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13953                                                           "    EmitVertex();\n"
13954                                                           "    gs_fs = tes_gs[0];\n"
13955                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13956                                                           "    EmitVertex();\n"
13957                                                           "}\n"
13958                                                           "\n";
13959         static const GLchar* gs_tested = "#version 430 core\n"
13960                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13961                                                                          "\n"
13962                                                                          "layout(points)                           in;\n"
13963                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13964                                                                          "\n"
13965                                                                          "BLOCK_DEFINITION"
13966                                                                          "\n"
13967                                                                          "in  vec4 tes_gs[];\n"
13968                                                                          "out vec4 gs_fs;\n"
13969                                                                          "\n"
13970                                                                          "void main()\n"
13971                                                                          "{\n"
13972                                                                          "    vec4 result = tes_gs[0];\n"
13973                                                                          "\n"
13974                                                                          "VARIABLE_USE"
13975                                                                          "\n"
13976                                                                          "    gs_fs = result;\n"
13977                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13978                                                                          "    EmitVertex();\n"
13979                                                                          "    gs_fs = result;\n"
13980                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13981                                                                          "    EmitVertex();\n"
13982                                                                          "    gs_fs = result;\n"
13983                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13984                                                                          "    EmitVertex();\n"
13985                                                                          "    gs_fs = result;\n"
13986                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13987                                                                          "    EmitVertex();\n"
13988                                                                          "}\n"
13989                                                                          "\n";
13990         static const GLchar* tcs = "#version 430 core\n"
13991                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13992                                                            "\n"
13993                                                            "layout(vertices = 1) out;\n"
13994                                                            "\n"
13995                                                            "in  vec4 vs_tcs[];\n"
13996                                                            "out vec4 tcs_tes[];\n"
13997                                                            "\n"
13998                                                            "void main()\n"
13999                                                            "{\n"
14000                                                            "\n"
14001                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14002                                                            "\n"
14003                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14004                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14005                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14006                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14007                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14008                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14009                                                            "}\n"
14010                                                            "\n";
14011         static const GLchar* tcs_tested = "#version 430 core\n"
14012                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14013                                                                           "\n"
14014                                                                           "layout(vertices = 1) out;\n"
14015                                                                           "\n"
14016                                                                           "BLOCK_DEFINITION"
14017                                                                           "\n"
14018                                                                           "in  vec4 vs_tcs[];\n"
14019                                                                           "out vec4 tcs_tes[];\n"
14020                                                                           "\n"
14021                                                                           "void main()\n"
14022                                                                           "{\n"
14023                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14024                                                                           "\n"
14025                                                                           "VARIABLE_USE"
14026                                                                           "\n"
14027                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14028                                                                           "\n"
14029                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14030                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14031                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14032                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14033                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14034                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14035                                                                           "}\n"
14036                                                                           "\n";
14037         static const GLchar* tes = "#version 430 core\n"
14038                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14039                                                            "\n"
14040                                                            "layout(isolines, point_mode) in;\n"
14041                                                            "\n"
14042                                                            "in  vec4 tcs_tes[];\n"
14043                                                            "out vec4 tes_gs;\n"
14044                                                            "\n"
14045                                                            "void main()\n"
14046                                                            "{\n"
14047                                                            "    tes_gs = tcs_tes[0];\n"
14048                                                            "}\n"
14049                                                            "\n";
14050         static const GLchar* tes_tested = "#version 430 core\n"
14051                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14052                                                                           "\n"
14053                                                                           "layout(isolines, point_mode) in;\n"
14054                                                                           "\n"
14055                                                                           "BLOCK_DEFINITION"
14056                                                                           "\n"
14057                                                                           "in  vec4 tcs_tes[];\n"
14058                                                                           "out vec4 tes_gs;\n"
14059                                                                           "\n"
14060                                                                           "void main()\n"
14061                                                                           "{\n"
14062                                                                           "    vec4 result = tcs_tes[0];\n"
14063                                                                           "\n"
14064                                                                           "VARIABLE_USE"
14065                                                                           "\n"
14066                                                                           "    tes_gs += result;\n"
14067                                                                           "}\n"
14068                                                                           "\n";
14069         static const GLchar* vs = "#version 430 core\n"
14070                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14071                                                           "\n"
14072                                                           "in  vec4 in_vs;\n"
14073                                                           "out vec4 vs_tcs;\n"
14074                                                           "\n"
14075                                                           "void main()\n"
14076                                                           "{\n"
14077                                                           "    vs_tcs = in_vs;\n"
14078                                                           "}\n"
14079                                                           "\n";
14080         static const GLchar* vs_tested = "#version 430 core\n"
14081                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14082                                                                          "\n"
14083                                                                          "BLOCK_DEFINITION"
14084                                                                          "\n"
14085                                                                          "in  vec4 in_vs;\n"
14086                                                                          "out vec4 vs_tcs;\n"
14087                                                                          "\n"
14088                                                                          "void main()\n"
14089                                                                          "{\n"
14090                                                                          "    vec4 result = in_vs;\n"
14091                                                                          "\n"
14092                                                                          "VARIABLE_USE"
14093                                                                          "\n"
14094                                                                          "    vs_tcs += result;\n"
14095                                                                          "}\n"
14096                                                                          "\n";
14097
14098         const GLchar* array             = "";
14099         const GLchar* direction = "out";
14100         const GLchar* index             = "";
14101         std::string   source;
14102         testCase&        test_case = m_test_cases[test_case_index];
14103         const GLchar* var_use   = output_use;
14104
14105         if (true == test_case.m_is_input)
14106         {
14107                 direction = "in ";
14108                 var_use   = input_use;
14109         }
14110
14111         if (test_case.m_stage == stage)
14112         {
14113                 size_t position = 0;
14114                 size_t temp;
14115
14116                 switch (stage)
14117                 {
14118                 case Utils::Shader::FRAGMENT:
14119                         source = fs_tested;
14120                         break;
14121                 case Utils::Shader::GEOMETRY:
14122                         source = gs_tested;
14123                         array  = "[]";
14124                         index  = "[0]";
14125                         break;
14126                 case Utils::Shader::TESS_CTRL:
14127                         source = tcs_tested;
14128                         array  = "[]";
14129                         index  = "[gl_InvocationID]";
14130                         break;
14131                 case Utils::Shader::TESS_EVAL:
14132                         source = tes_tested;
14133                         array  = "[]";
14134                         index  = "[0]";
14135                         break;
14136                 case Utils::Shader::VERTEX:
14137                         source = vs_tested;
14138                         break;
14139                 default:
14140                         TCU_FAIL("Invalid enum");
14141                 }
14142
14143                 temp = position;
14144                 Utils::replaceToken("BLOCK_DEFINITION", position, block_definition, source);
14145                 position = temp;
14146                 Utils::replaceToken("DIRECTION", position, direction, source);
14147                 Utils::replaceToken("ARRAY", position, array, source);
14148                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14149
14150                 Utils::replaceAllTokens("INDEX", index, source);
14151         }
14152         else
14153         {
14154                 switch (stage)
14155                 {
14156                 case Utils::Shader::FRAGMENT:
14157                         source = fs;
14158                         break;
14159                 case Utils::Shader::GEOMETRY:
14160                         source = gs;
14161                         break;
14162                 case Utils::Shader::TESS_CTRL:
14163                         source = tcs;
14164                         break;
14165                 case Utils::Shader::TESS_EVAL:
14166                         source = tes;
14167                         break;
14168                 case Utils::Shader::VERTEX:
14169                         source = vs;
14170                         break;
14171                 default:
14172                         TCU_FAIL("Invalid enum");
14173                 }
14174         }
14175
14176         return source;
14177 }
14178
14179 /** Get description of test case
14180  *
14181  * @param test_case_index Index of test case
14182  *
14183  * @return Test case description
14184  **/
14185 std::string VaryingBlockAutomaticMemberLocationsTest::getTestCaseName(GLuint test_case_index)
14186 {
14187         std::stringstream stream;
14188         testCase&                 test_case = m_test_cases[test_case_index];
14189
14190         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
14191
14192         if (true == test_case.m_is_input)
14193         {
14194                 stream << "input";
14195         }
14196         else
14197         {
14198                 stream << "output";
14199         }
14200
14201         return stream.str();
14202 }
14203
14204 /** Get number of test cases
14205  *
14206  * @return Number of test cases
14207  **/
14208 GLuint VaryingBlockAutomaticMemberLocationsTest::getTestCaseNumber()
14209 {
14210         return static_cast<GLuint>(m_test_cases.size());
14211 }
14212
14213 /** Selects if "compute" stage is relevant for test
14214  *
14215  * @param ignored
14216  *
14217  * @return false
14218  **/
14219 bool VaryingBlockAutomaticMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
14220 {
14221         return false;
14222 }
14223
14224 /** Prepare all test cases
14225  *
14226  **/
14227 void VaryingBlockAutomaticMemberLocationsTest::testInit()
14228 {
14229         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14230         {
14231                 if (Utils::Shader::COMPUTE == stage)
14232                 {
14233                         continue;
14234                 }
14235
14236                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
14237                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
14238
14239                 if (Utils::Shader::VERTEX != stage)
14240                 {
14241                         m_test_cases.push_back(test_case_in);
14242                 }
14243
14244                 if (Utils::Shader::FRAGMENT != stage)
14245                 {
14246                         m_test_cases.push_back(test_case_out);
14247                 }
14248         }
14249 }
14250
14251 /** Constructor
14252  *
14253  * @param context Test framework context
14254  **/
14255 VaryingLocationLimitTest::VaryingLocationLimitTest(deqp::Context& context)
14256         : NegativeTestBase(context, "varying_location_limit",
14257                                            "Test verifies that compiler reports error when location qualifier exceed limits")
14258 {
14259 }
14260
14261 /** Source for given test case and stage
14262  *
14263  * @param test_case_index Index of test case
14264  * @param stage           Shader stage
14265  *
14266  * @return Shader source
14267  **/
14268 std::string VaryingLocationLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
14269 {
14270         static const GLchar* var_definition = "layout (location = LAST + 1) FLAT DIRECTION TYPE gokuARRAY;\n";
14271         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
14272                                                                          "    {\n"
14273                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
14274                                                                          "    }\n";
14275         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
14276                                                                           "    if (vec4(0) == result)\n"
14277                                                                           "    {\n"
14278                                                                           "        gokuINDEX = TYPE(1);\n"
14279                                                                           "    }\n";
14280         static const GLchar* fs = "#version 430 core\n"
14281                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14282                                                           "\n"
14283                                                           "in  vec4 gs_fs;\n"
14284                                                           "out vec4 fs_out;\n"
14285                                                           "\n"
14286                                                           "void main()\n"
14287                                                           "{\n"
14288                                                           "    fs_out = gs_fs;\n"
14289                                                           "}\n"
14290                                                           "\n";
14291         static const GLchar* fs_tested = "#version 430 core\n"
14292                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14293                                                                          "\n"
14294                                                                          "VAR_DEFINITION"
14295                                                                          "\n"
14296                                                                          "in  vec4 gs_fs;\n"
14297                                                                          "out vec4 fs_out;\n"
14298                                                                          "\n"
14299                                                                          "void main()\n"
14300                                                                          "{\n"
14301                                                                          "    vec4 result = gs_fs;\n"
14302                                                                          "\n"
14303                                                                          "VARIABLE_USE"
14304                                                                          "\n"
14305                                                                          "    fs_out += result;\n"
14306                                                                          "}\n"
14307                                                                          "\n";
14308         static const GLchar* gs = "#version 430 core\n"
14309                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14310                                                           "\n"
14311                                                           "layout(points)                           in;\n"
14312                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14313                                                           "\n"
14314                                                           "in  vec4 tes_gs[];\n"
14315                                                           "out vec4 gs_fs;\n"
14316                                                           "\n"
14317                                                           "void main()\n"
14318                                                           "{\n"
14319                                                           "    gs_fs = tes_gs[0];\n"
14320                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14321                                                           "    EmitVertex();\n"
14322                                                           "    gs_fs = tes_gs[0];\n"
14323                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14324                                                           "    EmitVertex();\n"
14325                                                           "    gs_fs = tes_gs[0];\n"
14326                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14327                                                           "    EmitVertex();\n"
14328                                                           "    gs_fs = tes_gs[0];\n"
14329                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14330                                                           "    EmitVertex();\n"
14331                                                           "}\n"
14332                                                           "\n";
14333         static const GLchar* gs_tested = "#version 430 core\n"
14334                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14335                                                                          "\n"
14336                                                                          "layout(points)                           in;\n"
14337                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14338                                                                          "\n"
14339                                                                          "VAR_DEFINITION"
14340                                                                          "\n"
14341                                                                          "in  vec4 tes_gs[];\n"
14342                                                                          "out vec4 gs_fs;\n"
14343                                                                          "\n"
14344                                                                          "void main()\n"
14345                                                                          "{\n"
14346                                                                          "    vec4 result = tes_gs[0];\n"
14347                                                                          "\n"
14348                                                                          "VARIABLE_USE"
14349                                                                          "\n"
14350                                                                          "    gs_fs = result;\n"
14351                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14352                                                                          "    EmitVertex();\n"
14353                                                                          "    gs_fs = result;\n"
14354                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14355                                                                          "    EmitVertex();\n"
14356                                                                          "    gs_fs = result;\n"
14357                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14358                                                                          "    EmitVertex();\n"
14359                                                                          "    gs_fs = result;\n"
14360                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14361                                                                          "    EmitVertex();\n"
14362                                                                          "}\n"
14363                                                                          "\n";
14364         static const GLchar* tcs = "#version 430 core\n"
14365                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14366                                                            "\n"
14367                                                            "layout(vertices = 1) out;\n"
14368                                                            "\n"
14369                                                            "in  vec4 vs_tcs[];\n"
14370                                                            "out vec4 tcs_tes[];\n"
14371                                                            "\n"
14372                                                            "void main()\n"
14373                                                            "{\n"
14374                                                            "\n"
14375                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14376                                                            "\n"
14377                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14378                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14379                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14380                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14381                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14382                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14383                                                            "}\n"
14384                                                            "\n";
14385         static const GLchar* tcs_tested = "#version 430 core\n"
14386                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14387                                                                           "\n"
14388                                                                           "layout(vertices = 1) out;\n"
14389                                                                           "\n"
14390                                                                           "VAR_DEFINITION"
14391                                                                           "\n"
14392                                                                           "in  vec4 vs_tcs[];\n"
14393                                                                           "out vec4 tcs_tes[];\n"
14394                                                                           "\n"
14395                                                                           "void main()\n"
14396                                                                           "{\n"
14397                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14398                                                                           "\n"
14399                                                                           "VARIABLE_USE"
14400                                                                           "\n"
14401                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14402                                                                           "\n"
14403                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14404                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14405                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14406                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14407                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14408                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14409                                                                           "}\n"
14410                                                                           "\n";
14411         static const GLchar* tes = "#version 430 core\n"
14412                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14413                                                            "\n"
14414                                                            "layout(isolines, point_mode) in;\n"
14415                                                            "\n"
14416                                                            "in  vec4 tcs_tes[];\n"
14417                                                            "out vec4 tes_gs;\n"
14418                                                            "\n"
14419                                                            "void main()\n"
14420                                                            "{\n"
14421                                                            "    tes_gs = tcs_tes[0];\n"
14422                                                            "}\n"
14423                                                            "\n";
14424         static const GLchar* tes_tested = "#version 430 core\n"
14425                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14426                                                                           "\n"
14427                                                                           "layout(isolines, point_mode) in;\n"
14428                                                                           "\n"
14429                                                                           "VAR_DEFINITION"
14430                                                                           "\n"
14431                                                                           "in  vec4 tcs_tes[];\n"
14432                                                                           "out vec4 tes_gs;\n"
14433                                                                           "\n"
14434                                                                           "void main()\n"
14435                                                                           "{\n"
14436                                                                           "    vec4 result = tcs_tes[0];\n"
14437                                                                           "\n"
14438                                                                           "VARIABLE_USE"
14439                                                                           "\n"
14440                                                                           "    tes_gs += result;\n"
14441                                                                           "}\n"
14442                                                                           "\n";
14443         static const GLchar* vs = "#version 430 core\n"
14444                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14445                                                           "\n"
14446                                                           "in  vec4 in_vs;\n"
14447                                                           "out vec4 vs_tcs;\n"
14448                                                           "\n"
14449                                                           "void main()\n"
14450                                                           "{\n"
14451                                                           "    vs_tcs = in_vs;\n"
14452                                                           "}\n"
14453                                                           "\n";
14454         static const GLchar* vs_tested = "#version 430 core\n"
14455                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14456                                                                          "\n"
14457                                                                          "VAR_DEFINITION"
14458                                                                          "\n"
14459                                                                          "in  vec4 in_vs;\n"
14460                                                                          "out vec4 vs_tcs;\n"
14461                                                                          "\n"
14462                                                                          "void main()\n"
14463                                                                          "{\n"
14464                                                                          "    vec4 result = in_vs;\n"
14465                                                                          "\n"
14466                                                                          "VARIABLE_USE"
14467                                                                          "\n"
14468                                                                          "    vs_tcs += result;\n"
14469                                                                          "}\n"
14470                                                                          "\n";
14471
14472         std::string source;
14473         testCase&   test_case = m_test_cases[test_case_index];
14474
14475         if (test_case.m_stage == stage)
14476         {
14477                 const GLchar*                    array = "";
14478                 GLchar                                   buffer[16];
14479                 const GLchar*                    direction = "in ";
14480                 const GLchar*                    flat     = "";
14481                 const GLchar*                    index   = "";
14482                 GLuint                                   last     = getLastInputLocation(stage, test_case.m_type, 0);
14483                 size_t                                   position  = 0;
14484                 size_t                                   temp;
14485                 const GLchar*                    type_name = test_case.m_type.GetGLSLTypeName();
14486                 Utils::Variable::STORAGE storage   = Utils::Variable::VARYING_INPUT;
14487                 const GLchar*                    var_use   = input_use;
14488
14489                 if (false == test_case.m_is_input)
14490                 {
14491                         direction = "out";
14492                         last      = getLastOutputLocation(stage, test_case.m_type, 0);
14493                         storage   = Utils::Variable::VARYING_OUTPUT;
14494                         var_use   = output_use;
14495                 }
14496
14497                 if (true == isFlatRequired(stage, test_case.m_type, storage))
14498                 {
14499                         flat = "flat";
14500                 }
14501
14502                 sprintf(buffer, "%d", last);
14503
14504                 switch (stage)
14505                 {
14506                 case Utils::Shader::FRAGMENT:
14507                         source = fs_tested;
14508                         break;
14509                 case Utils::Shader::GEOMETRY:
14510                         source = gs_tested;
14511                         array  = "[]";
14512                         index  = "[0]";
14513                         break;
14514                 case Utils::Shader::TESS_CTRL:
14515                         source = tcs_tested;
14516                         array  = "[]";
14517                         index  = "[gl_InvocationID]";
14518                         break;
14519                 case Utils::Shader::TESS_EVAL:
14520                         source = tes_tested;
14521                         array  = "[]";
14522                         index  = "[0]";
14523                         break;
14524                 case Utils::Shader::VERTEX:
14525                         source = vs_tested;
14526                         break;
14527                 default:
14528                         TCU_FAIL("Invalid enum");
14529                 }
14530
14531                 temp = position;
14532                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
14533                 position = temp;
14534                 Utils::replaceToken("LAST", position, buffer, source);
14535                 Utils::replaceToken("FLAT", position, flat, source);
14536                 Utils::replaceToken("DIRECTION", position, direction, source);
14537                 Utils::replaceToken("ARRAY", position, array, source);
14538                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14539
14540                 Utils::replaceAllTokens("TYPE", type_name, source);
14541                 Utils::replaceAllTokens("INDEX", index, source);
14542         }
14543         else
14544         {
14545                 switch (stage)
14546                 {
14547                 case Utils::Shader::FRAGMENT:
14548                         source = fs;
14549                         break;
14550                 case Utils::Shader::GEOMETRY:
14551                         source = gs;
14552                         break;
14553                 case Utils::Shader::TESS_CTRL:
14554                         source = tcs;
14555                         break;
14556                 case Utils::Shader::TESS_EVAL:
14557                         source = tes;
14558                         break;
14559                 case Utils::Shader::VERTEX:
14560                         source = vs;
14561                         break;
14562                 default:
14563                         TCU_FAIL("Invalid enum");
14564                 }
14565         }
14566
14567         return source;
14568 }
14569
14570 /** Get description of test case
14571  *
14572  * @param test_case_index Index of test case
14573  *
14574  * @return Test case description
14575  **/
14576 std::string VaryingLocationLimitTest::getTestCaseName(GLuint test_case_index)
14577 {
14578         std::stringstream stream;
14579         testCase&                 test_case = m_test_cases[test_case_index];
14580
14581         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
14582                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
14583
14584         if (true == test_case.m_is_input)
14585         {
14586                 stream << "input";
14587         }
14588         else
14589         {
14590                 stream << "output";
14591         }
14592
14593         return stream.str();
14594 }
14595
14596 /** Get number of test cases
14597  *
14598  * @return Number of test cases
14599  **/
14600 GLuint VaryingLocationLimitTest::getTestCaseNumber()
14601 {
14602         return static_cast<GLuint>(m_test_cases.size());
14603 }
14604
14605 /** Selects if "compute" stage is relevant for test
14606  *
14607  * @param ignored
14608  *
14609  * @return false
14610  **/
14611 bool VaryingLocationLimitTest::isComputeRelevant(GLuint /* test_case_index */)
14612 {
14613         return false;
14614 }
14615
14616 /** Prepare all test cases
14617  *
14618  **/
14619 void VaryingLocationLimitTest::testInit()
14620 {
14621         const GLuint n_types = getTypesNumber();
14622
14623         for (GLuint i = 0; i < n_types; ++i)
14624         {
14625                 const Utils::Type& type = getType(i);
14626
14627                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14628                 {
14629                         if (Utils::Shader::COMPUTE == stage)
14630                         {
14631                                 continue;
14632                         }
14633
14634                         testCase test_case_in  = { true, type, (Utils::Shader::STAGES)stage };
14635                         testCase test_case_out = { false, type, (Utils::Shader::STAGES)stage };
14636
14637                         m_test_cases.push_back(test_case_in);
14638
14639                         if (Utils::Shader::FRAGMENT != stage)
14640                         {
14641                                 m_test_cases.push_back(test_case_out);
14642                         }
14643                 }
14644         }
14645 }
14646
14647 /** Constructor
14648  *
14649  * @param context Test framework context
14650  **/
14651 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context)
14652         : VaryingLocationsTest(context, "varying_components",
14653                                                    "Test verifies that input and output components are respected")
14654 {
14655 }
14656
14657 /** Constructor
14658  *
14659  * @param context          Test framework context
14660  * @param test_name        Name of test
14661  * @param test_description Description of test
14662  **/
14663 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context, const glw::GLchar* test_name,
14664                                                                                          const glw::GLchar* test_description)
14665         : VaryingLocationsTest(context, test_name, test_description)
14666 {
14667 }
14668
14669 /** Get interface of program
14670  *
14671  * @param test_case_index     Test case
14672  * @param program_interface   Interface of program
14673  * @param varying_passthrough Collection of connections between in and out variables
14674  **/
14675 void VaryingComponentsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
14676                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
14677 {
14678         GLuint                             array_length = getArrayLength();
14679         const testCase&            test_case    = m_test_cases[test_case_index];
14680         const Utils::Type         vector_type  = Utils::Type::GetType(test_case.m_type, 1, 4);
14681         Utils::ShaderInterface si                       = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
14682
14683         /* Zero means no array, however we still need at least 1 slot of data */
14684         if (0 == array_length)
14685         {
14686                 array_length += 1;
14687         }
14688
14689         /* Generate data */
14690         const std::vector<GLubyte>& data          = vector_type.GenerateDataPacked();
14691         const size_t                            data_size = data.size();
14692
14693         /* Prepare data for variables */
14694         m_data.resize(array_length * data_size);
14695
14696         GLubyte*           dst = &m_data[0];
14697         const GLubyte* src = &data[0];
14698
14699         for (GLuint i = 0; i < array_length; ++i)
14700         {
14701                 memcpy(dst + data_size * i, src, data_size);
14702         }
14703
14704         /* Prepare interface for each stage */
14705         prepareShaderStage(Utils::Shader::FRAGMENT, vector_type, program_interface, test_case, varying_passthrough);
14706         prepareShaderStage(Utils::Shader::GEOMETRY, vector_type, program_interface, test_case, varying_passthrough);
14707         prepareShaderStage(Utils::Shader::TESS_CTRL, vector_type, program_interface, test_case, varying_passthrough);
14708         prepareShaderStage(Utils::Shader::TESS_EVAL, vector_type, program_interface, test_case, varying_passthrough);
14709         prepareShaderStage(Utils::Shader::VERTEX, vector_type, program_interface, test_case, varying_passthrough);
14710 }
14711
14712 /** Get type name
14713  *
14714  * @param test_case_index Index of test case
14715  *
14716  * @return Name of type test in test_case_index
14717  **/
14718 std::string VaryingComponentsTest::getTestCaseName(glw::GLuint test_case_index)
14719 {
14720         std::string name;
14721
14722         const testCase& test_case = m_test_cases[test_case_index];
14723
14724         name = "Type: ";
14725
14726         switch (test_case.m_type)
14727         {
14728         case Utils::Type::Double:
14729                 name.append(Utils::Type::_double.GetGLSLTypeName());
14730                 break;
14731         case Utils::Type::Float:
14732                 name.append(Utils::Type::_float.GetGLSLTypeName());
14733                 break;
14734         case Utils::Type::Int:
14735                 name.append(Utils::Type::_int.GetGLSLTypeName());
14736                 break;
14737         case Utils::Type::Uint:
14738                 name.append(Utils::Type::uint.GetGLSLTypeName());
14739                 break;
14740         }
14741
14742         name.append(", layout: ");
14743
14744         switch (test_case.m_layout)
14745         {
14746         case GVEC4:
14747                 name.append("GVEC4");
14748                 break;
14749         case SCALAR_GVEC3:
14750                 name.append("SCALAR_GVEC3");
14751                 break;
14752         case GVEC3_SCALAR:
14753                 name.append("GVEC3_SCALAR");
14754                 break;
14755         case GVEC2_GVEC2:
14756                 name.append("GVEC2_GVEC2");
14757                 break;
14758         case GVEC2_SCALAR_SCALAR:
14759                 name.append("GVEC2_SCALAR_SCALAR");
14760                 break;
14761         case SCALAR_GVEC2_SCALAR:
14762                 name.append("SCALAR_GVEC2_SCALAR");
14763                 break;
14764         case SCALAR_SCALAR_GVEC2:
14765                 name.append("SCALAR_SCALAR_GVEC2");
14766                 break;
14767         case SCALAR_SCALAR_SCALAR_SCALAR:
14768                 name.append("SCALAR_SCALAR_SCALAR_SCALAR");
14769                 break;
14770         }
14771
14772         return name;
14773 }
14774
14775 /** Returns number of types to test
14776  *
14777  * @return Number of types, 34
14778  **/
14779 glw::GLuint VaryingComponentsTest::getTestCaseNumber()
14780 {
14781         return static_cast<GLuint>(m_test_cases.size());
14782 }
14783
14784 /* Prepare test cases */
14785 void VaryingComponentsTest::testInit()
14786 {
14787         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Double));
14788         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Double));
14789         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Double));
14790         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Double));
14791         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Double));
14792         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Double));
14793         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Double));
14794         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Double));
14795
14796         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Float));
14797         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Float));
14798         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Float));
14799         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Float));
14800         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Float));
14801         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Float));
14802         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Float));
14803         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Float));
14804
14805         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Int));
14806         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Int));
14807         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Int));
14808         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Int));
14809         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Int));
14810         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Int));
14811         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Int));
14812         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Int));
14813
14814         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Uint));
14815         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Uint));
14816         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Uint));
14817         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Uint));
14818         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Uint));
14819         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Uint));
14820         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Uint));
14821         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Uint));
14822 }
14823
14824 /** Inform that test use components
14825  *
14826  * @param ignored
14827  *
14828  * @return true
14829  **/
14830 bool VaryingComponentsTest::useComponentQualifier(glw::GLuint /* test_case_index */)
14831 {
14832         return true;
14833 }
14834
14835 /** Get length of arrays that should be used during test
14836  *
14837  * @return 0u - no array at all
14838  **/
14839 GLuint VaryingComponentsTest::getArrayLength()
14840 {
14841         return 0;
14842 }
14843
14844 std::string VaryingComponentsTest::prepareGlobals(GLuint last_in_location, GLuint last_out_location)
14845 {
14846         std::string globals = VaryingLocationsTest::prepareGlobals(last_in_location, last_out_location);
14847
14848         globals.append("const uint comp_x = 0u;\n"
14849                                    "const uint comp_y = 1u;\n"
14850                                    "const uint comp_z = 2u;\n"
14851                                    "const uint comp_w = 3u;\n");
14852
14853         return globals;
14854 }
14855
14856 /**
14857  *
14858  **/
14859 std::string VaryingComponentsTest::prepareName(const glw::GLchar* name, glw::GLint location, glw::GLint component,
14860                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
14861 {
14862         GLchar            buffer[16];
14863         std::string   result   = "PREFIXNAME_lLOCATION_cCOMPONENT";
14864         size_t            position = 0;
14865         const GLchar* prefix   = Utils::ProgramInterface::GetStagePrefix(stage, storage);
14866
14867         Utils::replaceToken("PREFIX", position, prefix, result);
14868         Utils::replaceToken("NAME", position, name, result);
14869
14870         sprintf(buffer, "%d", location);
14871         Utils::replaceToken("LOCATION", position, buffer, result);
14872
14873         sprintf(buffer, "%d", component);
14874         Utils::replaceToken("COMPONENT", position, buffer, result);
14875
14876         return result;
14877 }
14878
14879 std::string VaryingComponentsTest::prepareQualifiers(const glw::GLchar* location, const glw::GLchar* component,
14880                                                                                                          const glw::GLchar* interpolation)
14881 {
14882         size_t          position   = 0;
14883         std::string qualifiers = "layout (location = LOCATION, component = COMPONENT) INTERPOLATION";
14884
14885         Utils::replaceToken("LOCATION", position, location, qualifiers);
14886         Utils::replaceToken("COMPONENT", position, component, qualifiers);
14887         Utils::replaceToken("INTERPOLATION", position, interpolation, qualifiers);
14888
14889         return qualifiers;
14890 }
14891
14892 /**
14893  *
14894  **/
14895 void VaryingComponentsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& vector_type,
14896                                                                                            Utils::ProgramInterface& program_interface, const testCase& test_case,
14897                                                                                            Utils::VaryingPassthrough& varying_passthrough)
14898 {
14899         const GLuint                    array_length = getArrayLength();
14900         const Utils::Type&              basic_type = Utils::Type::GetType(vector_type.m_basic_type, 1 /* n_cols */, 1 /* n_rows */);
14901         descriptor                              desc_in[8];
14902         descriptor                              desc_out[8];
14903         const GLuint                    first_in_loc  = 0;
14904         const GLuint                    first_out_loc = 0;
14905         const GLchar*                   interpolation = "";
14906         const GLuint                    last_in_loc   = getLastInputLocation(stage, vector_type, array_length);
14907         GLuint                                  last_out_loc  = 0;
14908         GLuint                                  n_desc            = 0;
14909         Utils::ShaderInterface& si                        = program_interface.GetShaderInterface(stage);
14910
14911         /* Select interpolation */
14912         if ((Utils::Shader::FRAGMENT == stage) || (Utils::Shader::GEOMETRY == stage))
14913         {
14914                 interpolation = " flat";
14915         }
14916
14917         if (Utils::Shader::FRAGMENT != stage)
14918         {
14919                 last_out_loc = getLastOutputLocation(stage, vector_type, array_length);
14920         }
14921
14922         switch (test_case.m_layout)
14923         {
14924         case GVEC4:
14925                 n_desc = 2;
14926                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 4, "gvec4");
14927                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 4, "gvec4");
14928
14929                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 4, "gvec4");
14930                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 4, "gvec4");
14931                 break;
14932         case SCALAR_GVEC3:
14933                 n_desc = 4;
14934                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14935                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14936                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 3, "gvec3");
14937                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 3, "gvec3");
14938
14939                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14940                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14941                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 3, "gvec3");
14942                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 3, "gvec3");
14943                 break;
14944         case GVEC3_SCALAR:
14945                 n_desc = 4;
14946                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 3, "gvec3");
14947                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 3, "gvec3");
14948                 desc_in[2].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14949                 desc_in[3].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14950
14951                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 3, "gvec3");
14952                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 3, "gvec3");
14953                 desc_out[2].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14954                 desc_out[3].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14955                 break;
14956         case GVEC2_GVEC2:
14957                 n_desc = 4;
14958                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14959                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14960                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14961                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14962
14963                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14964                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14965                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
14966                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
14967                 break;
14968         case GVEC2_SCALAR_SCALAR:
14969                 n_desc = 6;
14970                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14971                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14972                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
14973                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
14974                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14975                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14976
14977                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14978                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14979                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
14980                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
14981                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14982                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14983                 break;
14984         case SCALAR_GVEC2_SCALAR:
14985                 n_desc = 6;
14986                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14987                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14988                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 2, "gvec2");
14989                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 2, "gvec2");
14990                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14991                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14992
14993                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14994                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14995                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 2, "gvec2");
14996                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 2, "gvec2");
14997                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14998                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14999                 break;
15000         case SCALAR_SCALAR_GVEC2:
15001                 n_desc = 6;
15002                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15003                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15004                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15005                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15006                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
15007                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
15008
15009                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15010                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15011                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15012                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15013                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
15014                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
15015                 break;
15016         case SCALAR_SCALAR_SCALAR_SCALAR:
15017                 n_desc = 8;
15018                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15019                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15020                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15021                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15022                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15023                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15024                 desc_in[6].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15025                 desc_in[7].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15026
15027                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15028                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15029                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15030                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15031                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15032                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15033                 desc_out[6].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15034                 desc_out[7].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15035                 break;
15036         }
15037
15038         for (GLuint i = 0; i < n_desc; ++i)
15039         {
15040                 const descriptor& in_desc = desc_in[i];
15041
15042                 Utils::Variable* in =
15043                         prepareVarying(basic_type, in_desc, interpolation, si, stage, Utils::Variable::VARYING_INPUT);
15044
15045                 if (Utils::Shader::FRAGMENT != stage)
15046                 {
15047                         const descriptor& out_desc = desc_out[i];
15048
15049                         Utils::Variable* out =
15050                                 prepareVarying(basic_type, out_desc, interpolation, si, stage, Utils::Variable::VARYING_OUTPUT);
15051
15052                         varying_passthrough.Add(stage, in, out);
15053                 }
15054         }
15055
15056         si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
15057 }
15058
15059 /**
15060  *
15061  **/
15062 Utils::Variable* VaryingComponentsTest::prepareVarying(const Utils::Type& basic_type, const descriptor& desc,
15063                                                                                                            const GLchar* interpolation, Utils::ShaderInterface& si,
15064                                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
15065 {
15066         const GLuint       array_length   = getArrayLength();
15067         const GLuint       component_size = basic_type.GetSize();
15068         const std::string& name                   = prepareName(desc.m_name, desc.m_location, desc.m_component, stage, storage);
15069         const GLuint       offset                 = desc.m_component * component_size;
15070         const std::string& qual                   = prepareQualifiers(desc.m_location_str, desc.m_component_str, interpolation);
15071         const GLuint       size                   = desc.m_n_rows * component_size;
15072         const Utils::Type& type                   = Utils::Type::GetType(basic_type.m_basic_type, 1 /* n_columns */, desc.m_n_rows);
15073         Utils::Variable*   var                    = 0;
15074
15075         if (Utils::Variable::VARYING_INPUT == storage)
15076         {
15077                 var = si.Input(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15078                                            desc.m_location /* expected_location */, type, /* built_in_type */
15079                                            GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15080                                            offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15081         }
15082         else
15083         {
15084                 var = si.Output(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15085                                                 desc.m_location /* expected_location */, type, /* built_in_type */
15086                                                 GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15087                                                 offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15088         }
15089
15090         return var;
15091 }
15092
15093 void VaryingComponentsTest::descriptor::assign(glw::GLint component, const glw::GLchar* component_str,
15094                                                                                            glw::GLint location, const glw::GLchar* location_str, glw::GLuint n_rows,
15095                                                                                            const glw::GLchar* name)
15096 {
15097         m_component             = component;
15098         m_component_str = component_str;
15099         m_location              = location;
15100         m_location_str  = location_str;
15101         m_n_rows                = n_rows;
15102         m_name                  = name;
15103 }
15104
15105 VaryingComponentsTest::testCase::testCase(COMPONENTS_LAYOUT layout, Utils::Type::TYPES type)
15106         : m_layout(layout), m_type(type)
15107 {
15108 }
15109
15110 /** Constructor
15111  *
15112  * @param context Test framework context
15113  **/
15114 VaryingArrayComponentsTest::VaryingArrayComponentsTest(deqp::Context& context)
15115         : VaryingComponentsTest(context, "varying_array_components",
15116                                                         "Test verifies that input and output components are respected for arrays")
15117 {
15118 }
15119
15120 /** Get length of arrays that should be used during test
15121  *
15122  * @return 4u
15123  **/
15124 GLuint VaryingArrayComponentsTest::getArrayLength()
15125 {
15126         return 4u;
15127 }
15128
15129 /** Constructor
15130  *
15131  * @param context Test framework context
15132  **/
15133 VaryingExceedingComponentsTest::VaryingExceedingComponentsTest(deqp::Context& context)
15134         : NegativeTestBase(context, "varying_exceeding_components",
15135                                            "Test verifies that compiler reports error when component qualifier exceed limits")
15136 {
15137 }
15138
15139 /** Source for given test case and stage
15140  *
15141  * @param test_case_index Index of test case
15142  * @param stage           Shader stage
15143  *
15144  * @return Shader source
15145  **/
15146 std::string VaryingExceedingComponentsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15147 {
15148         static const GLchar* var_definition_arr =
15149                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15150         static const GLchar* var_definition_one =
15151                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15152         static const GLchar* input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15153                                                                                  "    {\n"
15154                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15155                                                                                  "    }\n";
15156         static const GLchar* input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15157                                                                                  "    {\n"
15158                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15159                                                                                  "    }\n";
15160         static const GLchar* output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15161                                                                                   "    if (vec4(0) == result)\n"
15162                                                                                   "    {\n"
15163                                                                                   "        gokuINDEX[0] = TYPE(1);\n"
15164                                                                                   "    }\n";
15165         static const GLchar* output_use_one = "    gokuINDEX = TYPE(0);\n"
15166                                                                                   "    if (vec4(0) == result)\n"
15167                                                                                   "    {\n"
15168                                                                                   "        gokuINDEX = TYPE(1);\n"
15169                                                                                   "    }\n";
15170         static const GLchar* fs = "#version 430 core\n"
15171                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15172                                                           "\n"
15173                                                           "in  vec4 gs_fs;\n"
15174                                                           "out vec4 fs_out;\n"
15175                                                           "\n"
15176                                                           "void main()\n"
15177                                                           "{\n"
15178                                                           "    fs_out = gs_fs;\n"
15179                                                           "}\n"
15180                                                           "\n";
15181         static const GLchar* fs_tested = "#version 430 core\n"
15182                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15183                                                                          "\n"
15184                                                                          "VAR_DEFINITION"
15185                                                                          "\n"
15186                                                                          "in  vec4 gs_fs;\n"
15187                                                                          "out vec4 fs_out;\n"
15188                                                                          "\n"
15189                                                                          "void main()\n"
15190                                                                          "{\n"
15191                                                                          "    vec4 result = gs_fs;\n"
15192                                                                          "\n"
15193                                                                          "VARIABLE_USE"
15194                                                                          "\n"
15195                                                                          "    fs_out += result;\n"
15196                                                                          "}\n"
15197                                                                          "\n";
15198         static const GLchar* gs = "#version 430 core\n"
15199                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15200                                                           "\n"
15201                                                           "layout(points)                           in;\n"
15202                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15203                                                           "\n"
15204                                                           "in  vec4 tes_gs[];\n"
15205                                                           "out vec4 gs_fs;\n"
15206                                                           "\n"
15207                                                           "void main()\n"
15208                                                           "{\n"
15209                                                           "    gs_fs = tes_gs[0];\n"
15210                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15211                                                           "    EmitVertex();\n"
15212                                                           "    gs_fs = tes_gs[0];\n"
15213                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15214                                                           "    EmitVertex();\n"
15215                                                           "    gs_fs = tes_gs[0];\n"
15216                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15217                                                           "    EmitVertex();\n"
15218                                                           "    gs_fs = tes_gs[0];\n"
15219                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15220                                                           "    EmitVertex();\n"
15221                                                           "}\n"
15222                                                           "\n";
15223         static const GLchar* gs_tested = "#version 430 core\n"
15224                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15225                                                                          "\n"
15226                                                                          "layout(points)                           in;\n"
15227                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15228                                                                          "\n"
15229                                                                          "VAR_DEFINITION"
15230                                                                          "\n"
15231                                                                          "in  vec4 tes_gs[];\n"
15232                                                                          "out vec4 gs_fs;\n"
15233                                                                          "\n"
15234                                                                          "void main()\n"
15235                                                                          "{\n"
15236                                                                          "    vec4 result = tes_gs[0];\n"
15237                                                                          "\n"
15238                                                                          "VARIABLE_USE"
15239                                                                          "\n"
15240                                                                          "    gs_fs = result;\n"
15241                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15242                                                                          "    EmitVertex();\n"
15243                                                                          "    gs_fs = result;\n"
15244                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15245                                                                          "    EmitVertex();\n"
15246                                                                          "    gs_fs = result;\n"
15247                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15248                                                                          "    EmitVertex();\n"
15249                                                                          "    gs_fs = result;\n"
15250                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15251                                                                          "    EmitVertex();\n"
15252                                                                          "}\n"
15253                                                                          "\n";
15254         static const GLchar* tcs = "#version 430 core\n"
15255                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15256                                                            "\n"
15257                                                            "layout(vertices = 1) out;\n"
15258                                                            "\n"
15259                                                            "in  vec4 vs_tcs[];\n"
15260                                                            "out vec4 tcs_tes[];\n"
15261                                                            "\n"
15262                                                            "void main()\n"
15263                                                            "{\n"
15264                                                            "\n"
15265                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15266                                                            "\n"
15267                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15268                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15269                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15270                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15271                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15272                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15273                                                            "}\n"
15274                                                            "\n";
15275         static const GLchar* tcs_tested = "#version 430 core\n"
15276                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15277                                                                           "\n"
15278                                                                           "layout(vertices = 1) out;\n"
15279                                                                           "\n"
15280                                                                           "VAR_DEFINITION"
15281                                                                           "\n"
15282                                                                           "in  vec4 vs_tcs[];\n"
15283                                                                           "out vec4 tcs_tes[];\n"
15284                                                                           "\n"
15285                                                                           "void main()\n"
15286                                                                           "{\n"
15287                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15288                                                                           "\n"
15289                                                                           "VARIABLE_USE"
15290                                                                           "\n"
15291                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15292                                                                           "\n"
15293                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15294                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15295                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15296                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15297                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15298                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15299                                                                           "}\n"
15300                                                                           "\n";
15301         static const GLchar* tes = "#version 430 core\n"
15302                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15303                                                            "\n"
15304                                                            "layout(isolines, point_mode) in;\n"
15305                                                            "\n"
15306                                                            "in  vec4 tcs_tes[];\n"
15307                                                            "out vec4 tes_gs;\n"
15308                                                            "\n"
15309                                                            "void main()\n"
15310                                                            "{\n"
15311                                                            "    tes_gs = tcs_tes[0];\n"
15312                                                            "}\n"
15313                                                            "\n";
15314         static const GLchar* tes_tested = "#version 430 core\n"
15315                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15316                                                                           "\n"
15317                                                                           "layout(isolines, point_mode) in;\n"
15318                                                                           "\n"
15319                                                                           "VAR_DEFINITION"
15320                                                                           "\n"
15321                                                                           "in  vec4 tcs_tes[];\n"
15322                                                                           "out vec4 tes_gs;\n"
15323                                                                           "\n"
15324                                                                           "void main()\n"
15325                                                                           "{\n"
15326                                                                           "    vec4 result = tcs_tes[0];\n"
15327                                                                           "\n"
15328                                                                           "VARIABLE_USE"
15329                                                                           "\n"
15330                                                                           "    tes_gs += result;\n"
15331                                                                           "}\n"
15332                                                                           "\n";
15333         static const GLchar* vs = "#version 430 core\n"
15334                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15335                                                           "\n"
15336                                                           "in  vec4 in_vs;\n"
15337                                                           "out vec4 vs_tcs;\n"
15338                                                           "\n"
15339                                                           "void main()\n"
15340                                                           "{\n"
15341                                                           "    vs_tcs = in_vs;\n"
15342                                                           "}\n"
15343                                                           "\n";
15344         static const GLchar* vs_tested = "#version 430 core\n"
15345                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15346                                                                          "\n"
15347                                                                          "VAR_DEFINITION"
15348                                                                          "\n"
15349                                                                          "in  vec4 in_vs;\n"
15350                                                                          "out vec4 vs_tcs;\n"
15351                                                                          "\n"
15352                                                                          "void main()\n"
15353                                                                          "{\n"
15354                                                                          "    vec4 result = in_vs;\n"
15355                                                                          "\n"
15356                                                                          "VARIABLE_USE"
15357                                                                          "\n"
15358                                                                          "    vs_tcs += result;\n"
15359                                                                          "}\n"
15360                                                                          "\n";
15361
15362         std::string source;
15363         testCase&   test_case = m_test_cases[test_case_index];
15364
15365         if (test_case.m_stage == stage)
15366         {
15367                 const GLchar* array = "";
15368                 GLchar            buffer[16];
15369                 const GLchar* var_definition = 0;
15370                 const GLchar* direction          = "in ";
15371                 const GLchar* index                      = "";
15372                 size_t            position               = 0;
15373                 size_t            temp;
15374                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15375                 const GLchar* var_use   = 0;
15376
15377                 if (false == test_case.m_is_input)
15378                 {
15379                         direction = "out";
15380
15381                         if (false == test_case.m_is_array)
15382                         {
15383                                 var_definition = var_definition_one;
15384                                 var_use            = output_use_one;
15385                         }
15386                         else
15387                         {
15388                                 var_definition = var_definition_arr;
15389                                 var_use            = output_use_arr;
15390                         }
15391                 }
15392                 else
15393                 {
15394                         if (false == test_case.m_is_array)
15395                         {
15396                                 var_definition = var_definition_one;
15397                                 var_use            = input_use_one;
15398                         }
15399                         else
15400                         {
15401                                 var_definition = var_definition_arr;
15402                                 var_use            = input_use_arr;
15403                         }
15404                 }
15405
15406                 sprintf(buffer, "%d", test_case.m_component);
15407
15408                 switch (stage)
15409                 {
15410                 case Utils::Shader::FRAGMENT:
15411                         source = fs_tested;
15412                         break;
15413                 case Utils::Shader::GEOMETRY:
15414                         source = gs_tested;
15415                         array  = "[]";
15416                         index  = "[0]";
15417                         break;
15418                 case Utils::Shader::TESS_CTRL:
15419                         source = tcs_tested;
15420                         array  = "[]";
15421                         index  = "[gl_InvocationID]";
15422                         break;
15423                 case Utils::Shader::TESS_EVAL:
15424                         source = tes_tested;
15425                         array  = "[]";
15426                         index  = "[0]";
15427                         break;
15428                 case Utils::Shader::VERTEX:
15429                         source = vs_tested;
15430                         break;
15431                 default:
15432                         TCU_FAIL("Invalid enum");
15433                 }
15434
15435                 temp = position;
15436                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15437                 position = temp;
15438                 Utils::replaceToken("COMPONENT", position, buffer, source);
15439                 Utils::replaceToken("DIRECTION", position, direction, source);
15440                 Utils::replaceToken("ARRAY", position, array, source);
15441                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15442
15443                 Utils::replaceAllTokens("TYPE", type_name, source);
15444                 Utils::replaceAllTokens("INDEX", index, source);
15445         }
15446         else
15447         {
15448                 switch (stage)
15449                 {
15450                 case Utils::Shader::FRAGMENT:
15451                         source = fs;
15452                         break;
15453                 case Utils::Shader::GEOMETRY:
15454                         source = gs;
15455                         break;
15456                 case Utils::Shader::TESS_CTRL:
15457                         source = tcs;
15458                         break;
15459                 case Utils::Shader::TESS_EVAL:
15460                         source = tes;
15461                         break;
15462                 case Utils::Shader::VERTEX:
15463                         source = vs;
15464                         break;
15465                 default:
15466                         TCU_FAIL("Invalid enum");
15467                 }
15468         }
15469
15470         return source;
15471 }
15472
15473 /** Get description of test case
15474  *
15475  * @param test_case_index Index of test case
15476  *
15477  * @return Test case description
15478  **/
15479 std::string VaryingExceedingComponentsTest::getTestCaseName(GLuint test_case_index)
15480 {
15481         std::stringstream stream;
15482         testCase&                 test_case = m_test_cases[test_case_index];
15483
15484         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15485                    << " type: " << test_case.m_type.GetGLSLTypeName();
15486
15487         if (true == test_case.m_is_array)
15488         {
15489                 stream << "[1]";
15490         }
15491
15492         stream << ", direction: ";
15493
15494         if (true == test_case.m_is_input)
15495         {
15496                 stream << "input";
15497         }
15498         else
15499         {
15500                 stream << "output";
15501         }
15502
15503         stream << ", component: " << test_case.m_component;
15504
15505         return stream.str();
15506 }
15507
15508 /** Get number of test cases
15509  *
15510  * @return Number of test cases
15511  **/
15512 GLuint VaryingExceedingComponentsTest::getTestCaseNumber()
15513 {
15514         return static_cast<GLuint>(m_test_cases.size());
15515 }
15516
15517 /** Selects if "compute" stage is relevant for test
15518  *
15519  * @param ignored
15520  *
15521  * @return false
15522  **/
15523 bool VaryingExceedingComponentsTest::isComputeRelevant(GLuint /* test_case_index */)
15524 {
15525         return false;
15526 }
15527
15528 /** Prepare all test cases
15529  *
15530  **/
15531 void VaryingExceedingComponentsTest::testInit()
15532 {
15533         static const GLuint n_components_per_location = 4;
15534         const GLuint            n_types                                   = getTypesNumber();
15535
15536         for (GLuint i = 0; i < n_types; ++i)
15537         {
15538                 const Utils::Type& type                          = getType(i);
15539                 const GLuint       n_req_components  = type.m_n_rows;
15540                 const GLuint       valid_component   = n_components_per_location - n_req_components;
15541                 const GLuint       invalid_component = valid_component + 1;
15542
15543                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15544                 {
15545                         if (Utils::Shader::COMPUTE == stage)
15546                         {
15547                                 continue;
15548                         }
15549
15550                         /* Component cannot be used for matrices */
15551                         if (1 != type.m_n_columns)
15552                         {
15553                                 continue;
15554                         }
15555
15556                         testCase test_case_in_arr  = { invalid_component, true, true, (Utils::Shader::STAGES)stage, type };
15557                         testCase test_case_in_one  = { invalid_component, true, false, (Utils::Shader::STAGES)stage, type };
15558                         testCase test_case_out_arr = { invalid_component, false, true, (Utils::Shader::STAGES)stage, type };
15559                         testCase test_case_out_one = { invalid_component, false, false, (Utils::Shader::STAGES)stage, type };
15560
15561                         m_test_cases.push_back(test_case_in_arr);
15562                         m_test_cases.push_back(test_case_in_one);
15563
15564                         if (Utils::Shader::FRAGMENT != stage)
15565                         {
15566                                 m_test_cases.push_back(test_case_out_arr);
15567                                 m_test_cases.push_back(test_case_out_one);
15568                         }
15569                 }
15570         }
15571 }
15572
15573 /** Constructor
15574  *
15575  * @param context Test framework context
15576  **/
15577 VaryingComponentWithoutLocationTest::VaryingComponentWithoutLocationTest(deqp::Context& context)
15578         : NegativeTestBase(context, "varying_component_without_location",
15579                                            "Test verifies that compiler reports error when component qualifier is used without location")
15580 {
15581 }
15582
15583 /** Source for given test case and stage
15584  *
15585  * @param test_case_index Index of test case
15586  * @param stage           Shader stage
15587  *
15588  * @return Shader source
15589  **/
15590 std::string VaryingComponentWithoutLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15591 {
15592         static const GLchar* var_definition = "layout (component = COMPONENT) FLAT DIRECTION TYPE gokuARRAY;\n";
15593         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
15594                                                                          "    {\n"
15595                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15596                                                                          "    }\n";
15597         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
15598                                                                           "    if (vec4(0) == result)\n"
15599                                                                           "    {\n"
15600                                                                           "        gokuINDEX = TYPE(1);\n"
15601                                                                           "    }\n";
15602         static const GLchar* fs = "#version 430 core\n"
15603                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15604                                                           "\n"
15605                                                           "in  vec4 gs_fs;\n"
15606                                                           "out vec4 fs_out;\n"
15607                                                           "\n"
15608                                                           "void main()\n"
15609                                                           "{\n"
15610                                                           "    fs_out = gs_fs;\n"
15611                                                           "}\n"
15612                                                           "\n";
15613         static const GLchar* fs_tested = "#version 430 core\n"
15614                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15615                                                                          "\n"
15616                                                                          "VAR_DEFINITION"
15617                                                                          "\n"
15618                                                                          "in  vec4 gs_fs;\n"
15619                                                                          "out vec4 fs_out;\n"
15620                                                                          "\n"
15621                                                                          "void main()\n"
15622                                                                          "{\n"
15623                                                                          "    vec4 result = gs_fs;\n"
15624                                                                          "\n"
15625                                                                          "VARIABLE_USE"
15626                                                                          "\n"
15627                                                                          "    fs_out = result;\n"
15628                                                                          "}\n"
15629                                                                          "\n";
15630         static const GLchar* gs = "#version 430 core\n"
15631                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15632                                                           "\n"
15633                                                           "layout(points)                           in;\n"
15634                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15635                                                           "\n"
15636                                                           "in  vec4 tes_gs[];\n"
15637                                                           "out vec4 gs_fs;\n"
15638                                                           "\n"
15639                                                           "void main()\n"
15640                                                           "{\n"
15641                                                           "    gs_fs = tes_gs[0];\n"
15642                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15643                                                           "    EmitVertex();\n"
15644                                                           "    gs_fs = tes_gs[0];\n"
15645                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15646                                                           "    EmitVertex();\n"
15647                                                           "    gs_fs = tes_gs[0];\n"
15648                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15649                                                           "    EmitVertex();\n"
15650                                                           "    gs_fs = tes_gs[0];\n"
15651                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15652                                                           "    EmitVertex();\n"
15653                                                           "}\n"
15654                                                           "\n";
15655         static const GLchar* gs_tested = "#version 430 core\n"
15656                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15657                                                                          "\n"
15658                                                                          "layout(points)                           in;\n"
15659                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15660                                                                          "\n"
15661                                                                          "VAR_DEFINITION"
15662                                                                          "\n"
15663                                                                          "in  vec4 tes_gs[];\n"
15664                                                                          "out vec4 gs_fs;\n"
15665                                                                          "\n"
15666                                                                          "void main()\n"
15667                                                                          "{\n"
15668                                                                          "    vec4 result = tes_gs[0];\n"
15669                                                                          "\n"
15670                                                                          "VARIABLE_USE"
15671                                                                          "\n"
15672                                                                          "    gs_fs = result;\n"
15673                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15674                                                                          "    EmitVertex();\n"
15675                                                                          "    gs_fs = result;\n"
15676                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15677                                                                          "    EmitVertex();\n"
15678                                                                          "    gs_fs = result;\n"
15679                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15680                                                                          "    EmitVertex();\n"
15681                                                                          "    gs_fs = result;\n"
15682                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15683                                                                          "    EmitVertex();\n"
15684                                                                          "}\n"
15685                                                                          "\n";
15686         static const GLchar* tcs = "#version 430 core\n"
15687                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15688                                                            "\n"
15689                                                            "layout(vertices = 1) out;\n"
15690                                                            "\n"
15691                                                            "in  vec4 vs_tcs[];\n"
15692                                                            "out vec4 tcs_tes[];\n"
15693                                                            "\n"
15694                                                            "void main()\n"
15695                                                            "{\n"
15696                                                            "\n"
15697                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15698                                                            "\n"
15699                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15700                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15701                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15702                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15703                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15704                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15705                                                            "}\n"
15706                                                            "\n";
15707         static const GLchar* tcs_tested = "#version 430 core\n"
15708                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15709                                                                           "\n"
15710                                                                           "layout(vertices = 1) out;\n"
15711                                                                           "\n"
15712                                                                           "VAR_DEFINITION"
15713                                                                           "\n"
15714                                                                           "in  vec4 vs_tcs[];\n"
15715                                                                           "out vec4 tcs_tes[];\n"
15716                                                                           "\n"
15717                                                                           "void main()\n"
15718                                                                           "{\n"
15719                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15720                                                                           "\n"
15721                                                                           "VARIABLE_USE"
15722                                                                           "\n"
15723                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15724                                                                           "\n"
15725                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15726                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15727                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15728                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15729                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15730                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15731                                                                           "}\n"
15732                                                                           "\n";
15733         static const GLchar* tes = "#version 430 core\n"
15734                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15735                                                            "\n"
15736                                                            "layout(isolines, point_mode) in;\n"
15737                                                            "\n"
15738                                                            "in  vec4 tcs_tes[];\n"
15739                                                            "out vec4 tes_gs;\n"
15740                                                            "\n"
15741                                                            "void main()\n"
15742                                                            "{\n"
15743                                                            "    tes_gs = tcs_tes[0];\n"
15744                                                            "}\n"
15745                                                            "\n";
15746         static const GLchar* tes_tested = "#version 430 core\n"
15747                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15748                                                                           "\n"
15749                                                                           "layout(isolines, point_mode) in;\n"
15750                                                                           "\n"
15751                                                                           "VAR_DEFINITION"
15752                                                                           "\n"
15753                                                                           "in  vec4 tcs_tes[];\n"
15754                                                                           "out vec4 tes_gs;\n"
15755                                                                           "\n"
15756                                                                           "void main()\n"
15757                                                                           "{\n"
15758                                                                           "    vec4 result = tcs_tes[0];\n"
15759                                                                           "\n"
15760                                                                           "VARIABLE_USE"
15761                                                                           "\n"
15762                                                                           "    tes_gs = result;\n"
15763                                                                           "}\n"
15764                                                                           "\n";
15765         static const GLchar* vs = "#version 430 core\n"
15766                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15767                                                           "\n"
15768                                                           "in  vec4 in_vs;\n"
15769                                                           "out vec4 vs_tcs;\n"
15770                                                           "\n"
15771                                                           "void main()\n"
15772                                                           "{\n"
15773                                                           "    vs_tcs = in_vs;\n"
15774                                                           "}\n"
15775                                                           "\n";
15776         static const GLchar* vs_tested = "#version 430 core\n"
15777                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15778                                                                          "\n"
15779                                                                          "VAR_DEFINITION"
15780                                                                          "\n"
15781                                                                          "in  vec4 in_vs;\n"
15782                                                                          "out vec4 vs_tcs;\n"
15783                                                                          "\n"
15784                                                                          "void main()\n"
15785                                                                          "{\n"
15786                                                                          "    vec4 result = in_vs;\n"
15787                                                                          "\n"
15788                                                                          "VARIABLE_USE"
15789                                                                          "\n"
15790                                                                          "    vs_tcs = result;\n"
15791                                                                          "}\n"
15792                                                                          "\n";
15793
15794         std::string source;
15795         testCase&   test_case = m_test_cases[test_case_index];
15796
15797         if (test_case.m_stage == stage)
15798         {
15799                 const GLchar* array = "";
15800                 GLchar            buffer[16];
15801                 const GLchar* direction = "in ";
15802                 const GLchar* index             = "";
15803                 size_t            position  = 0;
15804                 size_t            temp;
15805                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15806                 const GLchar* var_use   = input_use;
15807                 const GLchar* flat              = "flat";
15808
15809                 if (false == test_case.m_is_input)
15810                 {
15811                         direction = "out";
15812                         var_use   = output_use;
15813                 }
15814
15815                 sprintf(buffer, "%d", test_case.m_component);
15816
15817                 switch (stage)
15818                 {
15819                 case Utils::Shader::FRAGMENT:
15820                         source = fs_tested;
15821                         break;
15822                 case Utils::Shader::GEOMETRY:
15823                         source = gs_tested;
15824                         array  = "[]";
15825                         index  = "[0]";
15826                         break;
15827                 case Utils::Shader::TESS_CTRL:
15828                         source = tcs_tested;
15829                         array  = "[]";
15830                         index  = "[gl_InvocationID]";
15831                         break;
15832                 case Utils::Shader::TESS_EVAL:
15833                         source = tes_tested;
15834                         array  = "[]";
15835                         index  = "[0]";
15836                         break;
15837                 case Utils::Shader::VERTEX:
15838                         source = vs_tested;
15839                         flat   = "";
15840                         break;
15841                 default:
15842                         TCU_FAIL("Invalid enum");
15843                 }
15844
15845                 temp = position;
15846                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15847                 position = temp;
15848                 Utils::replaceToken("COMPONENT", position, buffer, source);
15849                 Utils::replaceToken("FLAT", position, flat, source);
15850                 Utils::replaceToken("DIRECTION", position, direction, source);
15851                 Utils::replaceToken("ARRAY", position, array, source);
15852                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15853
15854                 Utils::replaceAllTokens("TYPE", type_name, source);
15855                 Utils::replaceAllTokens("INDEX", index, source);
15856         }
15857         else
15858         {
15859                 switch (stage)
15860                 {
15861                 case Utils::Shader::FRAGMENT:
15862                         source = fs;
15863                         break;
15864                 case Utils::Shader::GEOMETRY:
15865                         source = gs;
15866                         break;
15867                 case Utils::Shader::TESS_CTRL:
15868                         source = tcs;
15869                         break;
15870                 case Utils::Shader::TESS_EVAL:
15871                         source = tes;
15872                         break;
15873                 case Utils::Shader::VERTEX:
15874                         source = vs;
15875                         break;
15876                 default:
15877                         TCU_FAIL("Invalid enum");
15878                 }
15879         }
15880
15881         return source;
15882 }
15883
15884 /** Get description of test case
15885  *
15886  * @param test_case_index Index of test case
15887  *
15888  * @return Test case description
15889  **/
15890 std::string VaryingComponentWithoutLocationTest::getTestCaseName(GLuint test_case_index)
15891 {
15892         std::stringstream stream;
15893         testCase&                 test_case = m_test_cases[test_case_index];
15894
15895         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15896                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
15897
15898         if (true == test_case.m_is_input)
15899         {
15900                 stream << "input";
15901         }
15902         else
15903         {
15904                 stream << "output";
15905         }
15906
15907         stream << ", component: " << test_case.m_component;
15908
15909         return stream.str();
15910 }
15911
15912 /** Get number of test cases
15913  *
15914  * @return Number of test cases
15915  **/
15916 GLuint VaryingComponentWithoutLocationTest::getTestCaseNumber()
15917 {
15918         return static_cast<GLuint>(m_test_cases.size());
15919 }
15920
15921 /** Selects if "compute" stage is relevant for test
15922  *
15923  * @param ignored
15924  *
15925  * @return false
15926  **/
15927 bool VaryingComponentWithoutLocationTest::isComputeRelevant(GLuint /* test_case_index */)
15928 {
15929         return false;
15930 }
15931
15932 /** Prepare all test cases
15933  *
15934  **/
15935 void VaryingComponentWithoutLocationTest::testInit()
15936 {
15937         static const GLuint n_components_per_location = 4;
15938         const GLuint            n_types                                   = getTypesNumber();
15939
15940         for (GLuint i = 0; i < n_types; ++i)
15941         {
15942                 const Utils::Type& type                         = getType(i);
15943                 const GLuint       n_req_components = type.m_n_rows;
15944                 const GLuint       valid_component  = n_components_per_location - n_req_components;
15945
15946                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15947                 {
15948                         if (Utils::Shader::COMPUTE == stage)
15949                         {
15950                                 continue;
15951                         }
15952
15953                         /* Component cannot be used for matrices */
15954                         if (1 != type.m_n_columns)
15955                         {
15956                                 continue;
15957                         }
15958
15959                         testCase test_case_in  = { valid_component, true, (Utils::Shader::STAGES)stage, type };
15960                         testCase test_case_out = { valid_component, false, (Utils::Shader::STAGES)stage, type };
15961
15962                         m_test_cases.push_back(test_case_in);
15963
15964                         if (Utils::Shader::FRAGMENT != stage)
15965                         {
15966                                 m_test_cases.push_back(test_case_out);
15967                         }
15968                 }
15969         }
15970 }
15971
15972 /** Constructor
15973  *
15974  * @param context Test framework context
15975  **/
15976 VaryingComponentOfInvalidTypeTest::VaryingComponentOfInvalidTypeTest(deqp::Context& context)
15977         : NegativeTestBase(context, "varying_component_of_invalid_type",
15978                                            "Test verifies that compiler reports error when component qualifier is used for invalid type")
15979 {
15980 }
15981
15982 /** Source for given test case and stage
15983  *
15984  * @param test_case_index Index of test case
15985  * @param stage           Shader stage
15986  *
15987  * @return Shader source
15988  **/
15989 std::string VaryingComponentOfInvalidTypeTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15990 {
15991         static const GLchar* block_definition_arr = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15992                                                                                                 "    TYPE member;\n"
15993                                                                                                 "} gokuARRAY[1];\n";
15994         static const GLchar* block_definition_one = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15995                                                                                                 "    TYPE member;\n"
15996                                                                                                 "} gokuARRAY;\n";
15997         static const GLchar* matrix_definition_arr =
15998                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15999         static const GLchar* matrix_definition_one =
16000                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
16001         static const GLchar* struct_definition_arr =
16002                 "struct Goku {\n"
16003                 "    TYPE member;\n"
16004                 "};\n"
16005                 "\n"
16006                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY[1];\n";
16007         static const GLchar* struct_definition_one =
16008                 "struct Goku {\n"
16009                 "    TYPE member;\n"
16010                 "};\n"
16011                 "\n"
16012                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY;\n";
16013         static const GLchar* matrix_input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
16014                                                                                                 "    {\n"
16015                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16016                                                                                                 "    }\n";
16017         static const GLchar* matrix_input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
16018                                                                                                 "    {\n"
16019                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16020                                                                                                 "    }\n";
16021         static const GLchar* matrix_output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
16022                                                                                                  "    if (vec4(0) == result)\n"
16023                                                                                                  "    {\n"
16024                                                                                                  "        gokuINDEX[0] = TYPE(1);\n"
16025                                                                                                  "    }\n";
16026         static const GLchar* matrix_output_use_one = "    gokuINDEX = TYPE(0);\n"
16027                                                                                                  "    if (vec4(0) == result)\n"
16028                                                                                                  "    {\n"
16029                                                                                                  "        gokuINDEX = TYPE(1);\n"
16030                                                                                                  "    }\n";
16031         static const GLchar* member_input_use_arr = "    if (TYPE(0) == gokuINDEX[0].member)\n"
16032                                                                                                 "    {\n"
16033                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16034                                                                                                 "    }\n";
16035         static const GLchar* member_input_use_one = "    if (TYPE(0) == gokuINDEX.member)\n"
16036                                                                                                 "    {\n"
16037                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16038                                                                                                 "    }\n";
16039         static const GLchar* member_output_use_arr = "    gokuINDEX[0].member = TYPE(0);\n"
16040                                                                                                  "    if (vec4(0) == result)\n"
16041                                                                                                  "    {\n"
16042                                                                                                  "        gokuINDEX[0].member = TYPE(1);\n"
16043                                                                                                  "    }\n";
16044         static const GLchar* member_output_use_one = "    gokuINDEX.member = TYPE(0);\n"
16045                                                                                                  "    if (vec4(0) == result)\n"
16046                                                                                                  "    {\n"
16047                                                                                                  "        gokuINDEX.member = TYPE(1);\n"
16048                                                                                                  "    }\n";
16049         static const GLchar* fs = "#version 430 core\n"
16050                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16051                                                           "\n"
16052                                                           "in  vec4 gs_fs;\n"
16053                                                           "out vec4 fs_out;\n"
16054                                                           "\n"
16055                                                           "void main()\n"
16056                                                           "{\n"
16057                                                           "    fs_out = gs_fs;\n"
16058                                                           "}\n"
16059                                                           "\n";
16060         static const GLchar* fs_tested = "#version 430 core\n"
16061                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16062                                                                          "\n"
16063                                                                          "VAR_DEFINITION"
16064                                                                          "\n"
16065                                                                          "in  vec4 gs_fs;\n"
16066                                                                          "out vec4 fs_out;\n"
16067                                                                          "\n"
16068                                                                          "void main()\n"
16069                                                                          "{\n"
16070                                                                          "    vec4 result = gs_fs;\n"
16071                                                                          "\n"
16072                                                                          "VARIABLE_USE"
16073                                                                          "\n"
16074                                                                          "    fs_out += result;\n"
16075                                                                          "}\n"
16076                                                                          "\n";
16077         static const GLchar* gs = "#version 430 core\n"
16078                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16079                                                           "\n"
16080                                                           "layout(points)                           in;\n"
16081                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16082                                                           "\n"
16083                                                           "in  vec4 tes_gs[];\n"
16084                                                           "out vec4 gs_fs;\n"
16085                                                           "\n"
16086                                                           "void main()\n"
16087                                                           "{\n"
16088                                                           "    gs_fs = tes_gs[0];\n"
16089                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16090                                                           "    EmitVertex();\n"
16091                                                           "    gs_fs = tes_gs[0];\n"
16092                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16093                                                           "    EmitVertex();\n"
16094                                                           "    gs_fs = tes_gs[0];\n"
16095                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16096                                                           "    EmitVertex();\n"
16097                                                           "    gs_fs = tes_gs[0];\n"
16098                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16099                                                           "    EmitVertex();\n"
16100                                                           "}\n"
16101                                                           "\n";
16102         static const GLchar* gs_tested = "#version 430 core\n"
16103                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16104                                                                          "\n"
16105                                                                          "layout(points)                           in;\n"
16106                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16107                                                                          "\n"
16108                                                                          "VAR_DEFINITION"
16109                                                                          "\n"
16110                                                                          "in  vec4 tes_gs[];\n"
16111                                                                          "out vec4 gs_fs;\n"
16112                                                                          "\n"
16113                                                                          "void main()\n"
16114                                                                          "{\n"
16115                                                                          "    vec4 result = tes_gs[0];\n"
16116                                                                          "\n"
16117                                                                          "VARIABLE_USE"
16118                                                                          "\n"
16119                                                                          "    gs_fs = result;\n"
16120                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16121                                                                          "    EmitVertex();\n"
16122                                                                          "    gs_fs = result;\n"
16123                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16124                                                                          "    EmitVertex();\n"
16125                                                                          "    gs_fs = result;\n"
16126                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16127                                                                          "    EmitVertex();\n"
16128                                                                          "    gs_fs = result;\n"
16129                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16130                                                                          "    EmitVertex();\n"
16131                                                                          "}\n"
16132                                                                          "\n";
16133         static const GLchar* tcs = "#version 430 core\n"
16134                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16135                                                            "\n"
16136                                                            "layout(vertices = 1) out;\n"
16137                                                            "\n"
16138                                                            "in  vec4 vs_tcs[];\n"
16139                                                            "out vec4 tcs_tes[];\n"
16140                                                            "\n"
16141                                                            "void main()\n"
16142                                                            "{\n"
16143                                                            "\n"
16144                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16145                                                            "\n"
16146                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16147                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16148                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16149                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16150                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16151                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16152                                                            "}\n"
16153                                                            "\n";
16154         static const GLchar* tcs_tested = "#version 430 core\n"
16155                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16156                                                                           "\n"
16157                                                                           "layout(vertices = 1) out;\n"
16158                                                                           "\n"
16159                                                                           "VAR_DEFINITION"
16160                                                                           "\n"
16161                                                                           "in  vec4 vs_tcs[];\n"
16162                                                                           "out vec4 tcs_tes[];\n"
16163                                                                           "\n"
16164                                                                           "void main()\n"
16165                                                                           "{\n"
16166                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16167                                                                           "\n"
16168                                                                           "VARIABLE_USE"
16169                                                                           "\n"
16170                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16171                                                                           "\n"
16172                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16173                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16174                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16175                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16176                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16177                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16178                                                                           "}\n"
16179                                                                           "\n";
16180         static const GLchar* tes = "#version 430 core\n"
16181                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16182                                                            "\n"
16183                                                            "layout(isolines, point_mode) in;\n"
16184                                                            "\n"
16185                                                            "in  vec4 tcs_tes[];\n"
16186                                                            "out vec4 tes_gs;\n"
16187                                                            "\n"
16188                                                            "void main()\n"
16189                                                            "{\n"
16190                                                            "    tes_gs = tcs_tes[0];\n"
16191                                                            "}\n"
16192                                                            "\n";
16193         static const GLchar* tes_tested = "#version 430 core\n"
16194                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16195                                                                           "\n"
16196                                                                           "layout(isolines, point_mode) in;\n"
16197                                                                           "\n"
16198                                                                           "VAR_DEFINITION"
16199                                                                           "\n"
16200                                                                           "in  vec4 tcs_tes[];\n"
16201                                                                           "out vec4 tes_gs;\n"
16202                                                                           "\n"
16203                                                                           "void main()\n"
16204                                                                           "{\n"
16205                                                                           "    vec4 result = tcs_tes[0];\n"
16206                                                                           "\n"
16207                                                                           "VARIABLE_USE"
16208                                                                           "\n"
16209                                                                           "    tes_gs += result;\n"
16210                                                                           "}\n"
16211                                                                           "\n";
16212         static const GLchar* vs = "#version 430 core\n"
16213                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16214                                                           "\n"
16215                                                           "in  vec4 in_vs;\n"
16216                                                           "out vec4 vs_tcs;\n"
16217                                                           "\n"
16218                                                           "void main()\n"
16219                                                           "{\n"
16220                                                           "    vs_tcs = in_vs;\n"
16221                                                           "}\n"
16222                                                           "\n";
16223         static const GLchar* vs_tested = "#version 430 core\n"
16224                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16225                                                                          "\n"
16226                                                                          "VAR_DEFINITION"
16227                                                                          "\n"
16228                                                                          "in  vec4 in_vs;\n"
16229                                                                          "out vec4 vs_tcs;\n"
16230                                                                          "\n"
16231                                                                          "void main()\n"
16232                                                                          "{\n"
16233                                                                          "    vec4 result = in_vs;\n"
16234                                                                          "\n"
16235                                                                          "VARIABLE_USE"
16236                                                                          "\n"
16237                                                                          "    vs_tcs += result;\n"
16238                                                                          "}\n"
16239                                                                          "\n";
16240
16241         std::string source;
16242         testCase&   test_case = m_test_cases[test_case_index];
16243
16244         if (test_case.m_stage == stage)
16245         {
16246                 const GLchar* array = "";
16247                 GLchar            buffer[16];
16248                 const GLchar* var_definition = 0;
16249                 const GLchar* direction          = "in ";
16250                 const GLchar* index                      = "";
16251                 size_t            position               = 0;
16252                 size_t            temp;
16253                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16254                 const GLchar* var_use   = 0;
16255
16256                 if (false == test_case.m_is_input)
16257                 {
16258                         direction = "out";
16259
16260                         if (false == test_case.m_is_array)
16261                         {
16262                                 switch (test_case.m_case)
16263                                 {
16264                                 case BLOCK:
16265                                         var_definition = block_definition_one;
16266                                         var_use            = member_output_use_one;
16267                                         break;
16268                                 case MATRIX:
16269                                         var_definition = matrix_definition_one;
16270                                         var_use            = matrix_output_use_one;
16271                                         break;
16272                                 case STRUCT:
16273                                         var_definition = struct_definition_one;
16274                                         var_use            = member_output_use_one;
16275                                         break;
16276                                 default:
16277                                         TCU_FAIL("Invalid enum");
16278                                 }
16279                         }
16280                         else
16281                         {
16282                                 switch (test_case.m_case)
16283                                 {
16284                                 case BLOCK:
16285                                         var_definition = block_definition_arr;
16286                                         var_use            = member_output_use_arr;
16287                                         break;
16288                                 case MATRIX:
16289                                         var_definition = matrix_definition_arr;
16290                                         var_use            = matrix_output_use_arr;
16291                                         break;
16292                                 case STRUCT:
16293                                         var_definition = struct_definition_arr;
16294                                         var_use            = member_output_use_arr;
16295                                         break;
16296                                 default:
16297                                         TCU_FAIL("Invalid enum");
16298                                 }
16299                         }
16300                 }
16301                 else
16302                 {
16303                         if (false == test_case.m_is_array)
16304                         {
16305                                 switch (test_case.m_case)
16306                                 {
16307                                 case BLOCK:
16308                                         var_definition = block_definition_one;
16309                                         var_use            = member_input_use_one;
16310                                         break;
16311                                 case MATRIX:
16312                                         var_definition = matrix_definition_one;
16313                                         var_use            = matrix_input_use_one;
16314                                         break;
16315                                 case STRUCT:
16316                                         var_definition = struct_definition_one;
16317                                         var_use            = member_input_use_one;
16318                                         break;
16319                                 default:
16320                                         TCU_FAIL("Invalid enum");
16321                                 }
16322                         }
16323                         else
16324                         {
16325                                 switch (test_case.m_case)
16326                                 {
16327                                 case BLOCK:
16328                                         var_definition = block_definition_arr;
16329                                         var_use            = member_input_use_arr;
16330                                         break;
16331                                 case MATRIX:
16332                                         var_definition = matrix_definition_arr;
16333                                         var_use            = matrix_input_use_arr;
16334                                         break;
16335                                 case STRUCT:
16336                                         var_definition = struct_definition_arr;
16337                                         var_use            = member_input_use_arr;
16338                                         break;
16339                                 default:
16340                                         TCU_FAIL("Invalid enum");
16341                                 }
16342                         }
16343                 }
16344
16345                 sprintf(buffer, "%d", test_case.m_component);
16346
16347                 switch (stage)
16348                 {
16349                 case Utils::Shader::FRAGMENT:
16350                         source = fs_tested;
16351                         break;
16352                 case Utils::Shader::GEOMETRY:
16353                         source = gs_tested;
16354                         array  = "[]";
16355                         index  = "[0]";
16356                         break;
16357                 case Utils::Shader::TESS_CTRL:
16358                         source = tcs_tested;
16359                         array  = "[]";
16360                         index  = "[gl_InvocationID]";
16361                         break;
16362                 case Utils::Shader::TESS_EVAL:
16363                         source = tes_tested;
16364                         array  = "[]";
16365                         index  = "[0]";
16366                         break;
16367                 case Utils::Shader::VERTEX:
16368                         source = vs_tested;
16369                         break;
16370                 default:
16371                         TCU_FAIL("Invalid enum");
16372                 }
16373
16374                 temp = position;
16375                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16376                 position = temp;
16377                 Utils::replaceToken("COMPONENT", position, buffer, source);
16378                 Utils::replaceToken("DIRECTION", position, direction, source);
16379                 Utils::replaceToken("ARRAY", position, array, source);
16380                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16381
16382                 Utils::replaceAllTokens("TYPE", type_name, source);
16383                 Utils::replaceAllTokens("INDEX", index, source);
16384         }
16385         else
16386         {
16387                 switch (stage)
16388                 {
16389                 case Utils::Shader::FRAGMENT:
16390                         source = fs;
16391                         break;
16392                 case Utils::Shader::GEOMETRY:
16393                         source = gs;
16394                         break;
16395                 case Utils::Shader::TESS_CTRL:
16396                         source = tcs;
16397                         break;
16398                 case Utils::Shader::TESS_EVAL:
16399                         source = tes;
16400                         break;
16401                 case Utils::Shader::VERTEX:
16402                         source = vs;
16403                         break;
16404                 default:
16405                         TCU_FAIL("Invalid enum");
16406                 }
16407         }
16408
16409         return source;
16410 }
16411
16412 /** Get description of test case
16413  *
16414  * @param test_case_index Index of test case
16415  *
16416  * @return Test case description
16417  **/
16418 std::string VaryingComponentOfInvalidTypeTest::getTestCaseName(GLuint test_case_index)
16419 {
16420         std::stringstream stream;
16421         testCase&                 test_case = m_test_cases[test_case_index];
16422
16423         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16424                    << " type: " << test_case.m_type.GetGLSLTypeName();
16425
16426         if (true == test_case.m_is_array)
16427         {
16428                 stream << "[1]";
16429         }
16430
16431         stream << ", direction: ";
16432
16433         if (true == test_case.m_is_input)
16434         {
16435                 stream << "input";
16436         }
16437         else
16438         {
16439                 stream << "output";
16440         }
16441
16442         stream << ", component: " << test_case.m_component;
16443
16444         return stream.str();
16445 }
16446
16447 /** Get number of test cases
16448  *
16449  * @return Number of test cases
16450  **/
16451 GLuint VaryingComponentOfInvalidTypeTest::getTestCaseNumber()
16452 {
16453         return static_cast<GLuint>(m_test_cases.size());
16454 }
16455
16456 /** Selects if "compute" stage is relevant for test
16457  *
16458  * @param ignored
16459  *
16460  * @return false
16461  **/
16462 bool VaryingComponentOfInvalidTypeTest::isComputeRelevant(GLuint /* test_case_index */)
16463 {
16464         return false;
16465 }
16466
16467 /** Prepare all test cases
16468  *
16469  **/
16470 void VaryingComponentOfInvalidTypeTest::testInit()
16471 {
16472         static const GLuint n_components_per_location = 4;
16473         const GLuint            n_types                                   = getTypesNumber();
16474
16475         for (GLuint i = 0; i < n_types; ++i)
16476         {
16477                 const Utils::Type& type                         = getType(i);
16478                 const GLuint       n_req_components = type.m_n_rows;
16479                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16480
16481                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16482                 {
16483                         if (Utils::Shader::COMPUTE == stage)
16484                         {
16485                                 continue;
16486                         }
16487
16488                         /* Use different CASE for matrices */
16489                         if (1 != type.m_n_columns)
16490                         {
16491                                 testCase test_case_in_arr = { MATRIX, valid_component, true, true, (Utils::Shader::STAGES)stage, type };
16492                                 testCase test_case_in_one = {
16493                                         MATRIX, valid_component, false, true, (Utils::Shader::STAGES)stage, type
16494                                 };
16495                                 testCase test_case_out_arr = {
16496                                         MATRIX, valid_component, true, false, (Utils::Shader::STAGES)stage, type
16497                                 };
16498                                 testCase test_case_out_one = {
16499                                         MATRIX, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16500                                 };
16501
16502                                 m_test_cases.push_back(test_case_in_arr);
16503                                 m_test_cases.push_back(test_case_in_one);
16504
16505                                 if (Utils::Shader::FRAGMENT != stage)
16506                                 {
16507                                         m_test_cases.push_back(test_case_out_arr);
16508                                         m_test_cases.push_back(test_case_out_one);
16509                                 }
16510                         }
16511                         else
16512                         {
16513                                 for (GLuint c = BLOCK; c < MAX_CASES; ++c)
16514                                 {
16515                                         testCase test_case_in_arr = { (CASES)c, valid_component, true, true, (Utils::Shader::STAGES)stage,
16516                                                                                                   type };
16517                                         testCase test_case_in_one = { (CASES)c, valid_component, false, true, (Utils::Shader::STAGES)stage,
16518                                                                                                   type };
16519                                         testCase test_case_out_arr = { (CASES)c, valid_component, true, false, (Utils::Shader::STAGES)stage,
16520                                                                                                    type };
16521                                         testCase test_case_out_one = {
16522                                                 (CASES)c, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16523                                         };
16524
16525                                         if (Utils::Shader::VERTEX != stage)
16526                                         {
16527                                                 m_test_cases.push_back(test_case_in_arr);
16528                                                 m_test_cases.push_back(test_case_in_one);
16529                                         }
16530
16531                                         if (Utils::Shader::FRAGMENT != stage)
16532                                         {
16533                                                 m_test_cases.push_back(test_case_out_arr);
16534                                                 m_test_cases.push_back(test_case_out_one);
16535                                         }
16536                                 }
16537                         }
16538                 }
16539         }
16540 }
16541
16542 /** Constructor
16543  *
16544  * @param context Test framework context
16545  **/
16546 InputComponentAliasingTest::InputComponentAliasingTest(deqp::Context& context)
16547         : NegativeTestBase(context, "input_component_aliasing",
16548                                            "Test verifies that compiler reports component aliasing as error")
16549 {
16550 }
16551
16552 /** Source for given test case and stage
16553  *
16554  * @param test_case_index Index of test case
16555  * @param stage           Shader stage
16556  *
16557  * @return Shader source
16558  **/
16559 std::string InputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16560 {
16561         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) FLAT in TYPE gohanARRAY;\n"
16562                                                                                   "layout (location = 1, component = COMPONENT) FLAT in TYPE gotenARRAY;\n";
16563         static const GLchar* test_one = "    if (TYPE(0) == gohanINDEX)\n"
16564                                                                         "    {\n"
16565                                                                         "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16566                                                                         "    }\n";
16567         static const GLchar* test_both = "    if (TYPE(0) == gohanINDEX)\n"
16568                                                                          "    {\n"
16569                                                                          "        result = vec4(goten.xxxx);\n"
16570                                                                          "    }\n";
16571         static const GLchar* fs = "#version 430 core\n"
16572                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16573                                                           "\n"
16574                                                           "in  vec4 gs_fs;\n"
16575                                                           "out vec4 fs_out;\n"
16576                                                           "\n"
16577                                                           "void main()\n"
16578                                                           "{\n"
16579                                                           "    fs_out = gs_fs;\n"
16580                                                           "}\n"
16581                                                           "\n";
16582         static const GLchar* fs_tested = "#version 430 core\n"
16583                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16584                                                                          "\n"
16585                                                                          "VAR_DEFINITION"
16586                                                                          "\n"
16587                                                                          "in  vec4 gs_fs;\n"
16588                                                                          "out vec4 fs_out;\n"
16589                                                                          "\n"
16590                                                                          "void main()\n"
16591                                                                          "{\n"
16592                                                                          "    vec4 result = gs_fs;\n"
16593                                                                          "\n"
16594                                                                          "VARIABLE_USE"
16595                                                                          "\n"
16596                                                                          "    fs_out += result;\n"
16597                                                                          "}\n"
16598                                                                          "\n";
16599         static const GLchar* gs = "#version 430 core\n"
16600                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16601                                                           "\n"
16602                                                           "layout(points)                           in;\n"
16603                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16604                                                           "\n"
16605                                                           "in  vec4 tes_gs[];\n"
16606                                                           "out vec4 gs_fs;\n"
16607                                                           "\n"
16608                                                           "void main()\n"
16609                                                           "{\n"
16610                                                           "    gs_fs = tes_gs[0];\n"
16611                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16612                                                           "    EmitVertex();\n"
16613                                                           "    gs_fs = tes_gs[0];\n"
16614                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16615                                                           "    EmitVertex();\n"
16616                                                           "    gs_fs = tes_gs[0];\n"
16617                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16618                                                           "    EmitVertex();\n"
16619                                                           "    gs_fs = tes_gs[0];\n"
16620                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16621                                                           "    EmitVertex();\n"
16622                                                           "}\n"
16623                                                           "\n";
16624         static const GLchar* gs_tested = "#version 430 core\n"
16625                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16626                                                                          "\n"
16627                                                                          "layout(points)                           in;\n"
16628                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16629                                                                          "\n"
16630                                                                          "VAR_DEFINITION"
16631                                                                          "\n"
16632                                                                          "in  vec4 tes_gs[];\n"
16633                                                                          "out vec4 gs_fs;\n"
16634                                                                          "\n"
16635                                                                          "void main()\n"
16636                                                                          "{\n"
16637                                                                          "    vec4 result = tes_gs[0];\n"
16638                                                                          "\n"
16639                                                                          "VARIABLE_USE"
16640                                                                          "\n"
16641                                                                          "    gs_fs = result;\n"
16642                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16643                                                                          "    EmitVertex();\n"
16644                                                                          "    gs_fs = result;\n"
16645                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16646                                                                          "    EmitVertex();\n"
16647                                                                          "    gs_fs = result;\n"
16648                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16649                                                                          "    EmitVertex();\n"
16650                                                                          "    gs_fs = result;\n"
16651                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16652                                                                          "    EmitVertex();\n"
16653                                                                          "}\n"
16654                                                                          "\n";
16655         static const GLchar* tcs = "#version 430 core\n"
16656                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16657                                                            "\n"
16658                                                            "layout(vertices = 1) out;\n"
16659                                                            "\n"
16660                                                            "in  vec4 vs_tcs[];\n"
16661                                                            "out vec4 tcs_tes[];\n"
16662                                                            "\n"
16663                                                            "void main()\n"
16664                                                            "{\n"
16665                                                            "\n"
16666                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16667                                                            "\n"
16668                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16669                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16670                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16671                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16672                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16673                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16674                                                            "}\n"
16675                                                            "\n";
16676         static const GLchar* tcs_tested = "#version 430 core\n"
16677                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16678                                                                           "\n"
16679                                                                           "layout(vertices = 1) out;\n"
16680                                                                           "\n"
16681                                                                           "VAR_DEFINITION"
16682                                                                           "\n"
16683                                                                           "in  vec4 vs_tcs[];\n"
16684                                                                           "out vec4 tcs_tes[];\n"
16685                                                                           "\n"
16686                                                                           "void main()\n"
16687                                                                           "{\n"
16688                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16689                                                                           "\n"
16690                                                                           "VARIABLE_USE"
16691                                                                           "\n"
16692                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16693                                                                           "\n"
16694                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16695                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16696                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16697                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16698                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16699                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16700                                                                           "}\n"
16701                                                                           "\n";
16702         static const GLchar* tes = "#version 430 core\n"
16703                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16704                                                            "\n"
16705                                                            "layout(isolines, point_mode) in;\n"
16706                                                            "\n"
16707                                                            "in  vec4 tcs_tes[];\n"
16708                                                            "out vec4 tes_gs;\n"
16709                                                            "\n"
16710                                                            "void main()\n"
16711                                                            "{\n"
16712                                                            "    tes_gs = tcs_tes[0];\n"
16713                                                            "}\n"
16714                                                            "\n";
16715         static const GLchar* tes_tested = "#version 430 core\n"
16716                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16717                                                                           "\n"
16718                                                                           "layout(isolines, point_mode) in;\n"
16719                                                                           "\n"
16720                                                                           "VAR_DEFINITION"
16721                                                                           "\n"
16722                                                                           "in  vec4 tcs_tes[];\n"
16723                                                                           "out vec4 tes_gs;\n"
16724                                                                           "\n"
16725                                                                           "void main()\n"
16726                                                                           "{\n"
16727                                                                           "    vec4 result = tcs_tes[0];\n"
16728                                                                           "\n"
16729                                                                           "VARIABLE_USE"
16730                                                                           "\n"
16731                                                                           "    tes_gs += result;\n"
16732                                                                           "}\n"
16733                                                                           "\n";
16734         static const GLchar* vs = "#version 430 core\n"
16735                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16736                                                           "\n"
16737                                                           "in  vec4 in_vs;\n"
16738                                                           "out vec4 vs_tcs;\n"
16739                                                           "\n"
16740                                                           "void main()\n"
16741                                                           "{\n"
16742                                                           "    vs_tcs = in_vs;\n"
16743                                                           "}\n"
16744                                                           "\n";
16745         static const GLchar* vs_tested = "#version 430 core\n"
16746                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16747                                                                          "\n"
16748                                                                          "VAR_DEFINITION"
16749                                                                          "\n"
16750                                                                          "in  vec4 in_vs;\n"
16751                                                                          "out vec4 vs_tcs;\n"
16752                                                                          "\n"
16753                                                                          "void main()\n"
16754                                                                          "{\n"
16755                                                                          "    vec4 result = in_vs;\n"
16756                                                                          "\n"
16757                                                                          "VARIABLE_USE"
16758                                                                          "\n"
16759                                                                          "    vs_tcs += result;\n"
16760                                                                          "}\n"
16761                                                                          "\n";
16762
16763         std::string source;
16764         testCase&   test_case = m_test_cases[test_case_index];
16765
16766         if (test_case.m_stage == stage)
16767         {
16768                 const GLchar* array = "";
16769                 GLchar            buffer_gohan[16];
16770                 GLchar            buffer_goten[16];
16771                 const GLchar* flat                = "";
16772                 const GLchar* index               = "";
16773                 const bool      is_flat_req = isFlatRequired(stage, test_case.m_type, Utils::Variable::VARYING_INPUT);
16774                 size_t            position      = 0;
16775                 size_t            temp;
16776                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16777                 const GLchar* var_use   = test_one;
16778
16779                 if (true == test_case.m_use_both)
16780                 {
16781                         var_use = test_both;
16782                 }
16783
16784                 if (true == is_flat_req)
16785                 {
16786                         flat = "flat";
16787                 }
16788
16789                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
16790                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
16791
16792                 switch (stage)
16793                 {
16794                 case Utils::Shader::FRAGMENT:
16795                         source = fs_tested;
16796                         break;
16797                 case Utils::Shader::GEOMETRY:
16798                         source = gs_tested;
16799                         array  = "[]";
16800                         index  = "[0]";
16801                         break;
16802                 case Utils::Shader::TESS_CTRL:
16803                         source = tcs_tested;
16804                         array  = "[]";
16805                         index  = "[gl_InvocationID]";
16806                         break;
16807                 case Utils::Shader::TESS_EVAL:
16808                         source = tes_tested;
16809                         array  = "[]";
16810                         index  = "[0]";
16811                         break;
16812                 case Utils::Shader::VERTEX:
16813                         source = vs_tested;
16814                         break;
16815                 default:
16816                         TCU_FAIL("Invalid enum");
16817                 }
16818
16819                 temp = position;
16820                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16821                 position = temp;
16822                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
16823                 Utils::replaceToken("ARRAY", position, array, source);
16824                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
16825                 Utils::replaceToken("ARRAY", position, array, source);
16826                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16827
16828                 Utils::replaceAllTokens("FLAT", flat, source);
16829                 Utils::replaceAllTokens("TYPE", type_name, source);
16830                 Utils::replaceAllTokens("INDEX", index, source);
16831         }
16832         else
16833         {
16834                 switch (stage)
16835                 {
16836                 case Utils::Shader::FRAGMENT:
16837                         source = fs;
16838                         break;
16839                 case Utils::Shader::GEOMETRY:
16840                         source = gs;
16841                         break;
16842                 case Utils::Shader::TESS_CTRL:
16843                         source = tcs;
16844                         break;
16845                 case Utils::Shader::TESS_EVAL:
16846                         source = tes;
16847                         break;
16848                 case Utils::Shader::VERTEX:
16849                         source = vs;
16850                         break;
16851                 default:
16852                         TCU_FAIL("Invalid enum");
16853                 }
16854         }
16855
16856         return source;
16857 }
16858
16859 /** Get description of test case
16860  *
16861  * @param test_case_index Index of test case
16862  *
16863  * @return Test case description
16864  **/
16865 std::string InputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
16866 {
16867         std::stringstream stream;
16868         testCase&                 test_case = m_test_cases[test_case_index];
16869
16870         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16871                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
16872                    << " & " << test_case.m_component_goten;
16873
16874         return stream.str();
16875 }
16876
16877 /** Get number of test cases
16878  *
16879  * @return Number of test cases
16880  **/
16881 GLuint InputComponentAliasingTest::getTestCaseNumber()
16882 {
16883         return static_cast<GLuint>(m_test_cases.size());
16884 }
16885
16886 /** Selects if "compute" stage is relevant for test
16887  *
16888  * @param ignored
16889  *
16890  * @return false
16891  **/
16892 bool InputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
16893 {
16894         return false;
16895 }
16896
16897 /** Selects if compilation failure is expected result
16898  *
16899  * @param test_case_index Index of test case
16900  *
16901  * @return false for VS that use only single variable, true otherwise
16902  **/
16903 bool InputComponentAliasingTest::isFailureExpected(GLuint test_case_index)
16904 {
16905         testCase& test_case = m_test_cases[test_case_index];
16906
16907         return !((Utils::Shader::VERTEX == test_case.m_stage) && (false == test_case.m_use_both));
16908 }
16909
16910 /** Prepare all test cases
16911  *
16912  **/
16913 void InputComponentAliasingTest::testInit()
16914 {
16915         static const GLuint n_components_per_location = 4;
16916         const GLuint            n_types                                   = getTypesNumber();
16917
16918         for (GLuint i = 0; i < n_types; ++i)
16919         {
16920                 const Utils::Type& type                         = getType(i);
16921                 const GLuint       n_req_components = type.m_n_rows;
16922                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16923
16924                 /* Skip matrices */
16925                 if (1 != type.m_n_columns)
16926                 {
16927                         continue;
16928                 }
16929
16930                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16931                 {
16932                         if (Utils::Shader::COMPUTE == stage)
16933                         {
16934                                 continue;
16935                         }
16936
16937                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
16938                         {
16939                                 const GLint first_aliasing = gohan - n_req_components + 1;
16940                                 const GLint last_aliasing  = gohan + n_req_components - 1;
16941
16942                                 const GLuint goten_start = std::max(0, first_aliasing);
16943                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
16944
16945                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
16946                                 {
16947                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type, false };
16948
16949                                         m_test_cases.push_back(test_case);
16950
16951                                         if (Utils::Shader::VERTEX == test_case.m_stage)
16952                                         {
16953                                                 test_case.m_use_both = true;
16954
16955                                                 m_test_cases.push_back(test_case);
16956                                         }
16957                                 }
16958                         }
16959                 }
16960         }
16961 }
16962
16963 /** Constructor
16964  *
16965  * @param context Test framework context
16966  **/
16967 OutputComponentAliasingTest::OutputComponentAliasingTest(deqp::Context& context)
16968         : NegativeTestBase(context, "output_component_aliasing",
16969                                            "Test verifies that compiler reports component aliasing as error")
16970 {
16971 }
16972
16973 /** Source for given test case and stage
16974  *
16975  * @param test_case_index Index of test case
16976  * @param stage           Shader stage
16977  *
16978  * @return Shader source
16979  **/
16980 std::string OutputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16981 {
16982         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) flat out TYPE gohanARRAY;\n"
16983                                                                                   "layout (location = 1, component = COMPONENT) flat out TYPE gotenARRAY;\n";
16984         static const GLchar* l_test = "    gohanINDEX = TYPE(1);\n"
16985                                                                   "    gotenINDEX = TYPE(0);\n";
16986         static const GLchar* fs = "#version 430 core\n"
16987                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16988                                                           "\n"
16989                                                           "in  vec4 gs_fs;\n"
16990                                                           "out vec4 fs_out;\n"
16991                                                           "\n"
16992                                                           "void main()\n"
16993                                                           "{\n"
16994                                                           "    fs_out = gs_fs;\n"
16995                                                           "}\n"
16996                                                           "\n";
16997         static const GLchar* fs_tested = "#version 430 core\n"
16998                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16999                                                                          "\n"
17000                                                                          "VAR_DEFINITION"
17001                                                                          "\n"
17002                                                                          "in  vec4 gs_fs;\n"
17003                                                                          "out vec4 fs_out;\n"
17004                                                                          "\n"
17005                                                                          "void main()\n"
17006                                                                          "{\n"
17007                                                                          "    vec4 result = gs_fs;\n"
17008                                                                          "\n"
17009                                                                          "VARIABLE_USE"
17010                                                                          "\n"
17011                                                                          "    fs_out += result;\n"
17012                                                                          "}\n"
17013                                                                          "\n";
17014         static const GLchar* gs = "#version 430 core\n"
17015                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17016                                                           "\n"
17017                                                           "layout(points)                           in;\n"
17018                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17019                                                           "\n"
17020                                                           "in  vec4 tes_gs[];\n"
17021                                                           "out vec4 gs_fs;\n"
17022                                                           "\n"
17023                                                           "void main()\n"
17024                                                           "{\n"
17025                                                           "    gs_fs = tes_gs[0];\n"
17026                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17027                                                           "    EmitVertex();\n"
17028                                                           "    gs_fs = tes_gs[0];\n"
17029                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17030                                                           "    EmitVertex();\n"
17031                                                           "    gs_fs = tes_gs[0];\n"
17032                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17033                                                           "    EmitVertex();\n"
17034                                                           "    gs_fs = tes_gs[0];\n"
17035                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17036                                                           "    EmitVertex();\n"
17037                                                           "}\n"
17038                                                           "\n";
17039         static const GLchar* gs_tested = "#version 430 core\n"
17040                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17041                                                                          "\n"
17042                                                                          "layout(points)                           in;\n"
17043                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17044                                                                          "\n"
17045                                                                          "VAR_DEFINITION"
17046                                                                          "\n"
17047                                                                          "in  vec4 tes_gs[];\n"
17048                                                                          "out vec4 gs_fs;\n"
17049                                                                          "\n"
17050                                                                          "void main()\n"
17051                                                                          "{\n"
17052                                                                          "    vec4 result = tes_gs[0];\n"
17053                                                                          "\n"
17054                                                                          "VARIABLE_USE"
17055                                                                          "\n"
17056                                                                          "    gs_fs = result;\n"
17057                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17058                                                                          "    EmitVertex();\n"
17059                                                                          "    gs_fs = result;\n"
17060                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17061                                                                          "    EmitVertex();\n"
17062                                                                          "    gs_fs = result;\n"
17063                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17064                                                                          "    EmitVertex();\n"
17065                                                                          "    gs_fs = result;\n"
17066                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17067                                                                          "    EmitVertex();\n"
17068                                                                          "}\n"
17069                                                                          "\n";
17070         static const GLchar* tcs = "#version 430 core\n"
17071                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17072                                                            "\n"
17073                                                            "layout(vertices = 1) out;\n"
17074                                                            "\n"
17075                                                            "in  vec4 vs_tcs[];\n"
17076                                                            "out vec4 tcs_tes[];\n"
17077                                                            "\n"
17078                                                            "void main()\n"
17079                                                            "{\n"
17080                                                            "\n"
17081                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17082                                                            "\n"
17083                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17084                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17085                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17086                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17087                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17088                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17089                                                            "}\n"
17090                                                            "\n";
17091         static const GLchar* tcs_tested = "#version 430 core\n"
17092                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17093                                                                           "\n"
17094                                                                           "layout(vertices = 1) out;\n"
17095                                                                           "\n"
17096                                                                           "VAR_DEFINITION"
17097                                                                           "\n"
17098                                                                           "in  vec4 vs_tcs[];\n"
17099                                                                           "out vec4 tcs_tes[];\n"
17100                                                                           "\n"
17101                                                                           "void main()\n"
17102                                                                           "{\n"
17103                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17104                                                                           "\n"
17105                                                                           "VARIABLE_USE"
17106                                                                           "\n"
17107                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17108                                                                           "\n"
17109                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17110                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17111                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17112                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17113                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17114                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17115                                                                           "}\n"
17116                                                                           "\n";
17117         static const GLchar* tes = "#version 430 core\n"
17118                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17119                                                            "\n"
17120                                                            "layout(isolines, point_mode) in;\n"
17121                                                            "\n"
17122                                                            "in  vec4 tcs_tes[];\n"
17123                                                            "out vec4 tes_gs;\n"
17124                                                            "\n"
17125                                                            "void main()\n"
17126                                                            "{\n"
17127                                                            "    tes_gs = tcs_tes[0];\n"
17128                                                            "}\n"
17129                                                            "\n";
17130         static const GLchar* tes_tested = "#version 430 core\n"
17131                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17132                                                                           "\n"
17133                                                                           "layout(isolines, point_mode) in;\n"
17134                                                                           "\n"
17135                                                                           "VAR_DEFINITION"
17136                                                                           "\n"
17137                                                                           "in  vec4 tcs_tes[];\n"
17138                                                                           "out vec4 tes_gs;\n"
17139                                                                           "\n"
17140                                                                           "void main()\n"
17141                                                                           "{\n"
17142                                                                           "    vec4 result = tcs_tes[0];\n"
17143                                                                           "\n"
17144                                                                           "VARIABLE_USE"
17145                                                                           "\n"
17146                                                                           "    tes_gs += result;\n"
17147                                                                           "}\n"
17148                                                                           "\n";
17149         static const GLchar* vs = "#version 430 core\n"
17150                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17151                                                           "\n"
17152                                                           "in  vec4 in_vs;\n"
17153                                                           "out vec4 vs_tcs;\n"
17154                                                           "\n"
17155                                                           "void main()\n"
17156                                                           "{\n"
17157                                                           "    vs_tcs = in_vs;\n"
17158                                                           "}\n"
17159                                                           "\n";
17160         static const GLchar* vs_tested = "#version 430 core\n"
17161                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17162                                                                          "\n"
17163                                                                          "VAR_DEFINITION"
17164                                                                          "\n"
17165                                                                          "in  vec4 in_vs;\n"
17166                                                                          "out vec4 vs_tcs;\n"
17167                                                                          "\n"
17168                                                                          "void main()\n"
17169                                                                          "{\n"
17170                                                                          "    vec4 result = in_vs;\n"
17171                                                                          "\n"
17172                                                                          "VARIABLE_USE"
17173                                                                          "\n"
17174                                                                          "    vs_tcs += result;\n"
17175                                                                          "}\n"
17176                                                                          "\n";
17177
17178         std::string source;
17179         testCase&   test_case = m_test_cases[test_case_index];
17180
17181         if (test_case.m_stage == stage)
17182         {
17183                 const GLchar* array = "";
17184                 GLchar            buffer_gohan[16];
17185                 GLchar            buffer_goten[16];
17186                 const GLchar* index     = "";
17187                 size_t            position = 0;
17188                 size_t            temp;
17189                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
17190
17191                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17192                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17193
17194                 switch (stage)
17195                 {
17196                 case Utils::Shader::FRAGMENT:
17197                         source = fs_tested;
17198                         break;
17199                 case Utils::Shader::GEOMETRY:
17200                         source = gs_tested;
17201                         array  = "[]";
17202                         index  = "[0]";
17203                         break;
17204                 case Utils::Shader::TESS_CTRL:
17205                         source = tcs_tested;
17206                         array  = "[]";
17207                         index  = "[gl_InvocationID]";
17208                         break;
17209                 case Utils::Shader::TESS_EVAL:
17210                         source = tes_tested;
17211                         array  = "[]";
17212                         index  = "[0]";
17213                         break;
17214                 case Utils::Shader::VERTEX:
17215                         source = vs_tested;
17216                         break;
17217                 default:
17218                         TCU_FAIL("Invalid enum");
17219                 }
17220
17221                 temp = position;
17222                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17223                 position = temp;
17224                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17225                 Utils::replaceToken("ARRAY", position, array, source);
17226                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17227                 Utils::replaceToken("ARRAY", position, array, source);
17228                 Utils::replaceToken("VARIABLE_USE", position, l_test, source);
17229
17230                 Utils::replaceAllTokens("TYPE", type_name, source);
17231                 Utils::replaceAllTokens("INDEX", index, source);
17232         }
17233         else
17234         {
17235                 switch (stage)
17236                 {
17237                 case Utils::Shader::FRAGMENT:
17238                         source = fs;
17239                         break;
17240                 case Utils::Shader::GEOMETRY:
17241                         source = gs;
17242                         break;
17243                 case Utils::Shader::TESS_CTRL:
17244                         source = tcs;
17245                         break;
17246                 case Utils::Shader::TESS_EVAL:
17247                         source = tes;
17248                         break;
17249                 case Utils::Shader::VERTEX:
17250                         source = vs;
17251                         break;
17252                 default:
17253                         TCU_FAIL("Invalid enum");
17254                 }
17255         }
17256
17257         return source;
17258 }
17259
17260 /** Get description of test case
17261  *
17262  * @param test_case_index Index of test case
17263  *
17264  * @return Test case description
17265  **/
17266 std::string OutputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
17267 {
17268         std::stringstream stream;
17269         testCase&                 test_case = m_test_cases[test_case_index];
17270
17271         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
17272                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
17273                    << " & " << test_case.m_component_goten;
17274
17275         return stream.str();
17276 }
17277
17278 /** Get number of test cases
17279  *
17280  * @return Number of test cases
17281  **/
17282 GLuint OutputComponentAliasingTest::getTestCaseNumber()
17283 {
17284         return static_cast<GLuint>(m_test_cases.size());
17285 }
17286
17287 /** Selects if "compute" stage is relevant for test
17288  *
17289  * @param ignored
17290  *
17291  * @return false
17292  **/
17293 bool OutputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
17294 {
17295         return false;
17296 }
17297
17298 /** Prepare all test cases
17299  *
17300  **/
17301 void OutputComponentAliasingTest::testInit()
17302 {
17303         static const GLuint n_components_per_location = 4;
17304         const GLuint            n_types                                   = getTypesNumber();
17305
17306         for (GLuint i = 0; i < n_types; ++i)
17307         {
17308                 const Utils::Type& type                         = getType(i);
17309                 const GLuint       n_req_components = type.m_n_rows;
17310                 const GLuint       valid_component  = n_components_per_location - n_req_components;
17311
17312                 /* Skip matrices */
17313                 if (1 != type.m_n_columns)
17314                 {
17315                         continue;
17316                 }
17317
17318                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17319                 {
17320                         if (Utils::Shader::COMPUTE == stage)
17321                         {
17322                                 continue;
17323                         }
17324
17325                         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Type::Double == type.m_basic_type))
17326                         {
17327                                 continue;
17328                         }
17329
17330                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
17331                         {
17332                                 const GLint first_aliasing = gohan - n_req_components + 1;
17333                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17334
17335                                 const GLuint goten_start = std::max(0, first_aliasing);
17336                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
17337
17338                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17339                                 {
17340                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type };
17341
17342                                         m_test_cases.push_back(test_case);
17343                                 }
17344                         }
17345                 }
17346         }
17347 }
17348
17349 /** Constructor
17350  *
17351  * @param context Test framework context
17352  **/
17353 VaryingLocationAliasingWithMixedTypesTest::VaryingLocationAliasingWithMixedTypesTest(deqp::Context& context)
17354         : NegativeTestBase(context, "varying_location_aliasing_with_mixed_types",
17355                                            "Test verifies that compiler reports error when float/int types are mixed at one location")
17356 {
17357 }
17358
17359 /** Source for given test case and stage
17360  *
17361  * @param test_case_index Index of test case
17362  * @param stage           Shader stage
17363  *
17364  * @return Shader source
17365  **/
17366 std::string VaryingLocationAliasingWithMixedTypesTest::getShaderSource(GLuint                            test_case_index,
17367                                                                                                                                            Utils::Shader::STAGES stage)
17368 {
17369         static const GLchar* var_definition =
17370                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gohanARRAY;\n"
17371                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gotenARRAY;\n";
17372         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17373                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17374                                                                          "    {\n"
17375                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17376                                                                          "    }\n";
17377         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17378                                                                           "    gotenINDEX = TYPE(1);\n"
17379                                                                           "    if (vec4(0) == result)\n"
17380                                                                           "    {\n"
17381                                                                           "        gohanINDEX = TYPE(1);\n"
17382                                                                           "        gotenINDEX = TYPE(0);\n"
17383                                                                           "    }\n";
17384         static const GLchar* fs = "#version 430 core\n"
17385                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17386                                                           "\n"
17387                                                           "in  vec4 gs_fs;\n"
17388                                                           "out vec4 fs_out;\n"
17389                                                           "\n"
17390                                                           "void main()\n"
17391                                                           "{\n"
17392                                                           "    fs_out = gs_fs;\n"
17393                                                           "}\n"
17394                                                           "\n";
17395         static const GLchar* fs_tested = "#version 430 core\n"
17396                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17397                                                                          "\n"
17398                                                                          "VAR_DEFINITION"
17399                                                                          "\n"
17400                                                                          "in  vec4 gs_fs;\n"
17401                                                                          "out vec4 fs_out;\n"
17402                                                                          "\n"
17403                                                                          "void main()\n"
17404                                                                          "{\n"
17405                                                                          "    vec4 result = gs_fs;\n"
17406                                                                          "\n"
17407                                                                          "VARIABLE_USE"
17408                                                                          "\n"
17409                                                                          "    fs_out += result;\n"
17410                                                                          "}\n"
17411                                                                          "\n";
17412         static const GLchar* gs = "#version 430 core\n"
17413                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17414                                                           "\n"
17415                                                           "layout(points)                           in;\n"
17416                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17417                                                           "\n"
17418                                                           "in  vec4 tes_gs[];\n"
17419                                                           "out vec4 gs_fs;\n"
17420                                                           "\n"
17421                                                           "void main()\n"
17422                                                           "{\n"
17423                                                           "    gs_fs = tes_gs[0];\n"
17424                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17425                                                           "    EmitVertex();\n"
17426                                                           "    gs_fs = tes_gs[0];\n"
17427                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17428                                                           "    EmitVertex();\n"
17429                                                           "    gs_fs = tes_gs[0];\n"
17430                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17431                                                           "    EmitVertex();\n"
17432                                                           "    gs_fs = tes_gs[0];\n"
17433                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17434                                                           "    EmitVertex();\n"
17435                                                           "}\n"
17436                                                           "\n";
17437         static const GLchar* gs_tested = "#version 430 core\n"
17438                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17439                                                                          "\n"
17440                                                                          "layout(points)                           in;\n"
17441                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17442                                                                          "\n"
17443                                                                          "VAR_DEFINITION"
17444                                                                          "\n"
17445                                                                          "in  vec4 tes_gs[];\n"
17446                                                                          "out vec4 gs_fs;\n"
17447                                                                          "\n"
17448                                                                          "void main()\n"
17449                                                                          "{\n"
17450                                                                          "    vec4 result = tes_gs[0];\n"
17451                                                                          "\n"
17452                                                                          "VARIABLE_USE"
17453                                                                          "\n"
17454                                                                          "    gs_fs = result;\n"
17455                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17456                                                                          "    EmitVertex();\n"
17457                                                                          "    gs_fs = result;\n"
17458                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17459                                                                          "    EmitVertex();\n"
17460                                                                          "    gs_fs = result;\n"
17461                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17462                                                                          "    EmitVertex();\n"
17463                                                                          "    gs_fs = result;\n"
17464                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17465                                                                          "    EmitVertex();\n"
17466                                                                          "}\n"
17467                                                                          "\n";
17468         static const GLchar* tcs = "#version 430 core\n"
17469                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17470                                                            "\n"
17471                                                            "layout(vertices = 1) out;\n"
17472                                                            "\n"
17473                                                            "in  vec4 vs_tcs[];\n"
17474                                                            "out vec4 tcs_tes[];\n"
17475                                                            "\n"
17476                                                            "void main()\n"
17477                                                            "{\n"
17478                                                            "\n"
17479                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17480                                                            "\n"
17481                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17482                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17483                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17484                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17485                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17486                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17487                                                            "}\n"
17488                                                            "\n";
17489         static const GLchar* tcs_tested = "#version 430 core\n"
17490                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17491                                                                           "\n"
17492                                                                           "layout(vertices = 1) out;\n"
17493                                                                           "\n"
17494                                                                           "VAR_DEFINITION"
17495                                                                           "\n"
17496                                                                           "in  vec4 vs_tcs[];\n"
17497                                                                           "out vec4 tcs_tes[];\n"
17498                                                                           "\n"
17499                                                                           "void main()\n"
17500                                                                           "{\n"
17501                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17502                                                                           "\n"
17503                                                                           "VARIABLE_USE"
17504                                                                           "\n"
17505                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17506                                                                           "\n"
17507                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17508                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17509                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17510                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17511                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17512                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17513                                                                           "}\n"
17514                                                                           "\n";
17515         static const GLchar* tes = "#version 430 core\n"
17516                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17517                                                            "\n"
17518                                                            "layout(isolines, point_mode) in;\n"
17519                                                            "\n"
17520                                                            "in  vec4 tcs_tes[];\n"
17521                                                            "out vec4 tes_gs;\n"
17522                                                            "\n"
17523                                                            "void main()\n"
17524                                                            "{\n"
17525                                                            "    tes_gs = tcs_tes[0];\n"
17526                                                            "}\n"
17527                                                            "\n";
17528         static const GLchar* tes_tested = "#version 430 core\n"
17529                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17530                                                                           "\n"
17531                                                                           "layout(isolines, point_mode) in;\n"
17532                                                                           "\n"
17533                                                                           "VAR_DEFINITION"
17534                                                                           "\n"
17535                                                                           "in  vec4 tcs_tes[];\n"
17536                                                                           "out vec4 tes_gs;\n"
17537                                                                           "\n"
17538                                                                           "void main()\n"
17539                                                                           "{\n"
17540                                                                           "    vec4 result = tcs_tes[0];\n"
17541                                                                           "\n"
17542                                                                           "VARIABLE_USE"
17543                                                                           "\n"
17544                                                                           "    tes_gs += result;\n"
17545                                                                           "}\n"
17546                                                                           "\n";
17547         static const GLchar* vs = "#version 430 core\n"
17548                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17549                                                           "\n"
17550                                                           "in  vec4 in_vs;\n"
17551                                                           "out vec4 vs_tcs;\n"
17552                                                           "\n"
17553                                                           "void main()\n"
17554                                                           "{\n"
17555                                                           "    vs_tcs = in_vs;\n"
17556                                                           "}\n"
17557                                                           "\n";
17558         static const GLchar* vs_tested = "#version 430 core\n"
17559                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17560                                                                          "\n"
17561                                                                          "VAR_DEFINITION"
17562                                                                          "\n"
17563                                                                          "in  vec4 in_vs;\n"
17564                                                                          "out vec4 vs_tcs;\n"
17565                                                                          "\n"
17566                                                                          "void main()\n"
17567                                                                          "{\n"
17568                                                                          "    vec4 result = in_vs;\n"
17569                                                                          "\n"
17570                                                                          "VARIABLE_USE"
17571                                                                          "\n"
17572                                                                          "    vs_tcs += result;\n"
17573                                                                          "}\n"
17574                                                                          "\n";
17575
17576         std::string source;
17577         testCase&   test_case = m_test_cases[test_case_index];
17578
17579         if (test_case.m_stage == stage)
17580         {
17581                 const GLchar*                    array = "";
17582                 GLchar                                   buffer_gohan[16];
17583                 GLchar                                   buffer_goten[16];
17584                 const GLchar*                    direction  = "in ";
17585                 const GLchar*                    flat_gohan = "";
17586                 const GLchar*                    flat_goten = "";
17587                 const GLchar*                    index          = "";
17588                 size_t                                   position   = 0;
17589                 size_t                                   temp;
17590                 const GLchar*                    type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
17591                 const GLchar*                    type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
17592                 Utils::Variable::STORAGE storage                 = Utils::Variable::VARYING_INPUT;
17593                 const GLchar*                    var_use                 = input_use;
17594
17595                 if (false == test_case.m_is_input)
17596                 {
17597                         direction = "out";
17598                         storage   = Utils::Variable::VARYING_OUTPUT;
17599                         var_use   = output_use;
17600                 }
17601
17602                 if (true == isFlatRequired(stage, test_case.m_type_gohan, storage))
17603                 {
17604                         flat_gohan = "flat";
17605                 }
17606
17607                 if (true == isFlatRequired(stage, test_case.m_type_goten, storage))
17608                 {
17609                         flat_goten = "flat";
17610                 }
17611
17612                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17613                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17614
17615                 switch (stage)
17616                 {
17617                 case Utils::Shader::FRAGMENT:
17618                         source = fs_tested;
17619                         break;
17620                 case Utils::Shader::GEOMETRY:
17621                         source = gs_tested;
17622                         array  = "[]";
17623                         index  = "[0]";
17624                         break;
17625                 case Utils::Shader::TESS_CTRL:
17626                         source = tcs_tested;
17627                         array  = "[]";
17628                         index  = "[gl_InvocationID]";
17629                         break;
17630                 case Utils::Shader::TESS_EVAL:
17631                         source = tes_tested;
17632                         array  = "[]";
17633                         index  = "[0]";
17634                         break;
17635                 case Utils::Shader::VERTEX:
17636                         source = vs_tested;
17637                         break;
17638                 default:
17639                         TCU_FAIL("Invalid enum");
17640                 }
17641
17642                 temp = position;
17643                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17644                 position = temp;
17645                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17646                 Utils::replaceToken("FLAT", position, flat_gohan, source);
17647                 Utils::replaceToken("DIRECTION", position, direction, source);
17648                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
17649                 Utils::replaceToken("ARRAY", position, array, source);
17650                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17651                 Utils::replaceToken("FLAT", position, flat_goten, source);
17652                 Utils::replaceToken("DIRECTION", position, direction, source);
17653                 Utils::replaceToken("TYPE", position, type_goten_name, source);
17654                 Utils::replaceToken("ARRAY", position, array, source);
17655
17656                 temp = position;
17657                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
17658                 position = temp;
17659                 if (true == test_case.m_is_input)
17660                 {
17661                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17662                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17663                 }
17664                 else
17665                 {
17666                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17667                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17668                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17669                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17670                 }
17671
17672                 Utils::replaceAllTokens("INDEX", index, source);
17673         }
17674         else
17675         {
17676                 switch (stage)
17677                 {
17678                 case Utils::Shader::FRAGMENT:
17679                         source = fs;
17680                         break;
17681                 case Utils::Shader::GEOMETRY:
17682                         source = gs;
17683                         break;
17684                 case Utils::Shader::TESS_CTRL:
17685                         source = tcs;
17686                         break;
17687                 case Utils::Shader::TESS_EVAL:
17688                         source = tes;
17689                         break;
17690                 case Utils::Shader::VERTEX:
17691                         source = vs;
17692                         break;
17693                 default:
17694                         TCU_FAIL("Invalid enum");
17695                 }
17696         }
17697
17698         return source;
17699 }
17700
17701 /** Get description of test case
17702  *
17703  * @param test_case_index Index of test case
17704  *
17705  * @return Test case description
17706  **/
17707 std::string VaryingLocationAliasingWithMixedTypesTest::getTestCaseName(GLuint test_case_index)
17708 {
17709         std::stringstream stream;
17710         testCase&                 test_case = m_test_cases[test_case_index];
17711
17712         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
17713                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
17714                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
17715
17716         if (true == test_case.m_is_input)
17717         {
17718                 stream << "input";
17719         }
17720         else
17721         {
17722                 stream << "output";
17723         }
17724
17725         return stream.str();
17726 }
17727
17728 /** Get number of test cases
17729  *
17730  * @return Number of test cases
17731  **/
17732 GLuint VaryingLocationAliasingWithMixedTypesTest::getTestCaseNumber()
17733 {
17734         return static_cast<GLuint>(m_test_cases.size());
17735 }
17736
17737 /** Selects if "compute" stage is relevant for test
17738  *
17739  * @param ignored
17740  *
17741  * @return false
17742  **/
17743 bool VaryingLocationAliasingWithMixedTypesTest::isComputeRelevant(GLuint /* test_case_index */)
17744 {
17745         return false;
17746 }
17747
17748 /** Prepare all test cases
17749  *
17750  **/
17751 void VaryingLocationAliasingWithMixedTypesTest::testInit()
17752 {
17753         static const GLuint n_components_per_location = 4;
17754         const GLuint            n_types                                   = getTypesNumber();
17755
17756         for (GLuint i = 0; i < n_types; ++i)
17757         {
17758                 const Utils::Type& type_gohan              = getType(i);
17759                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
17760
17761                 /* Skip matrices */
17762                 if (1 != type_gohan.m_n_columns)
17763                 {
17764                         continue;
17765                 }
17766
17767                 for (GLuint j = 0; j < n_types; ++j)
17768                 {
17769                         const Utils::Type& type_goten              = getType(j);
17770                         const bool                 is_float_type_goten = isFloatType(type_goten);
17771
17772                         /* Skip matrices */
17773                         if (1 != type_goten.m_n_columns)
17774                         {
17775                                 continue;
17776                         }
17777
17778                         /* Skip valid combinations */
17779                         if (is_float_type_gohan == is_float_type_goten)
17780                         {
17781                                 continue;
17782                         }
17783
17784                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
17785                         const GLuint n_req_components_goten = type_goten.m_n_rows;
17786                         const GLuint valid_component_gohan  = n_components_per_location - n_req_components_gohan;
17787                         const GLuint valid_component_goten  = n_components_per_location - n_req_components_goten;
17788
17789                         /* Skip pairs that cannot fit into one location */
17790                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
17791                         {
17792                                 continue;
17793                         }
17794
17795                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17796                         {
17797                                 /* Skip compute shader */
17798                                 if (Utils::Shader::COMPUTE == stage)
17799                                 {
17800                                         continue;
17801                                 }
17802
17803                                 for (GLuint gohan = 0; gohan <= valid_component_gohan; ++gohan)
17804                                 {
17805                                         const GLint first_aliasing = gohan - n_req_components_goten + 1;
17806                                         const GLint last_aliasing  = gohan + n_req_components_gohan - 1;
17807
17808                                         const GLuint goten_lower_limit = std::max(0, first_aliasing);
17809                                         const GLuint goten_upper_limit = last_aliasing + 1;
17810
17811                                         /* Compoennets before gohan */
17812                                         for (GLuint goten = 0; goten < goten_lower_limit; ++goten)
17813                                         {
17814                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17815                                                                                                   type_gohan, type_goten };
17816                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17817                                                                                                    type_gohan, type_goten };
17818
17819                                                 m_test_cases.push_back(test_case_in);
17820
17821                                                 /* Skip double outputs in fragment shader */
17822                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17823                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17824                                                 {
17825                                                         m_test_cases.push_back(test_case_out);
17826                                                 }
17827                                         }
17828
17829                                         /* Components after gohan */
17830                                         for (GLuint goten = goten_upper_limit; goten <= valid_component_goten; ++goten)
17831                                         {
17832                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17833                                                                                                   type_gohan, type_goten };
17834                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17835                                                                                                    type_gohan, type_goten };
17836
17837                                                 m_test_cases.push_back(test_case_in);
17838
17839                                                 /* Skip double outputs in fragment shader */
17840                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17841                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17842                                                 {
17843                                                         m_test_cases.push_back(test_case_out);
17844                                                 }
17845                                         }
17846                                 }
17847                         }
17848                 }
17849         }
17850 }
17851
17852 /** Check if given type is float
17853  *
17854  * @param type Type in question
17855  *
17856  * @return true if tpye is float, false otherwise
17857  **/
17858 bool VaryingLocationAliasingWithMixedTypesTest::isFloatType(const Utils::Type& type)
17859 {
17860         bool is_float = false;
17861
17862         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
17863         {
17864                 is_float = true;
17865         }
17866
17867         return is_float;
17868 }
17869
17870 /** Constructor
17871  *
17872  * @param context Test framework context
17873  **/
17874 VaryingLocationAliasingWithMixedInterpolationTest::VaryingLocationAliasingWithMixedInterpolationTest(
17875         deqp::Context& context)
17876         : NegativeTestBase(
17877                   context, "varying_location_aliasing_with_mixed_interpolation",
17878                   "Test verifies that compiler reports error when interpolation qualifiers are mixed at one location")
17879 {
17880 }
17881
17882 /** Source for given test case and stage
17883  *
17884  * @param test_case_index Index of test case
17885  * @param stage           Shader stage
17886  *
17887  * @return Shader source
17888  **/
17889 std::string VaryingLocationAliasingWithMixedInterpolationTest::getShaderSource(GLuint                            test_case_index,
17890                                                                                                                                                            Utils::Shader::STAGES stage)
17891 {
17892         static const GLchar* var_definition =
17893                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
17894                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
17895         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17896                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17897                                                                          "    {\n"
17898                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17899                                                                          "    }\n";
17900         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17901                                                                           "    gotenINDEX = TYPE(1);\n"
17902                                                                           "    if (vec4(0) == result)\n"
17903                                                                           "    {\n"
17904                                                                           "        gohanINDEX = TYPE(1);\n"
17905                                                                           "        gotenINDEX = TYPE(0);\n"
17906                                                                           "    }\n";
17907         static const GLchar* fs = "#version 430 core\n"
17908                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17909                                                           "\n"
17910                                                           "in  vec4 gs_fs;\n"
17911                                                           "out vec4 fs_out;\n"
17912                                                           "\n"
17913                                                           "void main()\n"
17914                                                           "{\n"
17915                                                           "    fs_out = gs_fs;\n"
17916                                                           "}\n"
17917                                                           "\n";
17918         static const GLchar* fs_tested = "#version 430 core\n"
17919                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17920                                                                          "\n"
17921                                                                          "VAR_DEFINITION"
17922                                                                          "\n"
17923                                                                          "in  vec4 gs_fs;\n"
17924                                                                          "out vec4 fs_out;\n"
17925                                                                          "\n"
17926                                                                          "void main()\n"
17927                                                                          "{\n"
17928                                                                          "    vec4 result = gs_fs;\n"
17929                                                                          "\n"
17930                                                                          "VARIABLE_USE"
17931                                                                          "\n"
17932                                                                          "    fs_out = result;\n"
17933                                                                          "}\n"
17934                                                                          "\n";
17935         static const GLchar* gs = "#version 430 core\n"
17936                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17937                                                           "\n"
17938                                                           "layout(points)                           in;\n"
17939                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17940                                                           "\n"
17941                                                           "in  vec4 tes_gs[];\n"
17942                                                           "out vec4 gs_fs;\n"
17943                                                           "\n"
17944                                                           "void main()\n"
17945                                                           "{\n"
17946                                                           "    gs_fs = tes_gs[0];\n"
17947                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17948                                                           "    EmitVertex();\n"
17949                                                           "    gs_fs = tes_gs[0];\n"
17950                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17951                                                           "    EmitVertex();\n"
17952                                                           "    gs_fs = tes_gs[0];\n"
17953                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17954                                                           "    EmitVertex();\n"
17955                                                           "    gs_fs = tes_gs[0];\n"
17956                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17957                                                           "    EmitVertex();\n"
17958                                                           "}\n"
17959                                                           "\n";
17960         static const GLchar* gs_tested = "#version 430 core\n"
17961                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17962                                                                          "\n"
17963                                                                          "layout(points)                           in;\n"
17964                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17965                                                                          "\n"
17966                                                                          "VAR_DEFINITION"
17967                                                                          "\n"
17968                                                                          "in  vec4 tes_gs[];\n"
17969                                                                          "out vec4 gs_fs;\n"
17970                                                                          "\n"
17971                                                                          "void main()\n"
17972                                                                          "{\n"
17973                                                                          "    vec4 result = tes_gs[0];\n"
17974                                                                          "\n"
17975                                                                          "VARIABLE_USE"
17976                                                                          "\n"
17977                                                                          "    gs_fs = result;\n"
17978                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17979                                                                          "    EmitVertex();\n"
17980                                                                          "    gs_fs = result;\n"
17981                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17982                                                                          "    EmitVertex();\n"
17983                                                                          "    gs_fs = result;\n"
17984                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17985                                                                          "    EmitVertex();\n"
17986                                                                          "    gs_fs = result;\n"
17987                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17988                                                                          "    EmitVertex();\n"
17989                                                                          "}\n"
17990                                                                          "\n";
17991         static const GLchar* tcs = "#version 430 core\n"
17992                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17993                                                            "\n"
17994                                                            "layout(vertices = 1) out;\n"
17995                                                            "\n"
17996                                                            "in  vec4 vs_tcs[];\n"
17997                                                            "out vec4 tcs_tes[];\n"
17998                                                            "\n"
17999                                                            "void main()\n"
18000                                                            "{\n"
18001                                                            "\n"
18002                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18003                                                            "\n"
18004                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18005                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18006                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18007                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18008                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18009                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18010                                                            "}\n"
18011                                                            "\n";
18012         static const GLchar* tcs_tested = "#version 430 core\n"
18013                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18014                                                                           "\n"
18015                                                                           "layout(vertices = 1) out;\n"
18016                                                                           "\n"
18017                                                                           "VAR_DEFINITION"
18018                                                                           "\n"
18019                                                                           "in  vec4 vs_tcs[];\n"
18020                                                                           "out vec4 tcs_tes[];\n"
18021                                                                           "\n"
18022                                                                           "void main()\n"
18023                                                                           "{\n"
18024                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18025                                                                           "\n"
18026                                                                           "VARIABLE_USE"
18027                                                                           "\n"
18028                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18029                                                                           "\n"
18030                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18031                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18032                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18033                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18034                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18035                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18036                                                                           "}\n"
18037                                                                           "\n";
18038         static const GLchar* tes = "#version 430 core\n"
18039                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18040                                                            "\n"
18041                                                            "layout(isolines, point_mode) in;\n"
18042                                                            "\n"
18043                                                            "in  vec4 tcs_tes[];\n"
18044                                                            "out vec4 tes_gs;\n"
18045                                                            "\n"
18046                                                            "void main()\n"
18047                                                            "{\n"
18048                                                            "    tes_gs = tcs_tes[0];\n"
18049                                                            "}\n"
18050                                                            "\n";
18051         static const GLchar* tes_tested = "#version 430 core\n"
18052                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18053                                                                           "\n"
18054                                                                           "layout(isolines, point_mode) in;\n"
18055                                                                           "\n"
18056                                                                           "VAR_DEFINITION"
18057                                                                           "\n"
18058                                                                           "in  vec4 tcs_tes[];\n"
18059                                                                           "out vec4 tes_gs;\n"
18060                                                                           "\n"
18061                                                                           "void main()\n"
18062                                                                           "{\n"
18063                                                                           "    vec4 result = tcs_tes[0];\n"
18064                                                                           "\n"
18065                                                                           "VARIABLE_USE"
18066                                                                           "\n"
18067                                                                           "    tes_gs += result;\n"
18068                                                                           "}\n"
18069                                                                           "\n";
18070         static const GLchar* vs = "#version 430 core\n"
18071                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18072                                                           "\n"
18073                                                           "in  vec4 in_vs;\n"
18074                                                           "out vec4 vs_tcs;\n"
18075                                                           "\n"
18076                                                           "void main()\n"
18077                                                           "{\n"
18078                                                           "    vs_tcs = in_vs;\n"
18079                                                           "}\n"
18080                                                           "\n";
18081         static const GLchar* vs_tested = "#version 430 core\n"
18082                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18083                                                                          "\n"
18084                                                                          "VAR_DEFINITION"
18085                                                                          "\n"
18086                                                                          "in  vec4 in_vs;\n"
18087                                                                          "out vec4 vs_tcs;\n"
18088                                                                          "\n"
18089                                                                          "void main()\n"
18090                                                                          "{\n"
18091                                                                          "    vec4 result = in_vs;\n"
18092                                                                          "\n"
18093                                                                          "VARIABLE_USE"
18094                                                                          "\n"
18095                                                                          "    vs_tcs += result;\n"
18096                                                                          "}\n"
18097                                                                          "\n";
18098
18099         std::string source;
18100         testCase&   test_case = m_test_cases[test_case_index];
18101
18102         if (test_case.m_stage == stage)
18103         {
18104                 const GLchar* array = "";
18105                 GLchar            buffer_gohan[16];
18106                 GLchar            buffer_goten[16];
18107                 const GLchar* direction = "in ";
18108                 const GLchar* index             = "";
18109                 const GLchar* int_gohan = getInterpolationQualifier(test_case.m_interpolation_gohan);
18110                 const GLchar* int_goten = getInterpolationQualifier(test_case.m_interpolation_goten);
18111                 size_t            position  = 0;
18112                 size_t            temp;
18113                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18114                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18115                 const GLchar* var_use             = input_use;
18116
18117                 if (false == test_case.m_is_input)
18118                 {
18119                         direction = "out";
18120
18121                         var_use = output_use;
18122                 }
18123
18124                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18125                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18126
18127                 switch (stage)
18128                 {
18129                 case Utils::Shader::FRAGMENT:
18130                         source = fs_tested;
18131                         break;
18132                 case Utils::Shader::GEOMETRY:
18133                         source = gs_tested;
18134                         array  = "[]";
18135                         index  = "[0]";
18136                         break;
18137                 case Utils::Shader::TESS_CTRL:
18138                         source = tcs_tested;
18139                         array  = "[]";
18140                         index  = "[gl_InvocationID]";
18141                         break;
18142                 case Utils::Shader::TESS_EVAL:
18143                         source = tes_tested;
18144                         array  = "[]";
18145                         index  = "[0]";
18146                         break;
18147                 case Utils::Shader::VERTEX:
18148                         source = vs_tested;
18149                         break;
18150                 default:
18151                         TCU_FAIL("Invalid enum");
18152                 }
18153
18154                 temp = position;
18155                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18156                 position = temp;
18157                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18158                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18159                 Utils::replaceToken("DIRECTION", position, direction, source);
18160                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18161                 Utils::replaceToken("ARRAY", position, array, source);
18162                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18163                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18164                 Utils::replaceToken("DIRECTION", position, direction, source);
18165                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18166                 Utils::replaceToken("ARRAY", position, array, source);
18167
18168                 temp = position;
18169                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18170                 position = temp;
18171                 if (true == test_case.m_is_input)
18172                 {
18173                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18174                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18175                 }
18176                 else
18177                 {
18178                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18179                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18180                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18181                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18182                 }
18183
18184                 Utils::replaceAllTokens("INDEX", index, source);
18185         }
18186         else
18187         {
18188                 switch (stage)
18189                 {
18190                 case Utils::Shader::FRAGMENT:
18191                         source = fs;
18192                         break;
18193                 case Utils::Shader::GEOMETRY:
18194                         source = gs;
18195                         break;
18196                 case Utils::Shader::TESS_CTRL:
18197                         source = tcs;
18198                         break;
18199                 case Utils::Shader::TESS_EVAL:
18200                         source = tes;
18201                         break;
18202                 case Utils::Shader::VERTEX:
18203                         source = vs;
18204                         break;
18205                 default:
18206                         TCU_FAIL("Invalid enum");
18207                 }
18208         }
18209
18210         return source;
18211 }
18212
18213 /** Get description of test case
18214  *
18215  * @param test_case_index Index of test case
18216  *
18217  * @return Test case description
18218  **/
18219 std::string VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseName(GLuint test_case_index)
18220 {
18221         std::stringstream stream;
18222         testCase&                 test_case = m_test_cases[test_case_index];
18223
18224         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18225                    << getInterpolationQualifier(test_case.m_interpolation_gohan) << " "
18226                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
18227                    << getInterpolationQualifier(test_case.m_interpolation_goten) << " "
18228                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18229
18230         if (true == test_case.m_is_input)
18231         {
18232                 stream << "input";
18233         }
18234         else
18235         {
18236                 stream << "output";
18237         }
18238
18239         return stream.str();
18240 }
18241
18242 /** Get number of test cases
18243  *
18244  * @return Number of test cases
18245  **/
18246 GLuint VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseNumber()
18247 {
18248         return static_cast<GLuint>(m_test_cases.size());
18249 }
18250
18251 /** Selects if "compute" stage is relevant for test
18252  *
18253  * @param ignored
18254  *
18255  * @return false
18256  **/
18257 bool VaryingLocationAliasingWithMixedInterpolationTest::isComputeRelevant(GLuint /* test_case_index */)
18258 {
18259         return false;
18260 }
18261
18262 /** Prepare all test cases
18263  *
18264  **/
18265 void VaryingLocationAliasingWithMixedInterpolationTest::testInit()
18266 {
18267         static const GLuint n_components_per_location = 4;
18268         const GLuint            n_types                                   = getTypesNumber();
18269
18270         for (GLuint i = 0; i < n_types; ++i)
18271         {
18272                 const Utils::Type& type_gohan              = getType(i);
18273                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18274
18275                 /* Skip matrices */
18276                 if (1 != type_gohan.m_n_columns)
18277                 {
18278                         continue;
18279                 }
18280
18281                 for (GLuint j = 0; j < n_types; ++j)
18282                 {
18283                         const Utils::Type& type_goten              = getType(j);
18284                         const bool                 is_float_type_goten = isFloatType(type_goten);
18285
18286                         /* Skip matrices */
18287                         if (1 != type_goten.m_n_columns)
18288                         {
18289                                 continue;
18290                         }
18291
18292                         /* Skip invalid combinations */
18293                         if (is_float_type_gohan != is_float_type_goten)
18294                         {
18295                                 continue;
18296                         }
18297
18298                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18299                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18300
18301                         /* Skip pairs that cannot fit into one location */
18302                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18303                         {
18304                                 continue;
18305                         }
18306
18307                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
18308                         {
18309                                 /* Skip compute shader */
18310                                 if (Utils::Shader::COMPUTE == stage)
18311                                 {
18312                                         continue;
18313                                 }
18314
18315                                 const GLuint gohan = 0;
18316                                 const GLuint goten = gohan + n_req_components_gohan;
18317
18318                                 for (GLuint int_gohan = 0; int_gohan < INTERPOLATION_MAX; ++int_gohan)
18319                                 {
18320                                         for (GLuint int_goten = 0; int_goten < INTERPOLATION_MAX; ++int_goten)
18321                                         {
18322                                                 const bool is_gohan_double = (Utils::Type::Double == type_gohan.m_basic_type) ? true : false;
18323                                                 const bool is_goten_double = (Utils::Type::Double == type_goten.m_basic_type) ? true : false;
18324                                                 const bool is_gohan_flat   = (FLAT == int_gohan) ? true : false;
18325                                                 const bool is_goten_flat   = (FLAT == int_goten) ? true : false;
18326                                                 const bool is_gohan_accepted_as_fs_in =
18327                                                         (is_gohan_double && is_gohan_flat) || (!is_gohan_double);
18328                                                 const bool is_goten_accepted_as_fs_in =
18329                                                         (is_goten_double && is_goten_flat) || (!is_goten_double);
18330                                                 const bool is_comb_accepted_as_fs_in = is_gohan_accepted_as_fs_in && is_goten_accepted_as_fs_in;
18331
18332                                                 /* Skip when both are the same */
18333                                                 if (int_gohan == int_goten)
18334                                                 {
18335                                                         continue;
18336                                                 }
18337
18338                                                 testCase test_case_in = { gohan,
18339                                                                                                   goten,
18340                                                                                                   (INTERPOLATIONS)int_gohan,
18341                                                                                                   (INTERPOLATIONS)int_goten,
18342                                                                                                   true,
18343                                                                                                   (Utils::Shader::STAGES)stage,
18344                                                                                                   type_gohan,
18345                                                                                                   type_goten };
18346
18347                                                 testCase test_case_out = { gohan,
18348                                                                                                    goten,
18349                                                                                                    (INTERPOLATIONS)int_gohan,
18350                                                                                                    (INTERPOLATIONS)int_goten,
18351                                                                                                    false,
18352                                                                                                    (Utils::Shader::STAGES)stage,
18353                                                                                                    type_gohan,
18354                                                                                                    type_goten };
18355
18356                                                 /* Skip inputs in:
18357                                                  * vertex shader,
18358                                                  * fragment shader when not flat double is used
18359                                                  */
18360                                                 if ((Utils::Shader::VERTEX != stage) &&
18361                                                         ((Utils::Shader::FRAGMENT != stage) || (true == is_comb_accepted_as_fs_in)))
18362                                                 {
18363                                                         m_test_cases.push_back(test_case_in);
18364                                                 }
18365
18366                                                 /* Skip outputs in fragment shader */
18367                                                 if (Utils::Shader::FRAGMENT != stage)
18368                                                 {
18369                                                         m_test_cases.push_back(test_case_out);
18370                                                 }
18371                                         }
18372                                 }
18373                         }
18374                 }
18375         }
18376 }
18377
18378 /** Get interpolation qualifier
18379  *
18380  * @param interpolation Enumeration
18381  *
18382  * @return GLSL qualifier
18383  **/
18384 const GLchar* VaryingLocationAliasingWithMixedInterpolationTest::getInterpolationQualifier(INTERPOLATIONS interpolation)
18385 {
18386         const GLchar* result = 0;
18387
18388         switch (interpolation)
18389         {
18390         case SMOOTH:
18391                 result = "smooth";
18392                 break;
18393         case FLAT:
18394                 result = "flat";
18395                 break;
18396         case NO_PERSPECTIVE:
18397                 result = "noperspective";
18398                 break;
18399         default:
18400                 TCU_FAIL("Invalid enum");
18401         }
18402
18403         return result;
18404 }
18405
18406 /** Check if given type is float
18407  *
18408  * @param type Type in question
18409  *
18410  * @return true if tpye is float, false otherwise
18411  **/
18412 bool VaryingLocationAliasingWithMixedInterpolationTest::isFloatType(const Utils::Type& type)
18413 {
18414         bool is_float = false;
18415
18416         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18417         {
18418                 is_float = true;
18419         }
18420
18421         return is_float;
18422 }
18423
18424 /** Constructor
18425  *
18426  * @param context Test framework context
18427  **/
18428 VaryingLocationAliasingWithMixedAuxiliaryStorageTest::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(
18429         deqp::Context& context)
18430         : NegativeTestBase(
18431                   context, "varying_location_aliasing_with_mixed_auxiliary_storage",
18432                   "Test verifies that compiler reports error when auxiliary storage qualifiers are mixed at one location")
18433 {
18434 }
18435
18436 /** Source for given test case and stage
18437  *
18438  * @param test_case_index Index of test case
18439  * @param stage           Shader stage
18440  *
18441  * @return Shader source
18442  **/
18443 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getShaderSource(GLuint                                test_case_index,
18444                                                                                                                                                                   Utils::Shader::STAGES stage)
18445 {
18446         static const GLchar* var_definition =
18447                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
18448                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
18449         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX_GOHAN) &&\n"
18450                                                                          "        (TYPE(1) == gotenINDEX_GOTEN) )\n"
18451                                                                          "    {\n"
18452                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
18453                                                                          "    }\n";
18454         static const GLchar* output_use = "    gohanINDEX_GOHAN = TYPE(0);\n"
18455                                                                           "    gotenINDEX_GOTEN = TYPE(1);\n"
18456                                                                           "    if (vec4(0) == result)\n"
18457                                                                           "    {\n"
18458                                                                           "        gohanINDEX_GOHAN = TYPE(1);\n"
18459                                                                           "        gotenINDEX_GOTEN = TYPE(0);\n"
18460                                                                           "    }\n";
18461         static const GLchar* fs = "#version 430 core\n"
18462                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18463                                                           "\n"
18464                                                           "in  vec4 gs_fs;\n"
18465                                                           "out vec4 fs_out;\n"
18466                                                           "\n"
18467                                                           "void main()\n"
18468                                                           "{\n"
18469                                                           "    fs_out = gs_fs;\n"
18470                                                           "}\n"
18471                                                           "\n";
18472         static const GLchar* fs_tested = "#version 430 core\n"
18473                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18474                                                                          "\n"
18475                                                                          "VAR_DEFINITION"
18476                                                                          "\n"
18477                                                                          "in  vec4 gs_fs;\n"
18478                                                                          "out vec4 fs_out;\n"
18479                                                                          "\n"
18480                                                                          "void main()\n"
18481                                                                          "{\n"
18482                                                                          "    vec4 result = gs_fs;\n"
18483                                                                          "\n"
18484                                                                          "VARIABLE_USE"
18485                                                                          "\n"
18486                                                                          "    fs_out = result;\n"
18487                                                                          "}\n"
18488                                                                          "\n";
18489         static const GLchar* gs = "#version 430 core\n"
18490                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18491                                                           "\n"
18492                                                           "layout(points)                           in;\n"
18493                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18494                                                           "\n"
18495                                                           "in  vec4 tes_gs[];\n"
18496                                                           "out vec4 gs_fs;\n"
18497                                                           "\n"
18498                                                           "void main()\n"
18499                                                           "{\n"
18500                                                           "    gs_fs = tes_gs[0];\n"
18501                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18502                                                           "    EmitVertex();\n"
18503                                                           "    gs_fs = tes_gs[0];\n"
18504                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18505                                                           "    EmitVertex();\n"
18506                                                           "    gs_fs = tes_gs[0];\n"
18507                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18508                                                           "    EmitVertex();\n"
18509                                                           "    gs_fs = tes_gs[0];\n"
18510                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18511                                                           "    EmitVertex();\n"
18512                                                           "}\n"
18513                                                           "\n";
18514         static const GLchar* gs_tested = "#version 430 core\n"
18515                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18516                                                                          "\n"
18517                                                                          "layout(points)                           in;\n"
18518                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18519                                                                          "\n"
18520                                                                          "VAR_DEFINITION"
18521                                                                          "\n"
18522                                                                          "in  vec4 tes_gs[];\n"
18523                                                                          "out vec4 gs_fs;\n"
18524                                                                          "\n"
18525                                                                          "void main()\n"
18526                                                                          "{\n"
18527                                                                          "    vec4 result = tes_gs[0];\n"
18528                                                                          "\n"
18529                                                                          "VARIABLE_USE"
18530                                                                          "\n"
18531                                                                          "    gs_fs = result;\n"
18532                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18533                                                                          "    EmitVertex();\n"
18534                                                                          "    gs_fs = result;\n"
18535                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18536                                                                          "    EmitVertex();\n"
18537                                                                          "    gs_fs = result;\n"
18538                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18539                                                                          "    EmitVertex();\n"
18540                                                                          "    gs_fs = result;\n"
18541                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18542                                                                          "    EmitVertex();\n"
18543                                                                          "}\n"
18544                                                                          "\n";
18545         static const GLchar* tcs = "#version 430 core\n"
18546                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18547                                                            "\n"
18548                                                            "layout(vertices = 1) out;\n"
18549                                                            "\n"
18550                                                            "in  vec4 vs_tcs[];\n"
18551                                                            "out vec4 tcs_tes[];\n"
18552                                                            "\n"
18553                                                            "void main()\n"
18554                                                            "{\n"
18555                                                            "\n"
18556                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18557                                                            "\n"
18558                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18559                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18560                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18561                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18562                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18563                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18564                                                            "}\n"
18565                                                            "\n";
18566         static const GLchar* tcs_tested = "#version 430 core\n"
18567                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18568                                                                           "\n"
18569                                                                           "layout(vertices = 1) out;\n"
18570                                                                           "\n"
18571                                                                           "VAR_DEFINITION"
18572                                                                           "\n"
18573                                                                           "in  vec4 vs_tcs[];\n"
18574                                                                           "out vec4 tcs_tes[];\n"
18575                                                                           "\n"
18576                                                                           "void main()\n"
18577                                                                           "{\n"
18578                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18579                                                                           "\n"
18580                                                                           "VARIABLE_USE"
18581                                                                           "\n"
18582                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18583                                                                           "\n"
18584                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18585                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18586                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18587                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18588                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18589                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18590                                                                           "}\n"
18591                                                                           "\n";
18592         static const GLchar* tes = "#version 430 core\n"
18593                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18594                                                            "\n"
18595                                                            "layout(isolines, point_mode) in;\n"
18596                                                            "\n"
18597                                                            "in  vec4 tcs_tes[];\n"
18598                                                            "out vec4 tes_gs;\n"
18599                                                            "\n"
18600                                                            "void main()\n"
18601                                                            "{\n"
18602                                                            "    tes_gs = tcs_tes[0];\n"
18603                                                            "}\n"
18604                                                            "\n";
18605         static const GLchar* tes_tested = "#version 430 core\n"
18606                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18607                                                                           "\n"
18608                                                                           "layout(isolines, point_mode) in;\n"
18609                                                                           "\n"
18610                                                                           "VAR_DEFINITION"
18611                                                                           "\n"
18612                                                                           "in  vec4 tcs_tes[];\n"
18613                                                                           "out vec4 tes_gs;\n"
18614                                                                           "\n"
18615                                                                           "void main()\n"
18616                                                                           "{\n"
18617                                                                           "    vec4 result = tcs_tes[0];\n"
18618                                                                           "\n"
18619                                                                           "VARIABLE_USE"
18620                                                                           "\n"
18621                                                                           "    tes_gs += result;\n"
18622                                                                           "}\n"
18623                                                                           "\n";
18624         static const GLchar* vs = "#version 430 core\n"
18625                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18626                                                           "\n"
18627                                                           "in  vec4 in_vs;\n"
18628                                                           "out vec4 vs_tcs;\n"
18629                                                           "\n"
18630                                                           "void main()\n"
18631                                                           "{\n"
18632                                                           "    vs_tcs = in_vs;\n"
18633                                                           "}\n"
18634                                                           "\n";
18635         static const GLchar* vs_tested = "#version 430 core\n"
18636                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18637                                                                          "\n"
18638                                                                          "VAR_DEFINITION"
18639                                                                          "\n"
18640                                                                          "in  vec4 in_vs;\n"
18641                                                                          "out vec4 vs_tcs;\n"
18642                                                                          "\n"
18643                                                                          "void main()\n"
18644                                                                          "{\n"
18645                                                                          "    vec4 result = in_vs;\n"
18646                                                                          "\n"
18647                                                                          "VARIABLE_USE"
18648                                                                          "\n"
18649                                                                          "    vs_tcs += result;\n"
18650                                                                          "}\n"
18651                                                                          "\n";
18652
18653         std::string source;
18654         testCase&   test_case = m_test_cases[test_case_index];
18655
18656         if (test_case.m_stage == stage)
18657         {
18658                 const GLchar* array_gohan = "";
18659                 const GLchar* array_goten = "";
18660                 const GLchar* aux_gohan   = getAuxiliaryQualifier(test_case.m_aux_gohan);
18661                 const GLchar* aux_goten   = getAuxiliaryQualifier(test_case.m_aux_goten);
18662                 GLchar            buffer_gohan[16];
18663                 GLchar            buffer_goten[16];
18664                 const GLchar* direction   = "in ";
18665                 const GLchar* index_gohan = "";
18666                 const GLchar* index_goten = "";
18667                 const GLchar* int_gohan   = test_case.m_int_gohan;
18668                 const GLchar* int_goten   = test_case.m_int_goten;
18669                 size_t            position      = 0;
18670                 size_t            temp;
18671                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18672                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18673                 const GLchar* var_use             = input_use;
18674
18675                 if (false == test_case.m_is_input)
18676                 {
18677                         direction = "out";
18678
18679                         var_use = output_use;
18680                 }
18681
18682                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18683                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18684
18685                 switch (stage)
18686                 {
18687                 case Utils::Shader::FRAGMENT:
18688                         source = fs_tested;
18689                         break;
18690                 case Utils::Shader::GEOMETRY:
18691                         source          = gs_tested;
18692                         array_gohan = "[]";
18693                         index_gohan = "[0]";
18694                         array_goten = "[]";
18695                         index_goten = "[0]";
18696                         break;
18697                 case Utils::Shader::TESS_CTRL:
18698                         source = tcs_tested;
18699                         if (PATCH != test_case.m_aux_gohan)
18700                         {
18701                                 array_gohan = "[]";
18702                                 index_gohan = "[gl_InvocationID]";
18703                         }
18704                         if (PATCH != test_case.m_aux_goten)
18705                         {
18706                                 array_goten = "[]";
18707                                 index_goten = "[gl_InvocationID]";
18708                         }
18709                         break;
18710                 case Utils::Shader::TESS_EVAL:
18711                         source          = tes_tested;
18712                         array_gohan = "[]";
18713                         index_gohan = "[0]";
18714                         array_goten = "[]";
18715                         index_goten = "[0]";
18716                         break;
18717                 case Utils::Shader::VERTEX:
18718                         source = vs_tested;
18719                         break;
18720                 default:
18721                         TCU_FAIL("Invalid enum");
18722                 }
18723
18724                 temp = position;
18725                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18726                 position = temp;
18727                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18728                 Utils::replaceToken("AUX", position, aux_gohan, source);
18729                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18730                 Utils::replaceToken("DIRECTION", position, direction, source);
18731                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18732                 Utils::replaceToken("ARRAY", position, array_gohan, source);
18733                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18734                 Utils::replaceToken("AUX", position, aux_goten, source);
18735                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18736                 Utils::replaceToken("DIRECTION", position, direction, source);
18737                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18738                 Utils::replaceToken("ARRAY", position, array_goten, source);
18739
18740                 temp = position;
18741                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18742                 position = temp;
18743                 if (true == test_case.m_is_input)
18744                 {
18745                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18746                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18747                 }
18748                 else
18749                 {
18750                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18751                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18752                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18753                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18754                 }
18755
18756                 Utils::replaceAllTokens("INDEX_GOHAN", index_gohan, source);
18757                 Utils::replaceAllTokens("INDEX_GOTEN", index_goten, source);
18758         }
18759         else
18760         {
18761                 switch (stage)
18762                 {
18763                 case Utils::Shader::FRAGMENT:
18764                         source = fs;
18765                         break;
18766                 case Utils::Shader::GEOMETRY:
18767                         source = gs;
18768                         break;
18769                 case Utils::Shader::TESS_CTRL:
18770                         source = tcs;
18771                         break;
18772                 case Utils::Shader::TESS_EVAL:
18773                         source = tes;
18774                         break;
18775                 case Utils::Shader::VERTEX:
18776                         source = vs;
18777                         break;
18778                 default:
18779                         TCU_FAIL("Invalid enum");
18780                 }
18781         }
18782
18783         return source;
18784 }
18785
18786 /** Get description of test case
18787  *
18788  * @param test_case_index Index of test case
18789  *
18790  * @return Test case description
18791  **/
18792 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseName(GLuint test_case_index)
18793 {
18794         std::stringstream stream;
18795         testCase&                 test_case = m_test_cases[test_case_index];
18796
18797         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18798                    << getAuxiliaryQualifier(test_case.m_aux_gohan) << " " << test_case.m_type_gohan.GetGLSLTypeName() << " at "
18799                    << test_case.m_component_gohan << ", " << getAuxiliaryQualifier(test_case.m_aux_goten) << " "
18800                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18801
18802         if (true == test_case.m_is_input)
18803         {
18804                 stream << "input";
18805         }
18806         else
18807         {
18808                 stream << "output";
18809         }
18810
18811         return stream.str();
18812 }
18813
18814 /** Get number of test cases
18815  *
18816  * @return Number of test cases
18817  **/
18818 GLuint VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseNumber()
18819 {
18820         return static_cast<GLuint>(m_test_cases.size());
18821 }
18822
18823 /** Selects if "compute" stage is relevant for test
18824  *
18825  * @param ignored
18826  *
18827  * @return false
18828  **/
18829 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isComputeRelevant(GLuint /* test_case_index */)
18830 {
18831         return false;
18832 }
18833
18834 /** Prepare all test cases
18835  *
18836  **/
18837 void VaryingLocationAliasingWithMixedAuxiliaryStorageTest::testInit()
18838 {
18839         static const GLuint n_components_per_location = 4;
18840         const GLuint            n_types                                   = getTypesNumber();
18841
18842         for (GLuint i = 0; i < n_types; ++i)
18843         {
18844                 const Utils::Type& type_gohan              = getType(i);
18845                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18846
18847                 /* Skip matrices */
18848                 if (1 != type_gohan.m_n_columns)
18849                 {
18850                         continue;
18851                 }
18852
18853                 for (GLuint j = 0; j < n_types; ++j)
18854                 {
18855                         const Utils::Type& type_goten              = getType(j);
18856                         const bool                 is_flat_req_gohan   = (Utils::Type::Float == type_gohan.m_basic_type) ? false : true;
18857                         const bool                 is_flat_req_goten   = (Utils::Type::Float == type_goten.m_basic_type) ? false : true;
18858                         const bool                 is_float_type_goten = isFloatType(type_goten);
18859
18860                         /* Skip matrices */
18861                         if (1 != type_goten.m_n_columns)
18862                         {
18863                                 continue;
18864                         }
18865
18866                         /* Skip invalid combinations */
18867                         if (is_float_type_gohan != is_float_type_goten)
18868                         {
18869                                 continue;
18870                         }
18871
18872                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18873                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18874
18875                         /* Skip pairs that cannot fit into one location */
18876                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18877                         {
18878                                 continue;
18879                         }
18880
18881                         const GLuint gohan = 0;
18882                         const GLuint goten = gohan + n_req_components_gohan;
18883
18884                         const GLchar* fs_int_gohan = is_flat_req_gohan ? "flat" : "";
18885                         const GLchar* fs_int_goten = is_flat_req_goten ? "flat" : "";
18886
18887                         testCase test_case_tcs_np = { gohan,      goten,         NONE, PATCH, "", "", false, Utils::Shader::TESS_CTRL,
18888                                                                                   type_gohan, type_goten };
18889
18890                         testCase test_case_tcs_pn = { gohan,      goten,         PATCH, NONE, "", "", false, Utils::Shader::TESS_CTRL,
18891                                                                                   type_gohan, type_goten };
18892
18893                         testCase test_case_tes_np = { gohan,      goten,         NONE, PATCH, "", "", true, Utils::Shader::TESS_EVAL,
18894                                                                                   type_gohan, type_goten };
18895
18896                         testCase test_case_tes_pn = { gohan,      goten,         PATCH, NONE, "", "", true, Utils::Shader::TESS_EVAL,
18897                                                                                   type_gohan, type_goten };
18898
18899                         testCase test_case_fs_nc = { gohan,                goten,                NONE, CENTROID,
18900                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18901                                                                                  type_gohan,   type_goten };
18902
18903                         testCase test_case_fs_cn = { gohan,                goten,                CENTROID, NONE,
18904                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18905                                                                                  type_gohan,   type_goten };
18906
18907                         testCase test_case_fs_ns = { gohan,                goten,                NONE, SAMPLE,
18908                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18909                                                                                  type_gohan,   type_goten };
18910
18911                         testCase test_case_fs_sn = { gohan,                goten,                SAMPLE, NONE,
18912                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18913                                                                                  type_gohan,   type_goten };
18914
18915                         testCase test_case_fs_cs = { gohan,                goten,                CENTROID, SAMPLE,
18916                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18917                                                                                  type_gohan,   type_goten };
18918
18919                         testCase test_case_fs_sc = { gohan,                goten,                SAMPLE, CENTROID,
18920                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18921                                                                                  type_gohan,   type_goten };
18922
18923                         m_test_cases.push_back(test_case_tcs_np);
18924                         m_test_cases.push_back(test_case_tcs_pn);
18925                         m_test_cases.push_back(test_case_tes_np);
18926                         m_test_cases.push_back(test_case_tes_pn);
18927                         m_test_cases.push_back(test_case_fs_nc);
18928                         m_test_cases.push_back(test_case_fs_cn);
18929                         m_test_cases.push_back(test_case_fs_ns);
18930                         m_test_cases.push_back(test_case_fs_sn);
18931                         m_test_cases.push_back(test_case_fs_cs);
18932                         m_test_cases.push_back(test_case_fs_sc);
18933                 }
18934         }
18935 }
18936
18937 /** Get auxiliary storage qualifier
18938  *
18939  * @param aux Enumeration
18940  *
18941  * @return GLSL qualifier
18942  **/
18943 const GLchar* VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getAuxiliaryQualifier(AUXILIARIES aux)
18944 {
18945         const GLchar* result = 0;
18946
18947         switch (aux)
18948         {
18949         case NONE:
18950                 result = "";
18951                 break;
18952         case PATCH:
18953                 result = "patch";
18954                 break;
18955         case CENTROID:
18956                 result = "centroid";
18957                 break;
18958         case SAMPLE:
18959                 result = "sample";
18960                 break;
18961         default:
18962                 TCU_FAIL("Invalid enum");
18963         }
18964
18965         return result;
18966 }
18967
18968 /** Check if given type is float
18969  *
18970  * @param type Type in question
18971  *
18972  * @return true if tpye is float, false otherwise
18973  **/
18974 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isFloatType(const Utils::Type& type)
18975 {
18976         bool is_float = false;
18977
18978         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18979         {
18980                 is_float = true;
18981         }
18982
18983         return is_float;
18984 }
18985
18986 /* Constants used by VertexAttribLocationAPITest */
18987 const GLuint VertexAttribLocationAPITest::m_goten_location = 6;
18988
18989 /** Constructor
18990  *
18991  * @param context Test framework context
18992  **/
18993 VertexAttribLocationAPITest::VertexAttribLocationAPITest(deqp::Context& context)
18994         : TextureTestBase(context, "vertex_attrib_location_api",
18995                                           "Test verifies that attribute locations API works as expected")
18996 {
18997 }
18998
18999 /** Does BindAttribLocation for "goten" and relink program
19000  *
19001  * @param program           Program object
19002  * @param program_interface Interface of program
19003  **/
19004 void VertexAttribLocationAPITest::prepareAttribLocation(Utils::Program&                  program,
19005                                                                                                                 Utils::ProgramInterface& program_interface)
19006 {
19007         const Functions& gl = m_context.getRenderContext().getFunctions();
19008
19009         gl.bindAttribLocation(program.m_id, m_goten_location, "goten");
19010         GLU_EXPECT_NO_ERROR(gl.getError(), "BindAttribLocation");
19011
19012         program.Link(gl, program.m_id);
19013
19014         /* We still need to get locations for gohan and chichi */
19015         TextureTestBase::prepareAttribLocation(program, program_interface);
19016 }
19017
19018 /** Get interface of program
19019  *
19020  * @param ignored
19021  * @param program_interface   Interface of program
19022  * @param ignored
19023  **/
19024 void VertexAttribLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19025                                                                                                           Utils::ProgramInterface& program_interface,
19026                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19027 {
19028         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
19029         const Utils::Type&              type      = Utils::Type::vec4;
19030         const GLuint                    type_size = type.GetSize();
19031
19032         /* Offsets */
19033         const GLuint chichi_offset = 0;
19034         const GLuint goten_offset  = chichi_offset + type_size;
19035         const GLuint gohan_offset  = goten_offset + type_size;
19036         const GLuint goku_offset   = gohan_offset + type_size;
19037
19038         /* Locations */
19039         const GLuint goku_location  = 2;
19040         const GLuint goten_location = m_goten_location;
19041
19042         /* Generate data */
19043         m_goku_data   = type.GenerateDataPacked();
19044         m_gohan_data  = type.GenerateDataPacked();
19045         m_goten_data  = type.GenerateDataPacked();
19046         m_chichi_data = type.GenerateDataPacked();
19047
19048         /* Globals */
19049         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19050
19051         /* Attributes */
19052         si.Input("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19053                          goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19054                          0u /* n_array_elements */, 0u /* stride */, goku_offset /* offset */, (GLvoid*)&m_goku_data[0] /* data */,
19055                          m_goku_data.size() /* data_size */);
19056
19057         si.Input("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19058                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19059                          0u /* n_array_elements */, 0u /* stride */, gohan_offset /* offset */,
19060                          (GLvoid*)&m_gohan_data[0] /* data */, m_gohan_data.size() /* data_size */);
19061
19062         si.Input("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19063                          goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19064                          0u /* n_array_elements */, 0u /* stride */, goten_offset /* offset */,
19065                          (GLvoid*)&m_goten_data[0] /* data */, m_goten_data.size() /* data_size */);
19066
19067         si.Input("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19068                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19069                          0u /* n_array_elements */, 0u /* stride */, chichi_offset /* offset */,
19070                          (GLvoid*)&m_chichi_data[0] /* data */, m_chichi_data.size() /* data_size */);
19071 }
19072
19073 /** Selects if "compute" stage is relevant for test
19074  *
19075  * @param ignored
19076  *
19077  * @return false
19078  **/
19079 bool VertexAttribLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19080 {
19081         return false;
19082 }
19083
19084 /* Constants used by FragmentDataLocationAPITest */
19085 const GLuint FragmentDataLocationAPITest::m_goten_location = 6;
19086
19087 /** Constructor
19088  *
19089  * @param context Test framework context
19090  **/
19091 FragmentDataLocationAPITest::FragmentDataLocationAPITest(deqp::Context& context)
19092         : TextureTestBase(context, "fragment_data_location_api",
19093                                           "Test verifies that fragment data locations API works as expected")
19094         , m_goku(context)
19095         , m_gohan(context)
19096         , m_goten(context)
19097         , m_chichi(context)
19098 {
19099 }
19100
19101 /** Verifies contents of drawn images
19102  *
19103  * @param ignored
19104  * @param ignored
19105  *
19106  * @return true if images are filled with expected values, false otherwise
19107  **/
19108 bool FragmentDataLocationAPITest::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& /* color_0 */)
19109 {
19110         static const GLuint size                        = m_width * m_height;
19111         static const GLuint expected_goku   = 0xff000000;
19112         static const GLuint expected_gohan  = 0xff0000ff;
19113         static const GLuint expected_goten  = 0xff00ff00;
19114         static const GLuint expected_chichi = 0xffff0000;
19115
19116         std::vector<GLuint> data;
19117         data.resize(size);
19118
19119         m_goku.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19120
19121         for (GLuint i = 0; i < size; ++i)
19122         {
19123                 const GLuint color = data[i];
19124
19125                 if (expected_goku != color)
19126                 {
19127                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19128                                                                                                 << tcu::TestLog::EndMessage;
19129                         return false;
19130                 }
19131         }
19132
19133         m_gohan.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19134
19135         for (GLuint i = 0; i < size; ++i)
19136         {
19137                 const GLuint color = data[i];
19138
19139                 if (expected_gohan != color)
19140                 {
19141                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19142                                                                                                 << tcu::TestLog::EndMessage;
19143                         return false;
19144                 }
19145         }
19146
19147         m_goten.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19148
19149         for (GLuint i = 0; i < size; ++i)
19150         {
19151                 const GLuint color = data[i];
19152
19153                 if (expected_goten != color)
19154                 {
19155                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19156                                                                                                 << tcu::TestLog::EndMessage;
19157                         return false;
19158                 }
19159         }
19160
19161         m_chichi.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19162
19163         for (GLuint i = 0; i < size; ++i)
19164         {
19165                 const GLuint color = data[i];
19166
19167                 if (expected_chichi != color)
19168                 {
19169                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19170                                                                                                 << tcu::TestLog::EndMessage;
19171                         return false;
19172                 }
19173         }
19174
19175         return true;
19176 }
19177
19178 /** Prepare code snippet that will set out variables
19179  *
19180  * @param ignored
19181  * @param ignored
19182  * @param stage               Shader stage
19183  *
19184  * @return Code that pass in variables to next stage
19185  **/
19186 std::string FragmentDataLocationAPITest::getPassSnippet(GLuint /* test_case_index */,
19187                                                                                                                 Utils::VaryingPassthrough& /* varying_passthrough */,
19188                                                                                                                 Utils::Shader::STAGES stage)
19189 {
19190         std::string result;
19191
19192         /* Skip for compute shader */
19193         if (Utils::Shader::FRAGMENT != stage)
19194         {
19195                 result = "";
19196         }
19197         else
19198         {
19199                 result = "chichi = vec4(0, 0, 1, 1);\n"
19200                                  "    goku   = vec4(0, 0, 0, 1);\n"
19201                                  "    goten  = vec4(0, 1, 0, 1);\n"
19202                                  "    gohan  = vec4(1, 0, 0, 1);\n";
19203         }
19204
19205         return result;
19206 }
19207
19208 /** Get interface of program
19209  *
19210  * @param ignored
19211  * @param program_interface Interface of program
19212  * @param ignored
19213  **/
19214 void FragmentDataLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19215                                                                                                           Utils::ProgramInterface& program_interface,
19216                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19217 {
19218         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19219         const Utils::Type&              type = Utils::Type::vec4;
19220
19221         /* Locations */
19222         m_goku_location = 2;
19223
19224         /* Globals */
19225         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19226
19227         /* Attributes */
19228         si.Output("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19229                           m_goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19230                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19231
19232         si.Output("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19233                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19234                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19235
19236         si.Output("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19237                           m_goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19238                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19239
19240         si.Output("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19241                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19242                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19243 }
19244
19245 /** Selects if "compute" stage is relevant for test
19246  *
19247  * @param ignored
19248  *
19249  * @return false
19250  **/
19251 bool FragmentDataLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19252 {
19253         return false;
19254 }
19255
19256 /** Get locations for all outputs with automatic_location
19257  *
19258  * @param program           Program object
19259  * @param program_interface Interface of program
19260  **/
19261 void FragmentDataLocationAPITest::prepareFragmentDataLoc(Utils::Program&                  program,
19262                                                                                                                  Utils::ProgramInterface& program_interface)
19263 {
19264         /* Bind location of goten */
19265         const Functions& gl = m_context.getRenderContext().getFunctions();
19266
19267         gl.bindFragDataLocation(program.m_id, m_goten_location, "goten");
19268         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFragDataLocation");
19269
19270         program.Link(gl, program.m_id);
19271
19272         /* Prepare locations for gohan and chichi */
19273         TextureTestBase::prepareFragmentDataLoc(program, program_interface);
19274
19275         /* Get all locations */
19276         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19277
19278         Utils::Variable::PtrVector& outputs = si.m_outputs;
19279
19280         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
19281         {
19282                 const Utils::Variable::Descriptor& desc = (*it)->m_descriptor;
19283
19284                 if (0 == desc.m_name.compare("gohan"))
19285                 {
19286                         m_gohan_location = desc.m_expected_location;
19287                 }
19288                 else if (0 == desc.m_name.compare("chichi"))
19289                 {
19290                         m_chichi_location = desc.m_expected_location;
19291                 }
19292
19293                 /* Locations of goku and goten are fixed */
19294         }
19295 }
19296
19297 /** Prepare framebuffer with single texture as color attachment
19298  *
19299  * @param framebuffer     Framebuffer
19300  * @param color_0_texture Texture that will used as color attachment
19301  **/
19302 void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
19303 {
19304         /* Let parent prepare its stuff */
19305         TextureTestBase::prepareFramebuffer(framebuffer, color_0_texture);
19306
19307         /* Prepare data */
19308         std::vector<GLuint> texture_data;
19309         texture_data.resize(m_width * m_height);
19310
19311         for (GLuint i = 0; i < texture_data.size(); ++i)
19312         {
19313                 texture_data[i] = 0x20406080;
19314         }
19315
19316         /* Prepare textures */
19317         m_goku.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19318
19319         m_gohan.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19320
19321         m_goten.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19322
19323         m_chichi.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19324
19325         /* Attach textures to framebuffer */
19326         framebuffer.Bind();
19327         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goku_location, m_goku.m_id, m_width, m_height);
19328         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_gohan_location, m_gohan.m_id, m_width, m_height);
19329         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goten_location, m_goten.m_id, m_width, m_height);
19330         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_chichi_location, m_chichi.m_id, m_width, m_height);
19331
19332         /* Set up drawbuffers */
19333         const Functions& gl = m_context.getRenderContext().getFunctions();
19334         //  1. There are only 4 outputs in fragment shader, so only need to do buffer mapping for 4 attachments,
19335         //  2. another issue is each output variable has a location, it is the fragment color index, so the index of
19336         //  GL_COLOR_ATTACHMENT in glDrawBuffers() should keep the same with the location, to make test correct,
19337         //  we needt to change the above code of glDrawBuffers() as :
19338         GLint  buffers_size = 4;
19339         GLenum buffers[]        = { GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location),
19340                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location),
19341                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location),
19342                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location) };
19343         gl.drawBuffers(buffers_size, buffers);
19344         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
19345 }
19346
19347 /** Constructor
19348  *
19349  * @param context Test framework context
19350  **/
19351 XFBInputTest::XFBInputTest(deqp::Context& context)
19352         : NegativeTestBase(context, "xfb_input",
19353                                            "Test verifies that compiler reports error when xfb qualifiers are used with input")
19354 {
19355 }
19356
19357 /** Source for given test case and stage
19358  *
19359  * @param test_case_index Index of test case
19360  * @param stage           Shader stage
19361  *
19362  * @return Shader source
19363  **/
19364 std::string XFBInputTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
19365 {
19366         static const GLchar* buffer_var_definition = "layout (xfb_buffer = 2) in vec4 gohanARRAY;\n";
19367         static const GLchar* offset_var_definition = "layout (xfb_offset = 16) in vec4 gohanARRAY;\n";
19368         static const GLchar* stride_var_definition = "layout (xfb_stride = 32) in vec4 gohanARRAY;\n";
19369         static const GLchar* input_use                     = "    result += gohanINDEX;\n";
19370         static const GLchar* fs                                    = "#version 430 core\n"
19371                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19372                                                           "\n"
19373                                                           "in  vec4 gs_fs;\n"
19374                                                           "out vec4 fs_out;\n"
19375                                                           "\n"
19376                                                           "void main()\n"
19377                                                           "{\n"
19378                                                           "    fs_out = gs_fs;\n"
19379                                                           "}\n"
19380                                                           "\n";
19381         static const GLchar* fs_tested = "#version 430 core\n"
19382                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19383                                                                          "\n"
19384                                                                          "VAR_DEFINITION"
19385                                                                          "\n"
19386                                                                          "in  vec4 gs_fs;\n"
19387                                                                          "out vec4 fs_out;\n"
19388                                                                          "\n"
19389                                                                          "void main()\n"
19390                                                                          "{\n"
19391                                                                          "    vec4 result = gs_fs;\n"
19392                                                                          "\n"
19393                                                                          "VARIABLE_USE"
19394                                                                          "\n"
19395                                                                          "    fs_out = result;\n"
19396                                                                          "}\n"
19397                                                                          "\n";
19398         static const GLchar* gs = "#version 430 core\n"
19399                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19400                                                           "\n"
19401                                                           "layout(points)                           in;\n"
19402                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
19403                                                           "\n"
19404                                                           "in  vec4 tes_gs[];\n"
19405                                                           "out vec4 gs_fs;\n"
19406                                                           "\n"
19407                                                           "void main()\n"
19408                                                           "{\n"
19409                                                           "    gs_fs = tes_gs[0];\n"
19410                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19411                                                           "    EmitVertex();\n"
19412                                                           "    gs_fs = tes_gs[0];\n"
19413                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19414                                                           "    EmitVertex();\n"
19415                                                           "    gs_fs = tes_gs[0];\n"
19416                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
19417                                                           "    EmitVertex();\n"
19418                                                           "    gs_fs = tes_gs[0];\n"
19419                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
19420                                                           "    EmitVertex();\n"
19421                                                           "}\n"
19422                                                           "\n";
19423         static const GLchar* gs_tested = "#version 430 core\n"
19424                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19425                                                                          "\n"
19426                                                                          "layout(points)                           in;\n"
19427                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
19428                                                                          "\n"
19429                                                                          "VAR_DEFINITION"
19430                                                                          "\n"
19431                                                                          "in  vec4 tes_gs[];\n"
19432                                                                          "out vec4 gs_fs;\n"
19433                                                                          "\n"
19434                                                                          "void main()\n"
19435                                                                          "{\n"
19436                                                                          "    vec4 result = tes_gs[0];\n"
19437                                                                          "\n"
19438                                                                          "VARIABLE_USE"
19439                                                                          "\n"
19440                                                                          "    gs_fs = result;\n"
19441                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19442                                                                          "    EmitVertex();\n"
19443                                                                          "    gs_fs = result;\n"
19444                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19445                                                                          "    EmitVertex();\n"
19446                                                                          "    gs_fs = result;\n"
19447                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
19448                                                                          "    EmitVertex();\n"
19449                                                                          "    gs_fs = result;\n"
19450                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
19451                                                                          "    EmitVertex();\n"
19452                                                                          "}\n"
19453                                                                          "\n";
19454         static const GLchar* tcs = "#version 430 core\n"
19455                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19456                                                            "\n"
19457                                                            "layout(vertices = 1) out;\n"
19458                                                            "\n"
19459                                                            "in  vec4 vs_tcs[];\n"
19460                                                            "out vec4 tcs_tes[];\n"
19461                                                            "\n"
19462                                                            "void main()\n"
19463                                                            "{\n"
19464                                                            "\n"
19465                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
19466                                                            "\n"
19467                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
19468                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
19469                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
19470                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
19471                                                            "    gl_TessLevelInner[0] = 1.0;\n"
19472                                                            "    gl_TessLevelInner[1] = 1.0;\n"
19473                                                            "}\n"
19474                                                            "\n";
19475         static const GLchar* tcs_tested = "#version 430 core\n"
19476                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19477                                                                           "\n"
19478                                                                           "layout(vertices = 1) out;\n"
19479                                                                           "\n"
19480                                                                           "VAR_DEFINITION"
19481                                                                           "\n"
19482                                                                           "in  vec4 vs_tcs[];\n"
19483                                                                           "out vec4 tcs_tes[];\n"
19484                                                                           "\n"
19485                                                                           "void main()\n"
19486                                                                           "{\n"
19487                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
19488                                                                           "\n"
19489                                                                           "VARIABLE_USE"
19490                                                                           "\n"
19491                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
19492                                                                           "\n"
19493                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
19494                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
19495                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
19496                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
19497                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
19498                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
19499                                                                           "}\n"
19500                                                                           "\n";
19501         static const GLchar* tes = "#version 430 core\n"
19502                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19503                                                            "\n"
19504                                                            "layout(isolines, point_mode) in;\n"
19505                                                            "\n"
19506                                                            "in  vec4 tcs_tes[];\n"
19507                                                            "out vec4 tes_gs;\n"
19508                                                            "\n"
19509                                                            "void main()\n"
19510                                                            "{\n"
19511                                                            "    tes_gs = tcs_tes[0];\n"
19512                                                            "}\n"
19513                                                            "\n";
19514         static const GLchar* tes_tested = "#version 430 core\n"
19515                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19516                                                                           "\n"
19517                                                                           "layout(isolines, point_mode) in;\n"
19518                                                                           "\n"
19519                                                                           "VAR_DEFINITION"
19520                                                                           "\n"
19521                                                                           "in  vec4 tcs_tes[];\n"
19522                                                                           "out vec4 tes_gs;\n"
19523                                                                           "\n"
19524                                                                           "void main()\n"
19525                                                                           "{\n"
19526                                                                           "    vec4 result = tcs_tes[0];\n"
19527                                                                           "\n"
19528                                                                           "VARIABLE_USE"
19529                                                                           "\n"
19530                                                                           "    tes_gs += result;\n"
19531                                                                           "}\n"
19532                                                                           "\n";
19533         static const GLchar* vs = "#version 430 core\n"
19534                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19535                                                           "\n"
19536                                                           "in  vec4 in_vs;\n"
19537                                                           "out vec4 vs_tcs;\n"
19538                                                           "\n"
19539                                                           "void main()\n"
19540                                                           "{\n"
19541                                                           "    vs_tcs = in_vs;\n"
19542                                                           "}\n"
19543                                                           "\n";
19544         static const GLchar* vs_tested = "#version 430 core\n"
19545                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19546                                                                          "\n"
19547                                                                          "VAR_DEFINITION"
19548                                                                          "\n"
19549                                                                          "in  vec4 in_vs;\n"
19550                                                                          "out vec4 vs_tcs;\n"
19551                                                                          "\n"
19552                                                                          "void main()\n"
19553                                                                          "{\n"
19554                                                                          "    vec4 result = in_vs;\n"
19555                                                                          "\n"
19556                                                                          "VARIABLE_USE"
19557                                                                          "\n"
19558                                                                          "    vs_tcs += result;\n"
19559                                                                          "}\n"
19560                                                                          "\n";
19561
19562         std::string source;
19563         testCase&   test_case = m_test_cases[test_case_index];
19564
19565         if (test_case.m_stage == stage)
19566         {
19567                 const GLchar* array     = "";
19568                 const GLchar* index     = "";
19569                 size_t            position = 0;
19570                 size_t            temp;
19571                 const GLchar* var_definition = 0;
19572                 const GLchar* var_use            = input_use;
19573
19574                 switch (test_case.m_qualifier)
19575                 {
19576                 case BUFFER:
19577                         var_definition = buffer_var_definition;
19578                         break;
19579                 case OFFSET:
19580                         var_definition = offset_var_definition;
19581                         break;
19582                 case STRIDE:
19583                         var_definition = stride_var_definition;
19584                         break;
19585                 default:
19586                         TCU_FAIL("Invalid enum");
19587                 }
19588
19589                 switch (stage)
19590                 {
19591                 case Utils::Shader::FRAGMENT:
19592                         source = fs_tested;
19593                         break;
19594                 case Utils::Shader::GEOMETRY:
19595                         source = gs_tested;
19596                         array  = "[]";
19597                         index  = "[0]";
19598                         break;
19599                 case Utils::Shader::TESS_CTRL:
19600                         source = tcs_tested;
19601                         array  = "[]";
19602                         index  = "[gl_InvocationID]";
19603                         break;
19604                 case Utils::Shader::TESS_EVAL:
19605                         source = tes_tested;
19606                         array  = "[]";
19607                         index  = "[0]";
19608                         break;
19609                 case Utils::Shader::VERTEX:
19610                         source = vs_tested;
19611                         break;
19612                 default:
19613                         TCU_FAIL("Invalid enum");
19614                 }
19615
19616                 temp = position;
19617                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
19618                 position = temp;
19619                 Utils::replaceToken("ARRAY", position, array, source);
19620                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
19621
19622                 Utils::replaceAllTokens("INDEX", index, source);
19623         }
19624         else
19625         {
19626                 switch (stage)
19627                 {
19628                 case Utils::Shader::FRAGMENT:
19629                         source = fs;
19630                         break;
19631                 case Utils::Shader::GEOMETRY:
19632                         source = gs;
19633                         break;
19634                 case Utils::Shader::TESS_CTRL:
19635                         source = tcs;
19636                         break;
19637                 case Utils::Shader::TESS_EVAL:
19638                         source = tes;
19639                         break;
19640                 case Utils::Shader::VERTEX:
19641                         source = vs;
19642                         break;
19643                 default:
19644                         TCU_FAIL("Invalid enum");
19645                 }
19646         }
19647
19648         return source;
19649 }
19650
19651 /** Get description of test case
19652  *
19653  * @param test_case_index Index of test case
19654  *
19655  * @return Test case description
19656  **/
19657 std::string XFBInputTest::getTestCaseName(GLuint test_case_index)
19658 {
19659         std::stringstream stream;
19660         testCase&                 test_case = m_test_cases[test_case_index];
19661
19662         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", qualifier: ";
19663
19664         switch (test_case.m_qualifier)
19665         {
19666         case BUFFER:
19667                 stream << "xfb_buffer";
19668                 break;
19669         case OFFSET:
19670                 stream << "xfb_offset";
19671                 break;
19672         case STRIDE:
19673                 stream << "xfb_stride";
19674                 break;
19675         default:
19676                 TCU_FAIL("Invalid enum");
19677         }
19678
19679         return stream.str();
19680 }
19681
19682 /** Get number of test cases
19683  *
19684  * @return Number of test cases
19685  **/
19686 GLuint XFBInputTest::getTestCaseNumber()
19687 {
19688         return static_cast<GLuint>(m_test_cases.size());
19689 }
19690
19691 /** Selects if "compute" stage is relevant for test
19692  *
19693  * @param ignored
19694  *
19695  * @return false
19696  **/
19697 bool XFBInputTest::isComputeRelevant(GLuint /* test_case_index */)
19698 {
19699         return false;
19700 }
19701
19702 /** Prepare all test cases
19703  *
19704  **/
19705 void XFBInputTest::testInit()
19706 {
19707         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
19708         {
19709                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
19710                 {
19711                         if (Utils::Shader::COMPUTE == stage)
19712                         {
19713                                 continue;
19714                         }
19715
19716                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
19717
19718                         m_test_cases.push_back(test_case);
19719                 }
19720         }
19721 }
19722
19723 /* Constants used by XFBAllStagesTest */
19724 const GLuint XFBAllStagesTest::m_gs_index = 3;
19725
19726 /** Constructor
19727  *
19728  * @param context Test context
19729  **/
19730 XFBAllStagesTest::XFBAllStagesTest(deqp::Context& context)
19731         : BufferTestBase(context, "xfb_all_stages",
19732                                          "Test verifies that only last stage in vertex processing can output to transform feedback")
19733 {
19734         /* Nothing to be done here */
19735 }
19736
19737 /** Get descriptors of buffers necessary for test
19738  *
19739  * @param ignored
19740  * @param out_descriptors Descriptors of buffers used by test
19741  **/
19742 void XFBAllStagesTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
19743                                                                                         bufferDescriptor::Vector& out_descriptors)
19744 {
19745         static const GLuint n_stages = 4;
19746         const Utils::Type&  vec4         = Utils::Type::vec4;
19747
19748         /* Data */
19749         tcu::Vec4 sum;
19750
19751         /* Test uses single uniform and xfb per stage + uniform for fragment shader */
19752         out_descriptors.resize(n_stages * 2 + 1);
19753
19754         /* */
19755         for (GLuint i = 0; i < n_stages; ++i)
19756         {
19757                 /* Get references */
19758                 bufferDescriptor& uniform = out_descriptors[i + 0];
19759                 bufferDescriptor& xfb    = out_descriptors[i + n_stages];
19760
19761                 /* Index */
19762                 uniform.m_index = i;
19763                 xfb.m_index             = i;
19764
19765                 /* Target */
19766                 uniform.m_target = Utils::Buffer::Uniform;
19767                 xfb.m_target     = Utils::Buffer::Transform_feedback;
19768
19769                 /* Data */
19770                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19771
19772                 sum += var;
19773
19774                 uniform.m_initial_data.resize(vec4.GetSize());
19775                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19776
19777                 xfb.m_initial_data = vec4.GenerateDataPacked();
19778
19779                 if (m_gs_index != i)
19780                 {
19781                         xfb.m_expected_data = xfb.m_initial_data;
19782                 }
19783                 else
19784                 {
19785                         xfb.m_expected_data.resize(vec4.GetSize());
19786                         memcpy(&xfb.m_expected_data[0], sum.getPtr(), vec4.GetSize());
19787                 }
19788         }
19789
19790         /* FS */
19791         {
19792                 /* Get reference */
19793                 bufferDescriptor& uniform = out_descriptors[n_stages * 2];
19794
19795                 /* Index */
19796                 uniform.m_index = n_stages;
19797
19798                 /* Target */
19799                 uniform.m_target = Utils::Buffer::Uniform;
19800
19801                 /* Data */
19802                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19803
19804                 uniform.m_initial_data.resize(vec4.GetSize());
19805                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19806         }
19807 }
19808
19809 /** Get body of main function for given shader stage
19810  *
19811  * @param ignored
19812  * @param stage            Shader stage
19813  * @param out_assignments  Set to empty
19814  * @param out_calculations Set to empty
19815  **/
19816 void XFBAllStagesTest::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19817                                                                          std::string& out_assignments, std::string& out_calculations)
19818 {
19819         out_calculations = "";
19820
19821         static const GLchar* vs  = "    vs_tcs  = uni_vs;\n";
19822         static const GLchar* tcs = "    tcs_tes[gl_InvocationID] = uni_tcs + vs_tcs[gl_InvocationID];\n";
19823         static const GLchar* tes = "    tes_gs  = uni_tes + tcs_tes[0];\n";
19824         static const GLchar* gs  = "    gs_fs   = uni_gs  + tes_gs[0];\n";
19825         static const GLchar* fs  = "    fs_out  = uni_fs  + gs_fs;\n";
19826
19827         const GLchar* assignments = 0;
19828         switch (stage)
19829         {
19830         case Utils::Shader::FRAGMENT:
19831                 assignments = fs;
19832                 break;
19833         case Utils::Shader::GEOMETRY:
19834                 assignments = gs;
19835                 break;
19836         case Utils::Shader::TESS_CTRL:
19837                 assignments = tcs;
19838                 break;
19839         case Utils::Shader::TESS_EVAL:
19840                 assignments = tes;
19841                 break;
19842         case Utils::Shader::VERTEX:
19843                 assignments = vs;
19844                 break;
19845         default:
19846                 TCU_FAIL("Invalid enum");
19847         }
19848
19849         out_assignments = assignments;
19850 }
19851
19852 /** Get interface of shader
19853  *
19854  * @param ignored
19855  * @param stage         Shader stage
19856  * @param out_interface Set to ""
19857  **/
19858 void XFBAllStagesTest::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19859                                                                                   std::string& out_interface)
19860 {
19861         static const GLchar* vs = "layout(xfb_buffer = 0, xfb_offset = 0) out     vec4 vs_tcs;\n"
19862                                                           "layout(binding    = 0)                 uniform vs_block {\n"
19863                                                           "    vec4 uni_vs;\n"
19864                                                           "};\n";
19865         static const GLchar* tcs = "                                       in      vec4 vs_tcs[];\n"
19866                                                            "layout(xfb_buffer = 1, xfb_offset = 0) out     vec4 tcs_tes[1];\n"
19867                                                            "layout(binding    = 1)                 uniform tcs_block {\n"
19868                                                            "    vec4 uni_tcs;\n"
19869                                                            "};\n";
19870         static const GLchar* tes = "                                       in      vec4 tcs_tes[];\n"
19871                                                            "layout(xfb_buffer = 2, xfb_offset = 0) out     vec4 tes_gs;\n"
19872                                                            "layout(binding    = 2)                 uniform tes_block {\n"
19873                                                            "    vec4 uni_tes;\n"
19874                                                            "};\n";
19875         static const GLchar* gs = "                                       in      vec4 tes_gs[];\n"
19876                                                           "layout(xfb_buffer = 3, xfb_offset = 0) out     vec4 gs_fs;\n"
19877                                                           "layout(binding    = 3)                 uniform gs_block {\n"
19878                                                           "    vec4 uni_gs;\n"
19879                                                           "};\n";
19880         static const GLchar* fs = "                       in      vec4 gs_fs;\n"
19881                                                           "                       out     vec4 fs_out;\n"
19882                                                           "layout(binding    = 4) uniform fs_block {\n"
19883                                                           "    vec4 uni_fs;\n"
19884                                                           "};\n";
19885
19886         const GLchar* interface = 0;
19887         switch (stage)
19888         {
19889         case Utils::Shader::FRAGMENT:
19890                 interface = fs;
19891                 break;
19892         case Utils::Shader::GEOMETRY:
19893                 interface = gs;
19894                 break;
19895         case Utils::Shader::TESS_CTRL:
19896                 interface = tcs;
19897                 break;
19898         case Utils::Shader::TESS_EVAL:
19899                 interface = tes;
19900                 break;
19901         case Utils::Shader::VERTEX:
19902                 interface = vs;
19903                 break;
19904         default:
19905                 TCU_FAIL("Invalid enum");
19906         }
19907
19908         out_interface = interface;
19909 }
19910
19911 /* Constants used by XFBStrideOfEmptyListTest */
19912 const GLuint XFBStrideOfEmptyListTest::m_stride = 64;
19913
19914 /** Constructor
19915  *
19916  * @param context Test context
19917  **/
19918 XFBStrideOfEmptyListTest::XFBStrideOfEmptyListTest(deqp::Context& context)
19919         : BufferTestBase(context, "xfb_stride_of_empty_list",
19920                                          "Test verifies that xfb_stride qualifier is respected when no xfb_offset is specified")
19921 {
19922         /* Nothing to be done here */
19923 }
19924
19925 /** Execute drawArrays for single vertex
19926  *
19927  * @param test_case_index Index of test case
19928  *
19929  * @return true if proper error is reported
19930  **/
19931 bool XFBStrideOfEmptyListTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
19932 {
19933         const Functions& gl             = m_context.getRenderContext().getFunctions();
19934         bool                     result = true;
19935
19936         /* Draw */
19937         gl.disable(GL_RASTERIZER_DISCARD);
19938         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
19939
19940         gl.beginTransformFeedback(GL_POINTS);
19941         GLenum error = gl.getError();
19942         switch (test_case_index)
19943         {
19944         case VALID:
19945                 if (GL_NO_ERROR != error)
19946                 {
19947                         gl.endTransformFeedback();
19948                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
19949                 }
19950
19951                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
19952                 error = gl.getError();
19953
19954                 gl.endTransformFeedback();
19955                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
19956                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
19957
19958                 break;
19959
19960         case FIRST_MISSING:
19961                 if (GL_NO_ERROR == error)
19962                 {
19963                         gl.endTransformFeedback();
19964                 }
19965
19966                 if (GL_INVALID_OPERATION != error)
19967                 {
19968                         m_context.getTestContext().getLog()
19969                                 << tcu::TestLog::Message << "XFB at index 0, that is written by GS, is missing. It was expected that "
19970                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19971                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19972
19973                         result = false;
19974                 }
19975
19976                 break;
19977
19978         case SECOND_MISSING:
19979                 if (GL_NO_ERROR == error)
19980                 {
19981                         gl.endTransformFeedback();
19982                 }
19983
19984                 if (GL_INVALID_OPERATION != error)
19985                 {
19986                         m_context.getTestContext().getLog()
19987                                 << tcu::TestLog::Message << "XFB at index 1, that is declared as empty, is missing. It was expected "
19988                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19989                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19990
19991                         result = false;
19992                 }
19993
19994                 break;
19995         }
19996
19997         /* Done */
19998         return result;
19999 }
20000
20001 /** Get descriptors of buffers necessary for test
20002  *
20003  * @param test_case_index Index of test case
20004  * @param out_descriptors Descriptors of buffers used by test
20005  **/
20006 void XFBStrideOfEmptyListTest::getBufferDescriptors(glw::GLuint                           test_case_index,
20007                                                                                                         bufferDescriptor::Vector& out_descriptors)
20008 {
20009         switch (test_case_index)
20010         {
20011         case VALID:
20012         {
20013                 /* Test needs single uniform and two xfbs */
20014                 out_descriptors.resize(3);
20015
20016                 /* Get references */
20017                 bufferDescriptor& uniform = out_descriptors[0];
20018                 bufferDescriptor& xfb_0   = out_descriptors[1];
20019                 bufferDescriptor& xfb_1   = out_descriptors[2];
20020
20021                 /* Index */
20022                 uniform.m_index = 0;
20023                 xfb_0.m_index   = 0;
20024                 xfb_1.m_index   = 1;
20025
20026                 /* Target */
20027                 uniform.m_target = Utils::Buffer::Uniform;
20028                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20029                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20030
20031                 /* Data */
20032                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20033
20034                 xfb_0.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20035                 xfb_0.m_expected_data = uniform.m_initial_data;
20036
20037                 /* Data, contents are the same as no modification is expected */
20038                 xfb_1.m_initial_data.resize(m_stride);
20039                 xfb_1.m_expected_data.resize(m_stride);
20040
20041                 for (GLuint i = 0; i < m_stride; ++i)
20042                 {
20043                         xfb_1.m_initial_data[0]  = (glw::GLubyte)i;
20044                         xfb_1.m_expected_data[0] = (glw::GLubyte)i;
20045                 }
20046         }
20047
20048         break;
20049
20050         case FIRST_MISSING:
20051         {
20052                 /* Test needs single uniform and two xfbs */
20053                 out_descriptors.resize(2);
20054
20055                 /* Get references */
20056                 bufferDescriptor& uniform = out_descriptors[0];
20057                 bufferDescriptor& xfb_1   = out_descriptors[1];
20058
20059                 /* Index */
20060                 uniform.m_index = 0;
20061                 xfb_1.m_index   = 1;
20062
20063                 /* Target */
20064                 uniform.m_target = Utils::Buffer::Uniform;
20065                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20066
20067                 /* Data */
20068                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20069
20070                 /* Draw call will not be executed, contents does not matter */
20071                 xfb_1.m_initial_data.resize(m_stride);
20072         }
20073
20074         break;
20075
20076         case SECOND_MISSING:
20077         {
20078                 /* Test needs single uniform and two xfbs */
20079                 out_descriptors.resize(2);
20080
20081                 /* Get references */
20082                 bufferDescriptor& uniform = out_descriptors[0];
20083                 bufferDescriptor& xfb_0   = out_descriptors[1];
20084
20085                 /* Index */
20086                 uniform.m_index = 0;
20087                 xfb_0.m_index   = 0;
20088
20089                 /* Target */
20090                 uniform.m_target = Utils::Buffer::Uniform;
20091                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20092
20093                 /* Data */
20094                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20095
20096                 /* Draw call will not be executed, contents does not matter */
20097                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20098         }
20099
20100         break;
20101         }
20102 }
20103
20104 /** Get body of main function for given shader stage
20105  *
20106  * @param ignored
20107  * @param stage            Shader stage
20108  * @param out_assignments  Set to empty
20109  * @param out_calculations Set to empty
20110  **/
20111 void XFBStrideOfEmptyListTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20112                                                                                          std::string& out_assignments, std::string& out_calculations)
20113 {
20114         out_calculations = "";
20115
20116         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20117         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20118
20119         const GLchar* assignments = "";
20120         switch (stage)
20121         {
20122         case Utils::Shader::FRAGMENT:
20123                 assignments = fs;
20124                 break;
20125         case Utils::Shader::GEOMETRY:
20126                 assignments = gs;
20127                 break;
20128         default:
20129                 break;
20130         }
20131
20132         out_assignments = assignments;
20133 }
20134
20135 /** Get interface of shader
20136  *
20137  * @param ignored
20138  * @param stage            Shader stage
20139  * @param out_interface    Set to ""
20140  **/
20141 void XFBStrideOfEmptyListTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20142                                                                                                   std::string& out_interface)
20143 {
20144         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0)  out     vec4 gs_fs;\n"
20145                                                           "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
20146                                                           "\n"
20147                                                           "layout (binding    = 0)                  uniform gs_block {\n"
20148                                                           "    vec4 uni_gs;\n"
20149                                                           "};\n";
20150         static const GLchar* fs = "in  vec4 gs_fs;\n"
20151                                                           "out vec4 fs_out;\n";
20152
20153         switch (stage)
20154         {
20155         case Utils::Shader::FRAGMENT:
20156                 out_interface = fs;
20157                 break;
20158         case Utils::Shader::GEOMETRY:
20159                 out_interface = gs;
20160                 break;
20161         default:
20162                 out_interface = "";
20163                 return;
20164         }
20165 }
20166
20167 /** Returns buffer details in human readable form.
20168  *
20169  * @param test_case_index Index of test case
20170  *
20171  * @return Case description
20172  **/
20173 std::string XFBStrideOfEmptyListTest::getTestCaseName(GLuint test_case_index)
20174 {
20175         std::string result;
20176
20177         switch (test_case_index)
20178         {
20179         case VALID:
20180                 result = "Valid case";
20181                 break;
20182         case FIRST_MISSING:
20183                 result = "Missing xfb at index 0";
20184                 break;
20185         case SECOND_MISSING:
20186                 result = "Missing xfb at index 1";
20187                 break;
20188         default:
20189                 TCU_FAIL("Invalid enum");
20190         }
20191
20192         return result;
20193 }
20194
20195 /** Get number of test cases
20196  *
20197  * @return 3
20198  **/
20199 GLuint XFBStrideOfEmptyListTest::getTestCaseNumber()
20200 {
20201         return 3;
20202 }
20203
20204 /* Constants used by XFBStrideOfEmptyListTest */
20205 const GLuint XFBStrideOfEmptyListAndAPITest::m_stride = 64;
20206
20207 /** Constructor
20208  *
20209  * @param context Test context
20210  **/
20211 XFBStrideOfEmptyListAndAPITest::XFBStrideOfEmptyListAndAPITest(deqp::Context& context)
20212         : BufferTestBase(context, "xfb_stride_of_empty_list_and_api",
20213                                          "Test verifies that xfb_stride qualifier is not overriden by API")
20214 {
20215         /* Nothing to be done here */
20216 }
20217
20218 /** Execute drawArrays for single vertex
20219  *
20220  * @param test_case_index Index of test case
20221  *
20222  * @return true if proper error is reported
20223  **/
20224 bool XFBStrideOfEmptyListAndAPITest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
20225 {
20226         const Functions& gl             = m_context.getRenderContext().getFunctions();
20227         bool                     result = true;
20228
20229         /* Draw */
20230         gl.disable(GL_RASTERIZER_DISCARD);
20231         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20232
20233         gl.beginTransformFeedback(GL_POINTS);
20234         GLenum error = gl.getError();
20235         switch (test_case_index)
20236         {
20237         case VALID:
20238                 if (GL_NO_ERROR != error)
20239                 {
20240                         gl.endTransformFeedback();
20241                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20242                 }
20243
20244                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20245                 error = gl.getError();
20246
20247                 gl.endTransformFeedback();
20248                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20249                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20250
20251                 break;
20252
20253         case FIRST_MISSING:
20254                 if (GL_NO_ERROR == error)
20255                 {
20256                         gl.endTransformFeedback();
20257                 }
20258
20259                 if (GL_INVALID_OPERATION != error)
20260                 {
20261                         m_context.getTestContext().getLog()
20262                                 << tcu::TestLog::Message << "XFB at index 0, that is declared as empty, is missing. It was expected "
20263                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20264                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20265
20266                         result = false;
20267                 }
20268
20269                 break;
20270
20271         case SECOND_MISSING:
20272                 if (GL_NO_ERROR == error)
20273                 {
20274                         gl.endTransformFeedback();
20275                 }
20276
20277                 if (GL_INVALID_OPERATION != error)
20278                 {
20279                         m_context.getTestContext().getLog()
20280                                 << tcu::TestLog::Message << "XFB at index 1, that is written by GS, is missing. It was expected that "
20281                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20282                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20283
20284                         result = false;
20285                 }
20286
20287                 break;
20288         }
20289
20290         /* Done */
20291         return result;
20292 }
20293
20294 /** Get descriptors of buffers necessary for test
20295  *
20296  * @param test_case_index Index of test case
20297  * @param out_descriptors Descriptors of buffers used by test
20298  **/
20299 void XFBStrideOfEmptyListAndAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
20300                                                                                                                   bufferDescriptor::Vector& out_descriptors)
20301 {
20302         switch (test_case_index)
20303         {
20304         case VALID:
20305         {
20306                 /* Test needs single uniform and two xfbs */
20307                 out_descriptors.resize(3);
20308
20309                 /* Get references */
20310                 bufferDescriptor& uniform = out_descriptors[0];
20311                 bufferDescriptor& xfb_0   = out_descriptors[1];
20312                 bufferDescriptor& xfb_1   = out_descriptors[2];
20313
20314                 /* Index */
20315                 uniform.m_index = 0;
20316                 xfb_0.m_index   = 0;
20317                 xfb_1.m_index   = 1;
20318
20319                 /* Target */
20320                 uniform.m_target = Utils::Buffer::Uniform;
20321                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20322                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20323
20324                 /* Data */
20325                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20326
20327                 /* Data, contents are the same as no modification is expected */
20328                 xfb_0.m_initial_data.resize(m_stride);
20329                 xfb_0.m_expected_data.resize(m_stride);
20330
20331                 for (GLuint i = 0; i < m_stride; ++i)
20332                 {
20333                         xfb_0.m_initial_data[0]  = (glw::GLubyte)i;
20334                         xfb_0.m_expected_data[0] = (glw::GLubyte)i;
20335                 }
20336
20337                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20338                 xfb_1.m_expected_data = uniform.m_initial_data;
20339         }
20340
20341         break;
20342
20343         case FIRST_MISSING:
20344         {
20345                 /* Test needs single uniform and two xfbs */
20346                 out_descriptors.resize(2);
20347
20348                 /* Get references */
20349                 bufferDescriptor& uniform = out_descriptors[0];
20350                 bufferDescriptor& xfb_1   = out_descriptors[1];
20351
20352                 /* Index */
20353                 uniform.m_index = 0;
20354                 xfb_1.m_index   = 1;
20355
20356                 /* Target */
20357                 uniform.m_target = Utils::Buffer::Uniform;
20358                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20359
20360                 /* Data */
20361                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20362
20363                 /* Draw call will not be executed, contents does not matter */
20364                 xfb_1.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20365         }
20366
20367         break;
20368
20369         case SECOND_MISSING:
20370         {
20371                 /* Test needs single uniform and two xfbs */
20372                 out_descriptors.resize(2);
20373
20374                 /* Get references */
20375                 bufferDescriptor& uniform = out_descriptors[0];
20376                 bufferDescriptor& xfb_0   = out_descriptors[1];
20377
20378                 /* Index */
20379                 uniform.m_index = 0;
20380                 xfb_0.m_index   = 0;
20381
20382                 /* Target */
20383                 uniform.m_target = Utils::Buffer::Uniform;
20384                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20385
20386                 /* Data */
20387                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20388
20389                 /* Draw call will not be executed, contents does not matter */
20390                 xfb_0.m_initial_data.resize(m_stride);
20391         }
20392
20393         break;
20394         }
20395 }
20396
20397 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
20398  *
20399  * @param ignored
20400  * @param captured_varyings Vector of varying names to be captured
20401  **/
20402 void XFBStrideOfEmptyListAndAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
20403                                                                                                                  Utils::Program::NameVector& captured_varyings)
20404 {
20405         captured_varyings.push_back("gs_fs");
20406 }
20407
20408 /** Get body of main function for given shader stage
20409  *
20410  * @param ignored
20411  * @param stage            Shader stage
20412  * @param out_assignments  Set to empty
20413  * @param out_calculations Set to empty
20414  **/
20415 void XFBStrideOfEmptyListAndAPITest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20416                                                                                                    std::string& out_assignments, std::string& out_calculations)
20417 {
20418         out_calculations = "";
20419
20420         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20421         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20422
20423         const GLchar* assignments = "";
20424         switch (stage)
20425         {
20426         case Utils::Shader::FRAGMENT:
20427                 assignments = fs;
20428                 break;
20429         case Utils::Shader::GEOMETRY:
20430                 assignments = gs;
20431                 break;
20432         default:
20433                 break;
20434         }
20435
20436         out_assignments = assignments;
20437 }
20438
20439 /** Get interface of shader
20440  *
20441  * @param ignored
20442  * @param stage            Shader stage
20443  * @param out_interface    Set to ""
20444  **/
20445 void XFBStrideOfEmptyListAndAPITest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20446                                                                                                                 std::string& out_interface)
20447 {
20448         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_stride = 64) out;\n"
20449                                                           "layout (xfb_buffer = 1, xfb_offset = 0)  out vec4 gs_fs;\n"
20450                                                           "\n"
20451                                                           "layout(binding    = 0) uniform gs_block {\n"
20452                                                           "    vec4 uni_gs;\n"
20453                                                           "};\n";
20454         static const GLchar* fs = "in  vec4 gs_fs;\n"
20455                                                           "out vec4 fs_out;\n";
20456
20457         switch (stage)
20458         {
20459         case Utils::Shader::FRAGMENT:
20460                 out_interface = fs;
20461                 break;
20462         case Utils::Shader::GEOMETRY:
20463                 out_interface = gs;
20464                 break;
20465         default:
20466                 out_interface = "";
20467                 return;
20468         }
20469 }
20470
20471 /** Returns buffer details in human readable form.
20472  *
20473  * @param test_case_index Index of test case
20474  *
20475  * @return Case description
20476  **/
20477 std::string XFBStrideOfEmptyListAndAPITest::getTestCaseName(GLuint test_case_index)
20478 {
20479         std::string result;
20480
20481         switch (test_case_index)
20482         {
20483         case VALID:
20484                 result = "Valid case";
20485                 break;
20486         case FIRST_MISSING:
20487                 result = "Missing xfb at index 0";
20488                 break;
20489         case SECOND_MISSING:
20490                 result = "Missing xfb at index 1";
20491                 break;
20492         default:
20493                 TCU_FAIL("Invalid enum");
20494         }
20495
20496         return result;
20497 }
20498
20499 /** Get number of test cases
20500  *
20501  * @return 2
20502  **/
20503 GLuint XFBStrideOfEmptyListAndAPITest::getTestCaseNumber()
20504 {
20505         return 3;
20506 }
20507
20508 /** Constructor
20509  *
20510  * @param context Test framework context
20511  **/
20512 XFBTooSmallStrideTest::XFBTooSmallStrideTest(deqp::Context& context)
20513         : NegativeTestBase(context, "xfb_too_small_stride",
20514                                            "Test verifies that compiler reports error when xfb_stride sets not enough space")
20515 {
20516 }
20517
20518 /** Source for given test case and stage
20519  *
20520  * @param test_case_index Index of test case
20521  * @param stage           Shader stage
20522  *
20523  * @return Shader source
20524  **/
20525 std::string XFBTooSmallStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20526 {
20527         static const GLchar* array_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20528                                                                                                 "\n"
20529                                                                                                 "layout (xfb_offset = 16) out vec4 gohanARRAY[4];\n";
20530         static const GLchar* block_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20531                                                                                                 "\n"
20532                                                                                                 "layout (xfb_offset = 0) out Goku {\n"
20533                                                                                                 "    vec4 gohan;\n"
20534                                                                                                 "    vec4 goten;\n"
20535                                                                                                 "    vec4 chichi;\n"
20536                                                                                                 "} gokuARRAY;\n";
20537         static const GLchar* offset_var_definition = "layout (xfb_buffer = 0, xfb_stride = 40) out;\n"
20538                                                                                                  "\n"
20539                                                                                                  "layout (xfb_offset = 32) out vec4 gohanARRAY;\n";
20540         // The test considers gohan overflows the buffer 0, but according to spec, it is valid to declare the variable with qualifier "layout (xfb_offset = 16, xfb_stride = 32) out vec4 gohan;"
20541         // To make the shader failed to compile, change xfb_stride to a value that is smaller than 32
20542         static const GLchar* stride_var_definition = "layout (xfb_buffer = 0, xfb_stride = 28) out;\n"
20543                                                                                                  "\n"
20544                                                                                                  "layout (xfb_offset = 16, xfb_stride = 28) out vec4 gohanARRAY;\n";
20545         static const GLchar* array_use = "    gohanINDEX[0] = result / 2;\n"
20546                                                                          "    gohanINDEX[1] = result / 4;\n"
20547                                                                          "    gohanINDEX[2] = result / 6;\n"
20548                                                                          "    gohanINDEX[3] = result / 8;\n";
20549         static const GLchar* block_use = "    gokuINDEX.gohan  = result / 2;\n"
20550                                                                          "    gokuINDEX.goten  = result / 4;\n"
20551                                                                          "    gokuINDEX.chichi = result / 6;\n";
20552         static const GLchar* output_use = "gohanINDEX = result / 4;\n";
20553         static const GLchar* fs                 = "#version 430 core\n"
20554                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20555                                                           "\n"
20556                                                           "in  vec4 gs_fs;\n"
20557                                                           "out vec4 fs_out;\n"
20558                                                           "\n"
20559                                                           "void main()\n"
20560                                                           "{\n"
20561                                                           "    fs_out = gs_fs;\n"
20562                                                           "}\n"
20563                                                           "\n";
20564         static const GLchar* gs_tested = "#version 430 core\n"
20565                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20566                                                                          "\n"
20567                                                                          "layout(points)                           in;\n"
20568                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20569                                                                          "\n"
20570                                                                          "VAR_DEFINITION"
20571                                                                          "\n"
20572                                                                          "in  vec4 tes_gs[];\n"
20573                                                                          "out vec4 gs_fs;\n"
20574                                                                          "\n"
20575                                                                          "void main()\n"
20576                                                                          "{\n"
20577                                                                          "    vec4 result = tes_gs[0];\n"
20578                                                                          "\n"
20579                                                                          "VARIABLE_USE"
20580                                                                          "\n"
20581                                                                          "    gs_fs = result;\n"
20582                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20583                                                                          "    EmitVertex();\n"
20584                                                                          "    gs_fs = result;\n"
20585                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20586                                                                          "    EmitVertex();\n"
20587                                                                          "    gs_fs = result;\n"
20588                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20589                                                                          "    EmitVertex();\n"
20590                                                                          "    gs_fs = result;\n"
20591                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20592                                                                          "    EmitVertex();\n"
20593                                                                          "}\n"
20594                                                                          "\n";
20595         static const GLchar* tcs = "#version 430 core\n"
20596                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20597                                                            "\n"
20598                                                            "layout(vertices = 1) out;\n"
20599                                                            "\n"
20600                                                            "in  vec4 vs_tcs[];\n"
20601                                                            "out vec4 tcs_tes[];\n"
20602                                                            "\n"
20603                                                            "void main()\n"
20604                                                            "{\n"
20605                                                            "\n"
20606                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
20607                                                            "\n"
20608                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20609                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20610                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20611                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20612                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20613                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20614                                                            "}\n"
20615                                                            "\n";
20616         static const GLchar* tcs_tested = "#version 430 core\n"
20617                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20618                                                                           "\n"
20619                                                                           "layout(vertices = 1) out;\n"
20620                                                                           "\n"
20621                                                                           "VAR_DEFINITION"
20622                                                                           "\n"
20623                                                                           "in  vec4 vs_tcs[];\n"
20624                                                                           "out vec4 tcs_tes[];\n"
20625                                                                           "\n"
20626                                                                           "void main()\n"
20627                                                                           "{\n"
20628                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
20629                                                                           "\n"
20630                                                                           "VARIABLE_USE"
20631                                                                           "\n"
20632                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
20633                                                                           "\n"
20634                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20635                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
20636                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
20637                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
20638                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
20639                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
20640                                                                           "}\n"
20641                                                                           "\n";
20642         static const GLchar* tes_tested = "#version 430 core\n"
20643                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20644                                                                           "\n"
20645                                                                           "layout(isolines, point_mode) in;\n"
20646                                                                           "\n"
20647                                                                           "VAR_DEFINITION"
20648                                                                           "\n"
20649                                                                           "in  vec4 tcs_tes[];\n"
20650                                                                           "out vec4 tes_gs;\n"
20651                                                                           "\n"
20652                                                                           "void main()\n"
20653                                                                           "{\n"
20654                                                                           "    vec4 result = tcs_tes[0];\n"
20655                                                                           "\n"
20656                                                                           "VARIABLE_USE"
20657                                                                           "\n"
20658                                                                           "    tes_gs += result;\n"
20659                                                                           "}\n"
20660                                                                           "\n";
20661         static const GLchar* vs = "#version 430 core\n"
20662                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20663                                                           "\n"
20664                                                           "in  vec4 in_vs;\n"
20665                                                           "out vec4 vs_tcs;\n"
20666                                                           "\n"
20667                                                           "void main()\n"
20668                                                           "{\n"
20669                                                           "    vs_tcs = in_vs;\n"
20670                                                           "}\n"
20671                                                           "\n";
20672         static const GLchar* vs_tested = "#version 430 core\n"
20673                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20674                                                                          "\n"
20675                                                                          "VAR_DEFINITION"
20676                                                                          "\n"
20677                                                                          "in  vec4 in_vs;\n"
20678                                                                          "out vec4 vs_tcs;\n"
20679                                                                          "\n"
20680                                                                          "void main()\n"
20681                                                                          "{\n"
20682                                                                          "    vec4 result = in_vs;\n"
20683                                                                          "\n"
20684                                                                          "VARIABLE_USE"
20685                                                                          "\n"
20686                                                                          "    vs_tcs += result;\n"
20687                                                                          "}\n"
20688                                                                          "\n";
20689
20690         std::string source;
20691         testCase&   test_case = m_test_cases[test_case_index];
20692
20693         if (test_case.m_stage == stage)
20694         {
20695                 const GLchar* array     = "";
20696                 const GLchar* index     = "";
20697                 size_t            position = 0;
20698                 size_t            temp;
20699                 const GLchar* var_definition = 0;
20700                 const GLchar* var_use            = 0;
20701
20702                 switch (test_case.m_case)
20703                 {
20704                 case OFFSET:
20705                         var_definition = offset_var_definition;
20706                         var_use            = output_use;
20707                         break;
20708                 case STRIDE:
20709                         var_definition = stride_var_definition;
20710                         var_use            = output_use;
20711                         break;
20712                 case BLOCK:
20713                         var_definition = block_var_definition;
20714                         var_use            = block_use;
20715                         break;
20716                 case ARRAY:
20717                         var_definition = array_var_definition;
20718                         var_use            = array_use;
20719                         break;
20720                 default:
20721                         TCU_FAIL("Invalid enum");
20722                 }
20723
20724                 switch (stage)
20725                 {
20726                 case Utils::Shader::GEOMETRY:
20727                         source = gs_tested;
20728                         array  = "[]";
20729                         index  = "[0]";
20730                         break;
20731                 case Utils::Shader::TESS_CTRL:
20732                         source = tcs_tested;
20733                         array  = "[]";
20734                         index  = "[gl_InvocationID]";
20735                         break;
20736                 case Utils::Shader::TESS_EVAL:
20737                         source = tes_tested;
20738                         array  = "[]";
20739                         index  = "[0]";
20740                         break;
20741                 case Utils::Shader::VERTEX:
20742                         source = vs_tested;
20743                         break;
20744                 default:
20745                         TCU_FAIL("Invalid enum");
20746                 }
20747
20748                 temp = position;
20749                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
20750                 position = temp;
20751                 Utils::replaceToken("ARRAY", position, array, source);
20752                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
20753
20754                 Utils::replaceAllTokens("INDEX", index, source);
20755         }
20756         else
20757         {
20758                 switch (test_case.m_stage)
20759                 {
20760                 case Utils::Shader::GEOMETRY:
20761                         switch (stage)
20762                         {
20763                         case Utils::Shader::FRAGMENT:
20764                                 source = fs;
20765                                 break;
20766                         case Utils::Shader::VERTEX:
20767                                 source = vs;
20768                                 break;
20769                         default:
20770                                 source = "";
20771                         }
20772                         break;
20773                 case Utils::Shader::TESS_CTRL:
20774                         switch (stage)
20775                         {
20776                         case Utils::Shader::FRAGMENT:
20777                                 source = fs;
20778                                 break;
20779                         case Utils::Shader::VERTEX:
20780                                 source = vs;
20781                                 break;
20782                         default:
20783                                 source = "";
20784                         }
20785                         break;
20786                 case Utils::Shader::TESS_EVAL:
20787                         switch (stage)
20788                         {
20789                         case Utils::Shader::FRAGMENT:
20790                                 source = fs;
20791                                 break;
20792                         case Utils::Shader::TESS_CTRL:
20793                                 source = tcs;
20794                                 break;
20795                         case Utils::Shader::VERTEX:
20796                                 source = vs;
20797                                 break;
20798                         default:
20799                                 source = "";
20800                         }
20801                         break;
20802                 case Utils::Shader::VERTEX:
20803                         switch (stage)
20804                         {
20805                         case Utils::Shader::FRAGMENT:
20806                                 source = fs;
20807                                 break;
20808                         default:
20809                                 source = "";
20810                         }
20811                         break;
20812                 default:
20813                         TCU_FAIL("Invalid enum");
20814                         break;
20815                 }
20816         }
20817
20818         return source;
20819 }
20820
20821 /** Get description of test case
20822  *
20823  * @param test_case_index Index of test case
20824  *
20825  * @return Test case description
20826  **/
20827 std::string XFBTooSmallStrideTest::getTestCaseName(GLuint test_case_index)
20828 {
20829         std::stringstream stream;
20830         testCase&                 test_case = m_test_cases[test_case_index];
20831
20832         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
20833
20834         switch (test_case.m_case)
20835         {
20836         case OFFSET:
20837                 stream << "buffer stride: 40, vec4 offset: 32";
20838                 break;
20839         case STRIDE:
20840                 stream << "buffer stride: 32, vec4 off 16 stride: 32";
20841                 break;
20842         case BLOCK:
20843                 stream << "buffer stride: 32, block 3xvec4 offset 0";
20844                 break;
20845         case ARRAY:
20846                 stream << "buffer stride: 32, vec4[4] offset 16";
20847                 break;
20848         default:
20849                 TCU_FAIL("Invalid enum");
20850         }
20851
20852         return stream.str();
20853 }
20854
20855 /** Get number of test cases
20856  *
20857  * @return Number of test cases
20858  **/
20859 GLuint XFBTooSmallStrideTest::getTestCaseNumber()
20860 {
20861         return static_cast<GLuint>(m_test_cases.size());
20862 }
20863
20864 /** Selects if "compute" stage is relevant for test
20865  *
20866  * @param ignored
20867  *
20868  * @return false
20869  **/
20870 bool XFBTooSmallStrideTest::isComputeRelevant(GLuint /* test_case_index */)
20871 {
20872         return false;
20873 }
20874
20875 /** Prepare all test cases
20876  *
20877  **/
20878 void XFBTooSmallStrideTest::testInit()
20879 {
20880         for (GLuint c = 0; c < CASE_MAX; ++c)
20881         {
20882                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
20883                 {
20884                         /*
20885                          It is invalid to define transform feedback output in TCS, according to spec:
20886                          The data captured in transform feedback mode depends on the active programs on each of the shader stages.
20887                          If a program is active for the geometry shader stage, transform feedback captures the vertices of each
20888                          primitive emitted by the geometry shader. Otherwise, if a program is active for the tessellation evaluation
20889                          shader stage, transform feedback captures each primitive produced by the tessellation primitive generator,
20890                          whose vertices are processed by the tessellation evaluation shader. Otherwise, transform feedback captures
20891                          each primitive processed by the vertex shader.
20892                          */
20893                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
20894                                 (Utils::Shader::FRAGMENT == stage))
20895                         {
20896                                 continue;
20897                         }
20898
20899                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
20900
20901                         m_test_cases.push_back(test_case);
20902                 }
20903         }
20904 }
20905
20906 /** Constructor
20907  *
20908  * @param context Test framework context
20909  **/
20910 XFBVariableStrideTest::XFBVariableStrideTest(deqp::Context& context)
20911         : NegativeTestBase(context, "xfb_variable_stride", "Test verifies that stride qualifier is respected")
20912 {
20913 }
20914
20915 /** Source for given test case and stage
20916  *
20917  * @param test_case_index Index of test case
20918  * @param stage           Shader stage
20919  *
20920  * @return Shader source
20921  **/
20922 std::string XFBVariableStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20923 {
20924         static const GLchar* invalid_var_definition =
20925                 "const uint type_size = SIZE;\n"
20926                 "\n"
20927                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n"
20928                 "layout (xfb_offset = type_size)                     out TYPE vegetaARRAY;\n";
20929         static const GLchar* valid_var_definition =
20930                 "const uint type_size = SIZE;\n"
20931                 "\n"
20932                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n";
20933         static const GLchar* invalid_use = "    gokuINDEX   = TYPE(1);\n"
20934                                                                            "    vegetaINDEX = TYPE(0);\n"
20935                                                                            "    if (vec4(0) == result)\n"
20936                                                                            "    {\n"
20937                                                                            "        gokuINDEX   = TYPE(0);\n"
20938                                                                            "        vegetaINDEX = TYPE(1);\n"
20939                                                                            "    }\n";
20940         static const GLchar* valid_use = "    gokuINDEX   = TYPE(1);\n"
20941                                                                          "    if (vec4(0) == result)\n"
20942                                                                          "    {\n"
20943                                                                          "        gokuINDEX   = TYPE(0);\n"
20944                                                                          "    }\n";
20945         static const GLchar* fs = "#version 430 core\n"
20946                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20947                                                           "\n"
20948                                                           "in  vec4 any_fs;\n"
20949                                                           "out vec4 fs_out;\n"
20950                                                           "\n"
20951                                                           "void main()\n"
20952                                                           "{\n"
20953                                                           "    fs_out = any_fs;\n"
20954                                                           "}\n"
20955                                                           "\n";
20956         static const GLchar* gs_tested = "#version 430 core\n"
20957                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20958                                                                          "\n"
20959                                                                          "layout(points)                           in;\n"
20960                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20961                                                                          "\n"
20962                                                                          "VAR_DEFINITION"
20963                                                                          "\n"
20964                                                                          "in  vec4 vs_any[];\n"
20965                                                                          "out vec4 any_fs;\n"
20966                                                                          "\n"
20967                                                                          "void main()\n"
20968                                                                          "{\n"
20969                                                                          "    vec4 result = vs_any[0];\n"
20970                                                                          "\n"
20971                                                                          "VARIABLE_USE"
20972                                                                          "\n"
20973                                                                          "    any_fs = result;\n"
20974                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20975                                                                          "    EmitVertex();\n"
20976                                                                          "    any_fs = result;\n"
20977                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20978                                                                          "    EmitVertex();\n"
20979                                                                          "    any_fs = result;\n"
20980                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20981                                                                          "    EmitVertex();\n"
20982                                                                          "    any_fs = result;\n"
20983                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20984                                                                          "    EmitVertex();\n"
20985                                                                          "}\n"
20986                                                                          "\n";
20987         static const GLchar* tcs = "#version 430 core\n"
20988                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20989                                                            "\n"
20990                                                            "layout(vertices = 1) out;\n"
20991                                                            "\n"
20992                                                            "in  vec4 vs_any[];\n"
20993                                                            "out vec4 tcs_tes[];\n"
20994                                                            "\n"
20995                                                            "void main()\n"
20996                                                            "{\n"
20997                                                            "\n"
20998                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
20999                                                            "\n"
21000                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21001                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21002                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21003                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21004                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21005                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21006                                                            "}\n"
21007                                                            "\n";
21008         static const GLchar* tcs_tested = "#version 430 core\n"
21009                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21010                                                                           "\n"
21011                                                                           "layout(vertices = 1) out;\n"
21012                                                                           "\n"
21013                                                                           "VAR_DEFINITION"
21014                                                                           "\n"
21015                                                                           "in  vec4 vs_any[];\n"
21016                                                                           "out vec4 any_fs[];\n"
21017                                                                           "\n"
21018                                                                           "void main()\n"
21019                                                                           "{\n"
21020                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21021                                                                           "\n"
21022                                                                           "VARIABLE_USE"
21023                                                                           "\n"
21024                                                                           "    any_fs[gl_InvocationID] = result;\n"
21025                                                                           "\n"
21026                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21027                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21028                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21029                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21030                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21031                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21032                                                                           "}\n"
21033                                                                           "\n";
21034         static const GLchar* tes_tested = "#version 430 core\n"
21035                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21036                                                                           "\n"
21037                                                                           "layout(isolines, point_mode) in;\n"
21038                                                                           "\n"
21039                                                                           "VAR_DEFINITION"
21040                                                                           "\n"
21041                                                                           "in  vec4 tcs_tes[];\n"
21042                                                                           "out vec4 any_fs;\n"
21043                                                                           "\n"
21044                                                                           "void main()\n"
21045                                                                           "{\n"
21046                                                                           "    vec4 result = tcs_tes[0];\n"
21047                                                                           "\n"
21048                                                                           "VARIABLE_USE"
21049                                                                           "\n"
21050                                                                           "    any_fs = result;\n"
21051                                                                           "}\n"
21052                                                                           "\n";
21053         static const GLchar* vs = "#version 430 core\n"
21054                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21055                                                           "\n"
21056                                                           "in  vec4 in_vs;\n"
21057                                                           "out vec4 vs_any;\n"
21058                                                           "\n"
21059                                                           "void main()\n"
21060                                                           "{\n"
21061                                                           "    vs_any = in_vs;\n"
21062                                                           "}\n"
21063                                                           "\n";
21064         static const GLchar* vs_tested = "#version 430 core\n"
21065                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21066                                                                          "\n"
21067                                                                          "VAR_DEFINITION"
21068                                                                          "\n"
21069                                                                          "in  vec4 in_vs;\n"
21070                                                                          "out vec4 any_fs;\n"
21071                                                                          "\n"
21072                                                                          "void main()\n"
21073                                                                          "{\n"
21074                                                                          "    vec4 result = in_vs;\n"
21075                                                                          "\n"
21076                                                                          "VARIABLE_USE"
21077                                                                          "\n"
21078                                                                          "    any_fs = result;\n"
21079                                                                          "}\n"
21080                                                                          "\n";
21081
21082         std::string source;
21083         testCase&   test_case = m_test_cases[test_case_index];
21084
21085         if (test_case.m_stage == stage)
21086         {
21087                 const GLchar* array = "";
21088                 GLchar            buffer[16];
21089                 const GLchar* index     = "";
21090                 size_t            position = 0;
21091                 size_t            temp;
21092                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
21093                 const GLchar* var_definition = 0;
21094                 const GLchar* var_use            = 0;
21095
21096                 sprintf(buffer, "%d", test_case.m_type.GetSize());
21097
21098                 switch (test_case.m_case)
21099                 {
21100                 case VALID:
21101                         var_definition = valid_var_definition;
21102                         var_use            = valid_use;
21103                         break;
21104                 case INVALID:
21105                         var_definition = invalid_var_definition;
21106                         var_use            = invalid_use;
21107                         break;
21108                 default:
21109                         TCU_FAIL("Invalid enum");
21110                 }
21111
21112                 switch (stage)
21113                 {
21114                 case Utils::Shader::GEOMETRY:
21115                         source = gs_tested;
21116                         array  = "[1]";
21117                         index  = "[0]";
21118                         break;
21119                 case Utils::Shader::TESS_CTRL:
21120                         source = tcs_tested;
21121                         array  = "[1]";
21122                         index  = "[gl_InvocationID]";
21123                         break;
21124                 case Utils::Shader::TESS_EVAL:
21125                         source = tes_tested;
21126                         array  = "[1]";
21127                         index  = "[0]";
21128                         break;
21129                 case Utils::Shader::VERTEX:
21130                         source = vs_tested;
21131                         break;
21132                 default:
21133                         TCU_FAIL("Invalid enum");
21134                 }
21135
21136                 temp = position;
21137                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21138                 position = temp;
21139                 Utils::replaceToken("SIZE", position, buffer, source);
21140                 Utils::replaceToken("ARRAY", position, array, source);
21141                 if (INVALID == test_case.m_case)
21142                 {
21143                         Utils::replaceToken("ARRAY", position, array, source);
21144                 }
21145                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21146
21147                 Utils::replaceAllTokens("TYPE", type_name, source);
21148                 Utils::replaceAllTokens("INDEX", index, source);
21149         }
21150         else
21151         {
21152                 switch (test_case.m_stage)
21153                 {
21154                 case Utils::Shader::GEOMETRY:
21155                         switch (stage)
21156                         {
21157                         case Utils::Shader::FRAGMENT:
21158                                 source = fs;
21159                                 break;
21160                         case Utils::Shader::VERTEX:
21161                                 source = vs;
21162                                 break;
21163                         default:
21164                                 source = "";
21165                         }
21166                         break;
21167                 case Utils::Shader::TESS_CTRL:
21168                         switch (stage)
21169                         {
21170                         case Utils::Shader::FRAGMENT:
21171                                 source = fs;
21172                                 break;
21173                         case Utils::Shader::VERTEX:
21174                                 source = vs;
21175                                 break;
21176                         default:
21177                                 source = "";
21178                         }
21179                         break;
21180                 case Utils::Shader::TESS_EVAL:
21181                         switch (stage)
21182                         {
21183                         case Utils::Shader::FRAGMENT:
21184                                 source = fs;
21185                                 break;
21186                         case Utils::Shader::TESS_CTRL:
21187                                 source = tcs;
21188                                 break;
21189                         case Utils::Shader::VERTEX:
21190                                 source = vs;
21191                                 break;
21192                         default:
21193                                 source = "";
21194                         }
21195                         break;
21196                 case Utils::Shader::VERTEX:
21197                         switch (stage)
21198                         {
21199                         case Utils::Shader::FRAGMENT:
21200                                 source = fs;
21201                                 break;
21202                         default:
21203                                 source = "";
21204                         }
21205                         break;
21206                 default:
21207                         TCU_FAIL("Invalid enum");
21208                         break;
21209                 }
21210         }
21211
21212         return source;
21213 }
21214
21215 /** Get description of test case
21216  *
21217  * @param test_case_index Index of test case
21218  *
21219  * @return Test case description
21220  **/
21221 std::string XFBVariableStrideTest::getTestCaseName(GLuint test_case_index)
21222 {
21223         std::stringstream stream;
21224         testCase&                 test_case = m_test_cases[test_case_index];
21225
21226         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
21227                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
21228
21229         switch (test_case.m_case)
21230         {
21231         case VALID:
21232                 stream << "valid";
21233                 break;
21234         case INVALID:
21235                 stream << "invalid";
21236                 break;
21237         default:
21238                 TCU_FAIL("Invalid enum");
21239         }
21240
21241         return stream.str();
21242 }
21243
21244 /** Get number of test cases
21245  *
21246  * @return Number of test cases
21247  **/
21248 GLuint XFBVariableStrideTest::getTestCaseNumber()
21249 {
21250         return static_cast<GLuint>(m_test_cases.size());
21251 }
21252
21253 /** Selects if "compute" stage is relevant for test
21254  *
21255  * @param ignored
21256  *
21257  * @return false
21258  **/
21259 bool XFBVariableStrideTest::isComputeRelevant(GLuint /* test_case_index */)
21260 {
21261         return false;
21262 }
21263
21264 /** Selects if compilation failure is expected result
21265  *
21266  * @param test_case_index Index of test case
21267  *
21268  * @return true
21269  **/
21270 bool XFBVariableStrideTest::isFailureExpected(GLuint test_case_index)
21271 {
21272         testCase& test_case = m_test_cases[test_case_index];
21273
21274         return (INVALID == test_case.m_case);
21275 }
21276
21277 /** Prepare all test cases
21278  *
21279  **/
21280 void XFBVariableStrideTest::testInit()
21281 {
21282         const GLuint n_types = getTypesNumber();
21283
21284         for (GLuint i = 0; i < n_types; ++i)
21285         {
21286                 const Utils::Type& type = getType(i);
21287
21288                 /*
21289                  Some of the cases are declared as following are considered as invalid,
21290                  but accoring to spec, the following declaration is valid: shaders in the
21291                  transform feedback capturing mode have an initial global default of layout(xfb_buffer=0) out,
21292                  so for the first variable's declaration, the xfb_stride = 16 is applied on buffer 0,  for the
21293                  second variable, its buffer is also inherited from global buffer 0, and its offset does not overflows
21294                  the stride.
21295
21296                  The xfb_stride is the memory width of given buffer, not for variable even though xfb_stride
21297                  is declared on the variable. It seems that the writter of this case misunderstand the concept of
21298                  xfb_stride, because spec describes that xfb_stride can be declared multiple times for the same buffer,
21299                  it is a compile or link-time error to have different values specified for the stride for the same buffer.
21300
21301                  int type_size = 8;
21302                  layout (xfb_offset = 0, xfb_stride = 2 * type_size) out double goku;
21303                  layout (xfb_offset = type_size)                     out double vegeta;
21304                  */
21305                 // all the shaders are valid, so remove the following loop(it contains CASE_MAX is enum of valid and invalid)
21306                 // for (GLuint c = 0; c < CASE_MAX; ++c)
21307                 {
21308                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21309                         {
21310                                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21311                                         (Utils::Shader::FRAGMENT == stage))
21312                                 {
21313                                         continue;
21314                                 }
21315
21316                                 testCase test_case = { (CASES)VALID, (Utils::Shader::STAGES)stage, type };
21317
21318                                 m_test_cases.push_back(test_case);
21319                         }
21320                 }
21321         }
21322 }
21323
21324 /** Constructor
21325  *
21326  * @param context Test framework context
21327  **/
21328 XFBBlockStrideTest::XFBBlockStrideTest(deqp::Context& context)
21329         : TestBase(context, "xfb_block_stride", "Test verifies that stride qualifier is respected for blocks")
21330 {
21331 }
21332
21333 /** Source for given test case and stage
21334  *
21335  * @param test_case_index Index of test case
21336  * @param stage           Shader stage
21337  *
21338  * @return Shader source
21339  **/
21340 std::string XFBBlockStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21341 {
21342         static const GLchar* var_definition = "layout (xfb_offset = 0, xfb_stride = 128) out Goku {\n"
21343                                                                                   "    vec4 gohan;\n"
21344                                                                                   "    vec4 goten;\n"
21345                                                                                   "    vec4 chichi;\n"
21346                                                                                   "} gokuARRAY;\n";
21347         static const GLchar* var_use = "    gokuINDEX.gohan  = vec4(1, 0, 0, 0);\n"
21348                                                                    "    gokuINDEX.goten  = vec4(0, 0, 1, 0);\n"
21349                                                                    "    gokuINDEX.chichi = vec4(0, 1, 0, 0);\n"
21350                                                                    "    if (vec4(0) == result)\n"
21351                                                                    "    {\n"
21352                                                                    "        gokuINDEX.gohan  = vec4(0, 1, 1, 1);\n"
21353                                                                    "        gokuINDEX.goten  = vec4(1, 1, 0, 1);\n"
21354                                                                    "        gokuINDEX.chichi = vec4(1, 0, 1, 1);\n"
21355                                                                    "    }\n";
21356         static const GLchar* gs_tested =
21357                 "#version 430 core\n"
21358                 "#extension GL_ARB_enhanced_layouts : require\n"
21359                 "\n"
21360                 "layout(points)                           in;\n"
21361                 "layout(triangle_strip, max_vertices = 4) out;\n"
21362                 "\n"
21363                 "VAR_DEFINITION"
21364                 "\n"
21365                 "out gl_PerVertex \n"
21366                 "{ \n"
21367                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
21368                 "}; \n"
21369                 "in  vec4 tes_gs[];\n"
21370                 "out vec4 gs_fs;\n"
21371                 "\n"
21372                 "void main()\n"
21373                 "{\n"
21374                 "    vec4 result = tes_gs[0];\n"
21375                 "\n"
21376                 "VARIABLE_USE"
21377                 "\n"
21378                 "    gs_fs = result;\n"
21379                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21380                 "    EmitVertex();\n"
21381                 "    gs_fs = result;\n"
21382                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21383                 "    EmitVertex();\n"
21384                 "    gs_fs = result;\n"
21385                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
21386                 "    EmitVertex();\n"
21387                 "    gs_fs = result;\n"
21388                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
21389                 "    EmitVertex();\n"
21390                 "}\n"
21391                 "\n";
21392         static const GLchar* tcs = "#version 430 core\n"
21393                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21394                                                            "\n"
21395                                                            "layout(vertices = 1) out;\n"
21396                                                            "\n"
21397                                                            "in  vec4 vs_tcs[];\n"
21398                                                            "out vec4 tcs_tes[];\n"
21399                                                            "\n"
21400                                                            "void main()\n"
21401                                                            "{\n"
21402                                                            "\n"
21403                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
21404                                                            "\n"
21405                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21406                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21407                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21408                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21409                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21410                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21411                                                            "}\n"
21412                                                            "\n";
21413 #if 0
21414         static const GLchar* tcs_tested =
21415                 "#version 430 core\n"
21416                 "#extension GL_ARB_enhanced_layouts : require\n"
21417                 "\n"
21418                 "layout(vertices = 1) out;\n"
21419                 "\n"
21420                 "VAR_DEFINITION"
21421                 "\n"
21422                 "in  vec4 vs_tcs[];\n"
21423                 "out vec4 tcs_tes[];\n"
21424                 "\n"
21425                 "void main()\n"
21426                 "{\n"
21427                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
21428                 "\n"
21429                 "VARIABLE_USE"
21430                 "\n"
21431                 "    tcs_tes[gl_InvocationID] = result;\n"
21432                 "\n"
21433                 "    gl_TessLevelOuter[0] = 1.0;\n"
21434                 "    gl_TessLevelOuter[1] = 1.0;\n"
21435                 "    gl_TessLevelOuter[2] = 1.0;\n"
21436                 "    gl_TessLevelOuter[3] = 1.0;\n"
21437                 "    gl_TessLevelInner[0] = 1.0;\n"
21438                 "    gl_TessLevelInner[1] = 1.0;\n"
21439                 "}\n"
21440                 "\n";
21441 #endif
21442         static const GLchar* tes_tested = "#version 430 core\n"
21443                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21444                                                                           "\n"
21445                                                                           "layout(isolines, point_mode) in;\n"
21446                                                                           "\n"
21447                                                                           "VAR_DEFINITION"
21448                                                                           "\n"
21449                                                                           "in  vec4 tcs_tes[];\n"
21450                                                                           "out vec4 tes_gs;\n"
21451                                                                           "\n"
21452                                                                           "void main()\n"
21453                                                                           "{\n"
21454                                                                           "    vec4 result = tcs_tes[0];\n"
21455                                                                           "\n"
21456                                                                           "VARIABLE_USE"
21457                                                                           "\n"
21458                                                                           "    tes_gs += result;\n"
21459                                                                           "}\n"
21460                                                                           "\n";
21461         static const GLchar* vs = "#version 430 core\n"
21462                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21463                                                           "\n"
21464                                                           "in  vec4 in_vs;\n"
21465                                                           "out vec4 vs_tcs;\n"
21466                                                           "\n"
21467                                                           "void main()\n"
21468                                                           "{\n"
21469                                                           "    vs_tcs = in_vs;\n"
21470                                                           "}\n"
21471                                                           "\n";
21472         static const GLchar* vs_tested = "#version 430 core\n"
21473                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21474                                                                          "\n"
21475                                                                          "VAR_DEFINITION"
21476                                                                          "\n"
21477                                                                          "in  vec4 in_vs;\n"
21478                                                                          "out vec4 vs_tcs;\n"
21479                                                                          "\n"
21480                                                                          "void main()\n"
21481                                                                          "{\n"
21482                                                                          "    vec4 result = in_vs;\n"
21483                                                                          "\n"
21484                                                                          "VARIABLE_USE"
21485                                                                          "\n"
21486                                                                          "    vs_tcs += result;\n"
21487                                                                          "}\n"
21488                                                                          "\n";
21489
21490         std::string                       source;
21491         Utils::Shader::STAGES test_case = m_test_cases[test_case_index];
21492
21493         if (test_case == stage)
21494         {
21495                 const GLchar* array     = "";
21496                 const GLchar* index     = "";
21497                 size_t            position = 0;
21498                 size_t            temp;
21499                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
21500                 // change array = "[]" to "[1]"
21501                 switch (stage)
21502                 {
21503                 case Utils::Shader::GEOMETRY:
21504                         source = gs_tested;
21505                         array  = "[1]";
21506                         index  = "[0]";
21507                         break;
21508 /*
21509                          It is invalid to define transform feedback output in HS
21510                          */
21511 #if 0
21512                         case Utils::Shader::TESS_CTRL:
21513                         source = tcs_tested;
21514                         array = "[]";
21515                         index = "[gl_InvocationID]";
21516                         break;
21517 #endif
21518                 case Utils::Shader::TESS_EVAL:
21519                         source = tes_tested;
21520                         array  = "[1]";
21521                         index  = "[0]";
21522                         break;
21523                 case Utils::Shader::VERTEX:
21524                         source = vs_tested;
21525                         break;
21526                 default:
21527                         TCU_FAIL("Invalid enum");
21528                 }
21529
21530                 temp = position;
21531                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21532                 position = temp;
21533                 Utils::replaceToken("ARRAY", position, array, source);
21534                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21535
21536                 Utils::replaceAllTokens("INDEX", index, source);
21537         }
21538         else
21539         {
21540                 switch (test_case)
21541                 {
21542                 case Utils::Shader::GEOMETRY:
21543                         switch (stage)
21544                         {
21545                         case Utils::Shader::VERTEX:
21546                                 source = vs;
21547                                 break;
21548                         default:
21549                                 source = "";
21550                         }
21551                         break;
21552                 case Utils::Shader::TESS_CTRL:
21553                         switch (stage)
21554                         {
21555                         case Utils::Shader::VERTEX:
21556                                 source = vs;
21557                                 break;
21558                         default:
21559                                 source = "";
21560                         }
21561                         break;
21562                 case Utils::Shader::TESS_EVAL:
21563                         switch (stage)
21564                         {
21565                         case Utils::Shader::TESS_CTRL:
21566                                 source = tcs;
21567                                 break;
21568                         case Utils::Shader::VERTEX:
21569                                 source = vs;
21570                                 break;
21571                         default:
21572                                 source = "";
21573                         }
21574                         break;
21575                 case Utils::Shader::VERTEX:
21576                         source = "";
21577                         break;
21578                 default:
21579                         TCU_FAIL("Invalid enum");
21580                         break;
21581                 }
21582         }
21583
21584         return source;
21585 }
21586
21587 /** Get description of test case
21588  *
21589  * @param test_case_index Index of test case
21590  *
21591  * @return Test case description
21592  **/
21593 std::string XFBBlockStrideTest::getTestCaseName(GLuint test_case_index)
21594 {
21595         std::stringstream stream;
21596
21597         stream << "Stage: " << Utils::Shader::GetStageName(m_test_cases[test_case_index]);
21598
21599         return stream.str();
21600 }
21601
21602 /** Get number of test cases
21603  *
21604  * @return Number of test cases
21605  **/
21606 GLuint XFBBlockStrideTest::getTestCaseNumber()
21607 {
21608         return static_cast<GLuint>(m_test_cases.size());
21609 }
21610
21611 /** Inspects program for xfb stride
21612  *
21613  * @param program Program to query
21614  *
21615  * @return true if query results match expected values, false otherwise
21616  **/
21617 bool XFBBlockStrideTest::inspectProgram(Utils::Program& program)
21618 {
21619         GLint stride = 0;
21620
21621         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
21622                                                 1 /* buf_size */, &stride);
21623
21624         return (128 == stride);
21625 }
21626
21627 /** Runs test case
21628  *
21629  * @param test_case_index Id of test case
21630  *
21631  * @return true if test case pass, false otherwise
21632  **/
21633 bool XFBBlockStrideTest::testCase(GLuint test_case_index)
21634 {
21635         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
21636         Utils::Program   program(m_context);
21637         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
21638         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
21639         bool                       test_case_result = true;
21640         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
21641
21642         program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
21643
21644         test_case_result = inspectProgram(program);
21645
21646         return test_case_result;
21647 }
21648
21649 /** Prepare all test cases
21650  *
21651  **/
21652 void XFBBlockStrideTest::testInit()
21653 {
21654         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21655         {
21656                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21657                         (Utils::Shader::FRAGMENT == stage))
21658                 {
21659                         continue;
21660                 }
21661
21662                 m_test_cases.push_back((Utils::Shader::STAGES)stage);
21663         }
21664 }
21665
21666 /** Constructor
21667  *
21668  * @param context Test context
21669  **/
21670 XFBBlockMemberStrideTest::XFBBlockMemberStrideTest(deqp::Context& context)
21671         : BufferTestBase(context, "xfb_block_member_stride",
21672                                          "Test verifies that xfb_stride qualifier is respected for block member")
21673 {
21674         /* Nothing to be done here */
21675 }
21676
21677 /** Get descriptors of buffers necessary for test
21678  *
21679  * @param ignored
21680  * @param out_descriptors Descriptors of buffers used by test
21681  **/
21682 void XFBBlockMemberStrideTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
21683                                                                                                         bufferDescriptor::Vector& out_descriptors)
21684 {
21685         const Utils::Type& vec4 = Utils::Type::vec4;
21686
21687         /* Test needs single uniform and xfb */
21688         out_descriptors.resize(2);
21689
21690         /* Get references */
21691         bufferDescriptor& uniform = out_descriptors[0];
21692         bufferDescriptor& xfb    = out_descriptors[1];
21693
21694         /* Index */
21695         uniform.m_index = 0;
21696         xfb.m_index             = 0;
21697
21698         /* Target */
21699         uniform.m_target = Utils::Buffer::Uniform;
21700         xfb.m_target     = Utils::Buffer::Transform_feedback;
21701
21702         /* Data */
21703         static const GLuint                     vec4_size   = 16;
21704         const std::vector<GLubyte>& gohan_data  = vec4.GenerateDataPacked();
21705         const std::vector<GLubyte>& goten_data  = vec4.GenerateDataPacked();
21706         const std::vector<GLubyte>& chichi_data = vec4.GenerateDataPacked();
21707
21708         /* Uniform data */
21709         uniform.m_initial_data.resize(3 * vec4_size);
21710         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], vec4_size);
21711         memcpy(&uniform.m_initial_data[0] + vec4_size, &goten_data[0], vec4_size);
21712         memcpy(&uniform.m_initial_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21713
21714         /* XFB data */
21715         xfb.m_initial_data.resize(4 * vec4_size);
21716         xfb.m_expected_data.resize(4 * vec4_size);
21717
21718         for (GLuint i = 0; i < 4 * vec4_size; ++i)
21719         {
21720                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
21721                 xfb.m_expected_data[i] = (glw::GLubyte)i;
21722         }
21723
21724         // the xfb_offset of "chichi" should be 32
21725         memcpy(&xfb.m_expected_data[0] + 0, &gohan_data[0], vec4_size);
21726         memcpy(&xfb.m_expected_data[0] + vec4_size, &goten_data[0], vec4_size);
21727         memcpy(&xfb.m_expected_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21728 }
21729
21730 /** Get body of main function for given shader stage
21731  *
21732  * @param ignored
21733  * @param stage            Shader stage
21734  * @param out_assignments  Set to empty
21735  * @param out_calculations Set to empty
21736  **/
21737 void XFBBlockMemberStrideTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21738                                                                                          std::string& out_assignments, std::string& out_calculations)
21739 {
21740         out_calculations = "";
21741
21742         static const GLchar* gs = "    gohan  = uni_gohan;\n"
21743                                                           "    goten  = uni_goten;\n"
21744                                                           "    chichi = uni_chichi;\n";
21745         static const GLchar* fs = "    fs_out = gohan + goten + chichi;\n";
21746
21747         const GLchar* assignments = "";
21748         switch (stage)
21749         {
21750         case Utils::Shader::FRAGMENT:
21751                 assignments = fs;
21752                 break;
21753         case Utils::Shader::GEOMETRY:
21754                 assignments = gs;
21755                 break;
21756         default:
21757                 break;
21758         }
21759
21760         out_assignments = assignments;
21761 }
21762
21763 /** Get interface of shader
21764  *
21765  * @param ignored
21766  * @param stage            Shader stage
21767  * @param out_interface    Set to ""
21768  **/
21769 void XFBBlockMemberStrideTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21770                                                                                                   std::string& out_interface)
21771 {
21772         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0) out Goku {\n"
21773                                                           "                             vec4 gohan;\n"
21774                                                           "    layout (xfb_stride = 32) vec4 goten;\n"
21775                                                           "                             vec4 chichi;\n"
21776                                                           "};\n"
21777                                                           "layout(binding = 0) uniform gs_block {\n"
21778                                                           "    vec4 uni_gohan;\n"
21779                                                           "    vec4 uni_goten;\n"
21780                                                           "    vec4 uni_chichi;\n"
21781                                                           "};\n";
21782         static const GLchar* fs = "in Goku {\n"
21783                                                           "    vec4 gohan;\n"
21784                                                           "    vec4 goten;\n"
21785                                                           "    vec4 chichi;\n"
21786                                                           "};\n"
21787                                                           "out vec4 fs_out;\n";
21788
21789         switch (stage)
21790         {
21791         case Utils::Shader::FRAGMENT:
21792                 out_interface = fs;
21793                 break;
21794         case Utils::Shader::GEOMETRY:
21795                 out_interface = gs;
21796                 break;
21797         default:
21798                 out_interface = "";
21799                 return;
21800         }
21801 }
21802
21803 /** Inspects program to check if all resources are as expected
21804  *
21805  * @param ignored
21806  * @param program    Program instance
21807  * @param out_stream Error message
21808  *
21809  * @return true if everything is ok, false otherwise
21810  **/
21811 bool XFBBlockMemberStrideTest::inspectProgram(GLuint /* test_case_index*/, Utils::Program& program,
21812                                                                                           std::stringstream& out_stream)
21813 {
21814         const GLuint gohan_id  = program.GetResourceIndex("gohan", GL_TRANSFORM_FEEDBACK_VARYING);
21815         const GLuint goten_id  = program.GetResourceIndex("goten", GL_TRANSFORM_FEEDBACK_VARYING);
21816         const GLuint chichi_id = program.GetResourceIndex("chichi", GL_TRANSFORM_FEEDBACK_VARYING);
21817
21818         GLint gohan_offset  = 0;
21819         GLint goten_offset  = 0;
21820         GLint chichi_offset = 0;
21821
21822         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, gohan_id, GL_OFFSET, 1, &gohan_offset);
21823         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, goten_id, GL_OFFSET, 1, &goten_offset);
21824         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, chichi_id, GL_OFFSET, 1, &chichi_offset);
21825
21826         // the xfb_offset of "chichi" should be 32
21827         if ((0 != gohan_offset) || (16 != goten_offset) || (32 != chichi_offset))
21828         {
21829                 out_stream << "Got wrong offset: [" << gohan_offset << ", " << goten_offset << ", " << chichi_offset
21830                                    << "] expected: [0, 16, 48]";
21831                 return false;
21832         }
21833
21834         return true;
21835 }
21836
21837 /** Constructor
21838  *
21839  * @param context Test framework context
21840  **/
21841 XFBDuplicatedStrideTest::XFBDuplicatedStrideTest(deqp::Context& context)
21842         : NegativeTestBase(context, "xfb_duplicated_stride",
21843                                            "Test verifies that compiler reports error when conflicting stride qualifiers are used")
21844 {
21845 }
21846
21847 /** Source for given test case and stage
21848  *
21849  * @param test_case_index Index of test case
21850  * @param stage           Shader stage
21851  *
21852  * @return Shader source
21853  **/
21854 std::string XFBDuplicatedStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21855 {
21856         static const GLchar* invalid_var_definition = "const uint valid_stride = 64;\n"
21857                                                                                                   "const uint conflicting_stride = 128;\n"
21858                                                                                                   "\n"
21859                                                                                                   "layout (xfb_buffer = 0, xfb_stride = valid_stride)       out;\n"
21860                                                                                                   "layout (xfb_buffer = 0, xfb_stride = conflicting_stride) out;\n";
21861         static const GLchar* valid_var_definition = "const uint valid_stride = 64;\n"
21862                                                                                                 "\n"
21863                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n"
21864                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n";
21865         static const GLchar* fs = "#version 430 core\n"
21866                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21867                                                           "\n"
21868                                                           "in  vec4 any_fs;\n"
21869                                                           "out vec4 fs_out;\n"
21870                                                           "\n"
21871                                                           "void main()\n"
21872                                                           "{\n"
21873                                                           "    fs_out = any_fs;\n"
21874                                                           "}\n"
21875                                                           "\n";
21876         static const GLchar* gs_tested = "#version 430 core\n"
21877                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21878                                                                          "\n"
21879                                                                          "layout(points)                           in;\n"
21880                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21881                                                                          "\n"
21882                                                                          "VAR_DEFINITION"
21883                                                                          "\n"
21884                                                                          "in  vec4 vs_any[];\n"
21885                                                                          "out vec4 any_fs;\n"
21886                                                                          "\n"
21887                                                                          "void main()\n"
21888                                                                          "{\n"
21889                                                                          "    vec4 result = vs_any[0];\n"
21890                                                                          "\n"
21891                                                                          "VARIABLE_USE"
21892                                                                          "\n"
21893                                                                          "    any_fs = result;\n"
21894                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21895                                                                          "    EmitVertex();\n"
21896                                                                          "    any_fs = result;\n"
21897                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21898                                                                          "    EmitVertex();\n"
21899                                                                          "    any_fs = result;\n"
21900                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21901                                                                          "    EmitVertex();\n"
21902                                                                          "    any_fs = result;\n"
21903                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21904                                                                          "    EmitVertex();\n"
21905                                                                          "}\n"
21906                                                                          "\n";
21907         static const GLchar* tcs = "#version 430 core\n"
21908                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21909                                                            "\n"
21910                                                            "layout(vertices = 1) out;\n"
21911                                                            "\n"
21912                                                            "in  vec4 vs_any[];\n"
21913                                                            "out vec4 tcs_tes[];\n"
21914                                                            "\n"
21915                                                            "void main()\n"
21916                                                            "{\n"
21917                                                            "\n"
21918                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21919                                                            "\n"
21920                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21921                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21922                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21923                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21924                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21925                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21926                                                            "}\n"
21927                                                            "\n";
21928         static const GLchar* tcs_tested = "#version 430 core\n"
21929                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21930                                                                           "\n"
21931                                                                           "layout(vertices = 1) out;\n"
21932                                                                           "\n"
21933                                                                           "VAR_DEFINITION"
21934                                                                           "\n"
21935                                                                           "in  vec4 vs_any[];\n"
21936                                                                           "out vec4 any_fs[];\n"
21937                                                                           "\n"
21938                                                                           "void main()\n"
21939                                                                           "{\n"
21940                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21941                                                                           "\n"
21942                                                                           "VARIABLE_USE"
21943                                                                           "\n"
21944                                                                           "    any_fs[gl_InvocationID] = result;\n"
21945                                                                           "\n"
21946                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21947                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21948                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21949                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21950                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21951                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21952                                                                           "}\n"
21953                                                                           "\n";
21954         static const GLchar* tes_tested = "#version 430 core\n"
21955                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21956                                                                           "\n"
21957                                                                           "layout(isolines, point_mode) in;\n"
21958                                                                           "\n"
21959                                                                           "VAR_DEFINITION"
21960                                                                           "\n"
21961                                                                           "in  vec4 tcs_tes[];\n"
21962                                                                           "out vec4 any_fs;\n"
21963                                                                           "\n"
21964                                                                           "void main()\n"
21965                                                                           "{\n"
21966                                                                           "    vec4 result = tcs_tes[0];\n"
21967                                                                           "\n"
21968                                                                           "VARIABLE_USE"
21969                                                                           "\n"
21970                                                                           "    any_fs = result;\n"
21971                                                                           "}\n"
21972                                                                           "\n";
21973         static const GLchar* vs = "#version 430 core\n"
21974                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21975                                                           "\n"
21976                                                           "in  vec4 in_vs;\n"
21977                                                           "out vec4 vs_any;\n"
21978                                                           "\n"
21979                                                           "void main()\n"
21980                                                           "{\n"
21981                                                           "    vs_any = in_vs;\n"
21982                                                           "}\n"
21983                                                           "\n";
21984         static const GLchar* vs_tested = "#version 430 core\n"
21985                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21986                                                                          "\n"
21987                                                                          "VAR_DEFINITION"
21988                                                                          "\n"
21989                                                                          "in  vec4 in_vs;\n"
21990                                                                          "out vec4 any_fs;\n"
21991                                                                          "\n"
21992                                                                          "void main()\n"
21993                                                                          "{\n"
21994                                                                          "    vec4 result = in_vs;\n"
21995                                                                          "\n"
21996                                                                          "VARIABLE_USE"
21997                                                                          "\n"
21998                                                                          "    any_fs += result;\n"
21999                                                                          "}\n"
22000                                                                          "\n";
22001
22002         std::string source;
22003         testCase&   test_case = m_test_cases[test_case_index];
22004
22005         if (test_case.m_stage == stage)
22006         {
22007                 size_t            position               = 0;
22008                 const GLchar* var_definition = 0;
22009                 const GLchar* var_use            = "";
22010
22011                 switch (test_case.m_case)
22012                 {
22013                 case VALID:
22014                         var_definition = valid_var_definition;
22015                         break;
22016                 case INVALID:
22017                         var_definition = invalid_var_definition;
22018                         break;
22019                 default:
22020                         TCU_FAIL("Invalid enum");
22021                 }
22022
22023                 switch (stage)
22024                 {
22025                 case Utils::Shader::GEOMETRY:
22026                         source = gs_tested;
22027                         break;
22028                 case Utils::Shader::TESS_CTRL:
22029                         source = tcs_tested;
22030                         break;
22031                 case Utils::Shader::TESS_EVAL:
22032                         source = tes_tested;
22033                         break;
22034                 case Utils::Shader::VERTEX:
22035                         source = vs_tested;
22036                         break;
22037                 default:
22038                         TCU_FAIL("Invalid enum");
22039                 }
22040
22041                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22042                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22043         }
22044         else
22045         {
22046                 switch (test_case.m_stage)
22047                 {
22048                 case Utils::Shader::GEOMETRY:
22049                         switch (stage)
22050                         {
22051                         case Utils::Shader::FRAGMENT:
22052                                 source = fs;
22053                                 break;
22054                         case Utils::Shader::VERTEX:
22055                                 source = vs;
22056                                 break;
22057                         default:
22058                                 source = "";
22059                         }
22060                         break;
22061                 case Utils::Shader::TESS_CTRL:
22062                         switch (stage)
22063                         {
22064                         case Utils::Shader::FRAGMENT:
22065                                 source = fs;
22066                                 break;
22067                         case Utils::Shader::VERTEX:
22068                                 source = vs;
22069                                 break;
22070                         default:
22071                                 source = "";
22072                         }
22073                         break;
22074                 case Utils::Shader::TESS_EVAL:
22075                         switch (stage)
22076                         {
22077                         case Utils::Shader::FRAGMENT:
22078                                 source = fs;
22079                                 break;
22080                         case Utils::Shader::TESS_CTRL:
22081                                 source = tcs;
22082                                 break;
22083                         case Utils::Shader::VERTEX:
22084                                 source = vs;
22085                                 break;
22086                         default:
22087                                 source = "";
22088                         }
22089                         break;
22090                 case Utils::Shader::VERTEX:
22091                         switch (stage)
22092                         {
22093                         case Utils::Shader::FRAGMENT:
22094                                 source = fs;
22095                                 break;
22096                         default:
22097                                 source = "";
22098                         }
22099                         break;
22100                 default:
22101                         TCU_FAIL("Invalid enum");
22102                         break;
22103                 }
22104         }
22105
22106         return source;
22107 }
22108
22109 /** Get description of test case
22110  *
22111  * @param test_case_index Index of test case
22112  *
22113  * @return Test case description
22114  **/
22115 std::string XFBDuplicatedStrideTest::getTestCaseName(GLuint test_case_index)
22116 {
22117         std::stringstream stream;
22118         testCase&                 test_case = m_test_cases[test_case_index];
22119
22120         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
22121
22122         switch (test_case.m_case)
22123         {
22124         case VALID:
22125                 stream << "valid";
22126                 break;
22127         case INVALID:
22128                 stream << "invalid";
22129                 break;
22130         default:
22131                 TCU_FAIL("Invalid enum");
22132         }
22133
22134         return stream.str();
22135 }
22136
22137 /** Get number of test cases
22138  *
22139  * @return Number of test cases
22140  **/
22141 GLuint XFBDuplicatedStrideTest::getTestCaseNumber()
22142 {
22143         return static_cast<GLuint>(m_test_cases.size());
22144 }
22145
22146 /** Selects if "compute" stage is relevant for test
22147  *
22148  * @param ignored
22149  *
22150  * @return false
22151  **/
22152 bool XFBDuplicatedStrideTest::isComputeRelevant(GLuint /* test_case_index */)
22153 {
22154         return false;
22155 }
22156
22157 /** Selects if compilation failure is expected result
22158  *
22159  * @param test_case_index Index of test case
22160  *
22161  * @return true
22162  **/
22163 bool XFBDuplicatedStrideTest::isFailureExpected(GLuint test_case_index)
22164 {
22165         testCase& test_case = m_test_cases[test_case_index];
22166
22167         return (INVALID == test_case.m_case);
22168 }
22169
22170 /** Prepare all test cases
22171  *
22172  **/
22173 void XFBDuplicatedStrideTest::testInit()
22174 {
22175         for (GLuint c = 0; c < CASE_MAX; ++c)
22176         {
22177                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22178                 {
22179                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22180                                 (Utils::Shader::FRAGMENT == stage))
22181                         {
22182                                 continue;
22183                         }
22184
22185                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
22186
22187                         m_test_cases.push_back(test_case);
22188                 }
22189         }
22190 }
22191
22192 /** Constructor
22193  *
22194  * @param context Test framework context
22195  **/
22196 XFBGetProgramResourceAPITest::XFBGetProgramResourceAPITest(deqp::Context& context)
22197         : TestBase(context, "xfb_get_program_resource_api",
22198                            "Test verifies that get program resource reports correct results for XFB")
22199 {
22200 }
22201
22202 /** Source for given test case and stage
22203  *
22204  * @param test_case_index Index of test case
22205  * @param stage           Shader stage
22206  *
22207  * @return Shader source
22208  **/
22209 std::string XFBGetProgramResourceAPITest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
22210 {
22211         static const GLchar* api_var_definition = "out TYPE b0_v1ARRAY;\n"
22212                                                                                           "out TYPE b1_v1ARRAY;\n"
22213                                                                                           "out TYPE b0_v3ARRAY;\n"
22214                                                                                           "out TYPE b0_v0ARRAY;\n";
22215         static const GLchar* xfb_var_definition =
22216                 "const uint type_size = SIZE;\n"
22217                 "\n"
22218                 "layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;\n"
22219                 "\n"
22220                 "layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out TYPE b0_v1ARRAY;\n"
22221                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out TYPE b1_v1ARRAY;\n"
22222                 "layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out TYPE b0_v3ARRAY;\n"
22223                 "layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out TYPE b0_v0ARRAY;\n";
22224         static const GLchar* var_use = "    b0_v1INDEX = TYPE(0);\n"
22225                                                                    "    b1_v1INDEX = TYPE(1);\n"
22226                                                                    "    b0_v3INDEX = TYPE(0);\n"
22227                                                                    "    b0_v0INDEX = TYPE(1);\n"
22228                                                                    "    if (vec4(0) == result)\n"
22229                                                                    "    {\n"
22230                                                                    "        b0_v1INDEX = TYPE(1);\n"
22231                                                                    "        b1_v1INDEX = TYPE(0);\n"
22232                                                                    "        b0_v3INDEX = TYPE(1);\n"
22233                                                                    "        b0_v0INDEX = TYPE(0);\n"
22234                                                                    "    }\n";
22235         static const GLchar* gs_tested =
22236                 "#version 430 core\n"
22237                 "#extension GL_ARB_enhanced_layouts : require\n"
22238                 "\n"
22239                 "layout(points)                           in;\n"
22240                 "layout(triangle_strip, max_vertices = 4) out;\n"
22241                 "\n"
22242                 "VAR_DEFINITION"
22243                 "\n"
22244                 "out gl_PerVertex \n"
22245                 "{ \n"
22246                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
22247                 "}; \n"
22248                 "in  vec4 tes_gs[];\n"
22249                 "out vec4 gs_fs;\n"
22250                 "\n"
22251                 "void main()\n"
22252                 "{\n"
22253                 "    vec4 result = tes_gs[0];\n"
22254                 "\n"
22255                 "VARIABLE_USE"
22256                 "\n"
22257                 "    gs_fs = result;\n"
22258                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
22259                 "    EmitVertex();\n"
22260                 "    gs_fs = result;\n"
22261                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
22262                 "    EmitVertex();\n"
22263                 "    gs_fs = result;\n"
22264                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
22265                 "    EmitVertex();\n"
22266                 "    gs_fs = result;\n"
22267                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
22268                 "    EmitVertex();\n"
22269                 "}\n"
22270                 "\n";
22271 #if 0
22272         static const GLchar* tcs_tested =
22273                 "#version 430 core\n"
22274                 "#extension GL_ARB_enhanced_layouts : require\n"
22275                 "\n"
22276                 "layout(vertices = 1) out;\n"
22277                 "\n"
22278                 "VAR_DEFINITION"
22279                 "\n"
22280                 "in  vec4 vs_tcs[];\n"
22281                 "out vec4 tcs_tes[];\n"
22282                 "\n"
22283                 "void main()\n"
22284                 "{\n"
22285                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
22286                 "\n"
22287                 "VARIABLE_USE"
22288                 "\n"
22289                 "    tcs_tes[gl_InvocationID] = result;\n"
22290                 "\n"
22291                 "    gl_TessLevelOuter[0] = 1.0;\n"
22292                 "    gl_TessLevelOuter[1] = 1.0;\n"
22293                 "    gl_TessLevelOuter[2] = 1.0;\n"
22294                 "    gl_TessLevelOuter[3] = 1.0;\n"
22295                 "    gl_TessLevelInner[0] = 1.0;\n"
22296                 "    gl_TessLevelInner[1] = 1.0;\n"
22297                 "}\n"
22298                 "\n";
22299 #endif
22300         static const GLchar* tes_tested = "#version 430 core\n"
22301                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22302                                                                           "\n"
22303                                                                           "layout(isolines, point_mode) in;\n"
22304                                                                           "\n"
22305                                                                           "VAR_DEFINITION"
22306                                                                           "\n"
22307                                                                           "in  vec4 tcs_tes[];\n"
22308                                                                           "out vec4 tes_gs;\n"
22309                                                                           "\n"
22310                                                                           "void main()\n"
22311                                                                           "{\n"
22312                                                                           "    vec4 result = tcs_tes[0];\n"
22313                                                                           "\n"
22314                                                                           "VARIABLE_USE"
22315                                                                           "\n"
22316                                                                           "    tes_gs = result;\n"
22317                                                                           "}\n"
22318                                                                           "\n";
22319         static const GLchar* vs_tested = "#version 430 core\n"
22320                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22321                                                                          "\n"
22322                                                                          "VAR_DEFINITION"
22323                                                                          "\n"
22324                                                                          "in  vec4 in_vs;\n"
22325                                                                          "out vec4 vs_tcs;\n"
22326                                                                          "\n"
22327                                                                          "void main()\n"
22328                                                                          "{\n"
22329                                                                          "    vec4 result = in_vs;\n"
22330                                                                          "\n"
22331                                                                          "VARIABLE_USE"
22332                                                                          "\n"
22333                                                                          "    vs_tcs = result;\n"
22334                                                                          "}\n"
22335                                                                          "\n";
22336
22337         std::string              source;
22338         const test_Case& test_case = m_test_cases[test_case_index];
22339
22340         if (test_case.m_stage == stage)
22341         {
22342                 const GLchar* array = "";
22343                 GLchar            buffer[16];
22344                 const GLchar* index     = "";
22345                 size_t            position = 0;
22346                 size_t            temp;
22347                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
22348                 const GLchar* var_definition = 0;
22349
22350                 sprintf(buffer, "%d", test_case.m_type.GetSize());
22351
22352                 if (XFB == test_case.m_case)
22353                 {
22354                         var_definition = xfb_var_definition;
22355                 }
22356                 else
22357                 {
22358                         var_definition = api_var_definition;
22359                 }
22360
22361                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
22362                 // change array = "[]" to "[1]"
22363                 switch (stage)
22364                 {
22365                 case Utils::Shader::GEOMETRY:
22366                         source = gs_tested;
22367                         array  = "[1]";
22368                         index  = "[0]";
22369                         break;
22370 // It is invalid to output transform feedback varyings in tessellation control shader
22371 #if 0
22372                 case Utils::Shader::TESS_CTRL:
22373                         source = tcs_tested;
22374                         array = "[]";
22375                         index = "[gl_InvocationID]";
22376                         break;
22377 #endif
22378                 case Utils::Shader::TESS_EVAL:
22379                         source = tes_tested;
22380                         array  = "[1]";
22381                         index  = "[0]";
22382                         break;
22383                 case Utils::Shader::VERTEX:
22384                         source = vs_tested;
22385                         break;
22386                 default:
22387                         TCU_FAIL("Invalid enum");
22388                 }
22389
22390                 temp = position;
22391                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22392                 if (XFB == test_case.m_case)
22393                 {
22394                         position = temp;
22395                         Utils::replaceToken("SIZE", position, buffer, source);
22396                 }
22397                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22398
22399                 Utils::replaceAllTokens("ARRAY", array, source);
22400                 Utils::replaceAllTokens("INDEX", index, source);
22401                 Utils::replaceAllTokens("TYPE", type_name, source);
22402         }
22403         else
22404         {
22405                 source = "";
22406         }
22407
22408         return source;
22409 }
22410
22411 /** Get description of test case
22412  *
22413  * @param test_case_index Index of test case
22414  *
22415  * @return Test case description
22416  **/
22417 std::string XFBGetProgramResourceAPITest::getTestCaseName(GLuint test_case_index)
22418 {
22419         std::stringstream stream;
22420         const test_Case&  test_case = m_test_cases[test_case_index];
22421
22422         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
22423                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
22424
22425         switch (test_case.m_case)
22426         {
22427         case INTERLEAVED:
22428                 stream << "interleaved";
22429                 break;
22430         case SEPARATED:
22431                 stream << "separated";
22432                 break;
22433         case XFB:
22434                 stream << "xfb";
22435                 break;
22436         default:
22437                 TCU_FAIL("Invalid enum");
22438         }
22439
22440         return stream.str();
22441 }
22442
22443 /** Get number of test cases
22444  *
22445  * @return Number of test cases
22446  **/
22447 GLuint XFBGetProgramResourceAPITest::getTestCaseNumber()
22448 {
22449         return static_cast<GLuint>(m_test_cases.size());
22450 }
22451
22452 /** Inspects program for offset, buffer index, buffer stride and type
22453  *
22454  * @param test_case_index Index of test case
22455  * @param program         Program to query
22456  *
22457  * @return true if query results match expected values, false otherwise
22458  **/
22459 bool XFBGetProgramResourceAPITest::inspectProgram(glw::GLuint test_case_index, Utils::Program& program)
22460 {
22461         GLint                    b0_stride      = 0;
22462         GLint                    b1_stride      = 0;
22463         GLint                    b0_v0_buf      = 0;
22464         GLint                    b0_v0_offset = 0;
22465         GLint                    b0_v0_type   = 0;
22466         GLint                    b0_v1_buf      = 0;
22467         GLint                    b0_v1_offset = 0;
22468         GLint                    b0_v1_type   = 0;
22469         GLint                    b0_v3_buf      = 0;
22470         GLint                    b0_v3_offset = 0;
22471         GLint                    b0_v3_type   = 0;
22472         GLint                    b1_v1_buf      = 0;
22473         GLint                    b1_v1_offset = 0;
22474         GLint                    b1_v1_type   = 0;
22475         const test_Case& test_case      = m_test_cases[test_case_index];
22476         const GLenum     type_enum      = test_case.m_type.GetTypeGLenum();
22477         const GLint              type_size      = test_case.m_type.GetSize();
22478
22479         GLuint b0_v0_index = program.GetResourceIndex("b0_v0", GL_TRANSFORM_FEEDBACK_VARYING);
22480         GLuint b0_v1_index = program.GetResourceIndex("b0_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22481         GLuint b0_v3_index = program.GetResourceIndex("b0_v3", GL_TRANSFORM_FEEDBACK_VARYING);
22482         GLuint b1_v1_index = program.GetResourceIndex("b1_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22483
22484         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_OFFSET, 1 /* buf_size */, &b0_v0_offset);
22485         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_OFFSET, 1 /* buf_size */, &b0_v1_offset);
22486         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_OFFSET, 1 /* buf_size */, &b0_v3_offset);
22487         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_OFFSET, 1 /* buf_size */, &b1_v1_offset);
22488
22489         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TYPE, 1 /* buf_size */, &b0_v0_type);
22490         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TYPE, 1 /* buf_size */, &b0_v1_type);
22491         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TYPE, 1 /* buf_size */, &b0_v3_type);
22492         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TYPE, 1 /* buf_size */, &b1_v1_type);
22493
22494         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22495                                                 1 /* buf_size */, &b0_v0_buf);
22496         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22497                                                 1 /* buf_size */, &b0_v1_buf);
22498         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22499                                                 1 /* buf_size */, &b0_v3_buf);
22500         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22501                                                 1 /* buf_size */, &b1_v1_buf);
22502
22503         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b0_v0_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22504                                                 &b0_stride);
22505         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b1_v1_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22506                                                 &b1_stride);
22507
22508         if (SEPARATED != test_case.m_case)
22509         {
22510                 return (((GLint)(4 * type_size) == b0_stride) && ((GLint)(4 * type_size) == b1_stride) &&
22511                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0 * type_size) == b0_v0_offset) &&
22512                                 ((GLint)(type_enum) == b0_v0_type) && ((GLint)(0) == b0_v1_buf) &&
22513                                 ((GLint)(1 * type_size) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22514                                 ((GLint)(0) == b0_v3_buf) && ((GLint)(3 * type_size) == b0_v3_offset) &&
22515                                 ((GLint)(type_enum) == b0_v3_type) && ((GLint)(1) == b1_v1_buf) &&
22516                                 ((GLint)(1 * type_size) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22517         }
22518         else
22519         {
22520                 return (((GLint)(1 * type_size) == b0_stride) && ((GLint)(1 * type_size) == b1_stride) &&
22521                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0) == b0_v0_offset) && ((GLint)(type_enum) == b0_v0_type) &&
22522                                 ((GLint)(1) == b0_v1_buf) && ((GLint)(0) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22523                                 ((GLint)(2) == b0_v3_buf) && ((GLint)(0) == b0_v3_offset) && ((GLint)(type_enum) == b0_v3_type) &&
22524                                 ((GLint)(3) == b1_v1_buf) && ((GLint)(0) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22525         }
22526 }
22527
22528 /** Insert gl_SkipComponents
22529  *
22530  * @param num_components How many gl_SkipComponents1 need to be inserted
22531  * @param varyings The transform feedback varyings string vector
22532  *
22533  **/
22534 void XFBGetProgramResourceAPITest::insertSkipComponents(int num_components, Utils::Program::NameVector& varyings)
22535 {
22536         int num_component_4 = num_components / 4;
22537         int num_component_1 = num_components % 4;
22538         for (int i = 0; i < num_component_4; i++)
22539         {
22540                 varyings.push_back("gl_SkipComponents4");
22541         }
22542         switch (num_component_1)
22543         {
22544         case 1:
22545                 varyings.push_back("gl_SkipComponents1");
22546                 break;
22547         case 2:
22548                 varyings.push_back("gl_SkipComponents2");
22549                 break;
22550         case 3:
22551                 varyings.push_back("gl_SkipComponents3");
22552                 break;
22553         default:
22554                 break;
22555         }
22556 }
22557
22558 /** Runs test case
22559  *
22560  * @param test_case_index Id of test case
22561  *
22562  * @return true if test case pass, false otherwise
22563  **/
22564 bool XFBGetProgramResourceAPITest::testCase(GLuint test_case_index)
22565 {
22566         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
22567         Utils::Program   program(m_context);
22568         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
22569         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
22570         const test_Case&   test_case            = m_test_cases[test_case_index];
22571         bool                       test_case_result = true;
22572         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
22573
22574         // According to spec: gl_SkipComponents1 ~ gl_SkipComponents4 is treated as specifying a one- to four-component floating point output variables with undefined values.
22575         // No data will be recorded for such strings, but the offset assigned to the next variable in varyings and the stride of the assigned bingding point will be affected.
22576
22577         if (INTERLEAVED == test_case.m_case)
22578         {
22579                 /*
22580                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22581                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22582                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22583                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22584
22585                  Note: the type can be float, double, mat2, mat3x2, dmat2, dmat3x2..., so to make the each variable of "captured_varyings" has the same xfb_offset with the above shaders,
22586                  we need to calculate how many "gl_SkipComponents" need to be inserted.
22587                  */
22588                 Utils::Program::NameVector captured_varyings;
22589                 captured_varyings.push_back("b0_v0");
22590                 captured_varyings.push_back("b0_v1");
22591                 // Compute how many gl_SkipComponents to be inserted
22592                 int numComponents = test_case.m_type.GetSize() / 4;
22593                 insertSkipComponents(numComponents, captured_varyings);
22594                 captured_varyings.push_back("b0_v3");
22595                 captured_varyings.push_back("gl_NextBuffer");
22596                 insertSkipComponents(numComponents, captured_varyings);
22597                 captured_varyings.push_back("b1_v1");
22598                 insertSkipComponents(numComponents * 2, captured_varyings);
22599
22600                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, true,
22601                                          true /* separable */);
22602         }
22603         else if (SEPARATED == test_case.m_case)
22604         {
22605                 Utils::Program::NameVector captured_varyings;
22606
22607                 captured_varyings.push_back("b0_v0");
22608                 captured_varyings.push_back("b0_v1");
22609                 captured_varyings.push_back("b0_v3");
22610                 captured_varyings.push_back("b1_v1");
22611
22612                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, false,
22613                                          true /* separable */);
22614         }
22615         else
22616         {
22617
22618                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
22619         }
22620
22621         test_case_result = inspectProgram(test_case_index, program);
22622
22623         return test_case_result;
22624 }
22625
22626 /** Prepare all test cases
22627  *
22628  **/
22629 void XFBGetProgramResourceAPITest::testInit()
22630 {
22631         const Functions& gl              = m_context.getRenderContext().getFunctions();
22632         const GLuint     n_types = getTypesNumber();
22633         GLint                    max_xfb_int;
22634         GLint                    max_xfb_sep;
22635
22636         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_int);
22637         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22638
22639         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_xfb_sep);
22640         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22641
22642         GLint max_varyings;
22643         gl.getIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varyings);
22644
22645         for (GLuint i = 0; i < n_types; ++i)
22646         {
22647                 // When i == 7, the type is dmat4, i == 9 the type is dmat4x3, the number of output components exceeds the maximum value that AMD's driver supported,
22648                 // the MAX_VARYING_COMPONENTS is 32 in our driver, but when the variable type is dmat4 or dmat4x3, the number of output component is 33, to make the
22649                 // shader valid, we can either skip the dmat4, dmat4x3 or query the implementation-dependent value MAX_VARYING_COMPONENTS before generating the shader
22650                 // to guarantee the number of varying not exceeded.
22651                 /*
22652                  layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;
22653                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22654                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22655                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22656                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22657                  in  vec4 in_vs;
22658                  out vec4 vs_tcs;
22659                  */
22660                 if (i == 7 || i == 9)
22661                         continue;
22662                 const Utils::Type& type = getType(i);
22663                 if (4 * type.GetNumComponents() + 4 > (GLuint)max_varyings)
22664                 {
22665                         continue;
22666                 }
22667                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22668                 {
22669                         /*
22670                          It is invalid to define transform feedback output in HS
22671                          */
22672                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22673                                 (Utils::Shader::FRAGMENT == stage))
22674                         {
22675                                 continue;
22676                         }
22677
22678                         test_Case test_case_int = { INTERLEAVED, (Utils::Shader::STAGES)stage, type };
22679                         test_Case test_case_sep = { SEPARATED, (Utils::Shader::STAGES)stage, type };
22680                         test_Case test_case_xfb = { XFB, (Utils::Shader::STAGES)stage, type };
22681
22682                         if ((int)type.GetSize() <= max_xfb_int)
22683                         {
22684                                 m_test_cases.push_back(test_case_xfb);
22685                                 m_test_cases.push_back(test_case_int);
22686                         }
22687
22688                         if ((int)type.GetSize() <= max_xfb_sep)
22689                         {
22690                                 m_test_cases.push_back(test_case_sep);
22691                         }
22692                 }
22693         }
22694 }
22695
22696 /** Constructor
22697  *
22698  * @param context Test context
22699  **/
22700 XFBOverrideQualifiersWithAPITest::XFBOverrideQualifiersWithAPITest(deqp::Context& context)
22701         : BufferTestBase(context, "xfb_override_qualifiers_with_api",
22702                                          "Test verifies that xfb_offset qualifier is not overriden with API")
22703 {
22704         /* Nothing to be done here */
22705 }
22706
22707 /** Get descriptors of buffers necessary for test
22708  *
22709  * @param test_case_index Index of test case
22710  * @param out_descriptors Descriptors of buffers used by test
22711  **/
22712 void XFBOverrideQualifiersWithAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
22713                                                                                                                         bufferDescriptor::Vector& out_descriptors)
22714 {
22715         const Utils::Type& type = getType(test_case_index);
22716
22717         /* Test needs single uniform and xfb */
22718         out_descriptors.resize(2);
22719
22720         /* Get references */
22721         bufferDescriptor& uniform = out_descriptors[0];
22722         bufferDescriptor& xfb    = out_descriptors[1];
22723
22724         /* Index */
22725         uniform.m_index = 0;
22726         xfb.m_index             = 0;
22727
22728         /* Target */
22729         uniform.m_target = Utils::Buffer::Uniform;
22730         xfb.m_target     = Utils::Buffer::Transform_feedback;
22731
22732         /* Data */
22733         const GLuint                            gen_start   = Utils::s_rand;
22734         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22735         const std::vector<GLubyte>& trunks_data = type.GenerateData();
22736         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22737         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22738
22739         Utils::s_rand                                                           = gen_start;
22740         const std::vector<GLubyte>& vegeta_data_pck = type.GenerateDataPacked();
22741         /*
22742          The xfb varying goku is -0.375, it is expected to equal to xfb.m_expected_data[0], xfb.m_expected_data[0] is assigned from goku_data_pck(-0.5)
22743          how can make them equal ? is it as designed?  Add the following statement,  which can make sure goku_data_pck equals to goku_data
22744          */
22745         const std::vector<GLubyte>& goku_data_pck = type.GenerateDataPacked();
22746
22747         const GLuint type_size   = static_cast<GLuint>(vegeta_data.size());
22748         const GLuint type_size_pck = static_cast<GLuint>(vegeta_data_pck.size());
22749
22750         /* Uniform data */
22751         uniform.m_initial_data.resize(4 * type_size);
22752         memcpy(&uniform.m_initial_data[0] + 0, &vegeta_data[0], type_size);
22753         memcpy(&uniform.m_initial_data[0] + type_size, &trunks_data[0], type_size);
22754         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goku_data[0], type_size);
22755         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &gohan_data[0], type_size);
22756
22757         /* XFB data */
22758         xfb.m_initial_data.resize(4 * type_size_pck);
22759         xfb.m_expected_data.resize(4 * type_size_pck);
22760
22761         for (GLuint i = 0; i < 4 * type_size_pck; ++i)
22762         {
22763                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
22764                 xfb.m_expected_data[i] = (glw::GLubyte)i;
22765         }
22766
22767         memcpy(&xfb.m_expected_data[0] + 0, &goku_data_pck[0], type_size_pck);
22768         memcpy(&xfb.m_expected_data[0] + 2 * type_size_pck, &vegeta_data_pck[0], type_size_pck);
22769 }
22770
22771 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
22772  *
22773  * @param ignored
22774  * @param captured_varyings List of names
22775  **/
22776 void XFBOverrideQualifiersWithAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
22777                                                                                                                    Utils::Program::NameVector& captured_varyings)
22778 {
22779         captured_varyings.resize(2);
22780
22781         captured_varyings[0] = "trunks";
22782         captured_varyings[1] = "gohan";
22783 }
22784
22785 /** Get body of main function for given shader stage
22786  *
22787  * @param test_case_index  Index of test case
22788  * @param stage            Shader stage
22789  * @param out_assignments  Set to empty
22790  * @param out_calculations Set to empty
22791  **/
22792 void XFBOverrideQualifiersWithAPITest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
22793                                                                                                          std::string& out_assignments, std::string& out_calculations)
22794 {
22795         out_calculations = "";
22796
22797         static const GLchar* gs = "    vegeta = uni_vegeta;\n"
22798                                                           "    trunks = uni_trunks;\n"
22799                                                           "    goku   = uni_goku;\n"
22800                                                           "    gohan  = uni_gohan;\n";
22801         static const GLchar* fs = "    fs_out = vec4(0);\n"
22802                                                           "    if (TYPE(1) == gohan + goku + trunks + vegeta)\n"
22803                                                           "    {\n"
22804                                                           "        fs_out = vec4(1);\n"
22805                                                           "    }\n";
22806
22807         const GLchar* assignments = "";
22808         switch (stage)
22809         {
22810         case Utils::Shader::FRAGMENT:
22811                 assignments = fs;
22812                 break;
22813         case Utils::Shader::GEOMETRY:
22814                 assignments = gs;
22815                 break;
22816         default:
22817                 break;
22818         }
22819
22820         out_assignments = assignments;
22821
22822         if (Utils::Shader::FRAGMENT == stage)
22823         {
22824                 const Utils::Type& type = getType(test_case_index);
22825
22826                 Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_assignments);
22827         }
22828 }
22829
22830 /** Get interface of shader
22831  *
22832  * @param test_case_index  Index of test case
22833  * @param stage            Shader stage
22834  * @param out_interface    Set to ""
22835  **/
22836 void XFBOverrideQualifiersWithAPITest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
22837                                                                                                                   std::string& out_interface)
22838 {
22839         static const GLchar* gs = "const uint sizeof_type = SIZE;\n"
22840                                                           "\n"
22841                                                           "layout (xfb_offset = 2 * sizeof_type) flat out TYPE vegeta;\n"
22842                                                           "                                      flat out TYPE trunks;\n"
22843                                                           "layout (xfb_offset = 0)               flat out TYPE goku;\n"
22844                                                           "                                      flat out TYPE gohan;\n"
22845                                                           "\n"
22846                                                           /*
22847                  There is no packing qualifier for uniform block gs_block, according to spec, it should be "shared" by default,
22848                  the definition equals to "layout(binding=0, shared)", if the block is declared as shared, each block member will
22849                  not be packed, and each block member's layout in memory is implementation dependent, so we can't use the API
22850                  glBufferData() to update the UBO directly, we need to query each block member's offset first, then upload the
22851                  data to the corresponding offset, otherwise we can't get the correct data from UBO; to make the test passed,
22852                  we need to add the qualifier std140,  and change the declaration as layout(binding=0, std140), which can make
22853                  sure all the block members are packed and the application can upload the data by glBufferData() directly.
22854                  */
22855                                                           "layout(binding = 0, std140) uniform gs_block {\n"
22856                                                           "    TYPE uni_vegeta;\n"
22857                                                           "    TYPE uni_trunks;\n"
22858                                                           "    TYPE uni_goku;\n"
22859                                                           "    TYPE uni_gohan;\n"
22860                                                           "};\n";
22861         static const GLchar* fs = "flat in TYPE vegeta;\n"
22862                                                           "flat in TYPE trunks;\n"
22863                                                           "flat in TYPE goku;\n"
22864                                                           "flat in TYPE gohan;\n"
22865                                                           "\n"
22866                                                           "out vec4 fs_out;\n";
22867
22868         const Utils::Type& type = getType(test_case_index);
22869
22870         switch (stage)
22871         {
22872         case Utils::Shader::FRAGMENT:
22873                 out_interface = fs;
22874                 break;
22875         case Utils::Shader::GEOMETRY:
22876                 out_interface = gs;
22877                 break;
22878         default:
22879                 out_interface = "";
22880                 return;
22881         }
22882
22883         if (Utils::Shader::GEOMETRY == stage)
22884         {
22885                 GLchar           buffer[16];
22886                 size_t           position  = 0;
22887                 const GLuint type_size = type.GetSize();
22888
22889                 sprintf(buffer, "%d", type_size);
22890
22891                 Utils::replaceToken("SIZE", position, buffer, out_interface);
22892         }
22893
22894         Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_interface);
22895 }
22896
22897 /** Get type name
22898  *
22899  * @param test_case_index Index of test case
22900  *
22901  * @return Name of type test in test_case_index
22902  **/
22903 std::string XFBOverrideQualifiersWithAPITest::getTestCaseName(glw::GLuint test_case_index)
22904 {
22905         return getTypeName(test_case_index);
22906 }
22907
22908 /** Returns number of types to test
22909  *
22910  * @return Number of types, 34
22911  **/
22912 glw::GLuint XFBOverrideQualifiersWithAPITest::getTestCaseNumber()
22913 {
22914         return getTypesNumber();
22915 }
22916
22917 /** Inspects program to check if all resources are as expected
22918  *
22919  * @param test_case_index Index of test case
22920  * @param program         Program instance
22921  * @param out_stream      Error message
22922  *
22923  * @return true if everything is ok, false otherwise
22924  **/
22925 bool XFBOverrideQualifiersWithAPITest::inspectProgram(GLuint test_case_index, Utils::Program& program,
22926                                                                                                           std::stringstream& out_stream)
22927 {
22928         GLint                      stride       = 0;
22929         const Utils::Type& type          = getType(test_case_index);
22930         const GLuint       type_size = type.GetSize();
22931
22932         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
22933                                                 1 /* buf_size */, &stride);
22934
22935         if ((GLint)(3 * type_size) != stride)
22936         {
22937                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
22938
22939                 return false;
22940         }
22941
22942         return true;
22943 }
22944
22945 /** Constructor
22946  *
22947  * @param context Test context
22948  **/
22949 XFBVertexStreamsTest::XFBVertexStreamsTest(deqp::Context& context)
22950         : BufferTestBase(context, "xfb_vertex_streams",
22951                                          "Test verifies that xfb qualifier works with multiple output streams")
22952 {
22953         /* Nothing to be done here */
22954 }
22955
22956 /** Get descriptors of buffers necessary for test
22957  *
22958  * @param ignored
22959  * @param out_descriptors Descriptors of buffers used by test
22960  **/
22961 void XFBVertexStreamsTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
22962                                                                                                 bufferDescriptor::Vector& out_descriptors)
22963 {
22964         const Utils::Type& type = Utils::Type::vec4;
22965
22966         /* Test needs single uniform and three xfbs */
22967         out_descriptors.resize(4);
22968
22969         /* Get references */
22970         bufferDescriptor& uniform = out_descriptors[0];
22971         bufferDescriptor& xfb_1   = out_descriptors[1];
22972         bufferDescriptor& xfb_2   = out_descriptors[2];
22973         bufferDescriptor& xfb_3   = out_descriptors[3];
22974
22975         /* Index */
22976         uniform.m_index = 0;
22977         xfb_1.m_index   = 1;
22978         xfb_2.m_index   = 2;
22979         xfb_3.m_index   = 3;
22980
22981         /* Target */
22982         uniform.m_target = Utils::Buffer::Uniform;
22983         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
22984         xfb_2.m_target   = Utils::Buffer::Transform_feedback;
22985         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
22986
22987         /* Data */
22988         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22989         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22990         const std::vector<GLubyte>& goten_data  = type.GenerateData();
22991         const std::vector<GLubyte>& picolo_data = type.GenerateData();
22992         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22993         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
22994
22995         const GLuint type_size = static_cast<GLuint>(vegeta_data.size());
22996
22997         /* Uniform data */
22998         uniform.m_initial_data.resize(6 * type_size);
22999         memcpy(&uniform.m_initial_data[0] + 0, &goku_data[0], type_size);
23000         memcpy(&uniform.m_initial_data[0] + type_size, &gohan_data[0], type_size);
23001         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
23002         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &picolo_data[0], type_size);
23003         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
23004         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &bulma_data[0], type_size);
23005
23006         /* XFB data */
23007         static const GLuint xfb_stride = 64;
23008         xfb_1.m_initial_data.resize(xfb_stride);
23009         xfb_1.m_expected_data.resize(xfb_stride);
23010         xfb_2.m_initial_data.resize(xfb_stride);
23011         xfb_2.m_expected_data.resize(xfb_stride);
23012         xfb_3.m_initial_data.resize(xfb_stride);
23013         xfb_3.m_expected_data.resize(xfb_stride);
23014
23015         for (GLuint i = 0; i < xfb_stride; ++i)
23016         {
23017                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
23018                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
23019                 xfb_2.m_initial_data[i]  = (glw::GLubyte)i;
23020                 xfb_2.m_expected_data[i] = (glw::GLubyte)i;
23021                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
23022                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
23023         }
23024
23025         memcpy(&xfb_1.m_expected_data[0] + 48, &goku_data[0], type_size);
23026         memcpy(&xfb_1.m_expected_data[0] + 32, &gohan_data[0], type_size);
23027         memcpy(&xfb_1.m_expected_data[0] + 16, &goten_data[0], type_size);
23028         memcpy(&xfb_3.m_expected_data[0] + 48, &picolo_data[0], type_size);
23029         memcpy(&xfb_3.m_expected_data[0] + 32, &vegeta_data[0], type_size);
23030         memcpy(&xfb_2.m_expected_data[0] + 32, &bulma_data[0], type_size);
23031 }
23032
23033 /** Get body of main function for given shader stage
23034  *
23035  * @param ignored
23036  * @param stage            Shader stage
23037  * @param out_assignments  Set to empty
23038  * @param out_calculations Set to empty
23039  **/
23040 void XFBVertexStreamsTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23041                                                                                  std::string& out_assignments, std::string& out_calculations)
23042 {
23043         out_calculations = "";
23044
23045         // the shader declares the output variables with different "stream" qualifier, to make the data can export to
23046         // each stream, we must call the function EmitStreamVertex() and EndStreamPrimitive() to make each vertex emitted
23047         // by the GS is assigned to specific stream.
23048         static const GLchar* gs = "    goku   = uni_goku;\n"
23049                                                           "    gohan  = uni_gohan;\n"
23050                                                           "    goten  = uni_goten;\n"
23051                                                           "    EmitStreamVertex(0);\n"
23052                                                           "    EndStreamPrimitive(0);\n"
23053                                                           "    picolo = uni_picolo;\n"
23054                                                           "    vegeta = uni_vegeta;\n"
23055                                                           "    EmitStreamVertex(1);\n"
23056                                                           "    EndStreamPrimitive(1);\n"
23057                                                           "    bulma  = uni_bulma;\n"
23058                                                           "    EmitStreamVertex(2);\n"
23059                                                           "    EndStreamPrimitive(2);\n";
23060
23061         static const GLchar* fs = "    fs_out = gohan + goku + goten + picolo + vegeta + bulma;\n";
23062
23063         const GLchar* assignments = "";
23064         switch (stage)
23065         {
23066         case Utils::Shader::FRAGMENT:
23067                 assignments = fs;
23068                 break;
23069         case Utils::Shader::GEOMETRY:
23070                 assignments = gs;
23071                 break;
23072         default:
23073                 break;
23074         }
23075
23076         out_assignments = assignments;
23077 }
23078
23079 /** Get interface of shader
23080  *
23081  * @param ignored
23082  * @param stage            Shader stage
23083  * @param out_interface    Set to ""
23084  **/
23085 void XFBVertexStreamsTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23086                                                                                           std::string& out_interface)
23087 {
23088         static const GLchar* gs = "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
23089                                                           "layout (xfb_buffer = 2, xfb_stride = 64) out;\n"
23090                                                           "layout (xfb_buffer = 3, xfb_stride = 64) out;\n"
23091                                                           "\n"
23092                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23093                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23094                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n"
23095                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 48) out vec4 picolo;\n"
23096                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 32) out vec4 vegeta;\n"
23097                                                           "layout (stream = 2, xfb_buffer = 2, xfb_offset = 32) out vec4 bulma;\n"
23098                                                           "\n"
23099                                                           "layout(binding = 0) uniform gs_block {\n"
23100                                                           "    vec4 uni_goku;\n"
23101                                                           "    vec4 uni_gohan;\n"
23102                                                           "    vec4 uni_goten;\n"
23103                                                           "    vec4 uni_picolo;\n"
23104                                                           "    vec4 uni_vegeta;\n"
23105                                                           "    vec4 uni_bulma;\n"
23106                                                           "};\n";
23107         /*
23108          Fixed incorrect usage of in/out qualifier, the following variable should be input symbols for fragment shader
23109          */
23110         static const GLchar* fs = "in vec4 goku;\n"
23111                                                           "in vec4 gohan;\n"
23112                                                           "in vec4 goten;\n"
23113                                                           "in vec4 picolo;\n"
23114                                                           "in vec4 vegeta;\n"
23115                                                           "in vec4 bulma;\n"
23116                                                           "\n"
23117                                                           "out vec4 fs_out;\n";
23118
23119         switch (stage)
23120         {
23121         case Utils::Shader::FRAGMENT:
23122                 out_interface = fs;
23123                 break;
23124         case Utils::Shader::GEOMETRY:
23125                 out_interface = gs;
23126                 break;
23127         default:
23128                 out_interface = "";
23129                 return;
23130         }
23131 }
23132
23133 /** Constructor
23134  *
23135  * @param context Test framework context
23136  **/
23137 XFBMultipleVertexStreamsTest::XFBMultipleVertexStreamsTest(deqp::Context& context)
23138         : NegativeTestBase(
23139                   context, "xfb_multiple_vertex_streams",
23140                   "Test verifies that compiler reports error when multiple streams are captured with same xfb_buffer")
23141 {
23142 }
23143
23144 /** Source for given test case and stage
23145  *
23146  * @param ignored
23147  * @param stage           Shader stage
23148  *
23149  * @return Shader source
23150  **/
23151 std::string XFBMultipleVertexStreamsTest::getShaderSource(GLuint /* test_case_index */, Utils::Shader::STAGES stage)
23152 {
23153         static const GLchar* var_definition = "const uint valid_stride = 64;\n"
23154                                                                                   "\n"
23155                                                                                   "layout (xfb_buffer = 1, xfb_stride = valid_stride) out;\n"
23156                                                                                   "layout (xfb_buffer = 3, xfb_stride = valid_stride) out;\n"
23157                                                                                   "\n"
23158                                                                                   "\n"
23159                                                                                   "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23160                                                                                   "layout (stream = 1, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23161                                                                                   "layout (stream = 2, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n";
23162         static const GLchar* var_use = "    goku  = result / 2;\n"
23163                                                                    "    gohan = result / 4;\n"
23164                                                                    "    goten = result / 6;\n";
23165         static const GLchar* fs = "#version 430 core\n"
23166                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23167                                                           "\n"
23168                                                           "in  vec4 gs_fs;\n"
23169                                                           "in  vec4 goku;\n"
23170                                                           "out vec4 fs_out;\n"
23171                                                           "\n"
23172                                                           "void main()\n"
23173                                                           "{\n"
23174                                                           "    fs_out = gs_fs + goku;\n"
23175                                                           "}\n"
23176                                                           "\n";
23177         static const GLchar* gs = "#version 430 core\n"
23178                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23179                                                           "\n"
23180                                                           "layout(points)                           in;\n"
23181                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
23182                                                           "\n"
23183                                                           "VAR_DEFINITION"
23184                                                           "\n"
23185                                                           "in  vec4 tes_gs[];\n"
23186                                                           "out vec4 gs_fs;\n"
23187                                                           "\n"
23188                                                           "void main()\n"
23189                                                           "{\n"
23190                                                           "    vec4 result = tes_gs[0];\n"
23191                                                           "\n"
23192                                                           "VARIABLE_USE"
23193                                                           "\n"
23194                                                           "    gs_fs = result;\n"
23195                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23196                                                           "    EmitVertex();\n"
23197                                                           "    gs_fs = result;\n"
23198                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23199                                                           "    EmitVertex();\n"
23200                                                           "    gs_fs = result;\n"
23201                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
23202                                                           "    EmitVertex();\n"
23203                                                           "    gs_fs = result;\n"
23204                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
23205                                                           "    EmitVertex();\n"
23206                                                           "}\n"
23207                                                           "\n";
23208         static const GLchar* vs = "#version 430 core\n"
23209                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23210                                                           "\n"
23211                                                           "in  vec4 in_vs;\n"
23212                                                           "out vec4 vs_tcs;\n"
23213                                                           "\n"
23214                                                           "void main()\n"
23215                                                           "{\n"
23216                                                           "    vs_tcs = in_vs;\n"
23217                                                           "}\n"
23218                                                           "\n";
23219
23220         std::string source;
23221
23222         if (Utils::Shader::GEOMETRY == stage)
23223         {
23224                 size_t position = 0;
23225
23226                 source = gs;
23227
23228                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23229                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23230         }
23231         else
23232         {
23233                 switch (stage)
23234                 {
23235                 case Utils::Shader::FRAGMENT:
23236                         source = fs;
23237                         break;
23238                 case Utils::Shader::VERTEX:
23239                         source = vs;
23240                         break;
23241                 default:
23242                         source = "";
23243                 }
23244         }
23245
23246         return source;
23247 }
23248
23249 /** Selects if "compute" stage is relevant for test
23250  *
23251  * @param ignored
23252  *
23253  * @return false
23254  **/
23255 bool XFBMultipleVertexStreamsTest::isComputeRelevant(GLuint /* test_case_index */)
23256 {
23257         return false;
23258 }
23259
23260 /** Constructor
23261  *
23262  * @param context Test framework context
23263  **/
23264 XFBExceedBufferLimitTest::XFBExceedBufferLimitTest(deqp::Context& context)
23265         : NegativeTestBase(context, "xfb_exceed_buffer_limit",
23266                                            "Test verifies that compiler reports error when xfb_buffer qualifier exceeds limit")
23267 {
23268 }
23269
23270 /** Source for given test case and stage
23271  *
23272  * @param test_case_index Index of test case
23273  * @param stage           Shader stage
23274  *
23275  * @return Shader source
23276  **/
23277 std::string XFBExceedBufferLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23278 {
23279         static const GLchar* block_var_definition = "const uint buffer_index = BUFFER;\n"
23280                                                                                                 "\n"
23281                                                                                                 "layout (xfb_buffer = buffer_index, xfb_offset = 0) out Goku {\n"
23282                                                                                                 "    vec4 member;\n"
23283                                                                                                 "} gokuARRAY;\n";
23284         static const GLchar* global_var_definition = "const uint buffer_index = BUFFER;\n"
23285                                                                                                  "\n"
23286                                                                                                  "layout (xfb_buffer = buffer_index) out;\n";
23287         static const GLchar* vector_var_definition = "const uint buffer_index = BUFFER;\n"
23288                                                                                                  "\n"
23289                                                                                                  "layout (xfb_buffer = buffer_index) out vec4 gokuARRAY;\n";
23290         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23291         static const GLchar* global_use = "";
23292         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23293         static const GLchar* fs                 = "#version 430 core\n"
23294                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23295                                                           "\n"
23296                                                           "in  vec4 gs_fs;\n"
23297                                                           "out vec4 fs_out;\n"
23298                                                           "\n"
23299                                                           "void main()\n"
23300                                                           "{\n"
23301                                                           "    fs_out = gs_fs;\n"
23302                                                           "}\n"
23303                                                           "\n";
23304         static const GLchar* gs_tested = "#version 430 core\n"
23305                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23306                                                                          "\n"
23307                                                                          "layout(points)                           in;\n"
23308                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23309                                                                          "\n"
23310                                                                          "VAR_DEFINITION"
23311                                                                          "\n"
23312                                                                          "in  vec4 tes_gs[];\n"
23313                                                                          "out vec4 gs_fs;\n"
23314                                                                          "\n"
23315                                                                          "void main()\n"
23316                                                                          "{\n"
23317                                                                          "    vec4 result = tes_gs[0];\n"
23318                                                                          "\n"
23319                                                                          "VARIABLE_USE"
23320                                                                          "\n"
23321                                                                          "    gs_fs = result;\n"
23322                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23323                                                                          "    EmitVertex();\n"
23324                                                                          "    gs_fs = result;\n"
23325                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23326                                                                          "    EmitVertex();\n"
23327                                                                          "    gs_fs = result;\n"
23328                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23329                                                                          "    EmitVertex();\n"
23330                                                                          "    gs_fs = result;\n"
23331                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23332                                                                          "    EmitVertex();\n"
23333                                                                          "}\n"
23334                                                                          "\n";
23335         static const GLchar* tcs = "#version 430 core\n"
23336                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23337                                                            "\n"
23338                                                            "layout(vertices = 1) out;\n"
23339                                                            "\n"
23340                                                            "in  vec4 vs_tcs[];\n"
23341                                                            "out vec4 tcs_tes[];\n"
23342                                                            "\n"
23343                                                            "void main()\n"
23344                                                            "{\n"
23345                                                            "\n"
23346                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23347                                                            "\n"
23348                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23349                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23350                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23351                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23352                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23353                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23354                                                            "}\n"
23355                                                            "\n";
23356         static const GLchar* tcs_tested = "#version 430 core\n"
23357                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23358                                                                           "\n"
23359                                                                           "layout(vertices = 1) out;\n"
23360                                                                           "\n"
23361                                                                           "VAR_DEFINITION"
23362                                                                           "\n"
23363                                                                           "in  vec4 vs_tcs[];\n"
23364                                                                           "out vec4 tcs_tes[];\n"
23365                                                                           "\n"
23366                                                                           "void main()\n"
23367                                                                           "{\n"
23368                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23369                                                                           "\n"
23370                                                                           "VARIABLE_USE"
23371                                                                           "\n"
23372                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23373                                                                           "\n"
23374                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23375                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23376                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23377                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23378                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23379                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23380                                                                           "}\n"
23381                                                                           "\n";
23382         static const GLchar* tes_tested = "#version 430 core\n"
23383                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23384                                                                           "\n"
23385                                                                           "layout(isolines, point_mode) in;\n"
23386                                                                           "\n"
23387                                                                           "VAR_DEFINITION"
23388                                                                           "\n"
23389                                                                           "in  vec4 tcs_tes[];\n"
23390                                                                           "out vec4 tes_gs;\n"
23391                                                                           "\n"
23392                                                                           "void main()\n"
23393                                                                           "{\n"
23394                                                                           "    vec4 result = tcs_tes[0];\n"
23395                                                                           "\n"
23396                                                                           "VARIABLE_USE"
23397                                                                           "\n"
23398                                                                           "    tes_gs += result;\n"
23399                                                                           "}\n"
23400                                                                           "\n";
23401         static const GLchar* vs = "#version 430 core\n"
23402                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23403                                                           "\n"
23404                                                           "in  vec4 in_vs;\n"
23405                                                           "out vec4 vs_tcs;\n"
23406                                                           "\n"
23407                                                           "void main()\n"
23408                                                           "{\n"
23409                                                           "    vs_tcs = in_vs;\n"
23410                                                           "}\n"
23411                                                           "\n";
23412         static const GLchar* vs_tested = "#version 430 core\n"
23413                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23414                                                                          "\n"
23415                                                                          "VAR_DEFINITION"
23416                                                                          "\n"
23417                                                                          "in  vec4 in_vs;\n"
23418                                                                          "out vec4 vs_tcs;\n"
23419                                                                          "\n"
23420                                                                          "void main()\n"
23421                                                                          "{\n"
23422                                                                          "    vec4 result = in_vs;\n"
23423                                                                          "\n"
23424                                                                          "VARIABLE_USE"
23425                                                                          "\n"
23426                                                                          "    vs_tcs = result;\n"
23427                                                                          "}\n"
23428                                                                          "\n";
23429
23430         std::string source;
23431         testCase&   test_case = m_test_cases[test_case_index];
23432
23433         if (test_case.m_stage == stage)
23434         {
23435                 const GLchar*   array = "";
23436                 GLchar                   buffer[16];
23437                 const Functions& gl                = m_context.getRenderContext().getFunctions();
23438                 const GLchar*   index    = "";
23439                 GLint                    max_n_xfb = 0;
23440                 size_t                   position  = 0;
23441                 size_t                   temp;
23442                 const GLchar*   var_definition = 0;
23443                 const GLchar*   var_use         = 0;
23444
23445                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_n_xfb);
23446                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23447
23448                 sprintf(buffer, "%d", max_n_xfb);
23449
23450                 switch (test_case.m_case)
23451                 {
23452                 case BLOCK:
23453                         var_definition = block_var_definition;
23454                         var_use            = block_use;
23455                         break;
23456                 case GLOBAL:
23457                         var_definition = global_var_definition;
23458                         var_use            = global_use;
23459                         break;
23460                 case VECTOR:
23461                         var_definition = vector_var_definition;
23462                         var_use            = vector_use;
23463                         break;
23464                 default:
23465                         TCU_FAIL("Invalid enum");
23466                 }
23467
23468                 switch (stage)
23469                 {
23470                 case Utils::Shader::GEOMETRY:
23471                         source = gs_tested;
23472                         array  = "[]";
23473                         index  = "[0]";
23474                         break;
23475                 case Utils::Shader::TESS_CTRL:
23476                         source = tcs_tested;
23477                         array  = "[]";
23478                         index  = "[gl_InvocationID]";
23479                         break;
23480                 case Utils::Shader::TESS_EVAL:
23481                         source = tes_tested;
23482                         array  = "[]";
23483                         index  = "[0]";
23484                         break;
23485                 case Utils::Shader::VERTEX:
23486                         source = vs_tested;
23487                         break;
23488                 default:
23489                         TCU_FAIL("Invalid enum");
23490                 }
23491
23492                 temp = position;
23493                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23494                 position = temp;
23495                 Utils::replaceToken("BUFFER", position, buffer, source);
23496                 if (GLOBAL != test_case.m_case)
23497                 {
23498                         Utils::replaceToken("ARRAY", position, array, source);
23499                 }
23500                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23501
23502                 Utils::replaceAllTokens("INDEX", index, source);
23503         }
23504         else
23505         {
23506                 switch (test_case.m_stage)
23507                 {
23508                 case Utils::Shader::GEOMETRY:
23509                         switch (stage)
23510                         {
23511                         case Utils::Shader::FRAGMENT:
23512                                 source = fs;
23513                                 break;
23514                         case Utils::Shader::VERTEX:
23515                                 source = vs;
23516                                 break;
23517                         default:
23518                                 source = "";
23519                         }
23520                         break;
23521                 case Utils::Shader::TESS_CTRL:
23522                         switch (stage)
23523                         {
23524                         case Utils::Shader::FRAGMENT:
23525                                 source = fs;
23526                                 break;
23527                         case Utils::Shader::VERTEX:
23528                                 source = vs;
23529                                 break;
23530                         default:
23531                                 source = "";
23532                         }
23533                         break;
23534                 case Utils::Shader::TESS_EVAL:
23535                         switch (stage)
23536                         {
23537                         case Utils::Shader::FRAGMENT:
23538                                 source = fs;
23539                                 break;
23540                         case Utils::Shader::TESS_CTRL:
23541                                 source = tcs;
23542                                 break;
23543                         case Utils::Shader::VERTEX:
23544                                 source = vs;
23545                                 break;
23546                         default:
23547                                 source = "";
23548                         }
23549                         break;
23550                 case Utils::Shader::VERTEX:
23551                         switch (stage)
23552                         {
23553                         case Utils::Shader::FRAGMENT:
23554                                 source = fs;
23555                                 break;
23556                         default:
23557                                 source = "";
23558                         }
23559                         break;
23560                 default:
23561                         TCU_FAIL("Invalid enum");
23562                         break;
23563                 }
23564         }
23565
23566         return source;
23567 }
23568
23569 /** Get description of test case
23570  *
23571  * @param test_case_index Index of test case
23572  *
23573  * @return Test case description
23574  **/
23575 std::string XFBExceedBufferLimitTest::getTestCaseName(GLuint test_case_index)
23576 {
23577         std::stringstream stream;
23578         testCase&                 test_case = m_test_cases[test_case_index];
23579
23580         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23581
23582         switch (test_case.m_case)
23583         {
23584         case BLOCK:
23585                 stream << "BLOCK";
23586                 break;
23587         case GLOBAL:
23588                 stream << "GLOBAL";
23589                 break;
23590         case VECTOR:
23591                 stream << "VECTOR";
23592                 break;
23593         default:
23594                 TCU_FAIL("Invalid enum");
23595         }
23596
23597         return stream.str();
23598 }
23599
23600 /** Get number of test cases
23601  *
23602  * @return Number of test cases
23603  **/
23604 GLuint XFBExceedBufferLimitTest::getTestCaseNumber()
23605 {
23606         return static_cast<GLuint>(m_test_cases.size());
23607 }
23608
23609 /** Selects if "compute" stage is relevant for test
23610  *
23611  * @param ignored
23612  *
23613  * @return false
23614  **/
23615 bool XFBExceedBufferLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23616 {
23617         return false;
23618 }
23619
23620 /** Prepare all test cases
23621  *
23622  **/
23623 void XFBExceedBufferLimitTest::testInit()
23624 {
23625         for (GLuint c = 0; c < CASE_MAX; ++c)
23626         {
23627                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23628                 {
23629                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23630                                 (Utils::Shader::FRAGMENT == stage))
23631                         {
23632                                 continue;
23633                         }
23634
23635                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23636
23637                         m_test_cases.push_back(test_case);
23638                 }
23639         }
23640 }
23641
23642 /** Constructor
23643  *
23644  * @param context Test framework context
23645  **/
23646 XFBExceedOffsetLimitTest::XFBExceedOffsetLimitTest(deqp::Context& context)
23647         : NegativeTestBase(context, "xfb_exceed_offset_limit",
23648                                            "Test verifies that compiler reports error when xfb_offset qualifier exceeds limit")
23649 {
23650 }
23651
23652 /** Source for given test case and stage
23653  *
23654  * @param test_case_index Index of test case
23655  * @param stage           Shader stage
23656  *
23657  * @return Shader source
23658  **/
23659 std::string XFBExceedOffsetLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23660 {
23661         static const GLchar* block_var_definition = "const uint max_size = SIZE;\n"
23662                                                                                                 "\n"
23663                                                                                                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out Goku {\n"
23664                                                                                                 "    vec4 member;\n"
23665                                                                                                 "} gokuARRAY;\n";
23666         static const GLchar* global_var_definition = "const uint max_size = SIZE;\n"
23667                                                                                                  "\n"
23668                                                                                                  "layout (xfb_buffer = 0, xfb_stride = max_size + 16) out;\n";
23669         static const GLchar* vector_var_definition =
23670                 "const uint max_size = SIZE;\n"
23671                 "\n"
23672                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out vec4 gokuARRAY;\n";
23673         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23674         static const GLchar* global_use = "";
23675         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23676         static const GLchar* fs                 = "#version 430 core\n"
23677                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23678                                                           "\n"
23679                                                           "in  vec4 gs_fs;\n"
23680                                                           "out vec4 fs_out;\n"
23681                                                           "\n"
23682                                                           "void main()\n"
23683                                                           "{\n"
23684                                                           "    fs_out = gs_fs;\n"
23685                                                           "}\n"
23686                                                           "\n";
23687         static const GLchar* gs_tested = "#version 430 core\n"
23688                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23689                                                                          "\n"
23690                                                                          "layout(points)                           in;\n"
23691                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23692                                                                          "\n"
23693                                                                          "VAR_DEFINITION"
23694                                                                          "\n"
23695                                                                          "in  vec4 tes_gs[];\n"
23696                                                                          "out vec4 gs_fs;\n"
23697                                                                          "\n"
23698                                                                          "void main()\n"
23699                                                                          "{\n"
23700                                                                          "    vec4 result = tes_gs[0];\n"
23701                                                                          "\n"
23702                                                                          "VARIABLE_USE"
23703                                                                          "\n"
23704                                                                          "    gs_fs = result;\n"
23705                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23706                                                                          "    EmitVertex();\n"
23707                                                                          "    gs_fs = result;\n"
23708                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23709                                                                          "    EmitVertex();\n"
23710                                                                          "    gs_fs = result;\n"
23711                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23712                                                                          "    EmitVertex();\n"
23713                                                                          "    gs_fs = result;\n"
23714                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23715                                                                          "    EmitVertex();\n"
23716                                                                          "}\n"
23717                                                                          "\n";
23718         static const GLchar* tcs = "#version 430 core\n"
23719                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23720                                                            "\n"
23721                                                            "layout(vertices = 1) out;\n"
23722                                                            "\n"
23723                                                            "in  vec4 vs_tcs[];\n"
23724                                                            "out vec4 tcs_tes[];\n"
23725                                                            "\n"
23726                                                            "void main()\n"
23727                                                            "{\n"
23728                                                            "\n"
23729                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23730                                                            "\n"
23731                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23732                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23733                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23734                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23735                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23736                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23737                                                            "}\n"
23738                                                            "\n";
23739         static const GLchar* tcs_tested = "#version 430 core\n"
23740                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23741                                                                           "\n"
23742                                                                           "layout(vertices = 1) out;\n"
23743                                                                           "\n"
23744                                                                           "VAR_DEFINITION"
23745                                                                           "\n"
23746                                                                           "in  vec4 vs_tcs[];\n"
23747                                                                           "out vec4 tcs_tes[];\n"
23748                                                                           "\n"
23749                                                                           "void main()\n"
23750                                                                           "{\n"
23751                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23752                                                                           "\n"
23753                                                                           "VARIABLE_USE"
23754                                                                           "\n"
23755                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23756                                                                           "\n"
23757                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23758                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23759                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23760                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23761                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23762                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23763                                                                           "}\n"
23764                                                                           "\n";
23765         static const GLchar* tes_tested = "#version 430 core\n"
23766                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23767                                                                           "\n"
23768                                                                           "layout(isolines, point_mode) in;\n"
23769                                                                           "\n"
23770                                                                           "VAR_DEFINITION"
23771                                                                           "\n"
23772                                                                           "in  vec4 tcs_tes[];\n"
23773                                                                           "out vec4 tes_gs;\n"
23774                                                                           "\n"
23775                                                                           "void main()\n"
23776                                                                           "{\n"
23777                                                                           "    vec4 result = tcs_tes[0];\n"
23778                                                                           "\n"
23779                                                                           "VARIABLE_USE"
23780                                                                           "\n"
23781                                                                           "    tes_gs += result;\n"
23782                                                                           "}\n"
23783                                                                           "\n";
23784         static const GLchar* vs = "#version 430 core\n"
23785                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23786                                                           "\n"
23787                                                           "in  vec4 in_vs;\n"
23788                                                           "out vec4 vs_tcs;\n"
23789                                                           "\n"
23790                                                           "void main()\n"
23791                                                           "{\n"
23792                                                           "    vs_tcs = in_vs;\n"
23793                                                           "}\n"
23794                                                           "\n";
23795         static const GLchar* vs_tested = "#version 430 core\n"
23796                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23797                                                                          "\n"
23798                                                                          "VAR_DEFINITION"
23799                                                                          "\n"
23800                                                                          "in  vec4 in_vs;\n"
23801                                                                          "out vec4 vs_tcs;\n"
23802                                                                          "\n"
23803                                                                          "void main()\n"
23804                                                                          "{\n"
23805                                                                          "    vec4 result = in_vs;\n"
23806                                                                          "\n"
23807                                                                          "VARIABLE_USE"
23808                                                                          "\n"
23809                                                                          "    vs_tcs = result;\n"
23810                                                                          "}\n"
23811                                                                          "\n";
23812
23813         std::string source;
23814         testCase&   test_case = m_test_cases[test_case_index];
23815
23816         if (test_case.m_stage == stage)
23817         {
23818                 const GLchar*   array = "";
23819                 GLchar                   buffer[16];
23820                 const Functions& gl                              = m_context.getRenderContext().getFunctions();
23821                 const GLchar*   index                    = "";
23822                 GLint                    max_n_xfb_comp  = 0;
23823                 GLint                    max_n_xfb_bytes = 0;
23824                 size_t                   position                = 0;
23825                 size_t                   temp;
23826                 const GLchar*   var_definition = 0;
23827                 const GLchar*   var_use         = 0;
23828
23829                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_n_xfb_comp);
23830                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23831
23832                 max_n_xfb_bytes = max_n_xfb_comp * 4;
23833
23834                 sprintf(buffer, "%d", max_n_xfb_bytes);
23835
23836                 switch (test_case.m_case)
23837                 {
23838                 case BLOCK:
23839                         var_definition = block_var_definition;
23840                         var_use            = block_use;
23841                         break;
23842                 case GLOBAL:
23843                         var_definition = global_var_definition;
23844                         var_use            = global_use;
23845                         break;
23846                 case VECTOR:
23847                         var_definition = vector_var_definition;
23848                         var_use            = vector_use;
23849                         break;
23850                 default:
23851                         TCU_FAIL("Invalid enum");
23852                 }
23853                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
23854                 // change array = "[]" to "[1]"
23855                 switch (stage)
23856                 {
23857                 case Utils::Shader::GEOMETRY:
23858                         source = gs_tested;
23859                         array  = "[1]";
23860                         index  = "[0]";
23861                         break;
23862                 case Utils::Shader::TESS_CTRL:
23863                         source = tcs_tested;
23864                         array  = "[1]";
23865                         index  = "[gl_InvocationID]";
23866                         break;
23867                 case Utils::Shader::TESS_EVAL:
23868                         source = tes_tested;
23869                         array  = "[1]";
23870                         index  = "[0]";
23871                         break;
23872                 case Utils::Shader::VERTEX:
23873                         source = vs_tested;
23874                         break;
23875                 default:
23876                         TCU_FAIL("Invalid enum");
23877                 }
23878
23879                 temp = position;
23880                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23881                 position = temp;
23882                 Utils::replaceToken("SIZE", position, buffer, source);
23883                 if (GLOBAL != test_case.m_case)
23884                 {
23885                         Utils::replaceToken("ARRAY", position, array, source);
23886                 }
23887                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23888
23889                 Utils::replaceAllTokens("INDEX", index, source);
23890         }
23891         else
23892         {
23893                 switch (test_case.m_stage)
23894                 {
23895                 case Utils::Shader::GEOMETRY:
23896                         switch (stage)
23897                         {
23898                         case Utils::Shader::FRAGMENT:
23899                                 source = fs;
23900                                 break;
23901                         case Utils::Shader::VERTEX:
23902                                 source = vs;
23903                                 break;
23904                         default:
23905                                 source = "";
23906                         }
23907                         break;
23908                 case Utils::Shader::TESS_CTRL:
23909                         switch (stage)
23910                         {
23911                         case Utils::Shader::FRAGMENT:
23912                                 source = fs;
23913                                 break;
23914                         case Utils::Shader::VERTEX:
23915                                 source = vs;
23916                                 break;
23917                         default:
23918                                 source = "";
23919                         }
23920                         break;
23921                 case Utils::Shader::TESS_EVAL:
23922                         switch (stage)
23923                         {
23924                         case Utils::Shader::FRAGMENT:
23925                                 source = fs;
23926                                 break;
23927                         case Utils::Shader::TESS_CTRL:
23928                                 source = tcs;
23929                                 break;
23930                         case Utils::Shader::VERTEX:
23931                                 source = vs;
23932                                 break;
23933                         default:
23934                                 source = "";
23935                         }
23936                         break;
23937                 case Utils::Shader::VERTEX:
23938                         switch (stage)
23939                         {
23940                         case Utils::Shader::FRAGMENT:
23941                                 source = fs;
23942                                 break;
23943                         default:
23944                                 source = "";
23945                         }
23946                         break;
23947                 default:
23948                         TCU_FAIL("Invalid enum");
23949                         break;
23950                 }
23951         }
23952
23953         return source;
23954 }
23955
23956 /** Get description of test case
23957  *
23958  * @param test_case_index Index of test case
23959  *
23960  * @return Test case description
23961  **/
23962 std::string XFBExceedOffsetLimitTest::getTestCaseName(GLuint test_case_index)
23963 {
23964         std::stringstream stream;
23965         testCase&                 test_case = m_test_cases[test_case_index];
23966
23967         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23968
23969         switch (test_case.m_case)
23970         {
23971         case BLOCK:
23972                 stream << "BLOCK";
23973                 break;
23974         case GLOBAL:
23975                 stream << "GLOBAL";
23976                 break;
23977         case VECTOR:
23978                 stream << "VECTOR";
23979                 break;
23980         default:
23981                 TCU_FAIL("Invalid enum");
23982         }
23983
23984         return stream.str();
23985 }
23986
23987 /** Get number of test cases
23988  *
23989  * @return Number of test cases
23990  **/
23991 GLuint XFBExceedOffsetLimitTest::getTestCaseNumber()
23992 {
23993         return static_cast<GLuint>(m_test_cases.size());
23994 }
23995
23996 /** Selects if "compute" stage is relevant for test
23997  *
23998  * @param ignored
23999  *
24000  * @return false
24001  **/
24002 bool XFBExceedOffsetLimitTest::isComputeRelevant(GLuint /* test_case_index */)
24003 {
24004         return false;
24005 }
24006
24007 /** Prepare all test cases
24008  *
24009  **/
24010 void XFBExceedOffsetLimitTest::testInit()
24011 {
24012         for (GLuint c = 0; c < CASE_MAX; ++c)
24013         {
24014                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24015                 {
24016                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
24017                                 (Utils::Shader::FRAGMENT == stage))
24018                         {
24019                                 continue;
24020                         }
24021
24022                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
24023
24024                         m_test_cases.push_back(test_case);
24025                 }
24026         }
24027 }
24028
24029 /** Constructor
24030  *
24031  * @param context Test context
24032  **/
24033 XFBGlobalBufferTest::XFBGlobalBufferTest(deqp::Context& context)
24034         : BufferTestBase(context, "xfb_global_buffer", "Test verifies that global xfb_buffer qualifier is respected")
24035 {
24036         /* Nothing to be done here */
24037 }
24038
24039 /** Get descriptors of buffers necessary for test
24040  *
24041  * @param test_case_index Index of test case
24042  * @param out_descriptors Descriptors of buffers used by test
24043  **/
24044 void XFBGlobalBufferTest::getBufferDescriptors(glw::GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24045 {
24046         // the function "getType(test_case_index)" can't return correct data type, so change code as following:
24047         const Utils::Type& type = m_test_cases[test_case_index].m_type;
24048
24049         /* Test needs single uniform and two xfbs */
24050         out_descriptors.resize(3);
24051
24052         /* Get references */
24053         bufferDescriptor& uniform = out_descriptors[0];
24054         bufferDescriptor& xfb_1   = out_descriptors[1];
24055         bufferDescriptor& xfb_3   = out_descriptors[2];
24056
24057         /* Index */
24058         uniform.m_index = 0;
24059         xfb_1.m_index   = 1;
24060         xfb_3.m_index   = 3;
24061
24062         /* Target */
24063         uniform.m_target = Utils::Buffer::Uniform;
24064         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
24065         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
24066
24067         /* Data */
24068         const GLuint                            gen_start   = Utils::s_rand;
24069         const std::vector<GLubyte>& chichi_data = type.GenerateData();
24070         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
24071         const std::vector<GLubyte>& trunks_data = type.GenerateData();
24072         const std::vector<GLubyte>& bra_data    = type.GenerateData();
24073         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
24074         const std::vector<GLubyte>& goten_data  = type.GenerateData();
24075
24076         Utils::s_rand                                                           = gen_start;
24077         const std::vector<GLubyte>& chichi_data_pck = type.GenerateDataPacked();
24078         const std::vector<GLubyte>& bulma_data_pck  = type.GenerateDataPacked();
24079         const std::vector<GLubyte>& trunks_data_pck = type.GenerateDataPacked();
24080         const std::vector<GLubyte>& bra_data_pck        = type.GenerateDataPacked();
24081         const std::vector<GLubyte>& gohan_data_pck  = type.GenerateDataPacked();
24082         const std::vector<GLubyte>& goten_data_pck  = type.GenerateDataPacked();
24083
24084         const GLuint type_size   = static_cast<GLuint>(chichi_data.size());
24085         const GLuint type_size_pck = static_cast<GLuint>(chichi_data_pck.size());
24086
24087         /* Uniform data */
24088         uniform.m_initial_data.resize(6 * type_size);
24089         memcpy(&uniform.m_initial_data[0] + 0, &chichi_data[0], type_size);
24090         memcpy(&uniform.m_initial_data[0] + type_size, &bulma_data[0], type_size);
24091         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &trunks_data[0], type_size);
24092         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &bra_data[0], type_size);
24093         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &gohan_data[0], type_size);
24094         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &goten_data[0], type_size);
24095
24096         /* XFB data */
24097         xfb_1.m_initial_data.resize(3 * type_size_pck);
24098         xfb_1.m_expected_data.resize(3 * type_size_pck);
24099         xfb_3.m_initial_data.resize(3 * type_size_pck);
24100         xfb_3.m_expected_data.resize(3 * type_size_pck);
24101
24102         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
24103         {
24104                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
24105                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
24106                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
24107                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
24108         }
24109
24110         memcpy(&xfb_3.m_expected_data[0] + 2 * type_size_pck, &chichi_data_pck[0], type_size_pck);
24111         memcpy(&xfb_1.m_expected_data[0] + 0 * type_size_pck, &bulma_data_pck[0], type_size_pck);
24112         memcpy(&xfb_1.m_expected_data[0] + 1 * type_size_pck, &trunks_data_pck[0], type_size_pck);
24113         memcpy(&xfb_1.m_expected_data[0] + 2 * type_size_pck, &bra_data_pck[0], type_size_pck);
24114         memcpy(&xfb_3.m_expected_data[0] + 0 * type_size_pck, &gohan_data_pck[0], type_size_pck);
24115         memcpy(&xfb_3.m_expected_data[0] + 1 * type_size_pck, &goten_data_pck[0], type_size_pck);
24116 }
24117
24118 /** Source for given test case and stage
24119  *
24120  * @param test_case_index Index of test case
24121  * @param stage           Shader stage
24122  *
24123  * @return Shader source
24124  **/
24125 std::string XFBGlobalBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24126 {
24127         static const GLchar* fs =
24128                 "#version 430 core\n"
24129                 "#extension GL_ARB_enhanced_layouts : require\n"
24130                 "\n"
24131                 "flat in TYPE chichi;\n"
24132                 "flat in TYPE bulma;\n"
24133                 "in Vegeta {\n"
24134                 "    TYPE trunk;\n"
24135                 "    TYPE bra;\n"
24136                 "} vegeta;\n"
24137                 "in Goku {\n"
24138                 "    TYPE gohan;\n"
24139                 "    TYPE goten;\n"
24140                 "} goku;\n"
24141                 "\n"
24142                 "out vec4 fs_out;\n"
24143                 "\n"
24144                 "void main()\n"
24145                 "{\n"
24146                 "    fs_out = vec4(1);\n"
24147                 "    if (TYPE(1) != chichi + bulma + vegeta.trunk + vegeta.bra + goku.gohan + goku.goten)\n"
24148                 "    {\n"
24149                 "        fs_out = vec4(0);\n"
24150                 "    }\n"
24151                 "}\n"
24152                 "\n";
24153
24154         static const GLchar* gs = "#version 430 core\n"
24155                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24156                                                           "\n"
24157                                                           "layout(points)                   in;\n"
24158                                                           "layout(points, max_vertices = 1) out;\n"
24159                                                           "\n"
24160                                                           "INTERFACE"
24161                                                           "\n"
24162                                                           "void main()\n"
24163                                                           "{\n"
24164                                                           "ASSIGNMENTS"
24165                                                           "    EmitVertex();\n"
24166                                                           "}\n"
24167                                                           "\n";
24168
24169         static const GLchar* tcs = "#version 430 core\n"
24170                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24171                                                            "\n"
24172                                                            "layout(vertices = 1) out;\n"
24173                                                            "\n"
24174                                                            "\n"
24175                                                            "void main()\n"
24176                                                            "{\n"
24177                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24178                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24179                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24180                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24181                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24182                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24183                                                            "}\n"
24184                                                            "\n";
24185
24186         static const GLchar* tes = "#version 430 core\n"
24187                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24188                                                            "\n"
24189                                                            "layout(isolines, point_mode) in;\n"
24190                                                            "\n"
24191                                                            "INTERFACE"
24192                                                            "\n"
24193                                                            "void main()\n"
24194                                                            "{\n"
24195                                                            "ASSIGNMENTS"
24196                                                            "}\n"
24197                                                            "\n";
24198
24199         static const GLchar* vs = "#version 430 core\n"
24200                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24201                                                           "\n"
24202                                                           "void main()\n"
24203                                                           "{\n"
24204                                                           "}\n"
24205                                                           "\n";
24206
24207         static const GLchar* vs_tested = "#version 430 core\n"
24208                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24209                                                                          "\n"
24210                                                                          "INTERFACE"
24211                                                                          "\n"
24212                                                                          "void main()\n"
24213                                                                          "{\n"
24214                                                                          "ASSIGNMENTS"
24215                                                                          "}\n"
24216                                                                          "\n";
24217
24218         std::string              source;
24219         const _testCase& test_case = m_test_cases[test_case_index];
24220         const GLchar*   type_name = test_case.m_type.GetGLSLTypeName();
24221
24222         if (test_case.m_stage == stage)
24223         {
24224                 std::string assignments = "    chichi       = uni_chichi;\n"
24225                                                                   "    bulma        = uni_bulma;\n"
24226                                                                   "    vegeta.trunk = uni_trunk;\n"
24227                                                                   "    vegeta.bra   = uni_bra;\n"
24228                                                                   "    goku.gohan   = uni_gohan;\n"
24229                                                                   "    goku.goten   = uni_goten;\n";
24230
24231                 std::string interface = "layout (xfb_buffer = 3) out;\n"
24232                                                                 "\n"
24233                                                                 "const uint type_size = SIZE;\n"
24234                                                                 "\n"
24235                                                                 "layout (                xfb_offset = 2 * type_size) flat out TYPE chichi;\n"
24236                                                                 "layout (xfb_buffer = 1, xfb_offset = 0)             flat out TYPE bulma;\n"
24237                                                                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out Vegeta {\n"
24238                                                                 "    TYPE trunk;\n"
24239                                                                 "    TYPE bra;\n"
24240                                                                 "} vegeta;\n"
24241                                                                 "layout (                xfb_offset = 0)             out Goku {\n"
24242                                                                 "    TYPE gohan;\n"
24243                                                                 "    TYPE goten;\n"
24244                                                                 "} goku;\n"
24245                                                                 "\n"
24246                                                                 // Uniform block must be declared with std140, otherwise each block member is not packed
24247                                                                 "layout(binding = 0, std140) uniform block {\n"
24248                                                                 "    TYPE uni_chichi;\n"
24249                                                                 "    TYPE uni_bulma;\n"
24250                                                                 "    TYPE uni_trunk;\n"
24251                                                                 "    TYPE uni_bra;\n"
24252                                                                 "    TYPE uni_gohan;\n"
24253                                                                 "    TYPE uni_goten;\n"
24254                                                                 "};\n";
24255
24256                 /* Prepare interface string */
24257                 {
24258                         GLchar           buffer[16];
24259                         size_t           position  = 0;
24260                         const GLuint type_size = test_case.m_type.GetSize();
24261
24262                         sprintf(buffer, "%d", type_size);
24263
24264                         Utils::replaceToken("SIZE", position, buffer, interface);
24265                         Utils::replaceAllTokens("TYPE", type_name, interface);
24266                 }
24267
24268                 switch (stage)
24269                 {
24270                 case Utils::Shader::GEOMETRY:
24271                         source = gs;
24272                         break;
24273                 case Utils::Shader::TESS_EVAL:
24274                         source = tes;
24275                         break;
24276                 case Utils::Shader::VERTEX:
24277                         source = vs_tested;
24278                         break;
24279                 default:
24280                         TCU_FAIL("Invalid enum");
24281                 }
24282
24283                 /* Replace tokens */
24284                 {
24285                         size_t position = 0;
24286
24287                         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
24288                         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
24289                 }
24290         }
24291         else
24292         {
24293                 switch (test_case.m_stage)
24294                 {
24295                 case Utils::Shader::GEOMETRY:
24296                         switch (stage)
24297                         {
24298                         case Utils::Shader::FRAGMENT:
24299                                 source = fs;
24300                                 Utils::replaceAllTokens("TYPE", type_name, source);
24301                                 break;
24302                         case Utils::Shader::VERTEX:
24303                                 source = vs;
24304                                 break;
24305                         default:
24306                                 source = "";
24307                         }
24308                         break;
24309                 case Utils::Shader::TESS_EVAL:
24310                         switch (stage)
24311                         {
24312                         case Utils::Shader::FRAGMENT:
24313                                 source = fs;
24314                                 Utils::replaceAllTokens("TYPE", type_name, source);
24315                                 break;
24316                         case Utils::Shader::TESS_CTRL:
24317                                 source = tcs;
24318                                 break;
24319                         case Utils::Shader::VERTEX:
24320                                 source = vs;
24321                                 break;
24322                         default:
24323                                 source = "";
24324                         }
24325                         break;
24326                 case Utils::Shader::VERTEX:
24327                         switch (stage)
24328                         {
24329                         case Utils::Shader::FRAGMENT:
24330                                 source = fs;
24331                                 Utils::replaceAllTokens("TYPE", type_name, source);
24332                                 break;
24333                         default:
24334                                 source = "";
24335                         }
24336                         break;
24337                 default:
24338                         TCU_FAIL("Invalid enum");
24339                         break;
24340                 }
24341         }
24342
24343         return source;
24344 }
24345
24346 /** Get name of test case
24347  *
24348  * @param test_case_index Index of test case
24349  *
24350  * @return Name of case
24351  **/
24352 std::string XFBGlobalBufferTest::getTestCaseName(GLuint test_case_index)
24353 {
24354         std::string              name;
24355         const _testCase& test_case = m_test_cases[test_case_index];
24356
24357         name = "Tested stage: ";
24358         name.append(Utils::Shader::GetStageName(test_case.m_stage));
24359         name.append(". Tested type: ");
24360         name.append(test_case.m_type.GetGLSLTypeName());
24361
24362         return name;
24363 }
24364
24365 /** Get number of cases
24366  *
24367  * @return Number of test cases
24368  **/
24369 GLuint XFBGlobalBufferTest::getTestCaseNumber()
24370 {
24371         return static_cast<GLuint>(m_test_cases.size());
24372 }
24373
24374 /** Prepare set of test cases
24375  *
24376  **/
24377 void XFBGlobalBufferTest::testInit()
24378 {
24379         GLuint n_types = getTypesNumber();
24380
24381         for (GLuint i = 0; i < n_types; ++i)
24382         {
24383                 const Utils::Type& type = getType(i);
24384                 /*
24385                  When the tfx varying is the following type, the number of output exceeds the gl_MaxVaryingComponents, which will
24386                  cause a link time error.
24387                  */
24388                 if (strcmp(type.GetGLSLTypeName(), "dmat3") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4") == 0 ||
24389                         strcmp(type.GetGLSLTypeName(), "dmat3x4") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4x3") == 0)
24390                 {
24391                         continue;
24392                 }
24393                 const _testCase test_cases[] = { { Utils::Shader::VERTEX, type },
24394                                                                                  { Utils::Shader::GEOMETRY, type },
24395                                                                                  { Utils::Shader::TESS_EVAL, type } };
24396
24397                 m_test_cases.push_back(test_cases[0]);
24398                 m_test_cases.push_back(test_cases[1]);
24399                 m_test_cases.push_back(test_cases[2]);
24400         }
24401 }
24402
24403 /** Constructor
24404  *
24405  * @param context Test context
24406  **/
24407 XFBStrideTest::XFBStrideTest(deqp::Context& context)
24408         : BufferTestBase(context, "xfb_stride", "Test verifies that correct stride is used for all types")
24409 {
24410         /* Nothing to be done here */
24411 }
24412
24413 /** Execute drawArrays for single vertex
24414  *
24415  * @param test_case_index
24416  *
24417  * @return true
24418  **/
24419 bool XFBStrideTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
24420 {
24421         const Functions& gl                             = m_context.getRenderContext().getFunctions();
24422         GLenum                   primitive_type = GL_PATCHES;
24423         const testCase&  test_case              = m_test_cases[test_case_index];
24424
24425         if (Utils::Shader::VERTEX == test_case.m_stage)
24426         {
24427                 primitive_type = GL_POINTS;
24428         }
24429
24430         gl.disable(GL_RASTERIZER_DISCARD);
24431         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
24432
24433         gl.beginTransformFeedback(GL_POINTS);
24434         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
24435
24436         gl.drawArrays(primitive_type, 0 /* first */, 2 /* count */);
24437         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
24438
24439         gl.endTransformFeedback();
24440         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
24441
24442         return true;
24443 }
24444
24445 /** Get descriptors of buffers necessary for test
24446  *
24447  * @param test_case_index Index of test case
24448  * @param out_descriptors Descriptors of buffers used by test
24449  **/
24450 void XFBStrideTest::getBufferDescriptors(GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24451 {
24452         const testCase& test_case = m_test_cases[test_case_index];
24453         const Utils::Type& type          = test_case.m_type;
24454
24455         /* Test needs single uniform and xfb */
24456         out_descriptors.resize(2);
24457
24458         /* Get references */
24459         bufferDescriptor& uniform = out_descriptors[0];
24460         bufferDescriptor& xfb    = out_descriptors[1];
24461
24462         /* Index */
24463         uniform.m_index = 0;
24464         xfb.m_index             = 0;
24465
24466         /* Target */
24467         uniform.m_target = Utils::Buffer::Uniform;
24468         xfb.m_target     = Utils::Buffer::Transform_feedback;
24469
24470         /* Data */
24471         const GLuint                            rand_start   = Utils::s_rand;
24472         const std::vector<GLubyte>& uniform_data = type.GenerateData();
24473
24474         Utils::s_rand                                            = rand_start;
24475         const std::vector<GLubyte>& xfb_data = type.GenerateDataPacked();
24476
24477         const GLuint uni_type_size = static_cast<GLuint>(uniform_data.size());
24478         const GLuint xfb_type_size = static_cast<GLuint>(xfb_data.size());
24479         /*
24480          Note: If xfb varying output from vertex shader, the variable "goku" will only output once to transform feedback buffer,
24481          if xfb varying output from TES or GS, because the input primitive type in TES is defined as "layout(isolines, point_mode) in;",
24482          the primitive type is line which make the variable "goku" will output twice to transform feedback buffer, so for vertex shader
24483          only one valid data should be initialized in xfb.m_expected_data
24484          */
24485         const GLuint xfb_data_size = (test_case.m_stage == Utils::Shader::VERTEX) ? xfb_type_size : xfb_type_size * 2;
24486         /* Uniform data */
24487         uniform.m_initial_data.resize(uni_type_size);
24488         memcpy(&uniform.m_initial_data[0] + 0 * uni_type_size, &uniform_data[0], uni_type_size);
24489
24490         /* XFB data */
24491         xfb.m_initial_data.resize(xfb_data_size);
24492         xfb.m_expected_data.resize(xfb_data_size);
24493
24494         for (GLuint i = 0; i < xfb_data_size; ++i)
24495         {
24496                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
24497                 xfb.m_expected_data[i] = (glw::GLubyte)i;
24498         }
24499
24500         if (test_case.m_stage == Utils::Shader::VERTEX)
24501         {
24502                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24503         }
24504         else
24505         {
24506                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24507                 memcpy(&xfb.m_expected_data[0] + 1 * xfb_type_size, &xfb_data[0], xfb_type_size);
24508         }
24509 }
24510
24511 /** Get body of main function for given shader stage
24512  *
24513  * @param test_case_index  Index of test case
24514  * @param stage            Shader stage
24515  * @param out_assignments  Set to empty
24516  * @param out_calculations Set to empty
24517  **/
24518 void XFBStrideTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_assignments,
24519                                                                   std::string& out_calculations)
24520 {
24521         const testCase& test_case = m_test_cases[test_case_index];
24522
24523         out_calculations = "";
24524
24525         static const GLchar* vs_tes_gs = "    goku = uni_goku;\n";
24526         static const GLchar* fs            = "    fs_out = vec4(1, 0.25, 0.5, 0.75);\n"
24527                                                           "    if (TYPE(0) == goku)\n"
24528                                                           "    {\n"
24529                                                           "         fs_out = vec4(1, 0.75, 0.5, 0.5);\n"
24530                                                           "    }\n";
24531
24532         const GLchar* assignments = "";
24533
24534         if (test_case.m_stage == stage)
24535         {
24536                 switch (stage)
24537                 {
24538                 case Utils::Shader::GEOMETRY:
24539                         assignments = vs_tes_gs;
24540                         break;
24541                 case Utils::Shader::TESS_EVAL:
24542                         assignments = vs_tes_gs;
24543                         break;
24544                 case Utils::Shader::VERTEX:
24545                         assignments = vs_tes_gs;
24546                         break;
24547                 default:
24548                         TCU_FAIL("Invalid enum");
24549                 }
24550         }
24551         else
24552         {
24553                 switch (stage)
24554                 {
24555                 case Utils::Shader::FRAGMENT:
24556                         assignments = fs;
24557                         break;
24558                 case Utils::Shader::GEOMETRY:
24559                 case Utils::Shader::TESS_CTRL:
24560                 case Utils::Shader::TESS_EVAL:
24561                 case Utils::Shader::VERTEX:
24562                         break;
24563                 default:
24564                         TCU_FAIL("Invalid enum");
24565                 }
24566         }
24567
24568         out_assignments = assignments;
24569
24570         if (Utils::Shader::FRAGMENT == stage)
24571         {
24572                 Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_assignments);
24573         }
24574 }
24575
24576 /** Get interface of shader
24577  *
24578  * @param test_case_index  Index of test case
24579  * @param stage            Shader stage
24580  * @param out_interface    Set to ""
24581  **/
24582 void XFBStrideTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_interface)
24583 {
24584         static const GLchar* vs_tes_gs = "layout (xfb_offset = 0) FLAT out TYPE goku;\n"
24585                                                                          "\n"
24586                                                                          "layout(std140, binding = 0) uniform Goku {\n"
24587                                                                          "    TYPE uni_goku;\n"
24588                                                                          "};\n";
24589         static const GLchar* fs = "FLAT in TYPE goku;\n"
24590                                                           "\n"
24591                                                           "out vec4 fs_out;\n";
24592
24593         const testCase& test_case = m_test_cases[test_case_index];
24594         const GLchar*   interface = "";
24595         const GLchar*   flat      = "";
24596
24597         if (test_case.m_stage == stage)
24598         {
24599                 switch (stage)
24600                 {
24601                 case Utils::Shader::GEOMETRY:
24602                         interface = vs_tes_gs;
24603                         break;
24604                 case Utils::Shader::TESS_EVAL:
24605                         interface = vs_tes_gs;
24606                         break;
24607                 case Utils::Shader::VERTEX:
24608                         interface = vs_tes_gs;
24609                         break;
24610                 default:
24611                         TCU_FAIL("Invalid enum");
24612                 }
24613         }
24614         else
24615         {
24616                 switch (stage)
24617                 {
24618                 case Utils::Shader::FRAGMENT:
24619                         interface = fs;
24620                         break;
24621                 case Utils::Shader::GEOMETRY:
24622                 case Utils::Shader::TESS_CTRL:
24623                 case Utils::Shader::TESS_EVAL:
24624                 case Utils::Shader::VERTEX:
24625                         break;
24626                 default:
24627                         TCU_FAIL("Invalid enum");
24628                 }
24629         }
24630
24631         out_interface = interface;
24632
24633         if (Utils::Type::Float != test_case.m_type.m_basic_type)
24634         {
24635                 flat = "flat";
24636         }
24637
24638         Utils::replaceAllTokens("FLAT", flat, out_interface);
24639         Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_interface);
24640 }
24641
24642 /** Get source code of shader
24643  *
24644  * @param test_case_index Index of test case
24645  * @param stage           Shader stage
24646  *
24647  * @return Source
24648  **/
24649 std::string XFBStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24650 {
24651         std::string             source;
24652         const testCase& test_case = m_test_cases[test_case_index];
24653
24654         switch (test_case.m_stage)
24655         {
24656         case Utils::Shader::VERTEX:
24657                 switch (stage)
24658                 {
24659                 case Utils::Shader::FRAGMENT:
24660                 case Utils::Shader::VERTEX:
24661                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24662                         break;
24663                 default:
24664                         break;
24665                 }
24666                 break;
24667
24668         case Utils::Shader::TESS_EVAL:
24669                 switch (stage)
24670                 {
24671                 case Utils::Shader::FRAGMENT:
24672                 case Utils::Shader::TESS_CTRL:
24673                 case Utils::Shader::TESS_EVAL:
24674                 case Utils::Shader::VERTEX:
24675                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24676                         break;
24677                 default:
24678                         break;
24679                 }
24680                 break;
24681
24682         case Utils::Shader::GEOMETRY:
24683                 source = BufferTestBase::getShaderSource(test_case_index, stage);
24684                 break;
24685
24686         default:
24687                 TCU_FAIL("Invalid enum");
24688                 break;
24689         }
24690
24691         /* */
24692         return source;
24693 }
24694
24695 /** Get name of test case
24696  *
24697  * @param test_case_index Index of test case
24698  *
24699  * @return Name of tested stage
24700  **/
24701 std::string XFBStrideTest::getTestCaseName(glw::GLuint test_case_index)
24702 {
24703         std::stringstream stream;
24704         const testCase&   test_case = m_test_cases[test_case_index];
24705
24706         stream << "Type: " << test_case.m_type.GetGLSLTypeName()
24707                    << ", stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24708
24709         return stream.str();
24710 }
24711
24712 /** Returns number of test cases
24713  *
24714  * @return TEST_MAX
24715  **/
24716 glw::GLuint XFBStrideTest::getTestCaseNumber()
24717 {
24718         return static_cast<GLuint>(m_test_cases.size());
24719 }
24720
24721 /** Prepare all test cases
24722  *
24723  **/
24724 void XFBStrideTest::testInit()
24725 {
24726         const GLuint n_types = getTypesNumber();
24727
24728         for (GLuint i = 0; i < n_types; ++i)
24729         {
24730                 const Utils::Type& type = getType(i);
24731
24732                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24733                 {
24734                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
24735                                 (Utils::Shader::TESS_CTRL == stage))
24736                         {
24737                                 continue;
24738                         }
24739
24740                         testCase test_case = { (Utils::Shader::STAGES)stage, type };
24741
24742                         m_test_cases.push_back(test_case);
24743                 }
24744         }
24745 }
24746
24747 /** Constructor
24748  *
24749  * @param context Test framework context
24750  **/
24751 XFBBlockMemberBufferTest::XFBBlockMemberBufferTest(deqp::Context& context)
24752         : NegativeTestBase(
24753                   context, "xfb_block_member_buffer",
24754                   "Test verifies that compiler reports error when block member has different xfb_buffer qualifier than buffer")
24755 {
24756 }
24757
24758 /** Source for given test case and stage
24759  *
24760  * @param test_case_index Index of test case
24761  * @param stage           Shader stage
24762  *
24763  * @return Shader source
24764  **/
24765 std::string XFBBlockMemberBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24766 {
24767         static const GLchar* var_definition = "layout (xfb_offset = 0) out Goku {\n"
24768                                                                                   "                            vec4 gohan;\n"
24769                                                                                   "    layout (xfb_buffer = 1) vec4 goten;\n"
24770                                                                                   "} gokuARRAY;\n";
24771         static const GLchar* var_use = "    gokuINDEX.gohan = result / 2;\n"
24772                                                                    "    gokuINDEX.goten = result / 4;\n";
24773         static const GLchar* fs = "#version 430 core\n"
24774                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24775                                                           "\n"
24776                                                           "in  vec4 gs_fs;\n"
24777                                                           "out vec4 fs_out;\n"
24778                                                           "\n"
24779                                                           "void main()\n"
24780                                                           "{\n"
24781                                                           "    fs_out = gs_fs;\n"
24782                                                           "}\n"
24783                                                           "\n";
24784         static const GLchar* gs_tested = "#version 430 core\n"
24785                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24786                                                                          "\n"
24787                                                                          "layout(points)                           in;\n"
24788                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
24789                                                                          "\n"
24790                                                                          "VAR_DEFINITION"
24791                                                                          "\n"
24792                                                                          "in  vec4 tes_gs[];\n"
24793                                                                          "out vec4 gs_fs;\n"
24794                                                                          "\n"
24795                                                                          "void main()\n"
24796                                                                          "{\n"
24797                                                                          "    vec4 result = tes_gs[0];\n"
24798                                                                          "\n"
24799                                                                          "VARIABLE_USE"
24800                                                                          "\n"
24801                                                                          "    gs_fs = result;\n"
24802                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
24803                                                                          "    EmitVertex();\n"
24804                                                                          "    gs_fs = result;\n"
24805                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
24806                                                                          "    EmitVertex();\n"
24807                                                                          "    gs_fs = result;\n"
24808                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
24809                                                                          "    EmitVertex();\n"
24810                                                                          "    gs_fs = result;\n"
24811                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
24812                                                                          "    EmitVertex();\n"
24813                                                                          "}\n"
24814                                                                          "\n";
24815         static const GLchar* tcs = "#version 430 core\n"
24816                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24817                                                            "\n"
24818                                                            "layout(vertices = 1) out;\n"
24819                                                            "\n"
24820                                                            "in  vec4 vs_tcs[];\n"
24821                                                            "out vec4 tcs_tes[];\n"
24822                                                            "\n"
24823                                                            "void main()\n"
24824                                                            "{\n"
24825                                                            "\n"
24826                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
24827                                                            "\n"
24828                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24829                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24830                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24831                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24832                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24833                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24834                                                            "}\n"
24835                                                            "\n";
24836         static const GLchar* tcs_tested = "#version 430 core\n"
24837                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24838                                                                           "\n"
24839                                                                           "layout(vertices = 1) out;\n"
24840                                                                           "\n"
24841                                                                           "VAR_DEFINITION"
24842                                                                           "\n"
24843                                                                           "in  vec4 vs_tcs[];\n"
24844                                                                           "out vec4 tcs_tes[];\n"
24845                                                                           "\n"
24846                                                                           "void main()\n"
24847                                                                           "{\n"
24848                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
24849                                                                           "\n"
24850                                                                           "VARIABLE_USE"
24851                                                                           "\n"
24852                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
24853                                                                           "\n"
24854                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
24855                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
24856                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
24857                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
24858                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
24859                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
24860                                                                           "}\n"
24861                                                                           "\n";
24862         static const GLchar* tes_tested = "#version 430 core\n"
24863                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24864                                                                           "\n"
24865                                                                           "layout(isolines, point_mode) in;\n"
24866                                                                           "\n"
24867                                                                           "VAR_DEFINITION"
24868                                                                           "\n"
24869                                                                           "in  vec4 tcs_tes[];\n"
24870                                                                           "out vec4 tes_gs;\n"
24871                                                                           "\n"
24872                                                                           "void main()\n"
24873                                                                           "{\n"
24874                                                                           "    vec4 result = tcs_tes[0];\n"
24875                                                                           "\n"
24876                                                                           "VARIABLE_USE"
24877                                                                           "\n"
24878                                                                           "    tes_gs += result;\n"
24879                                                                           "}\n"
24880                                                                           "\n";
24881         static const GLchar* vs = "#version 430 core\n"
24882                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24883                                                           "\n"
24884                                                           "in  vec4 in_vs;\n"
24885                                                           "out vec4 vs_tcs;\n"
24886                                                           "\n"
24887                                                           "void main()\n"
24888                                                           "{\n"
24889                                                           "    vs_tcs = in_vs;\n"
24890                                                           "}\n"
24891                                                           "\n";
24892         static const GLchar* vs_tested = "#version 430 core\n"
24893                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24894                                                                          "\n"
24895                                                                          "VAR_DEFINITION"
24896                                                                          "\n"
24897                                                                          "in  vec4 in_vs;\n"
24898                                                                          "out vec4 vs_tcs;\n"
24899                                                                          "\n"
24900                                                                          "void main()\n"
24901                                                                          "{\n"
24902                                                                          "    vec4 result = in_vs;\n"
24903                                                                          "\n"
24904                                                                          "VARIABLE_USE"
24905                                                                          "\n"
24906                                                                          "    vs_tcs = result;\n"
24907                                                                          "}\n"
24908                                                                          "\n";
24909
24910         std::string source;
24911         testCase&   test_case = m_test_cases[test_case_index];
24912
24913         if (test_case.m_stage == stage)
24914         {
24915                 const GLchar* array     = "";
24916                 const GLchar* index     = "";
24917                 size_t            position = 0;
24918
24919                 switch (stage)
24920                 {
24921                 case Utils::Shader::GEOMETRY:
24922                         source = gs_tested;
24923                         array  = "[]";
24924                         index  = "[0]";
24925                         break;
24926                 case Utils::Shader::TESS_CTRL:
24927                         source = tcs_tested;
24928                         array  = "[]";
24929                         index  = "[gl_InvocationID]";
24930                         break;
24931                 case Utils::Shader::TESS_EVAL:
24932                         source = tes_tested;
24933                         array  = "[]";
24934                         index  = "[0]";
24935                         break;
24936                 case Utils::Shader::VERTEX:
24937                         source = vs_tested;
24938                         break;
24939                 default:
24940                         TCU_FAIL("Invalid enum");
24941                 }
24942
24943                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
24944                 position = 0;
24945                 Utils::replaceToken("ARRAY", position, array, source);
24946                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
24947
24948                 Utils::replaceAllTokens("INDEX", index, source);
24949         }
24950         else
24951         {
24952                 switch (test_case.m_stage)
24953                 {
24954                 case Utils::Shader::GEOMETRY:
24955                         switch (stage)
24956                         {
24957                         case Utils::Shader::FRAGMENT:
24958                                 source = fs;
24959                                 break;
24960                         case Utils::Shader::VERTEX:
24961                                 source = vs;
24962                                 break;
24963                         default:
24964                                 source = "";
24965                         }
24966                         break;
24967                 case Utils::Shader::TESS_CTRL:
24968                         switch (stage)
24969                         {
24970                         case Utils::Shader::FRAGMENT:
24971                                 source = fs;
24972                                 break;
24973                         case Utils::Shader::VERTEX:
24974                                 source = vs;
24975                                 break;
24976                         default:
24977                                 source = "";
24978                         }
24979                         break;
24980                 case Utils::Shader::TESS_EVAL:
24981                         switch (stage)
24982                         {
24983                         case Utils::Shader::FRAGMENT:
24984                                 source = fs;
24985                                 break;
24986                         case Utils::Shader::TESS_CTRL:
24987                                 source = tcs;
24988                                 break;
24989                         case Utils::Shader::VERTEX:
24990                                 source = vs;
24991                                 break;
24992                         default:
24993                                 source = "";
24994                         }
24995                         break;
24996                 case Utils::Shader::VERTEX:
24997                         switch (stage)
24998                         {
24999                         case Utils::Shader::FRAGMENT:
25000                                 source = fs;
25001                                 break;
25002                         default:
25003                                 source = "";
25004                         }
25005                         break;
25006                 default:
25007                         TCU_FAIL("Invalid enum");
25008                         break;
25009                 }
25010         }
25011
25012         return source;
25013 }
25014
25015 /** Get description of test case
25016  *
25017  * @param test_case_index Index of test case
25018  *
25019  * @return Test case description
25020  **/
25021 std::string XFBBlockMemberBufferTest::getTestCaseName(GLuint test_case_index)
25022 {
25023         std::stringstream stream;
25024         testCase&                 test_case = m_test_cases[test_case_index];
25025
25026         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
25027
25028         return stream.str();
25029 }
25030
25031 /** Get number of test cases
25032  *
25033  * @return Number of test cases
25034  **/
25035 GLuint XFBBlockMemberBufferTest::getTestCaseNumber()
25036 {
25037         return static_cast<GLuint>(m_test_cases.size());
25038 }
25039
25040 /** Selects if "compute" stage is relevant for test
25041  *
25042  * @param ignored
25043  *
25044  * @return false
25045  **/
25046 bool XFBBlockMemberBufferTest::isComputeRelevant(GLuint /* test_case_index */)
25047 {
25048         return false;
25049 }
25050
25051 /** Prepare all test cases
25052  *
25053  **/
25054 void XFBBlockMemberBufferTest::testInit()
25055 {
25056         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25057         {
25058                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25059                         (Utils::Shader::FRAGMENT == stage))
25060                 {
25061                         continue;
25062                 }
25063
25064                 testCase test_case = { (Utils::Shader::STAGES)stage };
25065
25066                 m_test_cases.push_back(test_case);
25067         }
25068 }
25069
25070 /** Constructor
25071  *
25072  * @param context Test framework context
25073  **/
25074 XFBOutputOverlappingTest::XFBOutputOverlappingTest(deqp::Context& context)
25075         : NegativeTestBase(context, "xfb_output_overlapping",
25076                                            "Test verifies that compiler reports error when two xfb qualified outputs overlap")
25077 {
25078 }
25079
25080 /** Source for given test case and stage
25081  *
25082  * @param test_case_index Index of test case
25083  * @param stage           Shader stage
25084  *
25085  * @return Shader source
25086  **/
25087 std::string XFBOutputOverlappingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25088 {
25089         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n"
25090                                                                                   "layout (xfb_offset = OFFSET) out TYPE gotenARRAY;\n";
25091         static const GLchar* var_use = "    gohanINDEX = TYPE(0);\n"
25092                                                                    "    gotenINDEX = TYPE(1);\n"
25093                                                                    "    if (vec4(0) == result)\n"
25094                                                                    "    {\n"
25095                                                                    "        gohanINDEX = TYPE(1);\n"
25096                                                                    "        gotenINDEX = TYPE(0);\n"
25097                                                                    "    }\n";
25098         static const GLchar* fs = "#version 430 core\n"
25099                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25100                                                           "\n"
25101                                                           "in  vec4 gs_fs;\n"
25102                                                           "out vec4 fs_out;\n"
25103                                                           "\n"
25104                                                           "void main()\n"
25105                                                           "{\n"
25106                                                           "    fs_out = gs_fs;\n"
25107                                                           "}\n"
25108                                                           "\n";
25109         static const GLchar* gs_tested = "#version 430 core\n"
25110                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25111                                                                          "\n"
25112                                                                          "layout(points)                           in;\n"
25113                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25114                                                                          "\n"
25115                                                                          "VAR_DEFINITION"
25116                                                                          "\n"
25117                                                                          "in  vec4 tes_gs[];\n"
25118                                                                          "out vec4 gs_fs;\n"
25119                                                                          "\n"
25120                                                                          "void main()\n"
25121                                                                          "{\n"
25122                                                                          "    vec4 result = tes_gs[0];\n"
25123                                                                          "\n"
25124                                                                          "VARIABLE_USE"
25125                                                                          "\n"
25126                                                                          "    gs_fs = result;\n"
25127                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25128                                                                          "    EmitVertex();\n"
25129                                                                          "    gs_fs = result;\n"
25130                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25131                                                                          "    EmitVertex();\n"
25132                                                                          "    gs_fs = result;\n"
25133                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25134                                                                          "    EmitVertex();\n"
25135                                                                          "    gs_fs = result;\n"
25136                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25137                                                                          "    EmitVertex();\n"
25138                                                                          "}\n"
25139                                                                          "\n";
25140         static const GLchar* tcs = "#version 430 core\n"
25141                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25142                                                            "\n"
25143                                                            "layout(vertices = 1) out;\n"
25144                                                            "\n"
25145                                                            "in  vec4 vs_tcs[];\n"
25146                                                            "out vec4 tcs_tes[];\n"
25147                                                            "\n"
25148                                                            "void main()\n"
25149                                                            "{\n"
25150                                                            "\n"
25151                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25152                                                            "\n"
25153                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25154                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25155                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25156                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25157                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25158                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25159                                                            "}\n"
25160                                                            "\n";
25161         static const GLchar* tcs_tested = "#version 430 core\n"
25162                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25163                                                                           "\n"
25164                                                                           "layout(vertices = 1) out;\n"
25165                                                                           "\n"
25166                                                                           "VAR_DEFINITION"
25167                                                                           "\n"
25168                                                                           "in  vec4 vs_tcs[];\n"
25169                                                                           "out vec4 tcs_tes[];\n"
25170                                                                           "\n"
25171                                                                           "void main()\n"
25172                                                                           "{\n"
25173                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25174                                                                           "\n"
25175                                                                           "VARIABLE_USE"
25176                                                                           "\n"
25177                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25178                                                                           "\n"
25179                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25180                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25181                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25182                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25183                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25184                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25185                                                                           "}\n"
25186                                                                           "\n";
25187         static const GLchar* tes_tested = "#version 430 core\n"
25188                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25189                                                                           "\n"
25190                                                                           "layout(isolines, point_mode) in;\n"
25191                                                                           "\n"
25192                                                                           "VAR_DEFINITION"
25193                                                                           "\n"
25194                                                                           "in  vec4 tcs_tes[];\n"
25195                                                                           "out vec4 tes_gs;\n"
25196                                                                           "\n"
25197                                                                           "void main()\n"
25198                                                                           "{\n"
25199                                                                           "    vec4 result = tcs_tes[0];\n"
25200                                                                           "\n"
25201                                                                           "VARIABLE_USE"
25202                                                                           "\n"
25203                                                                           "    tes_gs += result;\n"
25204                                                                           "}\n"
25205                                                                           "\n";
25206         static const GLchar* vs = "#version 430 core\n"
25207                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25208                                                           "\n"
25209                                                           "in  vec4 in_vs;\n"
25210                                                           "out vec4 vs_tcs;\n"
25211                                                           "\n"
25212                                                           "void main()\n"
25213                                                           "{\n"
25214                                                           "    vs_tcs = in_vs;\n"
25215                                                           "}\n"
25216                                                           "\n";
25217         static const GLchar* vs_tested = "#version 430 core\n"
25218                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25219                                                                          "\n"
25220                                                                          "VAR_DEFINITION"
25221                                                                          "\n"
25222                                                                          "in  vec4 in_vs;\n"
25223                                                                          "out vec4 vs_tcs;\n"
25224                                                                          "\n"
25225                                                                          "void main()\n"
25226                                                                          "{\n"
25227                                                                          "    vec4 result = in_vs;\n"
25228                                                                          "\n"
25229                                                                          "VARIABLE_USE"
25230                                                                          "\n"
25231                                                                          "    vs_tcs = result;\n"
25232                                                                          "}\n"
25233                                                                          "\n";
25234
25235         std::string source;
25236         testCase&   test_case = m_test_cases[test_case_index];
25237
25238         if (test_case.m_stage == stage)
25239         {
25240                 const GLchar* array = "";
25241                 GLchar            buffer_gohan[16];
25242                 GLchar            buffer_goten[16];
25243                 const GLchar* index                      = "";
25244                 size_t            position               = 0;
25245                 size_t            position_start = 0;
25246                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25247
25248                 sprintf(buffer_gohan, "%d", test_case.m_offset_gohan);
25249                 sprintf(buffer_goten, "%d", test_case.m_offset_goten);
25250
25251                 switch (stage)
25252                 {
25253                 case Utils::Shader::GEOMETRY:
25254                         source = gs_tested;
25255                         array  = "[]";
25256                         index  = "[0]";
25257                         break;
25258                 case Utils::Shader::TESS_CTRL:
25259                         source = tcs_tested;
25260                         array  = "[]";
25261                         index  = "[gl_InvocationID]";
25262                         break;
25263                 case Utils::Shader::TESS_EVAL:
25264                         source = tes_tested;
25265                         array  = "[]";
25266                         index  = "[0]";
25267                         break;
25268                 case Utils::Shader::VERTEX:
25269                         source = vs_tested;
25270                         break;
25271                 default:
25272                         TCU_FAIL("Invalid enum");
25273                 }
25274
25275                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25276                 position = 0;
25277                 Utils::replaceToken("OFFSET", position, buffer_gohan, source);
25278                 Utils::replaceToken("TYPE", position, type_name, source);
25279                 Utils::replaceToken("ARRAY", position, array, source);
25280                 Utils::replaceToken("OFFSET", position, buffer_goten, source);
25281                 Utils::replaceToken("TYPE", position, type_name, source);
25282                 Utils::replaceToken("ARRAY", position, array, source);
25283                 position_start = position;
25284                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25285                 position = position_start;
25286                 Utils::replaceToken("INDEX", position, index, source);
25287                 Utils::replaceToken("TYPE", position, type_name, source);
25288                 Utils::replaceToken("INDEX", position, index, source);
25289                 Utils::replaceToken("TYPE", position, type_name, source);
25290                 Utils::replaceToken("INDEX", position, index, source);
25291                 Utils::replaceToken("TYPE", position, type_name, source);
25292                 Utils::replaceToken("INDEX", position, index, source);
25293                 Utils::replaceToken("TYPE", position, type_name, source);
25294         }
25295         else
25296         {
25297                 switch (test_case.m_stage)
25298                 {
25299                 case Utils::Shader::GEOMETRY:
25300                         switch (stage)
25301                         {
25302                         case Utils::Shader::FRAGMENT:
25303                                 source = fs;
25304                                 break;
25305                         case Utils::Shader::VERTEX:
25306                                 source = vs;
25307                                 break;
25308                         default:
25309                                 source = "";
25310                         }
25311                         break;
25312                 case Utils::Shader::TESS_CTRL:
25313                         switch (stage)
25314                         {
25315                         case Utils::Shader::FRAGMENT:
25316                                 source = fs;
25317                                 break;
25318                         case Utils::Shader::VERTEX:
25319                                 source = vs;
25320                                 break;
25321                         default:
25322                                 source = "";
25323                         }
25324                         break;
25325                 case Utils::Shader::TESS_EVAL:
25326                         switch (stage)
25327                         {
25328                         case Utils::Shader::FRAGMENT:
25329                                 source = fs;
25330                                 break;
25331                         case Utils::Shader::TESS_CTRL:
25332                                 source = tcs;
25333                                 break;
25334                         case Utils::Shader::VERTEX:
25335                                 source = vs;
25336                                 break;
25337                         default:
25338                                 source = "";
25339                         }
25340                         break;
25341                 case Utils::Shader::VERTEX:
25342                         switch (stage)
25343                         {
25344                         case Utils::Shader::FRAGMENT:
25345                                 source = fs;
25346                                 break;
25347                         default:
25348                                 source = "";
25349                         }
25350                         break;
25351                 default:
25352                         TCU_FAIL("Invalid enum");
25353                         break;
25354                 }
25355         }
25356
25357         return source;
25358 }
25359
25360 /** Get description of test case
25361  *
25362  * @param test_case_index Index of test case
25363  *
25364  * @return Test case description
25365  **/
25366 std::string XFBOutputOverlappingTest::getTestCaseName(GLuint test_case_index)
25367 {
25368         std::stringstream stream;
25369         testCase&                 test_case = m_test_cases[test_case_index];
25370
25371         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25372                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offsets: " << test_case.m_offset_gohan << " & "
25373                    << test_case.m_offset_goten;
25374
25375         return stream.str();
25376 }
25377
25378 /** Get number of test cases
25379  *
25380  * @return Number of test cases
25381  **/
25382 GLuint XFBOutputOverlappingTest::getTestCaseNumber()
25383 {
25384         return static_cast<GLuint>(m_test_cases.size());
25385 }
25386
25387 /** Selects if "compute" stage is relevant for test
25388  *
25389  * @param ignored
25390  *
25391  * @return false
25392  **/
25393 bool XFBOutputOverlappingTest::isComputeRelevant(GLuint /* test_case_index */)
25394 {
25395         return false;
25396 }
25397
25398 /** Prepare all test cases
25399  *
25400  **/
25401 void XFBOutputOverlappingTest::testInit()
25402 {
25403         const GLuint n_types = getTypesNumber();
25404
25405         for (GLuint i = 0; i < n_types; ++i)
25406         {
25407                 const Utils::Type& type                   = getType(i);
25408                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25409
25410                 /* Skip scalars, not applicable as:
25411                  *
25412                  *     The offset must be a multiple of the size of the first component of the first
25413                  *     qualified variable or block member, or a compile-time error results.
25414                  */
25415                 if ((1 == type.m_n_columns) && (1 == type.m_n_rows))
25416                 {
25417                         continue;
25418                 }
25419
25420                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25421                 {
25422                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25423                                 (Utils::Shader::FRAGMENT == stage))
25424                         {
25425                                 continue;
25426                         }
25427
25428                         testCase test_case = { 0 /* gohan offset */, base_alingment /* goten_offset */,
25429                                                                    (Utils::Shader::STAGES)stage, type };
25430
25431                         m_test_cases.push_back(test_case);
25432                 }
25433         }
25434 }
25435
25436 /** Constructor
25437  *
25438  * @param context Test framework context
25439  **/
25440 XFBInvalidOffsetAlignmentTest::XFBInvalidOffsetAlignmentTest(deqp::Context& context)
25441         : NegativeTestBase(context, "xfb_invalid_offset_alignment",
25442                                            "Test verifies that compiler reports error when xfb_offset has invalid alignment")
25443 {
25444 }
25445
25446 /** Source for given test case and stage
25447  *
25448  * @param test_case_index Index of test case
25449  * @param stage           Shader stage
25450  *
25451  * @return Shader source
25452  **/
25453 std::string XFBInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25454 {
25455         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n";
25456         static const GLchar* var_use            = "    gohanINDEX = TYPE(0);\n"
25457                                                                    "    if (vec4(0) == result)\n"
25458                                                                    "    {\n"
25459                                                                    "        gohanINDEX = TYPE(1);\n"
25460                                                                    "    }\n";
25461         static const GLchar* fs = "#version 430 core\n"
25462                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25463                                                           "\n"
25464                                                           "in  vec4 gs_fs;\n"
25465                                                           "out vec4 fs_out;\n"
25466                                                           "\n"
25467                                                           "void main()\n"
25468                                                           "{\n"
25469                                                           "    fs_out = gs_fs;\n"
25470                                                           "}\n"
25471                                                           "\n";
25472         static const GLchar* gs_tested = "#version 430 core\n"
25473                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25474                                                                          "\n"
25475                                                                          "layout(points)                           in;\n"
25476                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25477                                                                          "\n"
25478                                                                          "VAR_DEFINITION"
25479                                                                          "\n"
25480                                                                          "in  vec4 tes_gs[];\n"
25481                                                                          "out vec4 gs_fs;\n"
25482                                                                          "\n"
25483                                                                          "void main()\n"
25484                                                                          "{\n"
25485                                                                          "    vec4 result = tes_gs[0];\n"
25486                                                                          "\n"
25487                                                                          "VARIABLE_USE"
25488                                                                          "\n"
25489                                                                          "    gs_fs = result;\n"
25490                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25491                                                                          "    EmitVertex();\n"
25492                                                                          "    gs_fs = result;\n"
25493                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25494                                                                          "    EmitVertex();\n"
25495                                                                          "    gs_fs = result;\n"
25496                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25497                                                                          "    EmitVertex();\n"
25498                                                                          "    gs_fs = result;\n"
25499                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25500                                                                          "    EmitVertex();\n"
25501                                                                          "}\n"
25502                                                                          "\n";
25503         static const GLchar* tcs = "#version 430 core\n"
25504                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25505                                                            "\n"
25506                                                            "layout(vertices = 1) out;\n"
25507                                                            "\n"
25508                                                            "in  vec4 vs_tcs[];\n"
25509                                                            "out vec4 tcs_tes[];\n"
25510                                                            "\n"
25511                                                            "void main()\n"
25512                                                            "{\n"
25513                                                            "\n"
25514                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25515                                                            "\n"
25516                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25517                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25518                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25519                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25520                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25521                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25522                                                            "}\n"
25523                                                            "\n";
25524         static const GLchar* tcs_tested = "#version 430 core\n"
25525                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25526                                                                           "\n"
25527                                                                           "layout(vertices = 1) out;\n"
25528                                                                           "\n"
25529                                                                           "VAR_DEFINITION"
25530                                                                           "\n"
25531                                                                           "in  vec4 vs_tcs[];\n"
25532                                                                           "out vec4 tcs_tes[];\n"
25533                                                                           "\n"
25534                                                                           "void main()\n"
25535                                                                           "{\n"
25536                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25537                                                                           "\n"
25538                                                                           "VARIABLE_USE"
25539                                                                           "\n"
25540                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25541                                                                           "\n"
25542                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25543                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25544                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25545                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25546                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25547                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25548                                                                           "}\n"
25549                                                                           "\n";
25550         static const GLchar* tes_tested = "#version 430 core\n"
25551                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25552                                                                           "\n"
25553                                                                           "layout(isolines, point_mode) in;\n"
25554                                                                           "\n"
25555                                                                           "VAR_DEFINITION"
25556                                                                           "\n"
25557                                                                           "in  vec4 tcs_tes[];\n"
25558                                                                           "out vec4 tes_gs;\n"
25559                                                                           "\n"
25560                                                                           "void main()\n"
25561                                                                           "{\n"
25562                                                                           "    vec4 result = tcs_tes[0];\n"
25563                                                                           "\n"
25564                                                                           "VARIABLE_USE"
25565                                                                           "\n"
25566                                                                           "    tes_gs += result;\n"
25567                                                                           "}\n"
25568                                                                           "\n";
25569         static const GLchar* vs = "#version 430 core\n"
25570                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25571                                                           "\n"
25572                                                           "in  vec4 in_vs;\n"
25573                                                           "out vec4 vs_tcs;\n"
25574                                                           "\n"
25575                                                           "void main()\n"
25576                                                           "{\n"
25577                                                           "    vs_tcs = in_vs;\n"
25578                                                           "}\n"
25579                                                           "\n";
25580         static const GLchar* vs_tested = "#version 430 core\n"
25581                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25582                                                                          "\n"
25583                                                                          "VAR_DEFINITION"
25584                                                                          "\n"
25585                                                                          "in  vec4 in_vs;\n"
25586                                                                          "out vec4 vs_tcs;\n"
25587                                                                          "\n"
25588                                                                          "void main()\n"
25589                                                                          "{\n"
25590                                                                          "    vec4 result = in_vs;\n"
25591                                                                          "\n"
25592                                                                          "VARIABLE_USE"
25593                                                                          "\n"
25594                                                                          "    vs_tcs = result;\n"
25595                                                                          "}\n"
25596                                                                          "\n";
25597
25598         std::string source;
25599         testCase&   test_case = m_test_cases[test_case_index];
25600
25601         if (test_case.m_stage == stage)
25602         {
25603                 const GLchar* array = "";
25604                 GLchar            buffer[16];
25605                 const GLchar* index                      = "";
25606                 size_t            position               = 0;
25607                 size_t            position_start = 0;
25608                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25609
25610                 sprintf(buffer, "%d", test_case.m_offset);
25611
25612                 switch (stage)
25613                 {
25614                 case Utils::Shader::GEOMETRY:
25615                         source = gs_tested;
25616                         array  = "[]";
25617                         index  = "[0]";
25618                         break;
25619                 case Utils::Shader::TESS_CTRL:
25620                         source = tcs_tested;
25621                         array  = "[]";
25622                         index  = "[gl_InvocationID]";
25623                         break;
25624                 case Utils::Shader::TESS_EVAL:
25625                         source = tes_tested;
25626                         array  = "[]";
25627                         index  = "[0]";
25628                         break;
25629                 case Utils::Shader::VERTEX:
25630                         source = vs_tested;
25631                         break;
25632                 default:
25633                         TCU_FAIL("Invalid enum");
25634                 }
25635
25636                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25637                 position = 0;
25638                 Utils::replaceToken("OFFSET", position, buffer, source);
25639                 Utils::replaceToken("TYPE", position, type_name, source);
25640                 Utils::replaceToken("ARRAY", position, array, source);
25641                 position_start = position;
25642                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25643                 position = position_start;
25644                 Utils::replaceToken("INDEX", position, index, source);
25645                 Utils::replaceToken("TYPE", position, type_name, source);
25646                 Utils::replaceToken("INDEX", position, index, source);
25647                 Utils::replaceToken("TYPE", position, type_name, source);
25648         }
25649         else
25650         {
25651                 switch (test_case.m_stage)
25652                 {
25653                 case Utils::Shader::GEOMETRY:
25654                         switch (stage)
25655                         {
25656                         case Utils::Shader::FRAGMENT:
25657                                 source = fs;
25658                                 break;
25659                         case Utils::Shader::VERTEX:
25660                                 source = vs;
25661                                 break;
25662                         default:
25663                                 source = "";
25664                         }
25665                         break;
25666                 case Utils::Shader::TESS_CTRL:
25667                         switch (stage)
25668                         {
25669                         case Utils::Shader::FRAGMENT:
25670                                 source = fs;
25671                                 break;
25672                         case Utils::Shader::VERTEX:
25673                                 source = vs;
25674                                 break;
25675                         default:
25676                                 source = "";
25677                         }
25678                         break;
25679                 case Utils::Shader::TESS_EVAL:
25680                         switch (stage)
25681                         {
25682                         case Utils::Shader::FRAGMENT:
25683                                 source = fs;
25684                                 break;
25685                         case Utils::Shader::TESS_CTRL:
25686                                 source = tcs;
25687                                 break;
25688                         case Utils::Shader::VERTEX:
25689                                 source = vs;
25690                                 break;
25691                         default:
25692                                 source = "";
25693                         }
25694                         break;
25695                 case Utils::Shader::VERTEX:
25696                         switch (stage)
25697                         {
25698                         case Utils::Shader::FRAGMENT:
25699                                 source = fs;
25700                                 break;
25701                         default:
25702                                 source = "";
25703                         }
25704                         break;
25705                 default:
25706                         TCU_FAIL("Invalid enum");
25707                         break;
25708                 }
25709         }
25710
25711         return source;
25712 }
25713
25714 /** Get description of test case
25715  *
25716  * @param test_case_index Index of test case
25717  *
25718  * @return Test case description
25719  **/
25720 std::string XFBInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
25721 {
25722         std::stringstream stream;
25723         testCase&                 test_case = m_test_cases[test_case_index];
25724
25725         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25726                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
25727
25728         return stream.str();
25729 }
25730
25731 /** Get number of test cases
25732  *
25733  * @return Number of test cases
25734  **/
25735 GLuint XFBInvalidOffsetAlignmentTest::getTestCaseNumber()
25736 {
25737         return static_cast<GLuint>(m_test_cases.size());
25738 }
25739
25740 /** Selects if "compute" stage is relevant for test
25741  *
25742  * @param ignored
25743  *
25744  * @return false
25745  **/
25746 bool XFBInvalidOffsetAlignmentTest::isComputeRelevant(GLuint /* test_case_index */)
25747 {
25748         return false;
25749 }
25750
25751 /** Prepare all test cases
25752  *
25753  **/
25754 void XFBInvalidOffsetAlignmentTest::testInit()
25755 {
25756         const GLuint n_types = getTypesNumber();
25757
25758         for (GLuint i = 0; i < n_types; ++i)
25759         {
25760                 const Utils::Type& type                   = getType(i);
25761                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25762
25763                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25764                 {
25765                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25766                                 (Utils::Shader::FRAGMENT == stage))
25767                         {
25768                                 continue;
25769                         }
25770
25771                         for (GLuint offset = base_alingment + 1; offset < 2 * base_alingment; ++offset)
25772                         {
25773                                 testCase test_case = { offset, (Utils::Shader::STAGES)stage, type };
25774
25775                                 m_test_cases.push_back(test_case);
25776                         }
25777                 }
25778         }
25779 }
25780
25781 /** Constructor
25782  *
25783  * @param context Test context
25784  **/
25785 XFBCaptureInactiveOutputVariableTest::XFBCaptureInactiveOutputVariableTest(deqp::Context& context)
25786         : BufferTestBase(context, "xfb_capture_inactive_output_variable",
25787                                          "Test verifies that inactive variables are captured")
25788 {
25789         /* Nothing to be done here */
25790 }
25791
25792 /** Execute drawArrays for single vertex
25793  *
25794  * @param test_case_index
25795  *
25796  * @return true
25797  **/
25798 bool XFBCaptureInactiveOutputVariableTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
25799 {
25800         const Functions& gl                             = m_context.getRenderContext().getFunctions();
25801         GLenum                   primitive_type = GL_PATCHES;
25802
25803         if (TEST_VS == test_case_index)
25804         {
25805                 primitive_type = GL_POINTS;
25806         }
25807
25808         gl.disable(GL_RASTERIZER_DISCARD);
25809         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
25810
25811         gl.beginTransformFeedback(GL_POINTS);
25812         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
25813
25814         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
25815         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
25816
25817         gl.endTransformFeedback();
25818         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
25819
25820         return true;
25821 }
25822
25823 /** Get descriptors of buffers necessary for test
25824  *
25825  * @param ignored
25826  * @param out_descriptors Descriptors of buffers used by test
25827  **/
25828 void XFBCaptureInactiveOutputVariableTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
25829                                                                                                                                 bufferDescriptor::Vector& out_descriptors)
25830 {
25831         const Utils::Type& type = Utils::Type::vec4;
25832
25833         /* Test needs single uniform and xfb */
25834         out_descriptors.resize(2);
25835
25836         /* Get references */
25837         bufferDescriptor& uniform = out_descriptors[0];
25838         bufferDescriptor& xfb    = out_descriptors[1];
25839
25840         /* Index */
25841         uniform.m_index = 0;
25842         xfb.m_index             = 0;
25843
25844         /* Target */
25845         uniform.m_target = Utils::Buffer::Uniform;
25846         xfb.m_target     = Utils::Buffer::Transform_feedback;
25847
25848         /* Data */
25849         const std::vector<GLubyte>& gohan_data = type.GenerateData();
25850         const std::vector<GLubyte>& goten_data = type.GenerateData();
25851
25852         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
25853
25854         /* Uniform data */
25855         uniform.m_initial_data.resize(2 * type_size);
25856         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
25857         memcpy(&uniform.m_initial_data[0] + type_size, &goten_data[0], type_size);
25858
25859         /* XFB data */
25860         xfb.m_initial_data.resize(3 * type_size);
25861         xfb.m_expected_data.resize(3 * type_size);
25862
25863         for (GLuint i = 0; i < 3 * type_size; ++i)
25864         {
25865                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
25866                 xfb.m_expected_data[i] = (glw::GLubyte)i;
25867         }
25868
25869         memcpy(&xfb.m_expected_data[0] + 2 * type_size, &gohan_data[0], type_size);
25870         memcpy(&xfb.m_expected_data[0] + 0 * type_size, &goten_data[0], type_size);
25871 }
25872
25873 /** Get body of main function for given shader stage
25874  *
25875  * @param test_case_index  Index of test case
25876  * @param stage            Shader stage
25877  * @param out_assignments  Set to empty
25878  * @param out_calculations Set to empty
25879  **/
25880 void XFBCaptureInactiveOutputVariableTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
25881                                                                                                                  std::string& out_assignments, std::string& out_calculations)
25882 {
25883         out_calculations = "";
25884
25885         static const GLchar* vs_tes_gs = "    goten = uni_goten;\n"
25886                                                                          "    gohan = uni_gohan;\n";
25887         static const GLchar* fs = "    fs_out = goku + gohan + goten;\n";
25888
25889         const GLchar* assignments = "";
25890
25891         switch (stage)
25892         {
25893         case Utils::Shader::FRAGMENT:
25894                 assignments = fs;
25895                 break;
25896
25897         case Utils::Shader::GEOMETRY:
25898                 if (TEST_GS == test_case_index)
25899                 {
25900                         assignments = vs_tes_gs;
25901                 }
25902                 break;
25903
25904         case Utils::Shader::TESS_CTRL:
25905                 break;
25906
25907         case Utils::Shader::TESS_EVAL:
25908                 if (TEST_TES == test_case_index)
25909                 {
25910                         assignments = vs_tes_gs;
25911                 }
25912                 break;
25913
25914         case Utils::Shader::VERTEX:
25915                 if (TEST_VS == test_case_index)
25916                 {
25917                         assignments = vs_tes_gs;
25918                 }
25919                 break;
25920
25921         default:
25922                 TCU_FAIL("Invalid enum");
25923         }
25924
25925         out_assignments = assignments;
25926 }
25927
25928 /** Get interface of shader
25929  *
25930  * @param test_case_index  Index of test case
25931  * @param stage            Shader stage
25932  * @param out_interface    Set to ""
25933  **/
25934 void XFBCaptureInactiveOutputVariableTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
25935                                                                                                                           std::string& out_interface)
25936 {
25937         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
25938                                                                          "\n"
25939                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goku;\n"
25940                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 gohan;\n"
25941                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 goten;\n"
25942                                                                          "\n"
25943                                                                          "layout(binding = 0) uniform block {\n"
25944                                                                          "    vec4 uni_gohan;\n"
25945                                                                          "    vec4 uni_goten;\n"
25946                                                                          "};\n";
25947         static const GLchar* fs = "in vec4 goku;\n"
25948                                                           "in vec4 gohan;\n"
25949                                                           "in vec4 goten;\n"
25950                                                           "out vec4 fs_out;\n";
25951
25952         const GLchar* interface = "";
25953
25954         switch (stage)
25955         {
25956         case Utils::Shader::FRAGMENT:
25957                 interface = fs;
25958                 break;
25959
25960         case Utils::Shader::GEOMETRY:
25961                 if (TEST_GS == test_case_index)
25962                 {
25963                         interface = vs_tes_gs;
25964                 }
25965                 break;
25966
25967         case Utils::Shader::TESS_CTRL:
25968                 break;
25969
25970         case Utils::Shader::TESS_EVAL:
25971                 if (TEST_TES == test_case_index)
25972                 {
25973                         interface = vs_tes_gs;
25974                 }
25975                 break;
25976
25977         case Utils::Shader::VERTEX:
25978                 if (TEST_VS == test_case_index)
25979                 {
25980                         interface = vs_tes_gs;
25981                 }
25982                 break;
25983
25984         default:
25985                 TCU_FAIL("Invalid enum");
25986         }
25987
25988         out_interface = interface;
25989 }
25990
25991 /** Get source code of shader
25992  *
25993  * @param test_case_index Index of test case
25994  * @param stage           Shader stage
25995  *
25996  * @return Source
25997  **/
25998 std::string XFBCaptureInactiveOutputVariableTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25999 {
26000         std::string source;
26001
26002         switch (test_case_index)
26003         {
26004         case TEST_VS:
26005                 switch (stage)
26006                 {
26007                 case Utils::Shader::FRAGMENT:
26008                 case Utils::Shader::VERTEX:
26009                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26010                         break;
26011                 default:
26012                         break;
26013                 }
26014                 break;
26015
26016         case TEST_TES:
26017                 switch (stage)
26018                 {
26019                 case Utils::Shader::FRAGMENT:
26020                 case Utils::Shader::TESS_CTRL:
26021                 case Utils::Shader::TESS_EVAL:
26022                 case Utils::Shader::VERTEX:
26023                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26024                         break;
26025                 default:
26026                         break;
26027                 }
26028                 break;
26029
26030         case TEST_GS:
26031                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26032                 break;
26033
26034         default:
26035                 TCU_FAIL("Invalid enum");
26036                 break;
26037         }
26038
26039         /* */
26040         return source;
26041 }
26042
26043 /** Get name of test case
26044  *
26045  * @param test_case_index Index of test case
26046  *
26047  * @return Name of tested stage
26048  **/
26049 std::string XFBCaptureInactiveOutputVariableTest::getTestCaseName(glw::GLuint test_case_index)
26050 {
26051         const GLchar* name = 0;
26052
26053         switch (test_case_index)
26054         {
26055         case TEST_VS:
26056                 name = "vertex";
26057                 break;
26058         case TEST_TES:
26059                 name = "tessellation evaluation";
26060                 break;
26061         case TEST_GS:
26062                 name = "geometry";
26063                 break;
26064         default:
26065                 TCU_FAIL("Invalid enum");
26066         }
26067
26068         return name;
26069 }
26070
26071 /** Returns number of test cases
26072  *
26073  * @return TEST_MAX
26074  **/
26075 glw::GLuint XFBCaptureInactiveOutputVariableTest::getTestCaseNumber()
26076 {
26077         return TEST_MAX;
26078 }
26079
26080 /** Inspects program to check if all resources are as expected
26081  *
26082  * @param ignored
26083  * @param program         Program instance
26084  * @param out_stream      Error message
26085  *
26086  * @return true if everything is ok, false otherwise
26087  **/
26088 bool XFBCaptureInactiveOutputVariableTest::inspectProgram(GLuint /* test_case_index */, Utils::Program& program,
26089                                                                                                                   std::stringstream& out_stream)
26090 {
26091         GLint                      stride       = 0;
26092         const Utils::Type& type          = Utils::Type::vec4;
26093         const GLuint       type_size = type.GetSize();
26094
26095         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
26096                                                 1 /* buf_size */, &stride);
26097
26098         if ((GLint)(3 * type_size) != stride)
26099         {
26100                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
26101
26102                 return false;
26103         }
26104
26105         return true;
26106 }
26107
26108 /** Verify contents of buffers
26109  *
26110  * @param buffers Collection of buffers to be verified
26111  *
26112  * @return true if everything is as expected, false otherwise
26113  **/
26114 bool XFBCaptureInactiveOutputVariableTest::verifyBuffers(bufferCollection& buffers)
26115 {
26116         bool result = true;
26117
26118         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26119         Utils::Buffer*                  buffer   = pair.m_buffer;
26120         bufferDescriptor*               descriptor = pair.m_descriptor;
26121
26122         /* Get pointer to contents of buffer */
26123         buffer->Bind();
26124         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26125
26126         /* Get pointer to expected data */
26127         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26128
26129         /* Compare */
26130         static const GLuint vec4_size = 16;
26131
26132         int res_gohan = memcmp(buffer_data + 2 * vec4_size, expected_data + 2 * vec4_size, vec4_size);
26133         int res_goten = memcmp(buffer_data + 0 * vec4_size, expected_data + 0 * vec4_size, vec4_size);
26134
26135         if ((0 != res_gohan) || (0 != res_goten))
26136         {
26137                 m_context.getTestContext().getLog()
26138                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26139                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26140
26141                 result = false;
26142         }
26143
26144         /* Release buffer mapping */
26145         buffer->UnMap();
26146
26147         return result;
26148 }
26149
26150 /** Constructor
26151  *
26152  * @param context Test context
26153  **/
26154 XFBCaptureInactiveOutputComponentTest::XFBCaptureInactiveOutputComponentTest(deqp::Context& context)
26155         : BufferTestBase(context, "xfb_capture_inactive_output_component",
26156                                          "Test verifies that inactive components are not modified")
26157 {
26158         /* Nothing to be done here */
26159 }
26160
26161 /** Execute drawArrays for single vertex
26162  *
26163  * @param test_case_index
26164  *
26165  * @return true
26166  **/
26167 bool XFBCaptureInactiveOutputComponentTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26168 {
26169         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26170         GLenum                   primitive_type = GL_PATCHES;
26171
26172         if (TEST_VS == test_case_index)
26173         {
26174                 primitive_type = GL_POINTS;
26175         }
26176
26177         gl.disable(GL_RASTERIZER_DISCARD);
26178         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26179
26180         gl.beginTransformFeedback(GL_POINTS);
26181         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26182
26183         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26184         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26185
26186         gl.endTransformFeedback();
26187         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26188
26189         return true;
26190 }
26191
26192 /** Get descriptors of buffers necessary for test
26193  *
26194  * @param ignored
26195  * @param out_descriptors Descriptors of buffers used by test
26196  **/
26197 void XFBCaptureInactiveOutputComponentTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26198                                                                                                                                  bufferDescriptor::Vector& out_descriptors)
26199 {
26200         const Utils::Type& type = Utils::Type::vec4;
26201
26202         /* Test needs single uniform and xfb */
26203         out_descriptors.resize(2);
26204
26205         /* Get references */
26206         bufferDescriptor& uniform = out_descriptors[0];
26207         bufferDescriptor& xfb    = out_descriptors[1];
26208
26209         /* Index */
26210         uniform.m_index = 0;
26211         xfb.m_index             = 0;
26212
26213         /* Target */
26214         uniform.m_target = Utils::Buffer::Uniform;
26215         xfb.m_target     = Utils::Buffer::Transform_feedback;
26216
26217         /* Data */
26218         const std::vector<GLubyte>& goku_data   = type.GenerateData();
26219         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26220         const std::vector<GLubyte>& goten_data  = type.GenerateData();
26221         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26222         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
26223         const std::vector<GLubyte>& trunks_data = type.GenerateData();
26224         const std::vector<GLubyte>& bra_data    = type.GenerateData();
26225         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
26226
26227         const GLuint comp_size = Utils::Type::GetTypeSize(type.m_basic_type);
26228         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26229
26230         /* Uniform data */
26231         uniform.m_initial_data.resize(8 * type_size);
26232         memcpy(&uniform.m_initial_data[0] + 0 * type_size, &goku_data[0], type_size);
26233         memcpy(&uniform.m_initial_data[0] + 1 * type_size, &gohan_data[0], type_size);
26234         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
26235         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &chichi_data[0], type_size);
26236         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
26237         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &trunks_data[0], type_size);
26238         memcpy(&uniform.m_initial_data[0] + 6 * type_size, &bra_data[0], type_size);
26239         memcpy(&uniform.m_initial_data[0] + 7 * type_size, &bulma_data[0], type_size);
26240
26241         /* XFB data */
26242         xfb.m_initial_data.resize(8 * type_size);
26243         xfb.m_expected_data.resize(8 * type_size);
26244
26245         for (GLuint i = 0; i < 8 * type_size; ++i)
26246         {
26247                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26248                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26249         }
26250
26251         /* goku - x, z - 32 */
26252         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 0 * comp_size, &goku_data[0] + 0 * comp_size, comp_size);
26253         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 2 * comp_size, &goku_data[0] + 2 * comp_size, comp_size);
26254
26255         /* gohan - y, w - 0 */
26256         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 1 * comp_size, &gohan_data[0] + 1 * comp_size, comp_size);
26257         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 3 * comp_size, &gohan_data[0] + 3 * comp_size, comp_size);
26258
26259         /* goten - x, y - 16 */
26260         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 0 * comp_size, &goten_data[0] + 0 * comp_size, comp_size);
26261         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 1 * comp_size, &goten_data[0] + 1 * comp_size, comp_size);
26262
26263         /* chichi - z, w - 48 */
26264         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 2 * comp_size, &chichi_data[0] + 2 * comp_size, comp_size);
26265         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 3 * comp_size, &chichi_data[0] + 3 * comp_size, comp_size);
26266
26267         /* vegeta - x - 112 */
26268         memcpy(&xfb.m_expected_data[0] + 7 * type_size + 0 * comp_size, &vegeta_data[0] + 0 * comp_size, comp_size);
26269
26270         /* trunks - y - 96 */
26271         memcpy(&xfb.m_expected_data[0] + 6 * type_size + 1 * comp_size, &trunks_data[0] + 1 * comp_size, comp_size);
26272
26273         /* bra - z - 80 */
26274         memcpy(&xfb.m_expected_data[0] + 5 * type_size + 2 * comp_size, &bra_data[0] + 2 * comp_size, comp_size);
26275
26276         /* bulma - w - 64 */
26277         memcpy(&xfb.m_expected_data[0] + 4 * type_size + 3 * comp_size, &bulma_data[0] + 3 * comp_size, comp_size);
26278 }
26279
26280 /** Get body of main function for given shader stage
26281  *
26282  * @param test_case_index  Index of test case
26283  * @param stage            Shader stage
26284  * @param out_assignments  Set to empty
26285  * @param out_calculations Set to empty
26286  **/
26287 void XFBCaptureInactiveOutputComponentTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26288                                                                                                                   std::string& out_assignments, std::string& out_calculations)
26289 {
26290         out_calculations = "";
26291
26292         static const GLchar* vs_tes_gs = "    goku.x    = uni_goku.x   ;\n"
26293                                                                          "    goku.z    = uni_goku.z   ;\n"
26294                                                                          "    gohan.y   = uni_gohan.y  ;\n"
26295                                                                          "    gohan.w   = uni_gohan.w  ;\n"
26296                                                                          "    goten.x   = uni_goten.x  ;\n"
26297                                                                          "    goten.y   = uni_goten.y  ;\n"
26298                                                                          "    chichi.z  = uni_chichi.z ;\n"
26299                                                                          "    chichi.w  = uni_chichi.w ;\n"
26300                                                                          "    vegeta.x  = uni_vegeta.x ;\n"
26301                                                                          "    trunks.y  = uni_trunks.y ;\n"
26302                                                                          "    bra.z     = uni_bra.z    ;\n"
26303                                                                          "    bulma.w   = uni_bulma.w  ;\n";
26304         static const GLchar* fs = "    fs_out = goku + gohan + goten + chichi + vegeta + trunks + bra + bulma;\n";
26305
26306         const GLchar* assignments = "";
26307
26308         switch (stage)
26309         {
26310         case Utils::Shader::FRAGMENT:
26311                 assignments = fs;
26312                 break;
26313
26314         case Utils::Shader::GEOMETRY:
26315                 if (TEST_GS == test_case_index)
26316                 {
26317                         assignments = vs_tes_gs;
26318                 }
26319                 break;
26320
26321         case Utils::Shader::TESS_CTRL:
26322                 break;
26323
26324         case Utils::Shader::TESS_EVAL:
26325                 if (TEST_TES == test_case_index)
26326                 {
26327                         assignments = vs_tes_gs;
26328                 }
26329                 break;
26330
26331         case Utils::Shader::VERTEX:
26332                 if (TEST_VS == test_case_index)
26333                 {
26334                         assignments = vs_tes_gs;
26335                 }
26336                 break;
26337
26338         default:
26339                 TCU_FAIL("Invalid enum");
26340         }
26341
26342         out_assignments = assignments;
26343 }
26344
26345 /** Get interface of shader
26346  *
26347  * @param test_case_index  Index of test case
26348  * @param stage            Shader stage
26349  * @param out_interface    Set to ""
26350  **/
26351 void XFBCaptureInactiveOutputComponentTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26352                                                                                                                            std::string& out_interface)
26353 {
26354         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26355                                                                          "\n"
26356                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 goku;\n"
26357                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 gohan;\n"
26358                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goten;\n"
26359                                                                          "layout (xfb_offset = 3 * sizeof_type) out vec4 chichi;\n"
26360                                                                          "layout (xfb_offset = 7 * sizeof_type) out vec4 vegeta;\n"
26361                                                                          "layout (xfb_offset = 6 * sizeof_type) out vec4 trunks;\n"
26362                                                                          "layout (xfb_offset = 5 * sizeof_type) out vec4 bra;\n"
26363                                                                          "layout (xfb_offset = 4 * sizeof_type) out vec4 bulma;\n"
26364                                                                          "\n"
26365                                                                          "layout(binding = 0) uniform block {\n"
26366                                                                          "    vec4 uni_goku;\n"
26367                                                                          "    vec4 uni_gohan;\n"
26368                                                                          "    vec4 uni_goten;\n"
26369                                                                          "    vec4 uni_chichi;\n"
26370                                                                          "    vec4 uni_vegeta;\n"
26371                                                                          "    vec4 uni_trunks;\n"
26372                                                                          "    vec4 uni_bra;\n"
26373                                                                          "    vec4 uni_bulma;\n"
26374                                                                          "};\n";
26375         static const GLchar* fs = "in vec4 vegeta;\n"
26376                                                           "in vec4 trunks;\n"
26377                                                           "in vec4 bra;\n"
26378                                                           "in vec4 bulma;\n"
26379                                                           "in vec4 goku;\n"
26380                                                           "in vec4 gohan;\n"
26381                                                           "in vec4 goten;\n"
26382                                                           "in vec4 chichi;\n"
26383                                                           "\n"
26384                                                           "out vec4 fs_out;\n";
26385
26386         const GLchar* interface = "";
26387
26388         switch (stage)
26389         {
26390         case Utils::Shader::FRAGMENT:
26391                 interface = fs;
26392                 break;
26393
26394         case Utils::Shader::GEOMETRY:
26395                 if (TEST_GS == test_case_index)
26396                 {
26397                         interface = vs_tes_gs;
26398                 }
26399                 break;
26400
26401         case Utils::Shader::TESS_CTRL:
26402                 break;
26403
26404         case Utils::Shader::TESS_EVAL:
26405                 if (TEST_TES == test_case_index)
26406                 {
26407                         interface = vs_tes_gs;
26408                 }
26409                 break;
26410
26411         case Utils::Shader::VERTEX:
26412                 if (TEST_VS == test_case_index)
26413                 {
26414                         interface = vs_tes_gs;
26415                 }
26416                 break;
26417
26418         default:
26419                 TCU_FAIL("Invalid enum");
26420         }
26421
26422         out_interface = interface;
26423 }
26424
26425 /** Get source code of shader
26426  *
26427  * @param test_case_index Index of test case
26428  * @param stage           Shader stage
26429  *
26430  * @return Source
26431  **/
26432 std::string XFBCaptureInactiveOutputComponentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26433 {
26434         std::string source;
26435
26436         switch (test_case_index)
26437         {
26438         case TEST_VS:
26439                 switch (stage)
26440                 {
26441                 case Utils::Shader::FRAGMENT:
26442                 case Utils::Shader::VERTEX:
26443                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26444                         break;
26445                 default:
26446                         break;
26447                 }
26448                 break;
26449
26450         case TEST_TES:
26451                 switch (stage)
26452                 {
26453                 case Utils::Shader::FRAGMENT:
26454                 case Utils::Shader::TESS_CTRL:
26455                 case Utils::Shader::TESS_EVAL:
26456                 case Utils::Shader::VERTEX:
26457                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26458                         break;
26459                 default:
26460                         break;
26461                 }
26462                 break;
26463
26464         case TEST_GS:
26465                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26466                 break;
26467
26468         default:
26469                 TCU_FAIL("Invalid enum");
26470                 break;
26471         }
26472
26473         /* */
26474         return source;
26475 }
26476
26477 /** Get name of test case
26478  *
26479  * @param test_case_index Index of test case
26480  *
26481  * @return Name of tested stage
26482  **/
26483 std::string XFBCaptureInactiveOutputComponentTest::getTestCaseName(glw::GLuint test_case_index)
26484 {
26485         const GLchar* name = 0;
26486
26487         switch (test_case_index)
26488         {
26489         case TEST_VS:
26490                 name = "vertex";
26491                 break;
26492         case TEST_TES:
26493                 name = "tessellation evaluation";
26494                 break;
26495         case TEST_GS:
26496                 name = "geometry";
26497                 break;
26498         default:
26499                 TCU_FAIL("Invalid enum");
26500         }
26501
26502         return name;
26503 }
26504
26505 /** Returns number of test cases
26506  *
26507  * @return TEST_MAX
26508  **/
26509 glw::GLuint XFBCaptureInactiveOutputComponentTest::getTestCaseNumber()
26510 {
26511         return TEST_MAX;
26512 }
26513
26514 /** Verify contents of buffers
26515  *
26516  * @param buffers Collection of buffers to be verified
26517  *
26518  * @return true if everything is as expected, false otherwise
26519  **/
26520 bool XFBCaptureInactiveOutputComponentTest::verifyBuffers(bufferCollection& buffers)
26521 {
26522         bool result = true;
26523
26524         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26525         Utils::Buffer*                  buffer   = pair.m_buffer;
26526         bufferDescriptor*               descriptor = pair.m_descriptor;
26527
26528         /* Get pointer to contents of buffer */
26529         buffer->Bind();
26530         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26531
26532         /* Get pointer to expected data */
26533         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26534
26535         /* Compare */
26536         static const GLuint comp_size = 4;
26537         static const GLuint vec4_size = 16;
26538
26539         int res_goku_x =
26540                 memcmp(buffer_data + 2 * vec4_size + 0 * comp_size, expected_data + 2 * vec4_size + 0 * comp_size, comp_size);
26541         int res_goku_z =
26542                 memcmp(buffer_data + 2 * vec4_size + 2 * comp_size, expected_data + 2 * vec4_size + 2 * comp_size, comp_size);
26543
26544         int res_gohan_y =
26545                 memcmp(buffer_data + 0 * vec4_size + 1 * comp_size, expected_data + 0 * vec4_size + 1 * comp_size, comp_size);
26546         int res_gohan_w =
26547                 memcmp(buffer_data + 0 * vec4_size + 3 * comp_size, expected_data + 0 * vec4_size + 3 * comp_size, comp_size);
26548
26549         int res_goten_x =
26550                 memcmp(buffer_data + 1 * vec4_size + 0 * comp_size, expected_data + 1 * vec4_size + 0 * comp_size, comp_size);
26551         int res_goten_y =
26552                 memcmp(buffer_data + 1 * vec4_size + 1 * comp_size, expected_data + 1 * vec4_size + 1 * comp_size, comp_size);
26553
26554         int res_chichi_z =
26555                 memcmp(buffer_data + 3 * vec4_size + 2 * comp_size, expected_data + 3 * vec4_size + 2 * comp_size, comp_size);
26556         int res_chichi_w =
26557                 memcmp(buffer_data + 3 * vec4_size + 3 * comp_size, expected_data + 3 * vec4_size + 3 * comp_size, comp_size);
26558
26559         int res_vegeta_x =
26560                 memcmp(buffer_data + 7 * vec4_size + 0 * comp_size, expected_data + 7 * vec4_size + 0 * comp_size, comp_size);
26561
26562         int res_trunks_y =
26563                 memcmp(buffer_data + 6 * vec4_size + 1 * comp_size, expected_data + 6 * vec4_size + 1 * comp_size, comp_size);
26564
26565         int res_bra_z =
26566                 memcmp(buffer_data + 5 * vec4_size + 2 * comp_size, expected_data + 5 * vec4_size + 2 * comp_size, comp_size);
26567
26568         int res_bulma_w =
26569                 memcmp(buffer_data + 4 * vec4_size + 3 * comp_size, expected_data + 4 * vec4_size + 3 * comp_size, comp_size);
26570
26571         if ((0 != res_goku_x) || (0 != res_goku_z) || (0 != res_gohan_y) || (0 != res_gohan_w) || (0 != res_goten_x) ||
26572                 (0 != res_goten_y) || (0 != res_chichi_z) || (0 != res_chichi_w) || (0 != res_vegeta_x) ||
26573                 (0 != res_trunks_y) || (0 != res_bra_z) || (0 != res_bulma_w))
26574         {
26575                 m_context.getTestContext().getLog()
26576                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26577                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26578
26579                 result = false;
26580         }
26581
26582         /* Release buffer mapping */
26583         buffer->UnMap();
26584
26585         return result;
26586 }
26587
26588 /** Constructor
26589  *
26590  * @param context Test context
26591  **/
26592 XFBCaptureInactiveOutputBlockMemberTest::XFBCaptureInactiveOutputBlockMemberTest(deqp::Context& context)
26593         : BufferTestBase(context, "xfb_capture_inactive_output_block_member",
26594                                          "Test verifies that inactive block members are captured")
26595 {
26596         /* Nothing to be done here */
26597 }
26598
26599 /** Execute drawArrays for single vertex
26600  *
26601  * @param test_case_index
26602  *
26603  * @return true
26604  **/
26605 bool XFBCaptureInactiveOutputBlockMemberTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26606 {
26607         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26608         GLenum                   primitive_type = GL_PATCHES;
26609
26610         if (TEST_VS == test_case_index)
26611         {
26612                 primitive_type = GL_POINTS;
26613         }
26614
26615         gl.disable(GL_RASTERIZER_DISCARD);
26616         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26617
26618         gl.beginTransformFeedback(GL_POINTS);
26619         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26620
26621         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26622         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26623
26624         gl.endTransformFeedback();
26625         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26626
26627         return true;
26628 }
26629
26630 /** Get descriptors of buffers necessary for test
26631  *
26632  * @param ignored
26633  * @param out_descriptors Descriptors of buffers used by test
26634  **/
26635 void XFBCaptureInactiveOutputBlockMemberTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26636                                                                                                                                    bufferDescriptor::Vector& out_descriptors)
26637 {
26638         const Utils::Type& type = Utils::Type::vec4;
26639
26640         /* Test needs single uniform and xfb */
26641         out_descriptors.resize(2);
26642
26643         /* Get references */
26644         bufferDescriptor& uniform = out_descriptors[0];
26645         bufferDescriptor& xfb    = out_descriptors[1];
26646
26647         /* Index */
26648         uniform.m_index = 0;
26649         xfb.m_index             = 0;
26650
26651         /* Target */
26652         uniform.m_target = Utils::Buffer::Uniform;
26653         xfb.m_target     = Utils::Buffer::Transform_feedback;
26654
26655         /* Data */
26656         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26657         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26658
26659         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26660
26661         /* Uniform data */
26662         uniform.m_initial_data.resize(2 * type_size);
26663         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26664         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26665
26666         /* XFB data */
26667         xfb.m_initial_data.resize(4 * type_size);
26668         xfb.m_expected_data.resize(4 * type_size);
26669
26670         for (GLuint i = 0; i < 4 * type_size; ++i)
26671         {
26672                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26673                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26674         }
26675
26676         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26677         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26678 }
26679
26680 /** Get body of main function for given shader stage
26681  *
26682  * @param test_case_index  Index of test case
26683  * @param stage            Shader stage
26684  * @param out_assignments  Set to empty
26685  * @param out_calculations Set to empty
26686  **/
26687 void XFBCaptureInactiveOutputBlockMemberTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26688                                                                                                                         std::string& out_assignments, std::string& out_calculations)
26689 {
26690         out_calculations = "";
26691
26692         static const GLchar* vs_tes_gs = "    chichi = uni_chichi;\n"
26693                                                                          "    gohan  = uni_gohan;\n";
26694         static const GLchar* fs = "    fs_out = goten + gohan + chichi;\n";
26695
26696         const GLchar* assignments = "";
26697
26698         switch (stage)
26699         {
26700         case Utils::Shader::FRAGMENT:
26701                 assignments = fs;
26702                 break;
26703
26704         case Utils::Shader::GEOMETRY:
26705                 if (TEST_GS == test_case_index)
26706                 {
26707                         assignments = vs_tes_gs;
26708                 }
26709                 break;
26710
26711         case Utils::Shader::TESS_CTRL:
26712                 break;
26713
26714         case Utils::Shader::TESS_EVAL:
26715                 if (TEST_TES == test_case_index)
26716                 {
26717                         assignments = vs_tes_gs;
26718                 }
26719                 break;
26720
26721         case Utils::Shader::VERTEX:
26722                 if (TEST_VS == test_case_index)
26723                 {
26724                         assignments = vs_tes_gs;
26725                 }
26726                 break;
26727
26728         default:
26729                 TCU_FAIL("Invalid enum");
26730         }
26731
26732         out_assignments = assignments;
26733 }
26734
26735 /** Get interface of shader
26736  *
26737  * @param test_case_index  Index of test case
26738  * @param stage            Shader stage
26739  * @param out_interface    Set to ""
26740  **/
26741 void XFBCaptureInactiveOutputBlockMemberTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26742                                                                                                                                  std::string& out_interface)
26743 {
26744         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26745                                                                          "\n"
26746                                                                          "layout (xfb_offset = 1 * sizeof_type) out Goku {\n"
26747                                                                          "    vec4 gohan;\n"
26748                                                                          "    vec4 goten;\n"
26749                                                                          "    vec4 chichi;\n"
26750                                                                          "};\n"
26751                                                                          "\n"
26752                                                                          "layout(binding = 0) uniform block {\n"
26753                                                                          "    vec4 uni_gohan;\n"
26754                                                                          "    vec4 uni_chichi;\n"
26755                                                                          "};\n";
26756         static const GLchar* fs = "in Goku {\n"
26757                                                           "    vec4 gohan;\n"
26758                                                           "    vec4 goten;\n"
26759                                                           "    vec4 chichi;\n"
26760                                                           "};\n"
26761                                                           "out vec4 fs_out;\n";
26762
26763         const GLchar* interface = "";
26764
26765         switch (stage)
26766         {
26767         case Utils::Shader::FRAGMENT:
26768                 interface = fs;
26769                 break;
26770
26771         case Utils::Shader::GEOMETRY:
26772                 if (TEST_GS == test_case_index)
26773                 {
26774                         interface = vs_tes_gs;
26775                 }
26776                 break;
26777
26778         case Utils::Shader::TESS_CTRL:
26779                 break;
26780
26781         case Utils::Shader::TESS_EVAL:
26782                 if (TEST_TES == test_case_index)
26783                 {
26784                         interface = vs_tes_gs;
26785                 }
26786                 break;
26787
26788         case Utils::Shader::VERTEX:
26789                 if (TEST_VS == test_case_index)
26790                 {
26791                         interface = vs_tes_gs;
26792                 }
26793                 break;
26794
26795         default:
26796                 TCU_FAIL("Invalid enum");
26797         }
26798
26799         out_interface = interface;
26800 }
26801
26802 /** Get source code of shader
26803  *
26804  * @param test_case_index Index of test case
26805  * @param stage           Shader stage
26806  *
26807  * @return Source
26808  **/
26809 std::string XFBCaptureInactiveOutputBlockMemberTest::getShaderSource(GLuint                                test_case_index,
26810                                                                                                                                          Utils::Shader::STAGES stage)
26811 {
26812         std::string source;
26813
26814         switch (test_case_index)
26815         {
26816         case TEST_VS:
26817                 switch (stage)
26818                 {
26819                 case Utils::Shader::FRAGMENT:
26820                 case Utils::Shader::VERTEX:
26821                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26822                         break;
26823                 default:
26824                         break;
26825                 }
26826                 break;
26827
26828         case TEST_TES:
26829                 switch (stage)
26830                 {
26831                 case Utils::Shader::FRAGMENT:
26832                 case Utils::Shader::TESS_CTRL:
26833                 case Utils::Shader::TESS_EVAL:
26834                 case Utils::Shader::VERTEX:
26835                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26836                         break;
26837                 default:
26838                         break;
26839                 }
26840                 break;
26841
26842         case TEST_GS:
26843                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26844                 break;
26845
26846         default:
26847                 TCU_FAIL("Invalid enum");
26848                 break;
26849         }
26850
26851         /* */
26852         return source;
26853 }
26854
26855 /** Get name of test case
26856  *
26857  * @param test_case_index Index of test case
26858  *
26859  * @return Name of tested stage
26860  **/
26861 std::string XFBCaptureInactiveOutputBlockMemberTest::getTestCaseName(glw::GLuint test_case_index)
26862 {
26863         const GLchar* name = 0;
26864
26865         switch (test_case_index)
26866         {
26867         case TEST_VS:
26868                 name = "vertex";
26869                 break;
26870         case TEST_TES:
26871                 name = "tessellation evaluation";
26872                 break;
26873         case TEST_GS:
26874                 name = "geometry";
26875                 break;
26876         default:
26877                 TCU_FAIL("Invalid enum");
26878         }
26879
26880         return name;
26881 }
26882
26883 /** Returns number of test cases
26884  *
26885  * @return TEST_MAX
26886  **/
26887 glw::GLuint XFBCaptureInactiveOutputBlockMemberTest::getTestCaseNumber()
26888 {
26889         return TEST_MAX;
26890 }
26891
26892 /** Verify contents of buffers
26893  *
26894  * @param buffers Collection of buffers to be verified
26895  *
26896  * @return true if everything is as expected, false otherwise
26897  **/
26898 bool XFBCaptureInactiveOutputBlockMemberTest::verifyBuffers(bufferCollection& buffers)
26899 {
26900         bool result = true;
26901
26902         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26903         Utils::Buffer*                  buffer   = pair.m_buffer;
26904         bufferDescriptor*               descriptor = pair.m_descriptor;
26905
26906         /* Get pointer to contents of buffer */
26907         buffer->Bind();
26908         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26909
26910         /* Get pointer to expected data */
26911         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26912
26913         /* Compare */
26914         static const GLuint vec4_size = 16;
26915
26916         int res_before = memcmp(buffer_data, expected_data, vec4_size);
26917         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
26918         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
26919
26920         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
26921         {
26922                 m_context.getTestContext().getLog()
26923                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26924                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26925
26926                 result = false;
26927         }
26928
26929         /* Release buffer mapping */
26930         buffer->UnMap();
26931
26932         return result;
26933 }
26934
26935 /** Constructor
26936  *
26937  * @param context Test context
26938  **/
26939 XFBCaptureStructTest::XFBCaptureStructTest(deqp::Context& context)
26940         : BufferTestBase(context, "xfb_capture_struct", "Test verifies that inactive structure members are captured")
26941 {
26942         /* Nothing to be done here */
26943 }
26944
26945 /** Execute drawArrays for single vertex
26946  *
26947  * @param test_case_index
26948  *
26949  * @return true
26950  **/
26951 bool XFBCaptureStructTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26952 {
26953         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26954         GLenum                   primitive_type = GL_PATCHES;
26955
26956         if (TEST_VS == test_case_index)
26957         {
26958                 primitive_type = GL_POINTS;
26959         }
26960
26961         gl.disable(GL_RASTERIZER_DISCARD);
26962         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26963
26964         gl.beginTransformFeedback(GL_POINTS);
26965         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26966
26967         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26968         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26969
26970         gl.endTransformFeedback();
26971         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26972
26973         return true;
26974 }
26975
26976 /** Get descriptors of buffers necessary for test
26977  *
26978  * @param ignored
26979  * @param out_descriptors Descriptors of buffers used by test
26980  **/
26981 void XFBCaptureStructTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26982                                                                                                 bufferDescriptor::Vector& out_descriptors)
26983 {
26984         const Utils::Type& type = Utils::Type::vec4;
26985
26986         /* Test needs single uniform and xfb */
26987         out_descriptors.resize(2);
26988
26989         /* Get references */
26990         bufferDescriptor& uniform = out_descriptors[0];
26991         bufferDescriptor& xfb    = out_descriptors[1];
26992
26993         /* Index */
26994         uniform.m_index = 0;
26995         xfb.m_index             = 0;
26996
26997         /* Target */
26998         uniform.m_target = Utils::Buffer::Uniform;
26999         xfb.m_target     = Utils::Buffer::Transform_feedback;
27000
27001         /* Data */
27002         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
27003         const std::vector<GLubyte>& chichi_data = type.GenerateData();
27004
27005         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
27006
27007         /* Uniform data */
27008         uniform.m_initial_data.resize(2 * type_size);
27009         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
27010         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
27011
27012         /* XFB data */
27013         xfb.m_initial_data.resize(4 * type_size);
27014         xfb.m_expected_data.resize(4 * type_size);
27015
27016         for (GLuint i = 0; i < 4 * type_size; ++i)
27017         {
27018                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
27019                 xfb.m_expected_data[i] = (glw::GLubyte)i;
27020         }
27021
27022         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
27023         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
27024 }
27025
27026 /** Get body of main function for given shader stage
27027  *
27028  * @param test_case_index  Index of test case
27029  * @param stage            Shader stage
27030  * @param out_assignments  Set to empty
27031  * @param out_calculations Set to empty
27032  **/
27033 void XFBCaptureStructTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
27034                                                                                  std::string& out_assignments, std::string& out_calculations)
27035 {
27036         out_calculations = "";
27037
27038         static const GLchar* vs_tes_gs = "    goku.chichi = uni_chichi;\n"
27039                                                                          "    goku.gohan  = uni_gohan;\n";
27040         static const GLchar* fs = "    fs_out = goku.goten + goku.gohan + goku.chichi;\n";
27041
27042         const GLchar* assignments = "";
27043
27044         switch (stage)
27045         {
27046         case Utils::Shader::FRAGMENT:
27047                 assignments = fs;
27048                 break;
27049
27050         case Utils::Shader::GEOMETRY:
27051                 if (TEST_GS == test_case_index)
27052                 {
27053                         assignments = vs_tes_gs;
27054                 }
27055                 break;
27056
27057         case Utils::Shader::TESS_CTRL:
27058                 break;
27059
27060         case Utils::Shader::TESS_EVAL:
27061                 if (TEST_TES == test_case_index)
27062                 {
27063                         assignments = vs_tes_gs;
27064                 }
27065                 break;
27066
27067         case Utils::Shader::VERTEX:
27068                 if (TEST_VS == test_case_index)
27069                 {
27070                         assignments = vs_tes_gs;
27071                 }
27072                 break;
27073
27074         default:
27075                 TCU_FAIL("Invalid enum");
27076         }
27077
27078         out_assignments = assignments;
27079 }
27080
27081 /** Get interface of shader
27082  *
27083  * @param test_case_index  Index of test case
27084  * @param stage            Shader stage
27085  * @param out_interface    Set to ""
27086  **/
27087 void XFBCaptureStructTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
27088                                                                                           std::string& out_interface)
27089 {
27090         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
27091                                                                          "\n"
27092                                                                          "struct Goku {\n"
27093                                                                          "    vec4 gohan;\n"
27094                                                                          "    vec4 goten;\n"
27095                                                                          "    vec4 chichi;\n"
27096                                                                          "};\n"
27097                                                                          "\n"
27098                                                                          "layout (xfb_offset = sizeof_type) out Goku goku;\n"
27099                                                                          "\n"
27100                                                                          "layout(binding = 0, std140) uniform block {\n"
27101                                                                          "    vec4 uni_gohan;\n"
27102                                                                          "    vec4 uni_chichi;\n"
27103                                                                          "};\n";
27104         static const GLchar* fs = "struct Goku {\n"
27105                                                           "    vec4 gohan;\n"
27106                                                           "    vec4 goten;\n"
27107                                                           "    vec4 chichi;\n"
27108                                                           "};\n"
27109                                                           "\n"
27110                                                           "in Goku goku;\n"
27111                                                           "\n"
27112                                                           "out vec4 fs_out;\n";
27113
27114         const GLchar* interface = "";
27115
27116         switch (stage)
27117         {
27118         case Utils::Shader::FRAGMENT:
27119                 interface = fs;
27120                 break;
27121
27122         case Utils::Shader::GEOMETRY:
27123                 if (TEST_GS == test_case_index)
27124                 {
27125                         interface = vs_tes_gs;
27126                 }
27127                 break;
27128
27129         case Utils::Shader::TESS_CTRL:
27130                 break;
27131
27132         case Utils::Shader::TESS_EVAL:
27133                 if (TEST_TES == test_case_index)
27134                 {
27135                         interface = vs_tes_gs;
27136                 }
27137                 break;
27138
27139         case Utils::Shader::VERTEX:
27140                 if (TEST_VS == test_case_index)
27141                 {
27142                         interface = vs_tes_gs;
27143                 }
27144                 break;
27145
27146         default:
27147                 TCU_FAIL("Invalid enum");
27148         }
27149
27150         out_interface = interface;
27151 }
27152
27153 /** Get source code of shader
27154  *
27155  * @param test_case_index Index of test case
27156  * @param stage           Shader stage
27157  *
27158  * @return Source
27159  **/
27160 std::string XFBCaptureStructTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27161 {
27162         std::string source;
27163
27164         switch (test_case_index)
27165         {
27166         case TEST_VS:
27167                 switch (stage)
27168                 {
27169                 case Utils::Shader::FRAGMENT:
27170                 case Utils::Shader::VERTEX:
27171                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27172                         break;
27173                 default:
27174                         break;
27175                 }
27176                 break;
27177
27178         case TEST_TES:
27179                 switch (stage)
27180                 {
27181                 case Utils::Shader::FRAGMENT:
27182                 case Utils::Shader::TESS_CTRL:
27183                 case Utils::Shader::TESS_EVAL:
27184                 case Utils::Shader::VERTEX:
27185                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27186                         break;
27187                 default:
27188                         break;
27189                 }
27190                 break;
27191
27192         case TEST_GS:
27193                 source = BufferTestBase::getShaderSource(test_case_index, stage);
27194                 break;
27195
27196         default:
27197                 TCU_FAIL("Invalid enum");
27198                 break;
27199         }
27200
27201         /* */
27202         return source;
27203 }
27204
27205 /** Get name of test case
27206  *
27207  * @param test_case_index Index of test case
27208  *
27209  * @return Name of tested stage
27210  **/
27211 std::string XFBCaptureStructTest::getTestCaseName(glw::GLuint test_case_index)
27212 {
27213         const GLchar* name = 0;
27214
27215         switch (test_case_index)
27216         {
27217         case TEST_VS:
27218                 name = "vertex";
27219                 break;
27220         case TEST_TES:
27221                 name = "tessellation evaluation";
27222                 break;
27223         case TEST_GS:
27224                 name = "geometry";
27225                 break;
27226         default:
27227                 TCU_FAIL("Invalid enum");
27228         }
27229
27230         return name;
27231 }
27232
27233 /** Returns number of test cases
27234  *
27235  * @return TEST_MAX
27236  **/
27237 glw::GLuint XFBCaptureStructTest::getTestCaseNumber()
27238 {
27239         return TEST_MAX;
27240 }
27241
27242 /** Verify contents of buffers
27243  *
27244  * @param buffers Collection of buffers to be verified
27245  *
27246  * @return true if everything is as expected, false otherwise
27247  **/
27248 bool XFBCaptureStructTest::verifyBuffers(bufferCollection& buffers)
27249 {
27250         bool result = true;
27251
27252         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
27253         Utils::Buffer*                  buffer   = pair.m_buffer;
27254         bufferDescriptor*               descriptor = pair.m_descriptor;
27255
27256         /* Get pointer to contents of buffer */
27257         buffer->Bind();
27258         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
27259
27260         /* Get pointer to expected data */
27261         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
27262
27263         /* Compare */
27264         static const GLuint vec4_size = 16;
27265
27266         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27267         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27268         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27269
27270         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27271         {
27272                 m_context.getTestContext().getLog()
27273                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27274                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27275
27276                 result = false;
27277         }
27278
27279         /* Release buffer mapping */
27280         buffer->UnMap();
27281
27282         return result;
27283 }
27284
27285 /** Constructor
27286  *
27287  * @param context Test framework context
27288  **/
27289 XFBCaptureUnsizedArrayTest::XFBCaptureUnsizedArrayTest(deqp::Context& context)
27290         : NegativeTestBase(context, "xfb_capture_unsized_array",
27291                                            "Test verifies that compiler reports error when unsized array is qualified with xfb_offset")
27292 {
27293 }
27294
27295 /** Source for given test case and stage
27296  *
27297  * @param test_case_index Index of test case
27298  * @param stage           Shader stage
27299  *
27300  * @return Shader source
27301  **/
27302 std::string XFBCaptureUnsizedArrayTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27303 {
27304         static const GLchar* var_definition = "layout (xfb_offset = 0) out vec4 gokuARRAY[];\n";
27305         static const GLchar* var_use            = "    gokuINDEX[0] = result / 2;\n";
27306         static const GLchar* fs                         = "#version 430 core\n"
27307                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27308                                                           "\n"
27309                                                           "in  vec4 gs_fs;\n"
27310                                                           "out vec4 fs_out;\n"
27311                                                           "\n"
27312                                                           "void main()\n"
27313                                                           "{\n"
27314                                                           "    fs_out = gs_fs;\n"
27315                                                           "}\n"
27316                                                           "\n";
27317         static const GLchar* gs_tested = "#version 430 core\n"
27318                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27319                                                                          "\n"
27320                                                                          "layout(points)                           in;\n"
27321                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
27322                                                                          "\n"
27323                                                                          "VAR_DEFINITION"
27324                                                                          "\n"
27325                                                                          "in  vec4 tes_gs[];\n"
27326                                                                          "out vec4 gs_fs;\n"
27327                                                                          "\n"
27328                                                                          "void main()\n"
27329                                                                          "{\n"
27330                                                                          "    vec4 result = tes_gs[0];\n"
27331                                                                          "\n"
27332                                                                          "VARIABLE_USE"
27333                                                                          "\n"
27334                                                                          "    gs_fs = result;\n"
27335                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
27336                                                                          "    EmitVertex();\n"
27337                                                                          "    gs_fs = result;\n"
27338                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
27339                                                                          "    EmitVertex();\n"
27340                                                                          "    gs_fs = result;\n"
27341                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
27342                                                                          "    EmitVertex();\n"
27343                                                                          "    gs_fs = result;\n"
27344                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
27345                                                                          "    EmitVertex();\n"
27346                                                                          "}\n"
27347                                                                          "\n";
27348         static const GLchar* tcs = "#version 430 core\n"
27349                                                            "#extension GL_ARB_enhanced_layouts : require\n"
27350                                                            "\n"
27351                                                            "layout(vertices = 1) out;\n"
27352                                                            "\n"
27353                                                            "in  vec4 vs_tcs[];\n"
27354                                                            "out vec4 tcs_tes[];\n"
27355                                                            "\n"
27356                                                            "void main()\n"
27357                                                            "{\n"
27358                                                            "\n"
27359                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
27360                                                            "\n"
27361                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
27362                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
27363                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
27364                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
27365                                                            "    gl_TessLevelInner[0] = 1.0;\n"
27366                                                            "    gl_TessLevelInner[1] = 1.0;\n"
27367                                                            "}\n"
27368                                                            "\n";
27369         static const GLchar* tcs_tested = "#version 430 core\n"
27370                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27371                                                                           "\n"
27372                                                                           "layout(vertices = 1) out;\n"
27373                                                                           "\n"
27374                                                                           "VAR_DEFINITION"
27375                                                                           "\n"
27376                                                                           "in  vec4 vs_tcs[];\n"
27377                                                                           "out vec4 tcs_tes[];\n"
27378                                                                           "\n"
27379                                                                           "void main()\n"
27380                                                                           "{\n"
27381                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
27382                                                                           "\n"
27383                                                                           "VARIABLE_USE"
27384                                                                           "\n"
27385                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
27386                                                                           "\n"
27387                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
27388                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
27389                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
27390                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
27391                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
27392                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
27393                                                                           "}\n"
27394                                                                           "\n";
27395         static const GLchar* tes_tested = "#version 430 core\n"
27396                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27397                                                                           "\n"
27398                                                                           "layout(isolines, point_mode) in;\n"
27399                                                                           "\n"
27400                                                                           "VAR_DEFINITION"
27401                                                                           "\n"
27402                                                                           "in  vec4 tcs_tes[];\n"
27403                                                                           "out vec4 tes_gs;\n"
27404                                                                           "\n"
27405                                                                           "void main()\n"
27406                                                                           "{\n"
27407                                                                           "    vec4 result = tcs_tes[0];\n"
27408                                                                           "\n"
27409                                                                           "VARIABLE_USE"
27410                                                                           "\n"
27411                                                                           "    tes_gs += result;\n"
27412                                                                           "}\n"
27413                                                                           "\n";
27414         static const GLchar* vs = "#version 430 core\n"
27415                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27416                                                           "\n"
27417                                                           "in  vec4 in_vs;\n"
27418                                                           "out vec4 vs_tcs;\n"
27419                                                           "\n"
27420                                                           "void main()\n"
27421                                                           "{\n"
27422                                                           "    vs_tcs = in_vs;\n"
27423                                                           "}\n"
27424                                                           "\n";
27425         static const GLchar* vs_tested = "#version 430 core\n"
27426                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27427                                                                          "\n"
27428                                                                          "VAR_DEFINITION"
27429                                                                          "\n"
27430                                                                          "in  vec4 in_vs;\n"
27431                                                                          "out vec4 vs_tcs;\n"
27432                                                                          "\n"
27433                                                                          "void main()\n"
27434                                                                          "{\n"
27435                                                                          "    vec4 result = in_vs;\n"
27436                                                                          "\n"
27437                                                                          "VARIABLE_USE"
27438                                                                          "\n"
27439                                                                          "    vs_tcs = result;\n"
27440                                                                          "}\n"
27441                                                                          "\n";
27442
27443         std::string source;
27444         testCase&   test_case = m_test_cases[test_case_index];
27445
27446         if (test_case.m_stage == stage)
27447         {
27448                 const GLchar* array     = "";
27449                 const GLchar* index     = "";
27450                 size_t            position = 0;
27451
27452                 switch (stage)
27453                 {
27454                 case Utils::Shader::GEOMETRY:
27455                         source = gs_tested;
27456                         array  = "[]";
27457                         index  = "[0]";
27458                         break;
27459                 case Utils::Shader::TESS_CTRL:
27460                         source = tcs_tested;
27461                         array  = "[]";
27462                         index  = "[gl_InvocationID]";
27463                         break;
27464                 case Utils::Shader::TESS_EVAL:
27465                         source = tes_tested;
27466                         array  = "[]";
27467                         index  = "[0]";
27468                         break;
27469                 case Utils::Shader::VERTEX:
27470                         source = vs_tested;
27471                         break;
27472                 default:
27473                         TCU_FAIL("Invalid enum");
27474                 }
27475
27476                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
27477                 position = 0;
27478                 Utils::replaceToken("ARRAY", position, array, source);
27479                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
27480
27481                 Utils::replaceAllTokens("INDEX", index, source);
27482         }
27483         else
27484         {
27485                 switch (test_case.m_stage)
27486                 {
27487                 case Utils::Shader::GEOMETRY:
27488                         switch (stage)
27489                         {
27490                         case Utils::Shader::FRAGMENT:
27491                                 source = fs;
27492                                 break;
27493                         case Utils::Shader::VERTEX:
27494                                 source = vs;
27495                                 break;
27496                         default:
27497                                 source = "";
27498                         }
27499                         break;
27500                 case Utils::Shader::TESS_CTRL:
27501                         switch (stage)
27502                         {
27503                         case Utils::Shader::FRAGMENT:
27504                                 source = fs;
27505                                 break;
27506                         case Utils::Shader::VERTEX:
27507                                 source = vs;
27508                                 break;
27509                         default:
27510                                 source = "";
27511                         }
27512                         break;
27513                 case Utils::Shader::TESS_EVAL:
27514                         switch (stage)
27515                         {
27516                         case Utils::Shader::FRAGMENT:
27517                                 source = fs;
27518                                 break;
27519                         case Utils::Shader::TESS_CTRL:
27520                                 source = tcs;
27521                                 break;
27522                         case Utils::Shader::VERTEX:
27523                                 source = vs;
27524                                 break;
27525                         default:
27526                                 source = "";
27527                         }
27528                         break;
27529                 case Utils::Shader::VERTEX:
27530                         switch (stage)
27531                         {
27532                         case Utils::Shader::FRAGMENT:
27533                                 source = fs;
27534                                 break;
27535                         default:
27536                                 source = "";
27537                         }
27538                         break;
27539                 default:
27540                         TCU_FAIL("Invalid enum");
27541                         break;
27542                 }
27543         }
27544
27545         return source;
27546 }
27547
27548 /** Get description of test case
27549  *
27550  * @param test_case_index Index of test case
27551  *
27552  * @return Test case description
27553  **/
27554 std::string XFBCaptureUnsizedArrayTest::getTestCaseName(GLuint test_case_index)
27555 {
27556         std::stringstream stream;
27557         testCase&                 test_case = m_test_cases[test_case_index];
27558
27559         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
27560
27561         return stream.str();
27562 }
27563
27564 /** Get number of test cases
27565  *
27566  * @return Number of test cases
27567  **/
27568 GLuint XFBCaptureUnsizedArrayTest::getTestCaseNumber()
27569 {
27570         return static_cast<GLuint>(m_test_cases.size());
27571 }
27572
27573 /** Selects if "compute" stage is relevant for test
27574  *
27575  * @param ignored
27576  *
27577  * @return false
27578  **/
27579 bool XFBCaptureUnsizedArrayTest::isComputeRelevant(GLuint /* test_case_index */)
27580 {
27581         return false;
27582 }
27583
27584 /** Prepare all test cases
27585  *
27586  **/
27587 void XFBCaptureUnsizedArrayTest::testInit()
27588 {
27589         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
27590         {
27591                 /* Not aplicable for */
27592                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
27593                         (Utils::Shader::GEOMETRY == stage) || (Utils::Shader::TESS_EVAL == stage))
27594                 {
27595                         continue;
27596                 }
27597
27598                 testCase test_case = { (Utils::Shader::STAGES)stage };
27599
27600                 m_test_cases.push_back(test_case);
27601         }
27602 }
27603 } /* EnhancedLayouts namespace */
27604
27605 /** Constructor.
27606  *
27607  *  @param context Rendering context.
27608  **/
27609 EnhancedLayoutsTests::EnhancedLayoutsTests(deqp::Context& context)
27610         : TestCaseGroup(context, "enhanced_layouts", "Verifies \"enhanced layouts\" functionality")
27611 {
27612         /* Left blank on purpose */
27613 }
27614
27615 /** Initializes a texture_storage_multisample test group.
27616  *
27617  **/
27618 void EnhancedLayoutsTests::init(void)
27619 {
27620         addChild(new EnhancedLayouts::APIConstantValuesTest(m_context));
27621         addChild(new EnhancedLayouts::APIErrorsTest(m_context));
27622         addChild(new EnhancedLayouts::GLSLContantValuesTest(m_context));
27623         addChild(new EnhancedLayouts::GLSLContantImmutablityTest(m_context));
27624         addChild(new EnhancedLayouts::GLSLConstantIntegralExpressionTest(m_context));
27625         addChild(new EnhancedLayouts::UniformBlockLayoutQualifierConflictTest(m_context));
27626         addChild(new EnhancedLayouts::SSBMemberInvalidOffsetAlignmentTest(m_context));
27627         addChild(new EnhancedLayouts::SSBMemberOverlappingOffsetsTest(m_context));
27628         addChild(new EnhancedLayouts::VaryingExceedingComponentsTest(m_context));
27629         addChild(new EnhancedLayouts::VaryingComponentOfInvalidTypeTest(m_context));
27630         addChild(new EnhancedLayouts::OutputComponentAliasingTest(m_context));
27631         addChild(new EnhancedLayouts::VertexAttribLocationAPITest(m_context));
27632         addChild(new EnhancedLayouts::XFBInputTest(m_context));
27633         addChild(new EnhancedLayouts::XFBAllStagesTest(m_context));
27634         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputVariableTest(m_context));
27635         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputComponentTest(m_context));
27636         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputBlockMemberTest(m_context));
27637         addChild(new EnhancedLayouts::XFBStrideTest(m_context));
27638
27639         addChild(new EnhancedLayouts::UniformBlockMemberOffsetAndAlignTest(m_context));
27640         addChild(new EnhancedLayouts::UniformBlockMemberInvalidOffsetAlignmentTest(m_context));
27641         addChild(new EnhancedLayouts::UniformBlockMemberOverlappingOffsetsTest(m_context));
27642         addChild(new EnhancedLayouts::UniformBlockMemberAlignNonPowerOf2Test(m_context));
27643         addChild(new EnhancedLayouts::SSBLayoutQualifierConflictTest(m_context));
27644         addChild(new EnhancedLayouts::SSBMemberAlignNonPowerOf2Test(m_context));
27645         addChild(new EnhancedLayouts::SSBAlignmentTest(m_context));
27646         addChild(new EnhancedLayouts::VaryingStructureMemberLocationTest(m_context));
27647         addChild(new EnhancedLayouts::VaryingBlockAutomaticMemberLocationsTest(m_context));
27648         addChild(new EnhancedLayouts::VaryingComponentWithoutLocationTest(m_context));
27649         addChild(new EnhancedLayouts::InputComponentAliasingTest(m_context));
27650         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedTypesTest(m_context));
27651         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedInterpolationTest(m_context));
27652         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(m_context));
27653         addChild(new EnhancedLayouts::XFBStrideOfEmptyListTest(m_context));
27654         addChild(new EnhancedLayouts::XFBStrideOfEmptyListAndAPITest(m_context));
27655         addChild(new EnhancedLayouts::XFBTooSmallStrideTest(m_context));
27656         addChild(new EnhancedLayouts::XFBBlockMemberStrideTest(m_context));
27657         addChild(new EnhancedLayouts::XFBDuplicatedStrideTest(m_context));
27658         addChild(new EnhancedLayouts::XFBGetProgramResourceAPITest(m_context));
27659         addChild(new EnhancedLayouts::XFBMultipleVertexStreamsTest(m_context));
27660         addChild(new EnhancedLayouts::XFBExceedBufferLimitTest(m_context));
27661         addChild(new EnhancedLayouts::XFBExceedOffsetLimitTest(m_context));
27662         addChild(new EnhancedLayouts::XFBBlockMemberBufferTest(m_context));
27663         addChild(new EnhancedLayouts::XFBOutputOverlappingTest(m_context));
27664         addChild(new EnhancedLayouts::XFBInvalidOffsetAlignmentTest(m_context));
27665         addChild(new EnhancedLayouts::XFBCaptureStructTest(m_context));
27666         addChild(new EnhancedLayouts::XFBCaptureUnsizedArrayTest(m_context));
27667         addChild(new EnhancedLayouts::UniformBlockAlignmentTest(m_context));
27668         addChild(new EnhancedLayouts::SSBMemberOffsetAndAlignTest(m_context));
27669         addChild(new EnhancedLayouts::VertexAttribLocationsTest(m_context));
27670         addChild(new EnhancedLayouts::VaryingLocationsTest(m_context));
27671         addChild(new EnhancedLayouts::VaryingArrayLocationsTest(m_context));
27672         addChild(new EnhancedLayouts::VaryingStructureLocationsTest(m_context));
27673         addChild(new EnhancedLayouts::VaryingBlockLocationsTest(m_context));
27674         addChild(new EnhancedLayouts::VaryingBlockMemberLocationsTest(m_context));
27675         addChild(new EnhancedLayouts::XFBVariableStrideTest(m_context));
27676         addChild(new EnhancedLayouts::XFBBlockStrideTest(m_context));
27677         addChild(new EnhancedLayouts::XFBOverrideQualifiersWithAPITest(m_context));
27678         addChild(new EnhancedLayouts::XFBVertexStreamsTest(m_context));
27679         addChild(new EnhancedLayouts::XFBGlobalBufferTest(m_context));
27680         addChild(new EnhancedLayouts::FragmentDataLocationAPITest(m_context));
27681         addChild(new EnhancedLayouts::VaryingLocationLimitTest(m_context));
27682         addChild(new EnhancedLayouts::VaryingComponentsTest(m_context));
27683         addChild(new EnhancedLayouts::VaryingArrayComponentsTest(m_context));
27684 }
27685
27686 } /* gl4cts namespace */