Fix spelling of 'tessellation'
[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. Note that this routine assumes tightly packing
524  *
525  * @return Formula Number of columns * number of rows * sizeof(base_type)
526  **/
527 GLuint Type::GetSize() const
528 {
529         const GLuint basic_type_size = GetTypeSize(m_basic_type);
530         const GLuint n_elements          = m_n_columns * m_n_rows;
531
532         return basic_type_size * n_elements;
533 }
534
535 /** Get GLenum representing the type
536  *
537  * @return GLenum
538  **/
539 GLenum Type::GetTypeGLenum() const
540 {
541         static const GLenum float_lut[4][4] = {
542                 { GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4 },
543                 { 0, GL_FLOAT_MAT2, GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4 },
544                 { 0, GL_FLOAT_MAT3x2, GL_FLOAT_MAT3, GL_FLOAT_MAT3x4 },
545                 { 0, GL_FLOAT_MAT4x2, GL_FLOAT_MAT4x3, GL_FLOAT_MAT4 },
546         };
547
548         static const GLenum double_lut[4][4] = {
549                 { GL_DOUBLE, GL_DOUBLE_VEC2, GL_DOUBLE_VEC3, GL_DOUBLE_VEC4 },
550                 { 0, GL_DOUBLE_MAT2, GL_DOUBLE_MAT2x3, GL_DOUBLE_MAT2x4 },
551                 { 0, GL_DOUBLE_MAT3x2, GL_DOUBLE_MAT3, GL_DOUBLE_MAT3x4 },
552                 { 0, GL_DOUBLE_MAT4x2, GL_DOUBLE_MAT4x3, GL_DOUBLE_MAT4 },
553         };
554
555         static const GLenum int_lut[4] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 };
556
557         static const GLenum uint_lut[4] = { GL_UNSIGNED_INT, GL_UNSIGNED_INT_VEC2, GL_UNSIGNED_INT_VEC3,
558                                                                                 GL_UNSIGNED_INT_VEC4 };
559
560         GLenum result = 0;
561
562         if ((1 > m_n_columns) || (1 > m_n_rows) || (4 < m_n_columns) || (4 < m_n_rows))
563         {
564                 return 0;
565         }
566
567         switch (m_basic_type)
568         {
569         case Float:
570                 result = float_lut[m_n_columns - 1][m_n_rows - 1];
571                 break;
572         case Double:
573                 result = double_lut[m_n_columns - 1][m_n_rows - 1];
574                 break;
575         case Int:
576                 result = int_lut[m_n_rows - 1];
577                 break;
578         case Uint:
579                 result = uint_lut[m_n_rows - 1];
580                 break;
581         default:
582                 TCU_FAIL("Invliad enum");
583         }
584
585         return result;
586 }
587
588 /** Calculate the numbe of components consumed by a type
589  *   according to 11.1.2.1 Output Variables
590  *
591  * @return Calculated number of components for the type
592  **/
593 GLuint Type::GetNumComponents() const
594 {
595         // Rule 3 of Section 7.6.2.2
596         // If the member is a three-component vector with components consuming N
597         // basic machine units, the base alignment is 4N.
598         GLuint num_components = (m_n_rows == 3 ? 4 : m_n_rows) * m_n_columns;
599
600         if (m_basic_type == Double)
601         {
602                 num_components *= 2;
603         }
604
605         return num_components;
606 }
607
608 /** Calculate stride for the type according to std140 rules
609  *
610  * @param alignment        Alignment of type
611  * @param n_columns        Number of columns
612  * @param n_array_elements Number of elements in array
613  *
614  * @return Calculated value
615  **/
616 GLuint Type::CalculateStd140Stride(GLuint alignment, GLuint n_columns, GLuint n_array_elements)
617 {
618         GLuint stride = alignment * n_columns;
619         if (0 != n_array_elements)
620         {
621                 stride *= n_array_elements;
622         }
623
624         return stride;
625 }
626
627 /** Check if glsl support matrices for specific basic type
628  *
629  * @param type Basic type
630  *
631  * @return true if matrices of <type> are supported, false otherwise
632  **/
633 bool Type::DoesTypeSupportMatrix(TYPES type)
634 {
635         bool result = false;
636
637         switch (type)
638         {
639         case Float:
640         case Double:
641                 result = true;
642                 break;
643         case Int:
644         case Uint:
645                 result = false;
646                 break;
647         default:
648                 TCU_FAIL("Invliad enum");
649         }
650
651         return result;
652 }
653
654 /** Creates instance of Type
655  *
656  * @param basic_type Select basic type of instance
657  * @param n_columns  Number of columns
658  * @param n_rows     Number of rows
659  *
660  * @return Type instance
661  **/
662 Type Type::GetType(TYPES basic_type, glw::GLuint n_columns, glw::GLuint n_rows)
663 {
664         Type type = { basic_type, n_columns, n_rows };
665
666         return type;
667 }
668
669 /** Get Size of given type in bytes
670  *
671  * @param type
672  *
673  * @return Size of type
674  **/
675 GLuint Type::GetTypeSize(TYPES type)
676 {
677         GLuint result = 0;
678
679         switch (type)
680         {
681         case Float:
682                 result = sizeof(GLfloat);
683                 break;
684         case Double:
685                 result = sizeof(GLdouble);
686                 break;
687         case Int:
688                 result = sizeof(GLint);
689                 break;
690         case Uint:
691                 result = sizeof(GLuint);
692                 break;
693         default:
694                 TCU_FAIL("Invalid enum");
695         }
696
697         return result;
698 }
699
700 /** Get GLenum representing given type
701  *
702  * @param type
703  *
704  * @return GLenum value
705  **/
706 GLenum Type::GetTypeGLenum(TYPES type)
707 {
708         GLenum result = 0;
709
710         switch (type)
711         {
712         case Float:
713                 result = GL_FLOAT;
714                 break;
715         case Double:
716                 result = GL_DOUBLE;
717                 break;
718         case Int:
719                 result = GL_INT;
720                 break;
721         case Uint:
722                 result = GL_UNSIGNED_INT;
723                 break;
724         default:
725                 TCU_FAIL("Invalid enum");
726         }
727
728         return result;
729 }
730
731 /** Get proper glUniformNdv routine for vectors with specified number of rows
732  *
733  * @param gl     GL functions
734  * @param n_rows Number of rows
735  *
736  * @return Function address
737  **/
738 uniformNdv getUniformNdv(const glw::Functions& gl, glw::GLuint n_rows)
739 {
740         uniformNdv result = 0;
741
742         switch (n_rows)
743         {
744         case 1:
745                 result = gl.uniform1dv;
746                 break;
747         case 2:
748                 result = gl.uniform2dv;
749                 break;
750         case 3:
751                 result = gl.uniform3dv;
752                 break;
753         case 4:
754                 result = gl.uniform4dv;
755                 break;
756         default:
757                 TCU_FAIL("Invalid number of rows");
758         }
759
760         return result;
761 }
762
763 /** Get proper glUniformNfv routine for vectors with specified number of rows
764  *
765  * @param gl     GL functions
766  * @param n_rows Number of rows
767  *
768  * @return Function address
769  **/
770 uniformNfv getUniformNfv(const glw::Functions& gl, glw::GLuint n_rows)
771 {
772         uniformNfv result = 0;
773
774         switch (n_rows)
775         {
776         case 1:
777                 result = gl.uniform1fv;
778                 break;
779         case 2:
780                 result = gl.uniform2fv;
781                 break;
782         case 3:
783                 result = gl.uniform3fv;
784                 break;
785         case 4:
786                 result = gl.uniform4fv;
787                 break;
788         default:
789                 TCU_FAIL("Invalid number of rows");
790         }
791
792         return result;
793 }
794
795 /** Get proper glUniformNiv routine for vectors with specified number of rows
796  *
797  * @param gl     GL functions
798  * @param n_rows Number of rows
799  *
800  * @return Function address
801  **/
802 uniformNiv getUniformNiv(const glw::Functions& gl, glw::GLuint n_rows)
803 {
804         uniformNiv result = 0;
805
806         switch (n_rows)
807         {
808         case 1:
809                 result = gl.uniform1iv;
810                 break;
811         case 2:
812                 result = gl.uniform2iv;
813                 break;
814         case 3:
815                 result = gl.uniform3iv;
816                 break;
817         case 4:
818                 result = gl.uniform4iv;
819                 break;
820         default:
821                 TCU_FAIL("Invalid number of rows");
822         }
823
824         return result;
825 }
826
827 /** Get proper glUniformNuiv routine for vectors with specified number of rows
828  *
829  * @param gl     GL functions
830  * @param n_rows Number of rows
831  *
832  * @return Function address
833  **/
834 uniformNuiv getUniformNuiv(const glw::Functions& gl, glw::GLuint n_rows)
835 {
836         uniformNuiv result = 0;
837
838         switch (n_rows)
839         {
840         case 1:
841                 result = gl.uniform1uiv;
842                 break;
843         case 2:
844                 result = gl.uniform2uiv;
845                 break;
846         case 3:
847                 result = gl.uniform3uiv;
848                 break;
849         case 4:
850                 result = gl.uniform4uiv;
851                 break;
852         default:
853                 TCU_FAIL("Invalid number of rows");
854         }
855
856         return result;
857 }
858
859 /** Get proper glUniformMatrixNdv routine for matrix with specified number of columns and rows
860  *
861  * @param gl     GL functions
862  * @param n_rows Number of rows
863  *
864  * @return Function address
865  **/
866 uniformMatrixNdv getUniformMatrixNdv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
867 {
868         uniformMatrixNdv result = 0;
869
870         switch (n_columns)
871         {
872         case 2:
873                 switch (n_rows)
874                 {
875                 case 2:
876                         result = gl.uniformMatrix2dv;
877                         break;
878                 case 3:
879                         result = gl.uniformMatrix2x3dv;
880                         break;
881                 case 4:
882                         result = gl.uniformMatrix2x4dv;
883                         break;
884                 default:
885                         TCU_FAIL("Invalid number of rows");
886                 }
887                 break;
888         case 3:
889                 switch (n_rows)
890                 {
891                 case 2:
892                         result = gl.uniformMatrix3x2dv;
893                         break;
894                 case 3:
895                         result = gl.uniformMatrix3dv;
896                         break;
897                 case 4:
898                         result = gl.uniformMatrix3x4dv;
899                         break;
900                 default:
901                         TCU_FAIL("Invalid number of rows");
902                 }
903                 break;
904         case 4:
905                 switch (n_rows)
906                 {
907                 case 2:
908                         result = gl.uniformMatrix4x2dv;
909                         break;
910                 case 3:
911                         result = gl.uniformMatrix4x3dv;
912                         break;
913                 case 4:
914                         result = gl.uniformMatrix4dv;
915                         break;
916                 default:
917                         TCU_FAIL("Invalid number of rows");
918                 }
919                 break;
920         default:
921                 TCU_FAIL("Invalid number of columns");
922         }
923
924         return result;
925 }
926
927 /** Get proper glUniformMatrixNfv routine for vectors with specified number of columns and rows
928  *
929  * @param gl     GL functions
930  * @param n_rows Number of rows
931  *
932  * @return Function address
933  **/
934 uniformMatrixNfv getUniformMatrixNfv(const glw::Functions& gl, glw::GLuint n_columns, glw::GLuint n_rows)
935 {
936         uniformMatrixNfv result = 0;
937
938         switch (n_columns)
939         {
940         case 2:
941                 switch (n_rows)
942                 {
943                 case 2:
944                         result = gl.uniformMatrix2fv;
945                         break;
946                 case 3:
947                         result = gl.uniformMatrix2x3fv;
948                         break;
949                 case 4:
950                         result = gl.uniformMatrix2x4fv;
951                         break;
952                 default:
953                         TCU_FAIL("Invalid number of rows");
954                 }
955                 break;
956         case 3:
957                 switch (n_rows)
958                 {
959                 case 2:
960                         result = gl.uniformMatrix3x2fv;
961                         break;
962                 case 3:
963                         result = gl.uniformMatrix3fv;
964                         break;
965                 case 4:
966                         result = gl.uniformMatrix3x4fv;
967                         break;
968                 default:
969                         TCU_FAIL("Invalid number of rows");
970                 }
971                 break;
972         case 4:
973                 switch (n_rows)
974                 {
975                 case 2:
976                         result = gl.uniformMatrix4x2fv;
977                         break;
978                 case 3:
979                         result = gl.uniformMatrix4x3fv;
980                         break;
981                 case 4:
982                         result = gl.uniformMatrix4fv;
983                         break;
984                 default:
985                         TCU_FAIL("Invalid number of rows");
986                 }
987                 break;
988         default:
989                 TCU_FAIL("Invalid number of columns");
990         }
991
992         return result;
993 }
994
995 bool verifyVarying(Program& program, const std::string& parent_name, const Variable::Descriptor& desc,
996                                    std::stringstream& stream, bool is_input)
997 {
998         GLint  component = 0;
999         GLuint index     = 0;
1000         GLenum interface = GL_PROGRAM_INPUT;
1001         GLint  location  = 0;
1002
1003         if (false == is_input)
1004         {
1005                 interface = GL_PROGRAM_OUTPUT;
1006         }
1007
1008         const std::string& name = Utils::Variable::GetReference(parent_name, desc, Utils::Variable::BASIC, 0);
1009
1010         try
1011         {
1012                 index = program.GetResourceIndex(name, interface);
1013
1014                 program.GetResource(interface, index, GL_LOCATION, 1 /* size */, &location);
1015                 program.GetResource(interface, index, GL_LOCATION_COMPONENT, 1 /* size */, &component);
1016         }
1017         catch (std::exception& exc)
1018         {
1019                 stream << "Failed to query program for varying: " << desc.m_name << ". Reason: " << exc.what() << "\n";
1020
1021                 return false;
1022         }
1023
1024         bool result = true;
1025
1026         if (location != desc.m_expected_location)
1027         {
1028                 stream << "Attribute: " << desc.m_name << " - invalid location: " << location
1029                            << " expected: " << desc.m_expected_location << std::endl;
1030                 result = false;
1031         }
1032         if (component != desc.m_expected_component)
1033         {
1034                 stream << "Attribute: " << desc.m_name << " - invalid component: " << component
1035                            << " expected: " << desc.m_expected_component << std::endl;
1036                 result = false;
1037         }
1038
1039         return result;
1040 }
1041
1042 /** Query program resource for given variable and verify that everything is as expected
1043  *
1044  * @param program  Program object
1045  * @param variable Variable object
1046  * @param stream   Stream that will be used to log any error
1047  * @param is_input Selects if varying is input or output
1048  *
1049  * @return true if verification is positive, false otherwise
1050  **/
1051 bool checkVarying(Program& program, const Variable& variable, std::stringstream& stream, bool is_input)
1052 {
1053         bool result = true;
1054
1055         if (variable.IsBlock())
1056         {
1057                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1058                 const size_t      n_members = interface->m_members.size();
1059
1060                 for (size_t i = 0; i < n_members; ++i)
1061                 {
1062                         const Variable::Descriptor& member = interface->m_members[i];
1063                         bool member_result                                 = verifyVarying(program, interface->m_name, member, stream, is_input);
1064
1065                         if (false == member_result)
1066                         {
1067                                 result = false;
1068                         }
1069                 }
1070         }
1071         /*
1072          To query the the location of struct member by glGetProgramResource, we need pass the variable name "gs_fs_output[0].single",
1073          but in original implementation, the test pass the name "Data.single", which can't get any valid result.
1074          struct Data {
1075          dmat2 single;
1076          dmat2 array[1];
1077          };
1078          layout (location = 0) in Data gs_fs_output[1];
1079          */
1080         else if (variable.IsStruct())
1081         {
1082                 Utils::Interface* interface              = variable.m_descriptor.m_interface;
1083                 const size_t      n_members              = interface->m_members.size();
1084                 std::string               structVariable = variable.m_descriptor.m_name;
1085                 // If struct variable is an array
1086                 if (0 != variable.m_descriptor.m_n_array_elements)
1087                 {
1088                         for (GLuint i = 0; i < variable.m_descriptor.m_n_array_elements; i++)
1089                         {
1090                                 GLchar buffer[16];
1091                                 sprintf(buffer, "%d", i);
1092                                 structVariable.append("[");
1093                                 structVariable.append(buffer);
1094                                 structVariable.append("]");
1095                                 for (size_t j = 0; j < n_members; ++j)
1096                                 {
1097                                         const Variable::Descriptor& member = interface->m_members[j];
1098                                         bool member_result = verifyVarying(program, structVariable, member, stream, is_input);
1099
1100                                         if (false == member_result)
1101                                         {
1102                                                 result = false;
1103                                         }
1104                                 }
1105                         }
1106                 }
1107                 else
1108                 {
1109                         for (GLuint i = 0; i < n_members; ++i)
1110                         {
1111                                 const Variable::Descriptor& member = interface->m_members[i];
1112                                 bool member_result                                 = verifyVarying(program, structVariable, member, stream, is_input);
1113
1114                                 if (false == member_result)
1115                                 {
1116                                         result = false;
1117                                 }
1118                         }
1119                 }
1120         }
1121         else
1122         {
1123                 result = verifyVarying(program, "", variable.m_descriptor, stream, is_input);
1124         }
1125         return result;
1126 }
1127
1128 /** Query program resource for given variable and verify that everything is as expected
1129  *
1130  * @param program  Program object
1131  * @param variable Variable object
1132  * @param stream   Stream that will be used to log any error
1133  *
1134  * @return true if verification is positive, false otherwise
1135  **/
1136 bool checkUniform(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1137 {
1138         bool result = true;
1139
1140         if (false == variable.IsBlock())
1141         {
1142                 TCU_FAIL("Not implemented");
1143         }
1144         else
1145         {
1146                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1147
1148                 size_t size = interface->m_members.size();
1149
1150                 std::vector<GLuint>              indices;
1151                 std::vector<const char*> names;
1152                 std::vector<std::string> names_str;
1153                 std::vector<GLint>               offsets;
1154
1155                 indices.resize(size);
1156                 names.resize(size);
1157                 names_str.resize(size);
1158                 offsets.resize(size);
1159
1160                 for (size_t i = 0; i < size; ++i)
1161                 {
1162                         indices[i] = 0;
1163                         offsets[i] = 0;
1164
1165                         const std::string& name =
1166                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1167
1168                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1169                         {
1170                                 const std::string& member_name = Utils::Variable::GetReference(
1171                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1172
1173                                 names_str[i] = member_name;
1174                         }
1175                         else
1176                         {
1177                                 names_str[i] = name;
1178                         }
1179
1180                         names[i] = names_str[i].c_str();
1181                 }
1182
1183                 try
1184                 {
1185                         program.GetUniformIndices(static_cast<glw::GLsizei>(size), &names[0], &indices[0]);
1186                         program.GetActiveUniformsiv(static_cast<glw::GLsizei>(size), &indices[0], GL_UNIFORM_OFFSET, &offsets[0]);
1187                 }
1188                 catch (std::exception& exc)
1189                 {
1190                         stream << "Failed to query program for uniforms in block: " << variable.m_descriptor.m_name
1191                                    << ". Reason: " << exc.what() << "\n";
1192
1193                         return false;
1194                 }
1195
1196                 for (size_t i = 0; i < size; ++i)
1197                 {
1198                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1199
1200                         if (offsets[i] != (GLint)desc.m_offset)
1201                         {
1202                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offsets[i]
1203                                            << " expected: " << desc.m_offset << std::endl;
1204                                 result = false;
1205                         }
1206                 }
1207         }
1208
1209         return result;
1210 }
1211
1212 /** Query program resource for given variable and verify that everything is as expected
1213  *
1214  * @param program  Program object
1215  * @param variable Variable object
1216  * @param stream   Stream that will be used to log any error
1217  *
1218  * @return true if verification is positive, false otherwise
1219  **/
1220 bool checkSSB(Program& program, const Utils::Variable& variable, std::stringstream& stream)
1221 {
1222         bool result = true;
1223
1224         if (false == variable.IsBlock())
1225         {
1226                 TCU_FAIL("Not implemented");
1227         }
1228         else
1229         {
1230                 Utils::Interface* interface = variable.m_descriptor.m_interface;
1231
1232                 size_t size = interface->m_members.size();
1233
1234                 for (size_t i = 0; i < size; ++i)
1235                 {
1236                         GLuint          index   = 0;
1237                         std::string name_str = "";
1238                         GLint           offset   = 0;
1239
1240                         const std::string& name =
1241                                 Utils::Variable::GetReference(interface->m_name, interface->m_members[i], Utils::Variable::BASIC, 0);
1242
1243                         if (Utils::Variable::INTERFACE == interface->m_members[i].m_type)
1244                         {
1245                                 const std::string& member_name = Utils::Variable::GetReference(
1246                                         name, interface->m_members[i].m_interface->m_members[0], Utils::Variable::BASIC, 0);
1247
1248                                 name_str = member_name;
1249                         }
1250                         else
1251                         {
1252                                 name_str = name;
1253                         }
1254
1255                         try
1256                         {
1257                                 index = program.GetResourceIndex(name_str, GL_BUFFER_VARIABLE);
1258
1259                                 program.GetResource(GL_BUFFER_VARIABLE, index, GL_OFFSET, 1, &offset);
1260                         }
1261                         catch (std::exception& exc)
1262                         {
1263                                 stream << "Failed to query program for buffer variable: " << variable.m_descriptor.m_name
1264                                            << ". Reason: " << exc.what() << "\n";
1265
1266                                 return false;
1267                         }
1268
1269                         Utils::Variable::Descriptor& desc = interface->m_members[i];
1270
1271                         if (offset != (GLint)desc.m_offset)
1272                         {
1273                                 stream << "Uniform: " << desc.m_name << " - invalid offset: " << offset
1274                                            << " expected: " << desc.m_offset << std::endl;
1275                                 result = false;
1276                         }
1277                 }
1278         }
1279
1280         return result;
1281 }
1282
1283 /** Query program resources at given stage and verifies results
1284  *
1285  * @param program           Program object
1286  * @param program_interface Definition of program interface
1287  * @param stage             Stage to be verified
1288  * @param check_inputs      Select if inputs should be verified
1289  * @param check_outputs     Select if output should be verified
1290  * @param check_uniforms    Select if uniforms should be verified
1291  * @param check_ssbs        Select if buffers should be verified
1292  * @param stream            Stream that will be used to log any error
1293  *
1294  * @return true if verification is positive, false otherwise
1295  **/
1296 bool checkProgramStage(Program& program, const ProgramInterface& program_interface, Utils::Shader::STAGES stage,
1297                                            bool check_inputs, bool check_outputs, bool check_uniforms, bool check_ssbs,
1298                                            std::stringstream& stream)
1299 {
1300         typedef Variable::PtrVector::const_iterator const_iterator;
1301
1302         const ShaderInterface& interface = program_interface.GetShaderInterface(stage);
1303
1304         bool result = true;
1305
1306         /* Inputs */
1307         if (true == check_inputs)
1308         {
1309                 const Variable::PtrVector& inputs = interface.m_inputs;
1310
1311                 for (const_iterator it = inputs.begin(); it != inputs.end(); ++it)
1312                 {
1313                         if (false == checkVarying(program, **it, stream, true))
1314                         {
1315                                 result = false;
1316                         }
1317                 }
1318         }
1319
1320         /* Outputs */
1321         if (true == check_outputs)
1322         {
1323                 const Variable::PtrVector& outputs = interface.m_outputs;
1324
1325                 for (const_iterator it = outputs.begin(); it != outputs.end(); ++it)
1326                 {
1327                         if (false == checkVarying(program, **it, stream, false))
1328                         {
1329                                 result = false;
1330                         }
1331                 }
1332         }
1333
1334         /* Uniforms */
1335         if (true == check_uniforms)
1336         {
1337                 const Variable::PtrVector& uniforms = interface.m_uniforms;
1338
1339                 for (const_iterator it = uniforms.begin(); it != uniforms.end(); ++it)
1340                 {
1341                         if (false == checkUniform(program, **it, stream))
1342                         {
1343                                 result = false;
1344                         }
1345                 }
1346         }
1347
1348         /* SSBs */
1349         if (true == check_ssbs)
1350         {
1351                 const Variable::PtrVector& ssbs = interface.m_ssb_blocks;
1352
1353                 for (const_iterator it = ssbs.begin(); it != ssbs.end(); ++it)
1354                 {
1355                         if (false == checkSSB(program, **it, stream))
1356                         {
1357                                 result = false;
1358                         }
1359                 }
1360         }
1361
1362         return result;
1363 }
1364
1365 /** Query resources of monolithic compute program and verifies results
1366  *
1367  * @param program           Program object
1368  * @param program_interface Definition of program interface
1369  * @param stream            Stream that will be used to log any error
1370  *
1371  * @return true if verification is positive, false otherwise
1372  **/
1373 bool checkMonolithicComputeProgramInterface(Program& program, const ProgramInterface& program_interface,
1374                                                                                         std::stringstream& stream)
1375 {
1376         bool result = true;
1377
1378         if (false == checkProgramStage(program, program_interface, Shader::COMPUTE, false, false, true, true, stream))
1379         {
1380                 result = false;
1381         }
1382
1383         /* Done */
1384         return result;
1385 }
1386
1387 /** Query resources of monolithic draw program and verifies results
1388  *
1389  * @param program           Program object
1390  * @param program_interface Definition of program interface
1391  * @param stream            Stream that will be used to log any error
1392  *
1393  * @return true if verification is positive, false otherwise
1394  **/
1395 bool checkMonolithicDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1396                                                                                  std::stringstream& stream)
1397 {
1398         bool result = true;
1399
1400         if (false == checkProgramStage(program, program_interface, Shader::VERTEX, true, false, true, true, stream))
1401         {
1402                 result = false;
1403         }
1404
1405         /* Done */
1406         return result;
1407 }
1408
1409 /** Query resources of separable draw program and verifies results
1410  *
1411  * @param program           Program object
1412  * @param program_interface Definition of program interface
1413  * @param stream            Stream that will be used to log any error
1414  *
1415  * @return true if verification is positive, false otherwise
1416  **/
1417 bool checkSeparableDrawProgramInterface(Program& program, const ProgramInterface& program_interface,
1418                                                                                 Utils::Shader::STAGES stage, std::stringstream& stream)
1419 {
1420         bool result = true;
1421
1422         if (false == checkProgramStage(program, program_interface, stage, true, true, true, true, stream))
1423         {
1424                 result = false;
1425         }
1426
1427         /* Done */
1428         return result;
1429 }
1430
1431 /** Check if extension is supported
1432  *
1433  * @param context        Test context
1434  * @param extension_name Name of extension
1435  *
1436  * @return true if extension is supported, false otherwise
1437  **/
1438 bool isExtensionSupported(deqp::Context& context, const GLchar* extension_name)
1439 {
1440         const std::vector<std::string>& extensions = context.getContextInfo().getExtensions();
1441
1442         if (std::find(extensions.begin(), extensions.end(), extension_name) == extensions.end())
1443         {
1444                 return false;
1445         }
1446
1447         return true;
1448 }
1449
1450 /** Check if GL context meets version requirements
1451  *
1452  * @param gl             Functions
1453  * @param required_major Minimum required MAJOR_VERSION
1454  * @param required_minor Minimum required MINOR_VERSION
1455  *
1456  * @return true if GL context version is at least as requested, false otherwise
1457  **/
1458 bool isGLVersionAtLeast(const Functions& gl, GLint required_major, GLint required_minor)
1459 {
1460         glw::GLint major = 0;
1461         glw::GLint minor = 0;
1462
1463         gl.getIntegerv(GL_MAJOR_VERSION, &major);
1464         gl.getIntegerv(GL_MINOR_VERSION, &minor);
1465
1466         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
1467
1468         if (major > required_major)
1469         {
1470                 /* Major is higher than required one */
1471                 return true;
1472         }
1473         else if (major == required_major)
1474         {
1475                 if (minor >= required_minor)
1476                 {
1477                         /* Major is equal to required one */
1478                         /* Minor is higher than or equal to required one */
1479                         return true;
1480                 }
1481                 else
1482                 {
1483                         /* Major is equal to required one */
1484                         /* Minor is lower than required one */
1485                         return false;
1486                 }
1487         }
1488         else
1489         {
1490                 /* Major is lower than required one */
1491                 return false;
1492         }
1493 }
1494
1495 /** Replace first occurance of <token> with <text> in <string> starting at <search_posistion>
1496  *
1497  * @param token           Token string
1498  * @param search_position Position at which find will start, it is updated to position at which replaced text ends
1499  * @param text            String that will be used as replacement for <token>
1500  * @param string          String to work on
1501  **/
1502 void replaceToken(const GLchar* token, size_t& search_position, const GLchar* text, std::string& string)
1503 {
1504         const size_t text_length        = strlen(text);
1505         const size_t token_length   = strlen(token);
1506         const size_t token_position = string.find(token, search_position);
1507
1508 #if DEBUG_REPLACE_TOKEN
1509         if (std::string::npos == token_position)
1510         {
1511                 string.append("\n\nInvalid token: ");
1512                 string.append(token);
1513
1514                 TCU_FAIL(string.c_str());
1515         }
1516 #endif /* DEBUG_REPLACE_TOKEN */
1517
1518         string.replace(token_position, token_length, text, text_length);
1519
1520         search_position = token_position + text_length;
1521 }
1522
1523 /** Replace all occurances of <token> with <text> in <string>
1524  *
1525  * @param token           Token string
1526  * @param text            String that will be used as replacement for <token>
1527  * @param string          String to work on
1528  **/
1529 void replaceAllTokens(const GLchar* token, const GLchar* text, std::string& string)
1530 {
1531         const size_t text_length  = strlen(text);
1532         const size_t token_length = strlen(token);
1533
1534         size_t search_position = 0;
1535
1536         while (1)
1537         {
1538                 const size_t token_position = string.find(token, search_position);
1539
1540                 if (std::string::npos == token_position)
1541                 {
1542                         break;
1543                 }
1544
1545                 search_position = token_position + text_length;
1546
1547                 string.replace(token_position, token_length, text, text_length);
1548         }
1549 }
1550
1551 /** Rounds up the value to the next power of 2.
1552  * This routine does not work for 0, see the url for explanations.
1553  *
1554  * @param value Starting point
1555  *
1556  * @return Calculated value
1557  **/
1558 glw::GLuint roundUpToPowerOf2(glw::GLuint value)
1559 {
1560         /* Taken from: graphics.stanford.edu/~seander/bithacks.html */
1561         --value;
1562
1563         value |= value >> 1;
1564         value |= value >> 2;
1565         value |= value >> 4;
1566         value |= value >> 8;
1567         value |= value >> 16;
1568
1569         ++value;
1570
1571         return value;
1572 }
1573
1574 /** Insert elements of list into string.
1575  * List in string is represented either by token "LIST" or "SEPARATORLIST".
1576  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>.
1577  * LIST is replaced with <element>SEPARATORLIST
1578  *
1579  * @param element         Element to be inserted
1580  * @param separator       Separator inserted between elements
1581  * @param search_position Position in string, where search for list should start
1582  * @param string          String
1583  **/
1584 void insertElementOfList(const GLchar* element, const GLchar* separator, size_t& search_position, std::string& string)
1585 {
1586         static const char* list         = g_list;
1587         static const char* sep_list = "SEPARATORLIST";
1588
1589         /* Try to get "list" positions */
1590         const size_t list_position       = string.find(list, search_position);
1591         const size_t sep_list_position = string.find(sep_list, search_position);
1592
1593         /* There is no list in string */
1594         if (std::string::npos == list_position)
1595         {
1596                 return;
1597         }
1598
1599         if (9 /* strlen(SEPARATOR) */ == list_position - sep_list_position)
1600         {
1601                 replaceToken("SEPARATOR", search_position, separator, string);
1602         }
1603
1604         /* Save search_position */
1605         const size_t start_position = search_position;
1606
1607         /* Prepare new element */
1608         replaceToken("LIST", search_position, "ELEMENTSEPARATORLIST", string);
1609
1610         /* Restore search_position */
1611         search_position = start_position;
1612
1613         /* Replace element and separator */
1614         replaceToken("ELEMENT", search_position, element, string);
1615 }
1616
1617 /** Close list in string.
1618  * If SEPARATORLIST is available, than SEPARATOR is replaced with <separator>
1619  * LIST is replaced with ""
1620  *
1621  * @param separator       Separator inserted between elements
1622  * @param search_position Position in string, where search for list should start
1623  * @param string          String
1624  **/
1625 void endList(const glw::GLchar* separator, size_t& search_position, std::string& string)
1626 {
1627         const size_t sep_position = string.find("SEPARATOR", search_position);
1628         if (std::string::npos != sep_position)
1629         {
1630                 replaceToken("SEPARATOR", search_position, separator, string);
1631         }
1632
1633         replaceToken("LIST", search_position, "", string);
1634 }
1635
1636 /* Buffer constants */
1637 const GLuint Buffer::m_invalid_id = -1;
1638
1639 /** Constructor.
1640  *
1641  * @param context CTS context.
1642  **/
1643 Buffer::Buffer(deqp::Context& context) : m_id(m_invalid_id), m_buffer(Array), m_context(context)
1644 {
1645 }
1646
1647 /** Destructor
1648  *
1649  **/
1650 Buffer::~Buffer()
1651 {
1652         Release();
1653 }
1654
1655 /** Initialize buffer instance
1656  *
1657  * @param buffer Buffer type
1658  * @param usage  Buffer usage enum
1659  * @param size   <size> parameter
1660  * @param data   <data> parameter
1661  **/
1662 void Buffer::Init(BUFFERS buffer, USAGE usage, GLsizeiptr size, GLvoid* data)
1663 {
1664         /* Delete previous buffer instance */
1665         Release();
1666
1667         m_buffer = buffer;
1668
1669         const Functions& gl = m_context.getRenderContext().getFunctions();
1670
1671         Generate(gl, m_id);
1672         Bind(gl, m_id, m_buffer);
1673         Data(gl, m_buffer, usage, size, data);
1674 }
1675
1676 /** Release buffer instance
1677  *
1678  **/
1679 void Buffer::Release()
1680 {
1681         if (m_invalid_id != m_id)
1682         {
1683                 const Functions& gl = m_context.getRenderContext().getFunctions();
1684
1685                 gl.deleteBuffers(1, &m_id);
1686                 m_id = m_invalid_id;
1687         }
1688 }
1689
1690 /** Binds buffer to its target
1691  *
1692  **/
1693 void Buffer::Bind() const
1694 {
1695         const Functions& gl = m_context.getRenderContext().getFunctions();
1696
1697         Bind(gl, m_id, m_buffer);
1698 }
1699
1700 /** Binds indexed buffer
1701  *
1702  * @param index <index> parameter
1703  **/
1704 void Buffer::BindBase(GLuint index) const
1705 {
1706         const Functions& gl = m_context.getRenderContext().getFunctions();
1707
1708         BindBase(gl, m_id, m_buffer, index);
1709 }
1710
1711 /** Binds range of buffer
1712  *
1713  * @param index  <index> parameter
1714  * @param offset <offset> parameter
1715  * @param size   <size> parameter
1716  **/
1717 void Buffer::BindRange(GLuint index, GLintptr offset, GLsizeiptr size) const
1718 {
1719         const Functions& gl = m_context.getRenderContext().getFunctions();
1720
1721         BindRange(gl, m_id, m_buffer, index, offset, size);
1722 }
1723
1724 /** Allocate memory for buffer and sends initial content
1725  *
1726  * @param usage  Buffer usage enum
1727  * @param size   <size> parameter
1728  * @param data   <data> parameter
1729  **/
1730 void Buffer::Data(USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1731 {
1732         const Functions& gl = m_context.getRenderContext().getFunctions();
1733
1734         Data(gl, m_buffer, usage, size, data);
1735 }
1736
1737 /** Maps contents of buffer into CPU space
1738  *
1739  * @param access Requested access
1740  *
1741  * @return Pointer to memory region available for CPU
1742  **/
1743 GLvoid* Buffer::Map(ACCESS access)
1744 {
1745         const Functions& gl = m_context.getRenderContext().getFunctions();
1746
1747         return Map(gl, m_buffer, access);
1748 }
1749
1750 /** Allocate memory for buffer and sends initial content
1751  *
1752  * @param offset Offset in buffer
1753  * @param size   <size> parameter
1754  * @param data   <data> parameter
1755  **/
1756 void Buffer::SubData(glw::GLintptr offset, glw::GLsizeiptr size, glw::GLvoid* data)
1757 {
1758         const Functions& gl = m_context.getRenderContext().getFunctions();
1759
1760         SubData(gl, m_buffer, offset, size, data);
1761 }
1762
1763 /** Maps contents of buffer into CPU space
1764  **/
1765 void Buffer::UnMap()
1766 {
1767         const Functions& gl = m_context.getRenderContext().getFunctions();
1768
1769         return UnMap(gl, m_buffer);
1770 }
1771
1772 /** Bind buffer to given target
1773  *
1774  * @param gl     GL functions
1775  * @param id     Id of buffer
1776  * @param buffer Buffer enum
1777  **/
1778 void Buffer::Bind(const Functions& gl, GLuint id, BUFFERS buffer)
1779 {
1780         GLenum target = GetBufferGLenum(buffer);
1781
1782         gl.bindBuffer(target, id);
1783         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBuffer");
1784 }
1785
1786 /** Binds indexed buffer
1787  *
1788  * @param gl     GL functions
1789  * @param id     Id of buffer
1790  * @param buffer Buffer enum
1791  * @param index  <index> parameter
1792  **/
1793 void Buffer::BindBase(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index)
1794 {
1795         GLenum target = GetBufferGLenum(buffer);
1796
1797         gl.bindBufferBase(target, index, id);
1798         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferBase");
1799 }
1800
1801 /** Binds buffer range
1802  *
1803  * @param gl     GL functions
1804  * @param id     Id of buffer
1805  * @param buffer Buffer enum
1806  * @param index  <index> parameter
1807  * @param offset <offset> parameter
1808  * @param size   <size> parameter
1809  **/
1810 void Buffer::BindRange(const Functions& gl, GLuint id, BUFFERS buffer, GLuint index, GLintptr offset, GLsizeiptr size)
1811 {
1812         GLenum target = GetBufferGLenum(buffer);
1813
1814         gl.bindBufferRange(target, index, id, offset, size);
1815         GLU_EXPECT_NO_ERROR(gl.getError(), "BindBufferRange");
1816 }
1817
1818 /** Allocate memory for buffer and sends initial content
1819  *
1820  * @param gl     GL functions
1821  * @param buffer Buffer enum
1822  * @param usage  Buffer usage enum
1823  * @param size   <size> parameter
1824  * @param data   <data> parameter
1825  **/
1826 void Buffer::Data(const glw::Functions& gl, BUFFERS buffer, USAGE usage, glw::GLsizeiptr size, glw::GLvoid* data)
1827 {
1828         GLenum target   = GetBufferGLenum(buffer);
1829         GLenum gl_usage = GetUsageGLenum(usage);
1830
1831         gl.bufferData(target, size, data, gl_usage);
1832         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferData");
1833 }
1834
1835 /** Allocate memory for buffer and sends initial content
1836  *
1837  * @param gl     GL functions
1838  * @param buffer Buffer enum
1839  * @param offset Offset in buffer
1840  * @param size   <size> parameter
1841  * @param data   <data> parameter
1842  **/
1843 void Buffer::SubData(const glw::Functions& gl, BUFFERS buffer, glw::GLintptr offset, glw::GLsizeiptr size,
1844                                          glw::GLvoid* data)
1845 {
1846         GLenum target = GetBufferGLenum(buffer);
1847
1848         gl.bufferSubData(target, offset, size, data);
1849         GLU_EXPECT_NO_ERROR(gl.getError(), "BufferSubData");
1850 }
1851
1852 /** Generate buffer
1853  *
1854  * @param gl     GL functions
1855  * @param out_id Id of buffer
1856  **/
1857 void Buffer::Generate(const Functions& gl, GLuint& out_id)
1858 {
1859         GLuint id = m_invalid_id;
1860
1861         gl.genBuffers(1, &id);
1862         GLU_EXPECT_NO_ERROR(gl.getError(), "GenBuffers");
1863
1864         if (m_invalid_id == id)
1865         {
1866                 TCU_FAIL("Got invalid id");
1867         }
1868
1869         out_id = id;
1870 }
1871
1872 /** Maps buffer content
1873  *
1874  * @param gl     GL functions
1875  * @param buffer Buffer enum
1876  * @param access Access rights for mapped region
1877  *
1878  * @return Mapped memory
1879  **/
1880 void* Buffer::Map(const Functions& gl, BUFFERS buffer, ACCESS access)
1881 {
1882         GLenum target   = GetBufferGLenum(buffer);
1883         GLenum gl_access = GetAccessGLenum(access);
1884
1885         void* result = gl.mapBuffer(target, gl_access);
1886         GLU_EXPECT_NO_ERROR(gl.getError(), "MapBuffer");
1887
1888         return result;
1889 }
1890
1891 /** Unmaps buffer
1892  *
1893  **/
1894 void Buffer::UnMap(const Functions& gl, BUFFERS buffer)
1895 {
1896         GLenum target = GetBufferGLenum(buffer);
1897
1898         gl.unmapBuffer(target);
1899         GLU_EXPECT_NO_ERROR(gl.getError(), "UnmapBuffer");
1900 }
1901
1902 /** Return GLenum representation of requested access
1903  *
1904  * @param access Requested access
1905  *
1906  * @return GLenum value
1907  **/
1908 GLenum Buffer::GetAccessGLenum(ACCESS access)
1909 {
1910         GLenum result = 0;
1911
1912         switch (access)
1913         {
1914         case ReadOnly:
1915                 result = GL_READ_ONLY;
1916                 break;
1917         case WriteOnly:
1918                 result = GL_WRITE_ONLY;
1919                 break;
1920         case ReadWrite:
1921                 result = GL_READ_WRITE;
1922                 break;
1923         default:
1924                 TCU_FAIL("Invalid enum");
1925         }
1926
1927         return result;
1928 }
1929
1930 /** Return GLenum representation of requested buffer type
1931  *
1932  * @param buffer Requested buffer type
1933  *
1934  * @return GLenum value
1935  **/
1936 GLenum Buffer::GetBufferGLenum(BUFFERS buffer)
1937 {
1938         GLenum result = 0;
1939
1940         switch (buffer)
1941         {
1942         case Array:
1943                 result = GL_ARRAY_BUFFER;
1944                 break;
1945         case Element:
1946                 result = GL_ELEMENT_ARRAY_BUFFER;
1947                 break;
1948         case Shader_Storage:
1949                 result = GL_SHADER_STORAGE_BUFFER;
1950                 break;
1951         case Texture:
1952                 result = GL_TEXTURE_BUFFER;
1953                 break;
1954         case Transform_feedback:
1955                 result = GL_TRANSFORM_FEEDBACK_BUFFER;
1956                 break;
1957         case Uniform:
1958                 result = GL_UNIFORM_BUFFER;
1959                 break;
1960         default:
1961                 TCU_FAIL("Invalid enum");
1962         }
1963
1964         return result;
1965 }
1966
1967 /** Return GLenum representation of requested usage
1968  *
1969  * @param usage Requested usage
1970  *
1971  * @return GLenum value
1972  **/
1973 GLenum Buffer::GetUsageGLenum(USAGE usage)
1974 {
1975         GLenum result = 0;
1976
1977         switch (usage)
1978         {
1979         case DynamicCopy:
1980                 result = GL_DYNAMIC_COPY;
1981                 break;
1982         case DynamicDraw:
1983                 result = GL_DYNAMIC_DRAW;
1984                 break;
1985         case DynamicRead:
1986                 result = GL_DYNAMIC_READ;
1987                 break;
1988         case StaticCopy:
1989                 result = GL_STATIC_COPY;
1990                 break;
1991         case StaticDraw:
1992                 result = GL_STATIC_DRAW;
1993                 break;
1994         case StaticRead:
1995                 result = GL_STATIC_READ;
1996                 break;
1997         case StreamCopy:
1998                 result = GL_STREAM_COPY;
1999                 break;
2000         case StreamDraw:
2001                 result = GL_STREAM_DRAW;
2002                 break;
2003         case StreamRead:
2004                 result = GL_STREAM_READ;
2005                 break;
2006         default:
2007                 TCU_FAIL("Invalid enum");
2008         }
2009
2010         return result;
2011 }
2012
2013 /** Returns name of buffer target
2014  *
2015  * @param buffer Target enum
2016  *
2017  * @return Name of target
2018  **/
2019 const GLchar* Buffer::GetBufferName(BUFFERS buffer)
2020 {
2021         const GLchar* name = 0;
2022
2023         switch (buffer)
2024         {
2025         case Array:
2026                 name = "Array";
2027                 break;
2028         case Element:
2029                 name = "Element";
2030                 break;
2031         case Shader_Storage:
2032                 name = "Shader_Storage";
2033                 break;
2034         case Texture:
2035                 name = "Texture";
2036                 break;
2037         case Transform_feedback:
2038                 name = "Transform_feedback";
2039                 break;
2040         case Uniform:
2041                 name = "Uniform";
2042                 break;
2043         default:
2044                 TCU_FAIL("Invalid enum");
2045         }
2046
2047         return name;
2048 }
2049
2050 /* Framebuffer constants */
2051 const GLuint Framebuffer::m_invalid_id = -1;
2052
2053 /** Constructor
2054  *
2055  * @param context CTS context
2056  **/
2057 Framebuffer::Framebuffer(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2058 {
2059         /* Nothing to be done here */
2060 }
2061
2062 /** Destructor
2063  *
2064  **/
2065 Framebuffer::~Framebuffer()
2066 {
2067         Release();
2068 }
2069
2070 /** Initialize framebuffer instance
2071  *
2072  **/
2073 void Framebuffer::Init()
2074 {
2075         /* Delete previous instance */
2076         Release();
2077
2078         const Functions& gl = m_context.getRenderContext().getFunctions();
2079
2080         Generate(gl, m_id);
2081 }
2082
2083 /** Release framebuffer instance
2084  *
2085  **/
2086 void Framebuffer::Release()
2087 {
2088         if (m_invalid_id != m_id)
2089         {
2090                 const Functions& gl = m_context.getRenderContext().getFunctions();
2091
2092                 gl.deleteFramebuffers(1, &m_id);
2093                 m_id = m_invalid_id;
2094         }
2095 }
2096
2097 /** Attach texture to specified attachment
2098  *
2099  * @param attachment Attachment
2100  * @param texture_id Texture id
2101  * @param width      Texture width
2102  * @param height     Texture height
2103  **/
2104 void Framebuffer::AttachTexture(GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2105 {
2106         const Functions& gl = m_context.getRenderContext().getFunctions();
2107
2108         AttachTexture(gl, attachment, texture_id, width, height);
2109 }
2110
2111 /** Binds framebuffer to DRAW_FRAMEBUFFER
2112  *
2113  **/
2114 void Framebuffer::Bind()
2115 {
2116         const Functions& gl = m_context.getRenderContext().getFunctions();
2117
2118         Bind(gl, m_id);
2119 }
2120
2121 /** Clear framebuffer
2122  *
2123  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2124  **/
2125 void Framebuffer::Clear(GLenum mask)
2126 {
2127         const Functions& gl = m_context.getRenderContext().getFunctions();
2128
2129         Clear(gl, mask);
2130 }
2131
2132 /** Specifies clear color
2133  *
2134  * @param red   Red channel
2135  * @param green Green channel
2136  * @param blue  Blue channel
2137  * @param alpha Alpha channel
2138  **/
2139 void Framebuffer::ClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2140 {
2141         const Functions& gl = m_context.getRenderContext().getFunctions();
2142
2143         ClearColor(gl, red, green, blue, alpha);
2144 }
2145
2146 /** Attach texture to specified attachment
2147  *
2148  * @param gl         GL functions
2149  * @param attachment Attachment
2150  * @param texture_id Texture id
2151  * @param width      Texture width
2152  * @param height     Texture height
2153  **/
2154 void Framebuffer::AttachTexture(const Functions& gl, GLenum attachment, GLuint texture_id, GLuint width, GLuint height)
2155 {
2156         gl.framebufferTexture(GL_DRAW_FRAMEBUFFER, attachment, texture_id, 0 /* level */);
2157         GLU_EXPECT_NO_ERROR(gl.getError(), "FramebufferTexture");
2158
2159         gl.viewport(0 /* x */, 0 /* y */, width, height);
2160         GLU_EXPECT_NO_ERROR(gl.getError(), "Viewport");
2161 }
2162
2163 /** Binds framebuffer to DRAW_FRAMEBUFFER
2164  *
2165  * @param gl GL functions
2166  * @param id ID of framebuffer
2167  **/
2168 void Framebuffer::Bind(const Functions& gl, GLuint id)
2169 {
2170         gl.bindFramebuffer(GL_DRAW_FRAMEBUFFER, id);
2171         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFramebuffer");
2172 }
2173
2174 /** Clear framebuffer
2175  *
2176  * @param gl   GL functions
2177  * @param mask <mask> parameter of glClear. Decides which shall be cleared
2178  **/
2179 void Framebuffer::Clear(const Functions& gl, GLenum mask)
2180 {
2181         gl.clear(mask);
2182         GLU_EXPECT_NO_ERROR(gl.getError(), "Clear");
2183 }
2184
2185 /** Specifies clear color
2186  *
2187  * @param gl    GL functions
2188  * @param red   Red channel
2189  * @param green Green channel
2190  * @param blue  Blue channel
2191  * @param alpha Alpha channel
2192  **/
2193 void Framebuffer::ClearColor(const Functions& gl, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
2194 {
2195         gl.clearColor(red, green, blue, alpha);
2196         GLU_EXPECT_NO_ERROR(gl.getError(), "ClearColor");
2197 }
2198
2199 /** Generate framebuffer
2200  *
2201  **/
2202 void Framebuffer::Generate(const Functions& gl, GLuint& out_id)
2203 {
2204         GLuint id = m_invalid_id;
2205
2206         gl.genFramebuffers(1, &id);
2207         GLU_EXPECT_NO_ERROR(gl.getError(), "GenFramebuffers");
2208
2209         if (m_invalid_id == id)
2210         {
2211                 TCU_FAIL("Invalid id");
2212         }
2213
2214         out_id = id;
2215 }
2216
2217 /* Shader's constants */
2218 const GLuint Shader::m_invalid_id = 0;
2219
2220 /** Constructor.
2221  *
2222  * @param context CTS context.
2223  **/
2224 Shader::Shader(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2225 {
2226         /* Nothing to be done here */
2227 }
2228
2229 /** Destructor
2230  *
2231  **/
2232 Shader::~Shader()
2233 {
2234         Release();
2235 }
2236
2237 /** Initialize shader instance
2238  *
2239  * @param stage  Shader stage
2240  * @param source Source code
2241  **/
2242 void Shader::Init(STAGES stage, const std::string& source)
2243 {
2244         if (true == source.empty())
2245         {
2246                 /* No source == no shader */
2247                 return;
2248         }
2249
2250         /* Delete any previous shader */
2251         Release();
2252
2253         /* Create, set source and compile */
2254         const Functions& gl = m_context.getRenderContext().getFunctions();
2255
2256         Create(gl, stage, m_id);
2257         Source(gl, m_id, source);
2258
2259         try
2260         {
2261                 Compile(gl, m_id);
2262         }
2263         catch (const CompilationException& exc)
2264         {
2265                 throw InvalidSourceException(exc.what(), source, stage);
2266         }
2267 }
2268
2269 /** Release shader instance
2270  *
2271  **/
2272 void Shader::Release()
2273 {
2274         if (m_invalid_id != m_id)
2275         {
2276                 const Functions& gl = m_context.getRenderContext().getFunctions();
2277
2278                 gl.deleteShader(m_id);
2279                 m_id = m_invalid_id;
2280         }
2281 }
2282
2283 /** Compile shader
2284  *
2285  * @param gl GL functions
2286  * @param id Shader id
2287  **/
2288 void Shader::Compile(const Functions& gl, GLuint id)
2289 {
2290         GLint status = GL_FALSE;
2291
2292         /* Compile */
2293         gl.compileShader(id);
2294         GLU_EXPECT_NO_ERROR(gl.getError(), "CompileShader");
2295
2296         /* Get compilation status */
2297         gl.getShaderiv(id, GL_COMPILE_STATUS, &status);
2298         GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2299
2300         /* Log compilation error */
2301         if (GL_TRUE != status)
2302         {
2303                 glw::GLint  length = 0;
2304                 std::string message;
2305
2306                 /* Error log length */
2307                 gl.getShaderiv(id, GL_INFO_LOG_LENGTH, &length);
2308                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderiv");
2309
2310                 /* Prepare storage */
2311                 message.resize(length, 0);
2312
2313                 /* Get error log */
2314                 gl.getShaderInfoLog(id, length, 0, &message[0]);
2315                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetShaderInfoLog");
2316
2317                 throw CompilationException(message.c_str());
2318         }
2319 }
2320
2321 /** Create shader
2322  *
2323  * @param gl     GL functions
2324  * @param stage  Shader stage
2325  * @param out_id Shader id
2326  **/
2327 void Shader::Create(const Functions& gl, STAGES stage, GLuint& out_id)
2328 {
2329         const GLenum shaderType = GetShaderStageGLenum(stage);
2330         const GLuint id                 = gl.createShader(shaderType);
2331         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateShader");
2332
2333         if (m_invalid_id == id)
2334         {
2335                 TCU_FAIL("Failed to create shader");
2336         }
2337
2338         out_id = id;
2339 }
2340
2341 /** Set shader's source code
2342  *
2343  * @param gl     GL functions
2344  * @param id     Shader id
2345  * @param source Shader source code
2346  **/
2347 void Shader::Source(const Functions& gl, GLuint id, const std::string& source)
2348 {
2349         const GLchar* code = source.c_str();
2350
2351         gl.shaderSource(id, 1 /* count */, &code, 0 /* lengths */);
2352         GLU_EXPECT_NO_ERROR(gl.getError(), "ShaderSource");
2353 }
2354
2355 /** Get GLenum repesenting shader stage
2356  *
2357  * @param stage Shader stage
2358  *
2359  * @return GLenum
2360  **/
2361 GLenum Shader::GetShaderStageGLenum(STAGES stage)
2362 {
2363         GLenum result = 0;
2364
2365         switch (stage)
2366         {
2367         case COMPUTE:
2368                 result = GL_COMPUTE_SHADER;
2369                 break;
2370         case FRAGMENT:
2371                 result = GL_FRAGMENT_SHADER;
2372                 break;
2373         case GEOMETRY:
2374                 result = GL_GEOMETRY_SHADER;
2375                 break;
2376         case TESS_CTRL:
2377                 result = GL_TESS_CONTROL_SHADER;
2378                 break;
2379         case TESS_EVAL:
2380                 result = GL_TESS_EVALUATION_SHADER;
2381                 break;
2382         case VERTEX:
2383                 result = GL_VERTEX_SHADER;
2384                 break;
2385         default:
2386                 TCU_FAIL("Invalid enum");
2387         }
2388
2389         return result;
2390 }
2391
2392 /** Get string representing name of shader stage
2393  *
2394  * @param stage Shader stage
2395  *
2396  * @return String with name of shader stage
2397  **/
2398 const glw::GLchar* Shader::GetStageName(STAGES stage)
2399 {
2400         const GLchar* result = 0;
2401
2402         switch (stage)
2403         {
2404         case COMPUTE:
2405                 result = "compute";
2406                 break;
2407         case VERTEX:
2408                 result = "vertex";
2409                 break;
2410         case TESS_CTRL:
2411                 result = "tessellation control";
2412                 break;
2413         case TESS_EVAL:
2414                 result = "tessellation evaluation";
2415                 break;
2416         case GEOMETRY:
2417                 result = "geometry";
2418                 break;
2419         case FRAGMENT:
2420                 result = "fragment";
2421                 break;
2422         default:
2423                 TCU_FAIL("Invalid enum");
2424         }
2425
2426         return result;
2427 }
2428
2429 /** Logs shader source
2430  *
2431  * @param context CTS context
2432  * @param source  Source of shader
2433  * @param stage   Shader stage
2434  **/
2435 void Shader::LogSource(deqp::Context& context, const std::string& source, STAGES stage)
2436 {
2437         /* Skip empty shaders */
2438         if (true == source.empty())
2439         {
2440                 return;
2441         }
2442
2443         context.getTestContext().getLog() << tcu::TestLog::Message
2444                                                                           << "Shader source. Stage: " << Shader::GetStageName(stage)
2445                                                                           << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(source);
2446 }
2447
2448 /** Constructor
2449  *
2450  * @param message Compilation error message
2451  **/
2452 Shader::CompilationException::CompilationException(const GLchar* message)
2453 {
2454         m_message = message;
2455 }
2456
2457 /** Returns error messages
2458  *
2459  * @return Compilation error message
2460  **/
2461 const char* Shader::CompilationException::what() const throw()
2462 {
2463         return m_message.c_str();
2464 }
2465
2466 /** Constructor
2467  *
2468  * @param message Compilation error message
2469  **/
2470 Shader::InvalidSourceException::InvalidSourceException(const GLchar* error_message, const std::string& source,
2471                                                                                                            STAGES stage)
2472         : m_message(error_message), m_source(source), m_stage(stage)
2473 {
2474 }
2475
2476 /** Returns error messages
2477  *
2478  * @return Compilation error message
2479  **/
2480 const char* Shader::InvalidSourceException::what() const throw()
2481 {
2482         return "Compilation error";
2483 }
2484
2485 /** Logs error message and shader sources **/
2486 void Shader::InvalidSourceException::log(deqp::Context& context) const
2487 {
2488         context.getTestContext().getLog() << tcu::TestLog::Message << "Failed to compile shader: " << m_message.c_str()
2489                                                                           << tcu::TestLog::EndMessage;
2490
2491         LogSource(context, m_source, m_stage);
2492 }
2493
2494 /* Program constants */
2495 const GLuint Pipeline::m_invalid_id = 0;
2496
2497 /** Constructor.
2498  *
2499  * @param context CTS context.
2500  **/
2501 Pipeline::Pipeline(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
2502 {
2503         /* Nothing to be done here */
2504 }
2505
2506 /** Destructor
2507  *
2508  **/
2509 Pipeline::~Pipeline()
2510 {
2511         Release();
2512 }
2513
2514 /** Initialize pipline object
2515  *
2516  **/
2517 void Pipeline::Init()
2518 {
2519         Release();
2520
2521         const Functions& gl = m_context.getRenderContext().getFunctions();
2522
2523         /* Generate */
2524         gl.genProgramPipelines(1, &m_id);
2525         GLU_EXPECT_NO_ERROR(gl.getError(), "GenProgramPipelines");
2526 }
2527
2528 /** Release pipeline object
2529  *
2530  **/
2531 void Pipeline::Release()
2532 {
2533         if (m_invalid_id != m_id)
2534         {
2535                 const Functions& gl = m_context.getRenderContext().getFunctions();
2536
2537                 /* Generate */
2538                 gl.deleteProgramPipelines(1, &m_id);
2539                 GLU_EXPECT_NO_ERROR(gl.getError(), "DeleteProgramPipelines");
2540
2541                 m_id = m_invalid_id;
2542         }
2543 }
2544
2545 /** Bind pipeline
2546  *
2547  **/
2548 void Pipeline::Bind()
2549 {
2550         const Functions& gl = m_context.getRenderContext().getFunctions();
2551
2552         Bind(gl, m_id);
2553 }
2554
2555 /** Set which stages should be active
2556  *
2557  * @param program_id Id of program
2558  * @param stages     Logical combination of enums representing stages
2559  **/
2560 void Pipeline::UseProgramStages(GLuint program_id, GLenum stages)
2561 {
2562         const Functions& gl = m_context.getRenderContext().getFunctions();
2563
2564         UseProgramStages(gl, m_id, program_id, stages);
2565 }
2566
2567 /** Bind pipeline
2568  *
2569  * @param gl Functiions
2570  * @param id Pipeline id
2571  **/
2572 void Pipeline::Bind(const Functions& gl, GLuint id)
2573 {
2574         gl.bindProgramPipeline(id);
2575         GLU_EXPECT_NO_ERROR(gl.getError(), "BindProgramPipeline");
2576 }
2577
2578 /** Set which stages should be active
2579  *
2580  * @param gl         Functiions
2581  * @param id         Pipeline id
2582  * @param program_id Id of program
2583  * @param stages     Logical combination of enums representing stages
2584  **/
2585 void Pipeline::UseProgramStages(const Functions& gl, GLuint id, GLuint program_id, GLenum stages)
2586 {
2587         gl.useProgramStages(id, stages, program_id);
2588         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgramStages");
2589 }
2590
2591 /* Program constants */
2592 const GLuint Program::m_invalid_id = 0;
2593
2594 /** Constructor.
2595  *
2596  * @param context CTS context.
2597  **/
2598 Program::Program(deqp::Context& context)
2599         : m_id(m_invalid_id)
2600         , m_compute(context)
2601         , m_fragment(context)
2602         , m_geometry(context)
2603         , m_tess_ctrl(context)
2604         , m_tess_eval(context)
2605         , m_vertex(context)
2606         , m_context(context)
2607 {
2608         /* Nothing to be done here */
2609 }
2610
2611 /** Destructor
2612  *
2613  **/
2614 Program::~Program()
2615 {
2616         Release();
2617 }
2618
2619 /** Initialize program instance
2620  *
2621  * @param compute_shader                    Compute shader source code
2622  * @param fragment_shader                   Fragment shader source code
2623  * @param geometry_shader                   Geometry shader source code
2624  * @param tessellation_control_shader       Tessellation control shader source code
2625  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2626  * @param vertex_shader                     Vertex shader source code
2627  * @param captured_varyings                 Vector of variables to be captured with transfrom feedback
2628  * @param capture_interleaved               Select mode of transform feedback (separate or interleaved)
2629  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2630  **/
2631 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2632                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2633                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2634                                    const NameVector& captured_varyings, bool capture_interleaved, bool is_separable)
2635 {
2636         /* Delete previous program */
2637         Release();
2638
2639         /* GL entry points */
2640         const Functions& gl = m_context.getRenderContext().getFunctions();
2641
2642         /* Initialize shaders */
2643         m_compute.Init(Shader::COMPUTE, compute_shader);
2644         m_fragment.Init(Shader::FRAGMENT, fragment_shader);
2645         m_geometry.Init(Shader::GEOMETRY, geometry_shader);
2646         m_tess_ctrl.Init(Shader::TESS_CTRL, tessellation_control_shader);
2647         m_tess_eval.Init(Shader::TESS_EVAL, tessellation_evaluation_shader);
2648         m_vertex.Init(Shader::VERTEX, vertex_shader);
2649
2650         /* Create program, set up transform feedback and attach shaders */
2651         Create(gl, m_id);
2652         Capture(gl, m_id, captured_varyings, capture_interleaved);
2653         Attach(gl, m_id, m_compute.m_id);
2654         Attach(gl, m_id, m_fragment.m_id);
2655         Attach(gl, m_id, m_geometry.m_id);
2656         Attach(gl, m_id, m_tess_ctrl.m_id);
2657         Attach(gl, m_id, m_tess_eval.m_id);
2658         Attach(gl, m_id, m_vertex.m_id);
2659
2660         /* Set separable parameter */
2661         if (true == is_separable)
2662         {
2663                 gl.programParameteri(m_id, GL_PROGRAM_SEPARABLE, GL_TRUE);
2664                 GLU_EXPECT_NO_ERROR(gl.getError(), "ProgramParameteri");
2665         }
2666
2667         try
2668         {
2669                 /* Link program */
2670                 Link(gl, m_id);
2671         }
2672         catch (const LinkageException& exc)
2673         {
2674                 throw BuildException(exc.what(), compute_shader, fragment_shader, geometry_shader, tessellation_control_shader,
2675                                                          tessellation_evaluation_shader, vertex_shader);
2676         }
2677 }
2678
2679 /** Initialize program instance
2680  *
2681  * @param compute_shader                    Compute shader source code
2682  * @param fragment_shader                   Fragment shader source code
2683  * @param geometry_shader                   Geometry shader source code
2684  * @param tessellation_control_shader       Tessellation control shader source code
2685  * @param tessellation_evaluation_shader    Tessellation evaluation shader source code
2686  * @param vertex_shader                     Vertex shader source code
2687  * @param is_separable                      Selects if monolithic or separable program should be built. Defaults to false
2688  **/
2689 void Program::Init(const std::string& compute_shader, const std::string& fragment_shader,
2690                                    const std::string& geometry_shader, const std::string& tessellation_control_shader,
2691                                    const std::string& tessellation_evaluation_shader, const std::string& vertex_shader,
2692                                    bool is_separable)
2693 {
2694         NameVector captured_varying;
2695
2696         Init(compute_shader, fragment_shader, geometry_shader, tessellation_control_shader, tessellation_evaluation_shader,
2697                  vertex_shader, captured_varying, true, is_separable);
2698 }
2699
2700 /** Release program instance
2701  *
2702  **/
2703 void Program::Release()
2704 {
2705         const Functions& gl = m_context.getRenderContext().getFunctions();
2706
2707         if (m_invalid_id != m_id)
2708         {
2709                 Use(gl, m_invalid_id);
2710
2711                 gl.deleteProgram(m_id);
2712                 m_id = m_invalid_id;
2713         }
2714
2715         m_compute.Release();
2716         m_fragment.Release();
2717         m_geometry.Release();
2718         m_tess_ctrl.Release();
2719         m_tess_eval.Release();
2720         m_vertex.Release();
2721 }
2722
2723 /** Get <pname> for a set of active uniforms
2724  *
2725  * @param count   Number of indices
2726  * @param indices Indices of uniforms
2727  * @param pname   Queired pname
2728  * @param params  Array that will be filled with values of parameters
2729  **/
2730 void Program::GetActiveUniformsiv(GLsizei count, const GLuint* indices, GLenum pname, GLint* params) const
2731 {
2732         const Functions& gl = m_context.getRenderContext().getFunctions();
2733
2734         GetActiveUniformsiv(gl, m_id, count, indices, pname, params);
2735 }
2736
2737 /** Get location of attribute
2738  *
2739  * @param name Name of attribute
2740  *
2741  * @return Result of query
2742  **/
2743 glw::GLint Program::GetAttribLocation(const std::string& name) const
2744 {
2745         const Functions& gl = m_context.getRenderContext().getFunctions();
2746
2747         return GetAttribLocation(gl, m_id, name);
2748 }
2749
2750 /** Query resource
2751  *
2752  * @param interface Interface to be queried
2753  * @param index     Index of resource
2754  * @param property  Property to be queried
2755  * @param buf_size  Size of <params> buffer
2756  * @param params    Results of query
2757  **/
2758 void Program::GetResource(GLenum interface, GLuint index, GLenum property, GLsizei buf_size, GLint* params) const
2759 {
2760         const Functions& gl = m_context.getRenderContext().getFunctions();
2761
2762         GetResource(gl, m_id, interface, index, property, buf_size, params);
2763 }
2764
2765 /** Query for index of resource
2766  *
2767  * @param name      Name of resource
2768  * @param interface Interface to be queried
2769  *
2770  * @return Result of query
2771  **/
2772 glw::GLuint Program::GetResourceIndex(const std::string& name, GLenum interface) const
2773 {
2774         const Functions& gl = m_context.getRenderContext().getFunctions();
2775
2776         return GetResourceIndex(gl, m_id, name, interface);
2777 }
2778
2779 /** Get indices for a set of uniforms
2780  *
2781  * @param count   Count number of uniforms
2782  * @param names   Names of uniforms
2783  * @param indices Buffer that will be filled with indices
2784  **/
2785 void Program::GetUniformIndices(GLsizei count, const GLchar** names, GLuint* indices) const
2786 {
2787         const Functions& gl = m_context.getRenderContext().getFunctions();
2788
2789         GetUniformIndices(gl, m_id, count, names, indices);
2790 }
2791
2792 /** Get uniform location
2793  *
2794  * @param name Name of uniform
2795  *
2796  * @return Results of query
2797  **/
2798 glw::GLint Program::GetUniformLocation(const std::string& name) const
2799 {
2800         const Functions& gl = m_context.getRenderContext().getFunctions();
2801
2802         return GetUniformLocation(gl, m_id, name);
2803 }
2804
2805 /** Set program as active
2806  *
2807  **/
2808 void Program::Use() const
2809 {
2810         const Functions& gl = m_context.getRenderContext().getFunctions();
2811
2812         Use(gl, m_id);
2813 }
2814
2815 /** Attach shader to program
2816  *
2817  * @param gl         GL functions
2818  * @param program_id Id of program
2819  * @param shader_id  Id of shader
2820  **/
2821 void Program::Attach(const Functions& gl, GLuint program_id, GLuint shader_id)
2822 {
2823         /* Sanity checks */
2824         if ((m_invalid_id == program_id) || (Shader::m_invalid_id == shader_id))
2825         {
2826                 return;
2827         }
2828
2829         gl.attachShader(program_id, shader_id);
2830         GLU_EXPECT_NO_ERROR(gl.getError(), "AttachShader");
2831 }
2832
2833 /** Set up captured varyings
2834  *
2835  * @param gl                  GL functions
2836  * @param id                  Id of program
2837  * @param captured_varyings   Vector of varyings
2838  * @param capture_interleaved Selects if interleaved or separate mode should be used
2839  **/
2840 void Program::Capture(const Functions& gl, GLuint id, const NameVector& captured_varyings, bool capture_interleaved)
2841 {
2842         const size_t n_varyings = captured_varyings.size();
2843
2844         if (0 == n_varyings)
2845         {
2846                 /* empty list, skip */
2847                 return;
2848         }
2849
2850         std::vector<const GLchar*> varying_names;
2851         varying_names.resize(n_varyings);
2852
2853         for (size_t i = 0; i < n_varyings; ++i)
2854         {
2855                 varying_names[i] = captured_varyings[i].c_str();
2856         }
2857
2858         GLenum mode = 0;
2859         if (true == capture_interleaved)
2860         {
2861                 mode = GL_INTERLEAVED_ATTRIBS;
2862         }
2863         else
2864         {
2865                 mode = GL_SEPARATE_ATTRIBS;
2866         }
2867
2868         gl.transformFeedbackVaryings(id, static_cast<GLsizei>(n_varyings), &varying_names[0], mode);
2869         GLU_EXPECT_NO_ERROR(gl.getError(), "TransformFeedbackVaryings");
2870 }
2871
2872 /** Create program instance
2873  *
2874  * @param gl     GL functions
2875  * @param out_id Id of program
2876  **/
2877 void Program::Create(const Functions& gl, GLuint& out_id)
2878 {
2879         const GLuint id = gl.createProgram();
2880         GLU_EXPECT_NO_ERROR(gl.getError(), "CreateProgram");
2881
2882         if (m_invalid_id == id)
2883         {
2884                 TCU_FAIL("Failed to create program");
2885         }
2886
2887         out_id = id;
2888 }
2889
2890 /** Get <pname> for a set of active uniforms
2891  *
2892  * @param gl         Functions
2893  * @param program_id Id of program
2894  * @param count      Number of indices
2895  * @param indices    Indices of uniforms
2896  * @param pname      Queired pname
2897  * @param params     Array that will be filled with values of parameters
2898  **/
2899 void Program::GetActiveUniformsiv(const Functions& gl, GLuint program_id, GLsizei count, const GLuint* indices,
2900                                                                   GLenum pname, GLint* params)
2901 {
2902         gl.getActiveUniformsiv(program_id, count, indices, pname, params);
2903         GLU_EXPECT_NO_ERROR(gl.getError(), "GetActiveUniformsiv");
2904 }
2905
2906 /** Get indices for a set of uniforms
2907  *
2908  * @param gl         Functions
2909  * @param program_id Id of program
2910  * @param count      Count number of uniforms
2911  * @param names      Names of uniforms
2912  * @param indices    Buffer that will be filled with indices
2913  **/
2914 void Program::GetUniformIndices(const Functions& gl, GLuint program_id, GLsizei count, const GLchar** names,
2915                                                                 GLuint* indices)
2916 {
2917         gl.getUniformIndices(program_id, count, names, indices);
2918         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformIndices");
2919 }
2920
2921 /** Link program
2922  *
2923  * @param gl GL functions
2924  * @param id Id of program
2925  **/
2926 void Program::Link(const Functions& gl, GLuint id)
2927 {
2928         GLint status = GL_FALSE;
2929
2930         gl.linkProgram(id);
2931         GLU_EXPECT_NO_ERROR(gl.getError(), "LinkProgram");
2932
2933         /* Get link status */
2934         gl.getProgramiv(id, GL_LINK_STATUS, &status);
2935         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2936
2937         /* Log link error */
2938         if (GL_TRUE != status)
2939         {
2940                 glw::GLint  length = 0;
2941                 std::string message;
2942
2943                 /* Get error log length */
2944                 gl.getProgramiv(id, GL_INFO_LOG_LENGTH, &length);
2945                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramiv");
2946
2947                 message.resize(length, 0);
2948
2949                 /* Get error log */
2950                 gl.getProgramInfoLog(id, length, 0, &message[0]);
2951                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramInfoLog");
2952
2953                 throw LinkageException(message.c_str());
2954         }
2955 }
2956
2957 /** Set generic uniform
2958  *
2959  * @param gl       Functions
2960  * @param type     Type of uniform
2961  * @param count    Length of array
2962  * @param location Location of uniform
2963  * @param data     Data that will be used
2964  **/
2965 void Program::Uniform(const Functions& gl, const Type& type, GLsizei count, GLint location, const GLvoid* data)
2966 {
2967         if (-1 == location)
2968         {
2969                 TCU_FAIL("Uniform is inactive");
2970         }
2971
2972         switch (type.m_basic_type)
2973         {
2974         case Type::Double:
2975                 if (1 == type.m_n_columns)
2976                 {
2977                         getUniformNdv(gl, type.m_n_rows)(location, count, (const GLdouble*)data);
2978                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNdv");
2979                 }
2980                 else
2981                 {
2982                         getUniformMatrixNdv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLdouble*)data);
2983                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNdv");
2984                 }
2985                 break;
2986         case Type::Float:
2987                 if (1 == type.m_n_columns)
2988                 {
2989                         getUniformNfv(gl, type.m_n_rows)(location, count, (const GLfloat*)data);
2990                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNfv");
2991                 }
2992                 else
2993                 {
2994                         getUniformMatrixNfv(gl, type.m_n_columns, type.m_n_rows)(location, count, false, (const GLfloat*)data);
2995                         GLU_EXPECT_NO_ERROR(gl.getError(), "UniformMatrixNfv");
2996                 }
2997                 break;
2998         case Type::Int:
2999                 getUniformNiv(gl, type.m_n_rows)(location, count, (const GLint*)data);
3000                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNiv");
3001                 break;
3002         case Type::Uint:
3003                 getUniformNuiv(gl, type.m_n_rows)(location, count, (const GLuint*)data);
3004                 GLU_EXPECT_NO_ERROR(gl.getError(), "UniformNuiv");
3005                 break;
3006         default:
3007                 TCU_FAIL("Invalid enum");
3008         }
3009 }
3010
3011 /** Use program
3012  *
3013  * @param gl GL functions
3014  * @param id Id of program
3015  **/
3016 void Program::Use(const Functions& gl, GLuint id)
3017 {
3018         gl.useProgram(id);
3019         GLU_EXPECT_NO_ERROR(gl.getError(), "UseProgram");
3020 }
3021
3022 /** Get location of attribute
3023  *
3024  * @param gl   GL functions
3025  * @param id   Id of program
3026  * @param name Name of attribute
3027  *
3028  * @return Location of attribute
3029  **/
3030 GLint Program::GetAttribLocation(const Functions& gl, GLuint id, const std::string& name)
3031 {
3032         GLint location = gl.getAttribLocation(id, name.c_str());
3033         GLU_EXPECT_NO_ERROR(gl.getError(), "GetAttribLocation");
3034
3035         return location;
3036 }
3037
3038 /** Query resource
3039  *
3040  * @param gl        GL functions
3041  * @param id        Id of program
3042  * @param interface Interface to be queried
3043  * @param index     Index of resource
3044  * @param property  Property to be queried
3045  * @param buf_size  Size of <params> buffer
3046  * @param params    Results of query
3047  **/
3048 void Program::GetResource(const Functions& gl, GLuint id, GLenum interface, GLuint index, GLenum property,
3049                                                   GLsizei buf_size, GLint* params)
3050 {
3051         gl.getProgramResourceiv(id, interface, index, 1 /* propCount */, &property, buf_size /* bufSize */, 0 /* length */,
3052                                                         params);
3053         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceiv");
3054 }
3055
3056 /** Get index of resource
3057  *
3058  * @param gl        GL functions
3059  * @param id        Id of program
3060  * @param name      Name of resource
3061  * @param interface Program interface to queried
3062  *
3063  * @return Location of attribute
3064  **/
3065 GLuint Program::GetResourceIndex(const Functions& gl, GLuint id, const std::string& name, GLenum interface)
3066 {
3067         GLuint index = gl.getProgramResourceIndex(id, interface, name.c_str());
3068         GLU_EXPECT_NO_ERROR(gl.getError(), "GetProgramResourceIndex");
3069
3070         return index;
3071 }
3072
3073 /** Get location of attribute
3074  *
3075  * @param gl   GL functions
3076  * @param id   Id of program
3077  * @param name Name of attribute
3078  *
3079  * @return Location of uniform
3080  **/
3081 GLint Program::GetUniformLocation(const Functions& gl, GLuint id, const std::string& name)
3082 {
3083         GLint location = gl.getUniformLocation(id, name.c_str());
3084         GLU_EXPECT_NO_ERROR(gl.getError(), "GetUniformLocation");
3085
3086         return location;
3087 }
3088
3089 /** Constructor
3090  *
3091  * @param error_message    Error message
3092  * @param compute_shader   Source code for compute stage
3093  * @param fragment_shader  Source code for fragment stage
3094  * @param geometry_shader  Source code for geometry stage
3095  * @param tess_ctrl_shader Source code for tessellation control stage
3096  * @param tess_eval_shader Source code for tessellation evaluation stage
3097  * @param vertex_shader    Source code for vertex stage
3098  **/
3099 Program::BuildException::BuildException(const glw::GLchar* error_message, const std::string compute_shader,
3100                                                                                 const std::string fragment_shader, const std::string geometry_shader,
3101                                                                                 const std::string tess_ctrl_shader, const std::string tess_eval_shader,
3102                                                                                 const std::string vertex_shader)
3103         : m_error_message(error_message)
3104         , m_compute_shader(compute_shader)
3105         , m_fragment_shader(fragment_shader)
3106         , m_geometry_shader(geometry_shader)
3107         , m_tess_ctrl_shader(tess_ctrl_shader)
3108         , m_tess_eval_shader(tess_eval_shader)
3109         , m_vertex_shader(vertex_shader)
3110 {
3111 }
3112
3113 /** Overwrites std::exception::what method
3114  *
3115  * @return Message compossed from error message and shader sources
3116  **/
3117 const char* Program::BuildException::what() const throw()
3118 {
3119         return "Failed to link program";
3120 }
3121
3122 /** Logs error message and shader sources **/
3123 void Program::BuildException::log(deqp::Context& context) const
3124 {
3125         context.getTestContext().getLog() << tcu::TestLog::Message << "Link failure: " << m_error_message
3126                                                                           << tcu::TestLog::EndMessage;
3127
3128         Shader::LogSource(context, m_vertex_shader, Shader::VERTEX);
3129         Shader::LogSource(context, m_tess_ctrl_shader, Shader::TESS_CTRL);
3130         Shader::LogSource(context, m_tess_eval_shader, Shader::TESS_EVAL);
3131         Shader::LogSource(context, m_geometry_shader, Shader::GEOMETRY);
3132         Shader::LogSource(context, m_fragment_shader, Shader::FRAGMENT);
3133         Shader::LogSource(context, m_compute_shader, Shader::COMPUTE);
3134 }
3135
3136 /** Constructor
3137  *
3138  * @param message Linking error message
3139  **/
3140 Program::LinkageException::LinkageException(const glw::GLchar* message) : m_error_message(message)
3141 {
3142         /* Nothing to be done */
3143 }
3144
3145 /** Returns error messages
3146  *
3147  * @return Linking error message
3148  **/
3149 const char* Program::LinkageException::what() const throw()
3150 {
3151         return m_error_message.c_str();
3152 }
3153
3154 /* Texture constants */
3155 const GLuint Texture::m_invalid_id = -1;
3156
3157 /** Constructor.
3158  *
3159  * @param context CTS context.
3160  **/
3161 Texture::Texture(deqp::Context& context) : m_id(m_invalid_id), m_context(context), m_type(TEX_2D)
3162 {
3163         /* Nothing to done here */
3164 }
3165
3166 /** Destructor
3167  *
3168  **/
3169 Texture::~Texture()
3170 {
3171         Release();
3172 }
3173
3174 /** Initialize texture instance
3175  *
3176  * @param tex_type        Type of texture
3177  * @param width           Width of texture
3178  * @param height          Height of texture
3179  * @param depth           Depth of texture
3180  * @param internal_format Internal format of texture
3181  * @param format          Format of texture data
3182  * @param type            Type of texture data
3183  * @param data            Texture data
3184  **/
3185 void Texture::Init(TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum internal_format, GLenum format,
3186                                    GLenum type, GLvoid* data)
3187 {
3188         const Functions& gl = m_context.getRenderContext().getFunctions();
3189
3190         /* Delete previous texture */
3191         Release();
3192
3193         m_type = tex_type;
3194
3195         /* Generate, bind, allocate storage and upload data */
3196         Generate(gl, m_id);
3197         Bind(gl, m_id, tex_type);
3198         Storage(gl, tex_type, width, height, depth, internal_format);
3199         Update(gl, tex_type, width, height, depth, format, type, data);
3200 }
3201
3202 /** Initialize buffer texture
3203  *
3204  * @param internal_format Internal format of texture
3205  * @param buffer_id       Id of buffer that will be used as data source
3206  **/
3207 void Texture::Init(GLenum internal_format, GLuint buffer_id)
3208 {
3209         const Functions& gl = m_context.getRenderContext().getFunctions();
3210
3211         /* Delete previous texture */
3212         Release();
3213
3214         m_type = TEX_BUFFER;
3215
3216         /* Generate, bind and attach buffer */
3217         Generate(gl, m_id);
3218         Bind(gl, m_id, TEX_BUFFER);
3219         TexBuffer(gl, buffer_id, internal_format);
3220 }
3221
3222 /** Release texture instance
3223  *
3224  **/
3225 void Texture::Release()
3226 {
3227         if (m_invalid_id != m_id)
3228         {
3229                 const Functions& gl = m_context.getRenderContext().getFunctions();
3230
3231                 gl.deleteTextures(1, &m_id);
3232                 m_id = m_invalid_id;
3233         }
3234 }
3235
3236 /** Bind texture to its target
3237  *
3238  **/
3239 void Texture::Bind() const
3240 {
3241         const Functions& gl = m_context.getRenderContext().getFunctions();
3242
3243         Bind(gl, m_id, m_type);
3244 }
3245
3246 /** Get texture data
3247  *
3248  * @param format   Format of data
3249  * @param type     Type of data
3250  * @param out_data Buffer for data
3251  **/
3252 void Texture::Get(GLenum format, GLenum type, GLvoid* out_data) const
3253 {
3254         const Functions& gl = m_context.getRenderContext().getFunctions();
3255
3256         Bind(gl, m_id, m_type);
3257         Get(gl, m_type, format, type, out_data);
3258 }
3259
3260 /** Bind texture to target
3261  *
3262  * @param gl       GL functions
3263  * @param id       Id of texture
3264  * @param tex_type Type of texture
3265  **/
3266 void Texture::Bind(const Functions& gl, GLuint id, TYPES tex_type)
3267 {
3268         GLenum target = GetTargetGLenum(tex_type);
3269
3270         gl.bindTexture(target, id);
3271         GLU_EXPECT_NO_ERROR(gl.getError(), "BindTexture");
3272 }
3273
3274 /** Generate texture instance
3275  *
3276  * @param gl     GL functions
3277  * @param out_id Id of texture
3278  **/
3279 void Texture::Generate(const Functions& gl, GLuint& out_id)
3280 {
3281         GLuint id = m_invalid_id;
3282
3283         gl.genTextures(1, &id);
3284         GLU_EXPECT_NO_ERROR(gl.getError(), "GenTextures");
3285
3286         if (m_invalid_id == id)
3287         {
3288                 TCU_FAIL("Invalid id");
3289         }
3290
3291         out_id = id;
3292 }
3293
3294 /** Get texture data
3295  *
3296  * @param gl       GL functions
3297  * @param format   Format of data
3298  * @param type     Type of data
3299  * @param out_data Buffer for data
3300  **/
3301 void Texture::Get(const Functions& gl, TYPES tex_type, GLenum format, GLenum type, GLvoid* out_data)
3302 {
3303         GLenum target = GetTargetGLenum(tex_type);
3304
3305         if (TEX_CUBE != tex_type)
3306         {
3307                 gl.getTexImage(target, 0 /* level */, format, type, out_data);
3308                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3309         }
3310         else
3311         {
3312                 GLint width;
3313                 GLint height;
3314
3315                 if ((GL_RGBA != format) && (GL_UNSIGNED_BYTE != type))
3316                 {
3317                         TCU_FAIL("Not implemented");
3318                 }
3319
3320                 GLuint texel_size = 4;
3321
3322                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_WIDTH, &width);
3323                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3324
3325                 gl.getTexLevelParameteriv(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, GL_TEXTURE_HEIGHT, &height);
3326                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexLevelParameteriv");
3327
3328                 const GLuint image_size = width * height * texel_size;
3329
3330                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 /* level */, format, type,
3331                                            (GLvoid*)((GLchar*)out_data + (image_size * 0)));
3332                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 /* level */, format, type,
3333                                            (GLvoid*)((GLchar*)out_data + (image_size * 1)));
3334                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 /* level */, format, type,
3335                                            (GLvoid*)((GLchar*)out_data + (image_size * 2)));
3336                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 /* level */, format, type,
3337                                            (GLvoid*)((GLchar*)out_data + (image_size * 3)));
3338                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 /* level */, format, type,
3339                                            (GLvoid*)((GLchar*)out_data + (image_size * 4)));
3340                 gl.getTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 /* level */, format, type,
3341                                            (GLvoid*)((GLchar*)out_data + (image_size * 5)));
3342                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetTexImage");
3343         }
3344 }
3345
3346 /** Allocate storage for texture
3347  *
3348  * @param gl              GL functions
3349  * @param tex_type        Type of texture
3350  * @param width           Width of texture
3351  * @param height          Height of texture
3352  * @param depth           Depth of texture
3353  * @param internal_format Internal format of texture
3354  **/
3355 void Texture::Storage(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth,
3356                                           GLenum internal_format)
3357 {
3358         static const GLuint levels = 1;
3359
3360         GLenum target = GetTargetGLenum(tex_type);
3361
3362         switch (tex_type)
3363         {
3364         case TEX_1D:
3365                 gl.texStorage1D(target, levels, internal_format, width);
3366                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3367                 break;
3368         case TEX_2D:
3369         case TEX_1D_ARRAY:
3370         case TEX_2D_RECT:
3371         case TEX_CUBE:
3372                 gl.texStorage2D(target, levels, internal_format, width, height);
3373                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3374                 break;
3375         case TEX_3D:
3376         case TEX_2D_ARRAY:
3377                 gl.texStorage3D(target, levels, internal_format, width, height, depth);
3378                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3379                 break;
3380         default:
3381                 TCU_FAIL("Invliad enum");
3382                 break;
3383         }
3384 }
3385
3386 /** Attach buffer as source of texture buffer data
3387  *
3388  * @param gl              GL functions
3389  * @param internal_format Internal format of texture
3390  * @param buffer_id       Id of buffer that will be used as data source
3391  **/
3392 void Texture::TexBuffer(const Functions& gl, GLenum internal_format, GLuint& buffer_id)
3393 {
3394         gl.texBuffer(GL_TEXTURE_BUFFER, internal_format, buffer_id);
3395         GLU_EXPECT_NO_ERROR(gl.getError(), "TexBuffer");
3396 }
3397
3398 /** Update contents of texture
3399  *
3400  * @param gl       GL functions
3401  * @param tex_type Type of texture
3402  * @param width    Width of texture
3403  * @param height   Height of texture
3404  * @param format   Format of data
3405  * @param type     Type of data
3406  * @param data     Buffer with image data
3407  **/
3408 void Texture::Update(const Functions& gl, TYPES tex_type, GLuint width, GLuint height, GLuint depth, GLenum format,
3409                                          GLenum type, GLvoid* data)
3410 {
3411         static const GLuint level = 0;
3412
3413         GLenum target = GetTargetGLenum(tex_type);
3414
3415         switch (tex_type)
3416         {
3417         case TEX_1D:
3418                 gl.texSubImage1D(target, level, 0 /* x */, width, format, type, data);
3419                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage1D");
3420                 break;
3421         case TEX_2D:
3422         case TEX_1D_ARRAY:
3423         case TEX_2D_RECT:
3424                 gl.texSubImage2D(target, level, 0 /* x */, 0 /* y */, width, height, format, type, data);
3425                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3426                 break;
3427         case TEX_CUBE:
3428                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3429                                                  data);
3430                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, level, 0 /* x */, 0 /* y */, width, height, format, type,
3431                                                  data);
3432                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3433                                                  data);
3434                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, level, 0 /* x */, 0 /* y */, width, height, format, type,
3435                                                  data);
3436                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3437                                                  data);
3438                 gl.texSubImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, level, 0 /* x */, 0 /* y */, width, height, format, type,
3439                                                  data);
3440                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage2D");
3441                 break;
3442         case TEX_3D:
3443         case TEX_2D_ARRAY:
3444                 gl.texSubImage3D(target, level, 0 /* x */, 0 /* y */, 0 /* z */, width, height, depth, format, type, data);
3445                 GLU_EXPECT_NO_ERROR(gl.getError(), "TexStorage3D");
3446                 break;
3447         default:
3448                 TCU_FAIL("Invliad enum");
3449                 break;
3450         }
3451 }
3452
3453 /** Get target for given texture type
3454  *
3455  * @param type Type of texture
3456  *
3457  * @return Target
3458  **/
3459 GLenum Texture::GetTargetGLenum(TYPES type)
3460 {
3461         GLenum result = 0;
3462
3463         switch (type)
3464         {
3465         case TEX_BUFFER:
3466                 result = GL_TEXTURE_BUFFER;
3467                 break;
3468         case TEX_2D:
3469                 result = GL_TEXTURE_2D;
3470                 break;
3471         case TEX_2D_RECT:
3472                 result = GL_TEXTURE_RECTANGLE;
3473                 break;
3474         case TEX_2D_ARRAY:
3475                 result = GL_TEXTURE_2D_ARRAY;
3476                 break;
3477         case TEX_3D:
3478                 result = GL_TEXTURE_3D;
3479                 break;
3480         case TEX_CUBE:
3481                 result = GL_TEXTURE_CUBE_MAP;
3482                 break;
3483         case TEX_1D:
3484                 result = GL_TEXTURE_1D;
3485                 break;
3486         case TEX_1D_ARRAY:
3487                 result = GL_TEXTURE_1D_ARRAY;
3488                 break;
3489         }
3490
3491         return result;
3492 }
3493
3494 /* VertexArray constants */
3495 const GLuint VertexArray::m_invalid_id = -1;
3496
3497 /** Constructor.
3498  *
3499  * @param context CTS context.
3500  **/
3501 VertexArray::VertexArray(deqp::Context& context) : m_id(m_invalid_id), m_context(context)
3502 {
3503 }
3504
3505 /** Destructor
3506  *
3507  **/
3508 VertexArray::~VertexArray()
3509 {
3510         Release();
3511 }
3512
3513 /** Initialize vertex array instance
3514  *
3515  **/
3516 void VertexArray::Init()
3517 {
3518         /* Delete previous instance */
3519         Release();
3520
3521         const Functions& gl = m_context.getRenderContext().getFunctions();
3522
3523         Generate(gl, m_id);
3524 }
3525
3526 /** Release vertex array object instance
3527  *
3528  **/
3529 void VertexArray::Release()
3530 {
3531         if (m_invalid_id != m_id)
3532         {
3533                 const Functions& gl = m_context.getRenderContext().getFunctions();
3534
3535                 gl.deleteVertexArrays(1, &m_id);
3536
3537                 m_id = m_invalid_id;
3538         }
3539 }
3540
3541 /** Set attribute in VAO
3542  *
3543  * @param index            Index of attribute
3544  * @param type             Type of attribute
3545  * @param n_array_elements Arary length
3546  * @param normalized       Selectis if values should be normalized
3547  * @param stride           Stride
3548  * @param pointer          Pointer to data, or offset in buffer
3549  **/
3550 void VertexArray::Attribute(GLuint index, const Type& type, GLuint n_array_elements, GLboolean normalized,
3551                                                         GLsizei stride, const GLvoid* pointer)
3552 {
3553         const Functions& gl = m_context.getRenderContext().getFunctions();
3554
3555         AttribPointer(gl, index, type, n_array_elements, normalized, stride, pointer);
3556         Enable(gl, index, type, n_array_elements);
3557 }
3558
3559 /** Binds Vertex array object
3560  *
3561  **/
3562 void VertexArray::Bind()
3563 {
3564         const Functions& gl = m_context.getRenderContext().getFunctions();
3565
3566         Bind(gl, m_id);
3567 }
3568
3569 /** Set attribute in VAO
3570  *
3571  * @param gl               Functions
3572  * @param index            Index of attribute
3573  * @param type             Type of attribute
3574  * @param n_array_elements Arary length
3575  * @param normalized       Selectis if values should be normalized
3576  * @param stride           Stride
3577  * @param pointer          Pointer to data, or offset in buffer
3578  **/
3579 void VertexArray::AttribPointer(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements,
3580                                                                 GLboolean normalized, GLsizei stride, const GLvoid* pointer)
3581 {
3582         const GLuint basic_type_size = Type::GetTypeSize(type.m_basic_type);
3583         const GLint  size                        = (GLint)type.m_n_rows;
3584         const GLuint column_size         = (GLuint)size * basic_type_size;
3585         const GLenum gl_type             = Type::GetTypeGLenum(type.m_basic_type);
3586
3587         GLuint offset = 0;
3588
3589         /* If attribute is not an array */
3590         if (0 == n_array_elements)
3591         {
3592                 n_array_elements = 1;
3593         }
3594
3595         /* For each element in array */
3596         for (GLuint element = 0; element < n_array_elements; ++element)
3597         {
3598                 /* For each column in matrix */
3599                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3600                 {
3601                         /* Calculate offset */
3602                         const GLvoid* ptr = (GLubyte*)pointer + offset;
3603
3604                         /* Set up attribute */
3605                         switch (type.m_basic_type)
3606                         {
3607                         case Type::Float:
3608                                 gl.vertexAttribPointer(index, size, gl_type, normalized, stride, ptr);
3609                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribPointer");
3610                                 break;
3611                         case Type::Int:
3612                         case Type::Uint:
3613                                 gl.vertexAttribIPointer(index, size, gl_type, stride, ptr);
3614                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribIPointer");
3615                                 break;
3616                         case Type::Double:
3617                                 gl.vertexAttribLPointer(index, size, gl_type, stride, ptr);
3618                                 GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribLPointer");
3619                                 break;
3620                         default:
3621                                 TCU_FAIL("Invalid enum");
3622                         }
3623
3624                         /* Next location */
3625                         offset += column_size;
3626                         index += 1;
3627                 }
3628         }
3629 }
3630
3631 /** Binds Vertex array object
3632  *
3633  * @param gl GL functions
3634  * @param id ID of vertex array object
3635  **/
3636 void VertexArray::Bind(const glw::Functions& gl, glw::GLuint id)
3637 {
3638         gl.bindVertexArray(id);
3639         GLU_EXPECT_NO_ERROR(gl.getError(), "BindVertexArray");
3640 }
3641
3642 /** Disable attribute in VAO
3643  *
3644  * @param gl               Functions
3645  * @param index            Index of attribute
3646  * @param type             Type of attribute
3647  * @param n_array_elements Arary length
3648  **/
3649 void VertexArray::Disable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3650 {
3651         /* If attribute is not an array */
3652         if (0 == n_array_elements)
3653         {
3654                 n_array_elements = 1;
3655         }
3656
3657         /* For each element in array */
3658         for (GLuint element = 0; element < n_array_elements; ++element)
3659         {
3660                 /* For each column in matrix */
3661                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3662                 {
3663                         /* Enable attribute array */
3664                         gl.disableVertexAttribArray(index);
3665                         GLU_EXPECT_NO_ERROR(gl.getError(), "DisableVertexAttribArray");
3666
3667                         /* Next location */
3668                         index += 1;
3669                 }
3670         }
3671 }
3672
3673 /** Set divisor for attribute
3674  *
3675  * @param gl               Functions
3676  * @param index            Index of attribute
3677  * @param divisor          New divisor value
3678  **/
3679 void VertexArray::Divisor(const Functions& gl, GLuint index, GLuint divisor)
3680 {
3681         gl.vertexAttribDivisor(index, divisor);
3682         GLU_EXPECT_NO_ERROR(gl.getError(), "VertexAttribDivisor");
3683 }
3684
3685 /** Enables attribute in VAO
3686  *
3687  * @param gl               Functions
3688  * @param index            Index of attribute
3689  * @param type             Type of attribute
3690  * @param n_array_elements Arary length
3691  **/
3692 void VertexArray::Enable(const Functions& gl, GLuint index, const Type& type, GLuint n_array_elements)
3693 {
3694         /* If attribute is not an array */
3695         if (0 == n_array_elements)
3696         {
3697                 n_array_elements = 1;
3698         }
3699
3700         /* For each element in array */
3701         for (GLuint element = 0; element < n_array_elements; ++element)
3702         {
3703                 /* For each column in matrix */
3704                 for (GLuint column = 1; column <= type.m_n_columns; ++column)
3705                 {
3706                         /* Enable attribute array */
3707                         gl.enableVertexAttribArray(index);
3708                         GLU_EXPECT_NO_ERROR(gl.getError(), "EnableVertexAttribArray");
3709
3710                         /* Next location */
3711                         index += 1;
3712                 }
3713         }
3714 }
3715
3716 /** Generates Vertex array object
3717  *
3718  * @param gl     GL functions
3719  * @param out_id ID of vertex array object
3720  **/
3721 void VertexArray::Generate(const glw::Functions& gl, glw::GLuint& out_id)
3722 {
3723         GLuint id = m_invalid_id;
3724
3725         gl.genVertexArrays(1, &id);
3726         GLU_EXPECT_NO_ERROR(gl.getError(), "GenVertexArrays");
3727
3728         if (m_invalid_id == id)
3729         {
3730                 TCU_FAIL("Invalid id");
3731         }
3732
3733         out_id = id;
3734 }
3735
3736 /* Constatns used by Variable */
3737 const GLint Variable::m_automatic_location = -1;
3738
3739 /** Copy constructor
3740  *
3741  **/
3742 Variable::Variable(const Variable& var)
3743         : m_data(var.m_data)
3744         , m_data_size(var.m_data_size)
3745         , m_descriptor(var.m_descriptor.m_name.c_str(), var.m_descriptor.m_qualifiers.c_str(),
3746                                    var.m_descriptor.m_expected_component, var.m_descriptor.m_expected_location,
3747                                    var.m_descriptor.m_builtin, var.m_descriptor.m_normalized, var.m_descriptor.m_n_array_elements,
3748                                    var.m_descriptor.m_expected_stride_of_element, var.m_descriptor.m_offset)
3749         , m_storage(var.m_storage)
3750 {
3751         m_descriptor.m_type = var.m_descriptor.m_type;
3752
3753         if (BUILTIN != var.m_descriptor.m_type)
3754         {
3755                 m_descriptor.m_interface = var.m_descriptor.m_interface;
3756         }
3757 }
3758
3759 /** Get code that defines variable
3760  *
3761  * @param flavour Provides info if variable is array or not
3762  *
3763  * @return String with code
3764  **/
3765 std::string Variable::GetDefinition(FLAVOUR flavour) const
3766 {
3767         return m_descriptor.GetDefinition(flavour, m_storage);
3768 }
3769
3770 /** Calcualtes stride of variable
3771  *
3772  * @return Calculated value
3773  **/
3774 GLuint Variable::GetStride() const
3775 {
3776         GLint variable_stride = 0;
3777
3778         if (0 == m_descriptor.m_n_array_elements)
3779         {
3780                 variable_stride = m_descriptor.m_expected_stride_of_element;
3781         }
3782         else
3783         {
3784                 variable_stride = m_descriptor.m_expected_stride_of_element * m_descriptor.m_n_array_elements;
3785         }
3786
3787         return variable_stride;
3788 }
3789
3790 /** Check if variable is block
3791  *
3792  * @return true if variable type is block, false otherwise
3793  **/
3794 bool Variable::IsBlock() const
3795 {
3796         if (BUILTIN == m_descriptor.m_type)
3797         {
3798                 return false;
3799         }
3800
3801         const Interface* interface = m_descriptor.m_interface;
3802         if (0 == interface)
3803         {
3804                 TCU_FAIL("Nullptr");
3805         }
3806
3807         return (Interface::BLOCK == interface->m_type);
3808 }
3809
3810 /** Check if variable is struct
3811  *
3812  * @return true if variable type is struct, false otherwise
3813  **/
3814 bool Variable::IsStruct() const
3815 {
3816         if (BUILTIN == m_descriptor.m_type)
3817         {
3818                 return false;
3819         }
3820
3821         const Interface* interface = m_descriptor.m_interface;
3822         if (0 == interface)
3823         {
3824                 TCU_FAIL("Nullptr");
3825         }
3826
3827         return (Interface::STRUCT == interface->m_type);
3828 }
3829 /** Get code that reference variable
3830  *
3831  * @param parent_name Name of parent
3832  * @param variable    Descriptor of variable
3833  * @param flavour     Provides info about how variable should be referenced
3834  * @param array_index Index of array, ignored when variable is not array
3835  *
3836  * @return String with code
3837  **/
3838 std::string Variable::GetReference(const std::string& parent_name, const Descriptor& variable, FLAVOUR flavour,
3839                                                                    GLuint array_index)
3840 {
3841         std::string name;
3842
3843         /* Prepare name */
3844         if (false == parent_name.empty())
3845         {
3846                 name = parent_name;
3847                 name.append(".");
3848                 name.append(variable.m_name);
3849         }
3850         else
3851         {
3852                 name = variable.m_name;
3853         }
3854
3855         /* */
3856         switch (flavour)
3857         {
3858         case Utils::Variable::BASIC:
3859                 break;
3860
3861         case Utils::Variable::ARRAY:
3862                 name.append("[0]");
3863                 break;
3864
3865         case Utils::Variable::INDEXED_BY_INVOCATION_ID:
3866                 name.append("[gl_InvocationID]");
3867                 break;
3868         }
3869
3870         /* Assumption that both variables have same lengths */
3871         if (0 != variable.m_n_array_elements)
3872         {
3873                 GLchar buffer[16];
3874                 sprintf(buffer, "%d", array_index);
3875                 name.append("[");
3876                 name.append(buffer);
3877                 name.append("]");
3878         }
3879
3880         return name;
3881 }
3882
3883 /** Get "flavour" of varying
3884  *
3885  * @param stage     Stage of shader
3886  * @param direction Selects if varying is in or out
3887  *
3888  * @return Flavour
3889  **/
3890 Variable::FLAVOUR Variable::GetFlavour(Shader::STAGES stage, VARYING_DIRECTION direction)
3891 {
3892         FLAVOUR result = BASIC;
3893
3894         switch (stage)
3895         {
3896         case Shader::GEOMETRY:
3897         case Shader::TESS_EVAL:
3898                 if (INPUT == direction)
3899                 {
3900                         result = ARRAY;
3901                 }
3902                 break;
3903         case Shader::TESS_CTRL:
3904                 result = INDEXED_BY_INVOCATION_ID;
3905                 break;
3906         default:
3907                 break;
3908         }
3909
3910         return result;
3911 }
3912
3913 /** Constructor, for built-in types
3914  *
3915  * @param name                       Name
3916  * @param qualifiers                 Qualifiers
3917  * @param expected_component         Expected component of variable
3918  * @param expected_location          Expected location
3919  * @param type                       Type
3920  * @param normalized                 Selects if data should be normalized
3921  * @param n_array_elements           Length of array
3922  * @param expected_stride_of_element Expected stride of element
3923  * @param offset                     Offset
3924  **/
3925 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
3926                                                                  GLint expected_location, const Type& type, GLboolean normalized,
3927                                                                  GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
3928         : m_expected_component(expected_component)
3929         , m_expected_location(expected_location)
3930         , m_expected_stride_of_element(expected_stride_of_element)
3931         , m_n_array_elements(n_array_elements)
3932         , m_name(name)
3933         , m_normalized(normalized)
3934         , m_offset(offset)
3935         , m_qualifiers(qualifiers)
3936         , m_type(BUILTIN)
3937         , m_builtin(type)
3938 {
3939 }
3940
3941 /** Constructor, for interface types
3942  *
3943  * @param name                       Name
3944  * @param qualifiers                 Qualifiers
3945  * @param expected_component         Expected component of variable
3946  * @param expected_location          Expected location
3947  * @param interface                  Interface of variable
3948  * @param n_array_elements           Length of array
3949  * @param expected_stride_of_element Expected stride of element
3950  * @param offset                     Offset
3951  **/
3952 Variable::Descriptor::Descriptor(const GLchar* name, const GLchar* qualifiers, GLint expected_componenet,
3953                                                                  GLint expected_location, Interface* interface, GLuint n_array_elements,
3954                                                                  GLint expected_stride_of_element, GLuint offset)
3955         : m_expected_component(expected_componenet)
3956         , m_expected_location(expected_location)
3957         , m_expected_stride_of_element(expected_stride_of_element)
3958         , m_n_array_elements(n_array_elements)
3959         , m_name(name)
3960         , m_normalized(GL_FALSE)
3961         , m_offset(offset)
3962         , m_qualifiers(qualifiers)
3963         , m_type(INTERFACE)
3964         , m_interface(interface)
3965 {
3966 }
3967
3968 /** Get definition of variable
3969  *
3970  * @param flavour Flavour of variable
3971  * @param storage Storage used for variable
3972  *
3973  * @return code with defintion
3974  **/
3975 std::string Variable::Descriptor::GetDefinition(FLAVOUR flavour, STORAGE storage) const
3976 {
3977         static const GLchar* basic_template = "QUALIFIERS STORAGETYPE NAMEARRAY;";
3978         static const GLchar* array_template = "QUALIFIERS STORAGETYPE NAME[]ARRAY;";
3979         const GLchar*            storage_str    = 0;
3980
3981         std::string definition;
3982         size_t          position = 0;
3983
3984         /* Select definition template */
3985         switch (flavour)
3986         {
3987         case BASIC:
3988                 definition = basic_template;
3989                 break;
3990         case ARRAY:
3991         case INDEXED_BY_INVOCATION_ID:
3992                 definition = array_template;
3993                 break;
3994         default:
3995                 TCU_FAIL("Invliad enum");
3996                 break;
3997         }
3998
3999         if (BUILTIN != m_type)
4000         {
4001                 if (0 == m_interface)
4002                 {
4003                         TCU_FAIL("Nullptr");
4004                 }
4005         }
4006
4007         /* Qualifiers */
4008         if (true == m_qualifiers.empty())
4009         {
4010                 replaceToken("QUALIFIERS ", position, "", definition);
4011         }
4012         else
4013         {
4014                 replaceToken("QUALIFIERS", position, m_qualifiers.c_str(), definition);
4015         }
4016
4017         // According to spec: integer or unsigned integer type must always be declared with flat qualifier
4018         bool flat_qualifier = false;
4019         if (m_type != BUILTIN && m_interface != NULL)
4020         {
4021                 if (m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Int ||
4022                         m_interface->m_members[0].m_builtin.m_basic_type == Utils::Type::Uint)
4023                 {
4024                         flat_qualifier = true;
4025                 }
4026         }
4027         /* Storage */
4028         switch (storage)
4029         {
4030         case VARYING_INPUT:
4031                 storage_str = flat_qualifier ? "flat in " : "in ";
4032                 break;
4033         case VARYING_OUTPUT:
4034                 storage_str = "out ";
4035                 break;
4036         case UNIFORM:
4037                 storage_str = "uniform ";
4038                 break;
4039         case SSB:
4040                 storage_str = "buffer ";
4041                 break;
4042         case MEMBER:
4043                 storage_str = "";
4044                 break;
4045         default:
4046                 TCU_FAIL("Invalid enum");
4047                 break;
4048         }
4049
4050         replaceToken("STORAGE", position, storage_str, definition);
4051
4052         /* Type */
4053         if (BUILTIN == m_type)
4054         {
4055                 replaceToken("TYPE", position, m_builtin.GetGLSLTypeName(), definition);
4056         }
4057         else
4058         {
4059                 if (Interface::STRUCT == m_interface->m_type)
4060                 {
4061                         replaceToken("TYPE", position, m_interface->m_name.c_str(), definition);
4062                 }
4063                 else
4064                 {
4065                         const std::string& block_definition = m_interface->GetDefinition();
4066
4067                         replaceToken("TYPE", position, block_definition.c_str(), definition);
4068                 }
4069         }
4070
4071         /* Name */
4072         replaceToken("NAME", position, m_name.c_str(), definition);
4073
4074         /* Array size */
4075         if (0 == m_n_array_elements)
4076         {
4077                 replaceToken("ARRAY", position, "", definition);
4078         }
4079         else
4080         {
4081                 char buffer[16];
4082                 sprintf(buffer, "[%d]", m_n_array_elements);
4083
4084                 replaceToken("ARRAY", position, buffer, definition);
4085         }
4086
4087         /* Done */
4088         return definition;
4089 }
4090
4091 /** Get definitions for variables collected in vector
4092  *
4093  * @param vector  Collection of variables
4094  * @param flavour Flavour of variables
4095  *
4096  * @return Code with definitions
4097  **/
4098 std::string GetDefinitions(const Variable::PtrVector& vector, Variable::FLAVOUR flavour)
4099 {
4100         std::string list         = Utils::g_list;
4101         size_t          position = 0;
4102
4103         for (GLuint i = 0; i < vector.size(); ++i)
4104         {
4105                 Utils::insertElementOfList(vector[i]->GetDefinition(flavour).c_str(), "\n", position, list);
4106         }
4107
4108         Utils::endList("", position, list);
4109
4110         return list;
4111 }
4112
4113 /** Get definitions for interfaces collected in vector
4114  *
4115  * @param vector Collection of interfaces
4116  *
4117  * @return Code with definitions
4118  **/
4119 std::string GetDefinitions(const Interface::PtrVector& vector)
4120 {
4121         std::string list         = Utils::g_list;
4122         size_t          position = 0;
4123
4124         for (GLuint i = 0; i < vector.size(); ++i)
4125         {
4126                 Utils::insertElementOfList(vector[i]->GetDefinition().c_str(), "\n", position, list);
4127         }
4128
4129         Utils::endList("", position, list);
4130
4131         return list;
4132 }
4133
4134 /** Constructor
4135  *
4136  * @param name Name
4137  * @param type Type of interface
4138  **/
4139 Interface::Interface(const GLchar* name, Interface::TYPE type) : m_name(name), m_type(type)
4140 {
4141 }
4142
4143 /** Adds member to interface
4144  *
4145  * @param member Descriptor of new member
4146  *
4147  * @return Pointer to just created member
4148  **/
4149 Variable::Descriptor* Interface::AddMember(const Variable::Descriptor& member)
4150 {
4151         m_members.push_back(member);
4152
4153         return &m_members.back();
4154 }
4155
4156 /** Get definition of interface
4157  *
4158  * @param Code with definition
4159  **/
4160 std::string Interface::GetDefinition() const
4161 {
4162         std::string definition;
4163         size_t          position = 0;
4164
4165         const GLchar* member_list = "    MEMBER_DEFINITION\nMEMBER_LIST";
4166
4167         if (STRUCT == m_type)
4168         {
4169                 definition = "struct NAME {\nMEMBER_LIST};";
4170         }
4171         else
4172         {
4173                 definition = "NAME {\nMEMBER_LIST}";
4174         }
4175
4176         /* Name */
4177         replaceToken("NAME", position, m_name.c_str(), definition);
4178
4179         /* Member list */
4180         for (GLuint i = 0; i < m_members.size(); ++i)
4181         {
4182                 const size_t       start_position       = position;
4183                 const std::string& member_definition = m_members[i].GetDefinition(Variable::BASIC, Variable::MEMBER);
4184
4185                 /* Member list */
4186                 replaceToken("MEMBER_LIST", position, member_list, definition);
4187
4188                 /* Move back position */
4189                 position = start_position;
4190
4191                 /* Member definition */
4192                 replaceToken("MEMBER_DEFINITION", position, member_definition.c_str(), definition);
4193         }
4194
4195         /* Remove last member list */
4196         replaceToken("MEMBER_LIST", position, "", definition);
4197
4198         /* Done */
4199         return definition;
4200 }
4201
4202 /** Adds member of built-in type to interface
4203  *
4204  * @param name                       Name
4205  * @param qualifiers                 Qualifiers
4206  * @param expected_component         Expected component of variable
4207  * @param expected_location          Expected location
4208  * @param type                       Type
4209  * @param normalized                 Selects if data should be normalized
4210  * @param n_array_elements           Length of array
4211  * @param expected_stride_of_element Expected stride of element
4212  * @param offset                     Offset
4213  *
4214  * @return Pointer to just created member
4215  **/
4216 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4217                                                                                 GLint expected_location, const Type& type, GLboolean normalized,
4218                                                                                 GLuint n_array_elements, GLint expected_stride_of_element, GLuint offset)
4219 {
4220         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, type, normalized,
4221                                                                                   n_array_elements, expected_stride_of_element, offset));
4222 }
4223
4224 /** Adds member of interface type to interface
4225  *
4226  * @param name                       Name
4227  * @param qualifiers                 Qualifiers
4228  * @param expected_component         Expected component of variable
4229  * @param expected_location          Expected location
4230  * @param type                       Type
4231  * @param normalized                 Selects if data should be normalized
4232  * @param n_array_elements           Length of array
4233  * @param expected_stride_of_element Expected stride of element
4234  * @param offset                     Offset
4235  *
4236  * @return Pointer to just created member
4237  **/
4238 Variable::Descriptor* Interface::Member(const GLchar* name, const GLchar* qualifiers, GLint expected_component,
4239                                                                                 GLint expected_location, Interface* nterface, GLuint n_array_elements,
4240                                                                                 GLint expected_stride_of_element, GLuint offset)
4241 {
4242         return AddMember(Variable::Descriptor(name, qualifiers, expected_component, expected_location, nterface,
4243                                                                                   n_array_elements, expected_stride_of_element, offset));
4244 }
4245
4246 /** Clears contents of vector of pointers
4247  *
4248  * @tparam T Type of elements
4249  *
4250  * @param vector Collection to be cleared
4251  **/
4252 template <typename T>
4253 void clearPtrVector(std::vector<T*>& vector)
4254 {
4255         for (size_t i = 0; i < vector.size(); ++i)
4256         {
4257                 T* t = vector[i];
4258
4259                 vector[i] = 0;
4260
4261                 if (0 != t)
4262                 {
4263                         delete t;
4264                 }
4265         }
4266
4267         vector.clear();
4268 }
4269
4270 /** Constructor
4271  *
4272  * @param stage Stage described by that interface
4273  **/
4274 ShaderInterface::ShaderInterface(Shader::STAGES stage) : m_stage(stage)
4275 {
4276         /* Nothing to be done */
4277 }
4278
4279 /** Get definitions of globals
4280  *
4281  * @return Code with definitions
4282  **/
4283 std::string ShaderInterface::GetDefinitionsGlobals() const
4284 {
4285         return m_globals;
4286 }
4287
4288 /** Get definitions of inputs
4289  *
4290  * @return Code with definitions
4291  **/
4292 std::string ShaderInterface::GetDefinitionsInputs() const
4293 {
4294         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::INPUT);
4295
4296         return GetDefinitions(m_inputs, flavour);
4297 }
4298
4299 /** Get definitions of outputs
4300  *
4301  * @return Code with definitions
4302  **/
4303 std::string ShaderInterface::GetDefinitionsOutputs() const
4304 {
4305         Variable::FLAVOUR flavour = Variable::GetFlavour(m_stage, Variable::OUTPUT);
4306
4307         return GetDefinitions(m_outputs, flavour);
4308 }
4309
4310 /** Get definitions of buffers
4311  *
4312  * @return Code with definitions
4313  **/
4314 std::string ShaderInterface::GetDefinitionsSSBs() const
4315 {
4316         return GetDefinitions(m_ssb_blocks, Variable::BASIC);
4317 }
4318
4319 /** Get definitions of uniforms
4320  *
4321  * @return Code with definitions
4322  **/
4323 std::string ShaderInterface::GetDefinitionsUniforms() const
4324 {
4325         return GetDefinitions(m_uniforms, Variable::BASIC);
4326 }
4327
4328 /** Constructor
4329  *
4330  * @param in  Input variable
4331  * @param out Output variable
4332  **/
4333 VaryingConnection::VaryingConnection(Variable* in, Variable* out) : m_in(in), m_out(out)
4334 {
4335         /* NBothing to be done here */
4336 }
4337
4338 /** Adds new varying connection to given stage
4339  *
4340  * @param stage Shader stage
4341  * @param in    In varying
4342  * @param out   Out varying
4343  **/
4344 void VaryingPassthrough::Add(Shader::STAGES stage, Variable* in, Variable* out)
4345 {
4346         VaryingConnection::Vector& vector = Get(stage);
4347
4348         vector.push_back(VaryingConnection(in, out));
4349 }
4350
4351 /** Get all passthrough connections for given stage
4352  *
4353  * @param stage Shader stage
4354  *
4355  * @return Vector of connections
4356  **/
4357 VaryingConnection::Vector& VaryingPassthrough::Get(Shader::STAGES stage)
4358 {
4359         VaryingConnection::Vector* result = 0;
4360
4361         switch (stage)
4362         {
4363         case Shader::FRAGMENT:
4364                 result = &m_fragment;
4365                 break;
4366         case Shader::GEOMETRY:
4367                 result = &m_geometry;
4368                 break;
4369         case Shader::TESS_CTRL:
4370                 result = &m_tess_ctrl;
4371                 break;
4372         case Shader::TESS_EVAL:
4373                 result = &m_tess_eval;
4374                 break;
4375         case Shader::VERTEX:
4376                 result = &m_vertex;
4377                 break;
4378         default:
4379                 TCU_FAIL("Invalid enum");
4380         }
4381
4382         return *result;
4383 }
4384
4385 /** Constructor
4386  *
4387  **/
4388 ProgramInterface::ProgramInterface()
4389         : m_compute(Shader::COMPUTE)
4390         , m_vertex(Shader::VERTEX)
4391         , m_tess_ctrl(Shader::TESS_CTRL)
4392         , m_tess_eval(Shader::TESS_EVAL)
4393         , m_geometry(Shader::GEOMETRY)
4394         , m_fragment(Shader::FRAGMENT)
4395 {
4396 }
4397
4398 /** Destructor
4399  *
4400  **/
4401 ProgramInterface::~ProgramInterface()
4402 {
4403         clearPtrVector(m_blocks);
4404         clearPtrVector(m_structures);
4405 }
4406
4407 /** Adds new interface
4408  *
4409  * @param name
4410  * @param type
4411  *
4412  * @return Pointer to created interface
4413  **/
4414 Interface* ProgramInterface::AddInterface(const GLchar* name, Interface::TYPE type)
4415 {
4416         Interface* interface = 0;
4417
4418         if (Interface::STRUCT == type)
4419         {
4420                 interface = new Interface(name, type);
4421
4422                 m_structures.push_back(interface);
4423         }
4424         else
4425         {
4426                 interface = new Interface(name, type);
4427
4428                 m_blocks.push_back(interface);
4429         }
4430
4431         return interface;
4432 }
4433
4434 /** Adds new block interface
4435  *
4436  * @param name
4437  *
4438  * @return Pointer to created interface
4439  **/
4440 Interface* ProgramInterface::Block(const GLchar* name)
4441 {
4442         return AddInterface(name, Interface::BLOCK);
4443 }
4444
4445 /** Get interface of given shader stage
4446  *
4447  * @param stage Shader stage
4448  *
4449  * @return Reference to stage interface
4450  **/
4451 ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage)
4452 {
4453         ShaderInterface* interface = 0;
4454
4455         switch (stage)
4456         {
4457         case Shader::COMPUTE:
4458                 interface = &m_compute;
4459                 break;
4460         case Shader::FRAGMENT:
4461                 interface = &m_fragment;
4462                 break;
4463         case Shader::GEOMETRY:
4464                 interface = &m_geometry;
4465                 break;
4466         case Shader::TESS_CTRL:
4467                 interface = &m_tess_ctrl;
4468                 break;
4469         case Shader::TESS_EVAL:
4470                 interface = &m_tess_eval;
4471                 break;
4472         case Shader::VERTEX:
4473                 interface = &m_vertex;
4474                 break;
4475         default:
4476                 TCU_FAIL("Invalid enum");
4477         }
4478
4479         return *interface;
4480 }
4481
4482 /** Get interface of given shader stage
4483  *
4484  * @param stage Shader stage
4485  *
4486  * @return Reference to stage interface
4487  **/
4488 const ShaderInterface& ProgramInterface::GetShaderInterface(Shader::STAGES stage) const
4489 {
4490         const ShaderInterface* interface = 0;
4491
4492         switch (stage)
4493         {
4494         case Shader::COMPUTE:
4495                 interface = &m_compute;
4496                 break;
4497         case Shader::FRAGMENT:
4498                 interface = &m_fragment;
4499                 break;
4500         case Shader::GEOMETRY:
4501                 interface = &m_geometry;
4502                 break;
4503         case Shader::TESS_CTRL:
4504                 interface = &m_tess_ctrl;
4505                 break;
4506         case Shader::TESS_EVAL:
4507                 interface = &m_tess_eval;
4508                 break;
4509         case Shader::VERTEX:
4510                 interface = &m_vertex;
4511                 break;
4512         default:
4513                 TCU_FAIL("Invalid enum");
4514         }
4515
4516         return *interface;
4517 }
4518
4519 /** Clone interface of Vertex shader stage to other stages
4520  * It creates matching inputs, outputs, uniforms and buffers in other stages.
4521  * There are no additional outputs for FRAGMENT shader generated.
4522  *
4523  * @param varying_passthrough Collection of varyings connections
4524  **/
4525 void ProgramInterface::CloneVertexInterface(VaryingPassthrough& varying_passthrough)
4526 {
4527         /* VS outputs >> TCS inputs >> TCS outputs >> ..  >> FS inputs */
4528         for (size_t i = 0; i < m_vertex.m_outputs.size(); ++i)
4529         {
4530                 const Variable& vs_var = *m_vertex.m_outputs[i];
4531                 const GLchar*   prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4532
4533                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4534                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4535                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4536                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4537         }
4538
4539         /* Copy uniforms from VS to other stages */
4540         for (size_t i = 0; i < m_vertex.m_uniforms.size(); ++i)
4541         {
4542                 Variable&        vs_var = *m_vertex.m_uniforms[i];
4543                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4544
4545                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4546                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4547                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4548                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4549                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4550
4551                 /* Uniform blocks needs unique binding */
4552                 if (true == vs_var.IsBlock())
4553                 {
4554                         replaceBinding(vs_var, Shader::VERTEX);
4555                 }
4556         }
4557
4558         /* Copy SSBs from VS to other stages */
4559         for (size_t i = 0; i < m_vertex.m_ssb_blocks.size(); ++i)
4560         {
4561                 Variable&        vs_var = *m_vertex.m_ssb_blocks[i];
4562                 const GLchar* prefix = GetStagePrefix(Shader::VERTEX, vs_var.m_storage);
4563
4564                 cloneVariableForStage(vs_var, Shader::COMPUTE, prefix, varying_passthrough);
4565                 cloneVariableForStage(vs_var, Shader::TESS_CTRL, prefix, varying_passthrough);
4566                 cloneVariableForStage(vs_var, Shader::TESS_EVAL, prefix, varying_passthrough);
4567                 cloneVariableForStage(vs_var, Shader::GEOMETRY, prefix, varying_passthrough);
4568                 cloneVariableForStage(vs_var, Shader::FRAGMENT, prefix, varying_passthrough);
4569
4570                 /* SSBs blocks needs unique binding */
4571                 if (true == vs_var.IsBlock())
4572                 {
4573                         replaceBinding(vs_var, Shader::VERTEX);
4574                 }
4575         }
4576
4577         m_compute.m_globals   = m_vertex.m_globals;
4578         m_fragment.m_globals  = m_vertex.m_globals;
4579         m_geometry.m_globals  = m_vertex.m_globals;
4580         m_tess_ctrl.m_globals = m_vertex.m_globals;
4581         m_tess_eval.m_globals = m_vertex.m_globals;
4582 }
4583
4584 /** Clone variable for specific stage
4585  *
4586  * @param variable            Variable
4587  * @param stage               Requested stage
4588  * @param prefix              Prefix used in variable name that is specific for original stage
4589  * @param varying_passthrough Collection of varyings connections
4590  **/
4591 void ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage, const GLchar* prefix,
4592                                                                                          VaryingPassthrough& varying_passthrough)
4593 {
4594         switch (variable.m_storage)
4595         {
4596         case Variable::VARYING_OUTPUT:
4597         {
4598                 Variable* in = cloneVariableForStage(variable, stage, Variable::VARYING_INPUT, prefix);
4599
4600                 if (Shader::FRAGMENT != stage)
4601                 {
4602                         Variable* out = cloneVariableForStage(variable, stage, Variable::VARYING_OUTPUT, prefix);
4603                         varying_passthrough.Add(stage, in, out);
4604                 }
4605         }
4606         break;
4607         case Variable::UNIFORM:
4608         case Variable::SSB:
4609                 cloneVariableForStage(variable, stage, variable.m_storage, prefix);
4610                 break;
4611         default:
4612                 TCU_FAIL("Invalid enum");
4613                 break;
4614         }
4615 }
4616
4617 /** Clone variable for specific stage
4618  *
4619  * @param variable Variable
4620  * @param stage    Requested stage
4621  * @param storage  Storage used by variable
4622  * @param prefix   Prefix used in variable name that is specific for original stage
4623  *
4624  * @return New variable
4625  **/
4626 Variable* ProgramInterface::cloneVariableForStage(const Variable& variable, Shader::STAGES stage,
4627                                                                                                   Variable::STORAGE storage, const GLchar* prefix)
4628 {
4629         /* Initialize with original variable */
4630         Variable* var = new Variable(variable);
4631         if (0 == var)
4632         {
4633                 TCU_FAIL("Memory allocation");
4634         }
4635
4636         /* Set up storage */
4637         var->m_storage = storage;
4638
4639         /* Get name */
4640         std::string name = variable.m_descriptor.m_name;
4641
4642         /* Prefix name with stage ID, empty means default block */
4643         if (false == name.empty())
4644         {
4645                 size_t            position       = 0;
4646                 const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4647                 Utils::replaceToken(prefix, position, stage_prefix, name);
4648         }
4649         var->m_descriptor.m_name = name;
4650
4651         /* Clone block */
4652         const bool is_block = variable.IsBlock();
4653         if (true == is_block)
4654         {
4655                 const Interface* interface = variable.m_descriptor.m_interface;
4656
4657                 Interface* block = CloneBlockForStage(*interface, stage, storage, prefix);
4658
4659                 var->m_descriptor.m_interface = block;
4660         }
4661
4662         /* Store variable */
4663         ShaderInterface& si             = GetShaderInterface(stage);
4664         Variable*                result = 0;
4665
4666         switch (storage)
4667         {
4668         case Variable::VARYING_INPUT:
4669                 si.m_inputs.push_back(var);
4670                 result = si.m_inputs.back();
4671                 break;
4672         case Variable::VARYING_OUTPUT:
4673                 si.m_outputs.push_back(var);
4674                 result = si.m_outputs.back();
4675                 break;
4676         case Variable::UNIFORM:
4677                 /* Uniform blocks needs unique binding */
4678                 if (true == is_block)
4679                 {
4680                         replaceBinding(*var, stage);
4681                 }
4682
4683                 si.m_uniforms.push_back(var);
4684                 result = si.m_uniforms.back();
4685                 break;
4686         case Variable::SSB:
4687                 /* SSBs needs unique binding */
4688                 if (true == is_block)
4689                 {
4690                         replaceBinding(*var, stage);
4691                 }
4692
4693                 si.m_ssb_blocks.push_back(var);
4694                 result = si.m_ssb_blocks.back();
4695                 break;
4696         default:
4697                 TCU_FAIL("Invalid enum");
4698                 break;
4699         }
4700
4701         return result;
4702 }
4703
4704 /** clone block to specific stage
4705  *
4706  * @param block   Block to be copied
4707  * @param stage   Specific stage
4708  * @param storage Storage used by block
4709  * @param prefix  Prefix used in block name
4710  *
4711  * @return New interface
4712  **/
4713 Interface* ProgramInterface::CloneBlockForStage(const Interface& block, Shader::STAGES stage, Variable::STORAGE storage,
4714                                                                                                 const GLchar* prefix)
4715 {
4716         /* Get name */
4717         std::string name = block.m_name;
4718
4719         /* Prefix name with stage ID */
4720         size_t            position       = 0;
4721         const GLchar* stage_prefix = GetStagePrefix(stage, storage);
4722         Utils::replaceToken(prefix, position, stage_prefix, name);
4723
4724         Interface* ptr = GetBlock(name.c_str());
4725
4726         if (0 == ptr)
4727         {
4728                 ptr = AddInterface(name.c_str(), Interface::BLOCK);
4729         }
4730
4731         ptr->m_members = block.m_members;
4732
4733         return ptr;
4734 }
4735
4736 /** Get stage specific prefix used in names
4737  *
4738  * @param stage   Stage
4739  * @param storage Storage class
4740  *
4741  * @return String
4742  **/
4743 const GLchar* ProgramInterface::GetStagePrefix(Shader::STAGES stage, Variable::STORAGE storage)
4744 {
4745         static const GLchar* lut[Shader::STAGE_MAX][Variable::STORAGE_MAX] = {
4746                 /*          IN          OUT         UNIFORM     SSB        MEMBER       */
4747                 /* CS  */ { 0, 0, "cs_uni_", "cs_buf_", "" },
4748                 /* VS  */ { "in_vs_", "vs_tcs_", "vs_uni_", "vs_buf_", "" },
4749                 /* TCS */ { "vs_tcs_", "tcs_tes_", "tcs_uni_", "tcs_buf_", "" },
4750                 /* TES */ { "tcs_tes_", "tes_gs_", "tes_uni_", "tes_buf_", "" },
4751                 /* GS  */ { "tes_gs_", "gs_fs_", "gs_uni_", "gs_buf_", "" },
4752                 /* FS  */ { "gs_fs_", "fs_out_", "fs_uni_", "fs_buf_", "" },
4753         };
4754
4755         const GLchar* result = 0;
4756
4757         result = lut[stage][storage];
4758
4759         return result;
4760 }
4761
4762 /** Get definitions of all structures used in program interface
4763  *
4764  * @return String with code
4765  **/
4766 std::string ProgramInterface::GetDefinitionsStructures() const
4767 {
4768         return GetDefinitions(m_structures);
4769 }
4770
4771 /** Get interface code for stage
4772  *
4773  * @param stage Specific stage
4774  *
4775  * @return String with code
4776  **/
4777 std::string ProgramInterface::GetInterfaceForStage(Shader::STAGES stage) const
4778 {
4779         size_t          position  = 0;
4780         std::string interface = "/* Globals */\n"
4781                                                         "GLOBALS\n"
4782                                                         "\n"
4783                                                         "/* Structures */\n"
4784                                                         "STRUCTURES\n"
4785                                                         "\n"
4786                                                         "/* Uniforms */\n"
4787                                                         "UNIFORMS\n"
4788                                                         "\n"
4789                                                         "/* Inputs */\n"
4790                                                         "INPUTS\n"
4791                                                         "\n"
4792                                                         "/* Outputs */\n"
4793                                                         "OUTPUTS\n"
4794                                                         "\n"
4795                                                         "/* Storage */\n"
4796                                                         "STORAGE\n";
4797
4798         const ShaderInterface& si = GetShaderInterface(stage);
4799
4800         const std::string& structures = GetDefinitionsStructures();
4801
4802         const std::string& globals  = si.GetDefinitionsGlobals();
4803         const std::string& inputs   = si.GetDefinitionsInputs();
4804         const std::string& outputs  = si.GetDefinitionsOutputs();
4805         const std::string& uniforms = si.GetDefinitionsUniforms();
4806         const std::string& ssbs         = si.GetDefinitionsSSBs();
4807
4808         replaceToken("GLOBALS", position, globals.c_str(), interface);
4809         replaceToken("STRUCTURES", position, structures.c_str(), interface);
4810         replaceToken("UNIFORMS", position, uniforms.c_str(), interface);
4811         replaceToken("INPUTS", position, inputs.c_str(), interface);
4812         replaceToken("OUTPUTS", position, outputs.c_str(), interface);
4813         replaceToken("STORAGE", position, ssbs.c_str(), interface);
4814
4815         return interface;
4816 }
4817
4818 /** Functional object used in find_if algorithm, in search for interface of given name
4819  *
4820  **/
4821 struct matchInterfaceName
4822 {
4823         matchInterfaceName(const GLchar* name) : m_name(name)
4824         {
4825         }
4826
4827         bool operator()(const Interface* interface)
4828         {
4829                 return 0 == interface->m_name.compare(m_name);
4830         }
4831
4832         const GLchar* m_name;
4833 };
4834
4835 /** Finds interface of given name in given vector of interfaces
4836  *
4837  * @param vector Collection of interfaces
4838  * @param name   Requested name
4839  *
4840  * @return Pointer to interface if available, 0 otherwise
4841  **/
4842 static Interface* findInterfaceByName(Interface::PtrVector& vector, const GLchar* name)
4843 {
4844         Interface::PtrVector::iterator it = std::find_if(vector.begin(), vector.end(), matchInterfaceName(name));
4845
4846         if (vector.end() != it)
4847         {
4848                 return *it;
4849         }
4850         else
4851         {
4852                 return 0;
4853         }
4854 }
4855
4856 /** Search for block of given name
4857  *
4858  * @param name Name of block
4859  *
4860  * @return Pointer to block or 0
4861  **/
4862 Interface* ProgramInterface::GetBlock(const GLchar* name)
4863 {
4864         return findInterfaceByName(m_blocks, name);
4865 }
4866
4867 /** Search for structure of given name
4868  *
4869  * @param name Name of structure
4870  *
4871  * @return Pointer to structure or 0
4872  **/
4873 Interface* ProgramInterface::GetStructure(const GLchar* name)
4874 {
4875         return findInterfaceByName(m_structures, name);
4876 }
4877
4878 /** Adds new sturcture to interface
4879  *
4880  * @param name Name of structure
4881  *
4882  * @return Created structure
4883  **/
4884 Interface* ProgramInterface::Structure(const GLchar* name)
4885 {
4886         return AddInterface(name, Interface::STRUCT);
4887 }
4888
4889 /** Replace "BINDING" token in qualifiers string to value specific for given stage
4890  *
4891  * @param variable Variable to modify
4892  * @param stage    Requested stage
4893  **/
4894 void ProgramInterface::replaceBinding(Variable& variable, Shader::STAGES stage)
4895 {
4896         GLchar binding[16];
4897         sprintf(binding, "%d", stage);
4898         replaceAllTokens("BINDING", binding, variable.m_descriptor.m_qualifiers);
4899 }
4900 } /* Utils namespace */
4901
4902 /** Debuging procedure. Logs parameters.
4903  *
4904  * @param source   As specified in GL spec.
4905  * @param type     As specified in GL spec.
4906  * @param id       As specified in GL spec.
4907  * @param severity As specified in GL spec.
4908  * @param ignored
4909  * @param message  As specified in GL spec.
4910  * @param info     Pointer to instance of Context used by test.
4911  */
4912 void GLW_APIENTRY debug_proc(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /* length */,
4913                                                          const GLchar* message, void* info)
4914 {
4915         deqp::Context* ctx = (deqp::Context*)info;
4916
4917         const GLchar* source_str   = "Unknown";
4918         const GLchar* type_str   = "Unknown";
4919         const GLchar* severity_str = "Unknown";
4920
4921         switch (source)
4922         {
4923         case GL_DEBUG_SOURCE_API:
4924                 source_str = "API";
4925                 break;
4926         case GL_DEBUG_SOURCE_APPLICATION:
4927                 source_str = "APP";
4928                 break;
4929         case GL_DEBUG_SOURCE_OTHER:
4930                 source_str = "OTR";
4931                 break;
4932         case GL_DEBUG_SOURCE_SHADER_COMPILER:
4933                 source_str = "COM";
4934                 break;
4935         case GL_DEBUG_SOURCE_THIRD_PARTY:
4936                 source_str = "3RD";
4937                 break;
4938         case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
4939                 source_str = "WS";
4940                 break;
4941         default:
4942                 break;
4943         }
4944
4945         switch (type)
4946         {
4947         case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
4948                 type_str = "DEPRECATED_BEHAVIOR";
4949                 break;
4950         case GL_DEBUG_TYPE_ERROR:
4951                 type_str = "ERROR";
4952                 break;
4953         case GL_DEBUG_TYPE_MARKER:
4954                 type_str = "MARKER";
4955                 break;
4956         case GL_DEBUG_TYPE_OTHER:
4957                 type_str = "OTHER";
4958                 break;
4959         case GL_DEBUG_TYPE_PERFORMANCE:
4960                 type_str = "PERFORMANCE";
4961                 break;
4962         case GL_DEBUG_TYPE_POP_GROUP:
4963                 type_str = "POP_GROUP";
4964                 break;
4965         case GL_DEBUG_TYPE_PORTABILITY:
4966                 type_str = "PORTABILITY";
4967                 break;
4968         case GL_DEBUG_TYPE_PUSH_GROUP:
4969                 type_str = "PUSH_GROUP";
4970                 break;
4971         case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
4972                 type_str = "UNDEFINED_BEHAVIOR";
4973                 break;
4974         default:
4975                 break;
4976         }
4977
4978         switch (severity)
4979         {
4980         case GL_DEBUG_SEVERITY_HIGH:
4981                 severity_str = "H";
4982                 break;
4983         case GL_DEBUG_SEVERITY_LOW:
4984                 severity_str = "L";
4985                 break;
4986         case GL_DEBUG_SEVERITY_MEDIUM:
4987                 severity_str = "M";
4988                 break;
4989         case GL_DEBUG_SEVERITY_NOTIFICATION:
4990                 severity_str = "N";
4991                 break;
4992         default:
4993                 break;
4994         }
4995
4996         ctx->getTestContext().getLog() << tcu::TestLog::Message << "DEBUG_INFO: " << std::setw(3) << source_str << "|"
4997                                                                    << severity_str << "|" << std::setw(18) << type_str << "|" << std::setw(12) << id
4998                                                                    << ": " << message << tcu::TestLog::EndMessage;
4999 }
5000
5001 /** Constructor
5002  *
5003  * @param context          Test context
5004  * @param test_name        Test name
5005  * @param test_description Test description
5006  **/
5007 TestBase::TestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5008         : TestCase(context, test_name, test_description)
5009 {
5010         /* Nothing to be done here */
5011 }
5012
5013 /** Execute test
5014  *
5015  * @return tcu::TestNode::STOP otherwise
5016  **/
5017 tcu::TestNode::IterateResult TestBase::iterate()
5018 {
5019         bool test_result;
5020
5021 #if DEBUG_ENBALE_MESSAGE_CALLBACK
5022         const Functions& gl = m_context.getRenderContext().getFunctions();
5023
5024         gl.debugMessageCallback(debug_proc, &m_context);
5025         GLU_EXPECT_NO_ERROR(gl.getError(), "DebugMessageCallback");
5026 #endif /* DEBUG_ENBALE_MESSAGE_CALLBACK */
5027
5028         try
5029         {
5030                 /* Execute test */
5031                 test_result = test();
5032         }
5033         catch (std::exception& exc)
5034         {
5035                 TCU_FAIL(exc.what());
5036         }
5037
5038         /* Set result */
5039         if (true == test_result)
5040         {
5041                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
5042         }
5043         else
5044         {
5045                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
5046         }
5047
5048         /* Done */
5049         return tcu::TestNode::STOP;
5050 }
5051
5052 /** Get last input location available for given type at specific stage
5053  *
5054  * @param stage        Shader stage
5055  * @param type         Input type
5056  * @param array_length Length of input array
5057  *
5058  * @return Last location index
5059  **/
5060 GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5061 {
5062         GLint  divide = 4; /* 4 components per location */
5063         GLint  param  = 0;
5064         GLenum pname  = 0;
5065
5066         /* Select pnmae */
5067         switch (stage)
5068         {
5069         case Utils::Shader::FRAGMENT:
5070                 pname = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
5071                 break;
5072         case Utils::Shader::GEOMETRY:
5073                 pname = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
5074                 break;
5075         case Utils::Shader::TESS_CTRL:
5076                 pname = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
5077                 break;
5078         case Utils::Shader::TESS_EVAL:
5079                 pname = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
5080                 break;
5081         case Utils::Shader::VERTEX:
5082                 pname  = GL_MAX_VERTEX_ATTRIBS;
5083                 divide = 1;
5084                 break;
5085         default:
5086                 TCU_FAIL("Invalid enum");
5087                 break;
5088         }
5089
5090         /* Zero means no array, but 1 slot is required */
5091         if (0 == array_length)
5092         {
5093                 array_length += 1;
5094         }
5095
5096         /* Get MAX */
5097         const Functions& gl = m_context.getRenderContext().getFunctions();
5098
5099         gl.getIntegerv(pname, &param);
5100         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5101
5102 /* Calculate */
5103 #if WRKARD_VARYINGLOCATIONSTEST
5104
5105         const GLint n_avl_locations = 16;
5106
5107 #else
5108
5109         const GLint n_avl_locations = param / divide;
5110
5111 #endif
5112
5113         const GLuint n_req_location = type.GetLocations() * array_length;
5114
5115         return n_avl_locations - n_req_location; /* last is max - 1 */
5116 }
5117
5118 /** Get last input location available for given type at specific stage
5119  *
5120  * @param stage        Shader stage
5121  * @param type         Input type
5122  * @param array_length Length of input array
5123  *
5124  * @return Last location index
5125  **/
5126 GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
5127 {
5128         GLint  param = 0;
5129         GLenum pname = 0;
5130
5131         /* Select pnmae */
5132         switch (stage)
5133         {
5134         case Utils::Shader::GEOMETRY:
5135                 pname = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
5136                 break;
5137         case Utils::Shader::TESS_CTRL:
5138                 pname = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
5139                 break;
5140         case Utils::Shader::TESS_EVAL:
5141                 pname = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
5142                 break;
5143         case Utils::Shader::VERTEX:
5144                 pname = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
5145                 break;
5146         default:
5147                 TCU_FAIL("Invalid enum");
5148                 break;
5149         }
5150
5151         /* Zero means no array, but 1 slot is required */
5152         if (0 == array_length)
5153         {
5154                 array_length += 1;
5155         }
5156
5157         /* Get MAX */
5158         const Functions& gl = m_context.getRenderContext().getFunctions();
5159
5160         gl.getIntegerv(pname, &param);
5161         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5162
5163 /* Calculate */
5164 #if WRKARD_VARYINGLOCATIONSTEST
5165
5166         const GLint n_avl_locations = 16;
5167
5168 #else
5169
5170         const GLint n_avl_locations = param / 4; /* 4 components per location */
5171
5172 #endif
5173
5174         const GLuint n_req_location = type.GetLocations() * array_length;
5175
5176         return n_avl_locations - n_req_location; /* last is max - 1 */
5177 }
5178
5179 /** Basic implementation
5180  *
5181  * @param ignored
5182  *
5183  * @return Empty string
5184  **/
5185 std::string TestBase::getTestCaseName(GLuint /* test_case_index */)
5186 {
5187         std::string result;
5188
5189         return result;
5190 }
5191
5192 /** Basic implementation
5193  *
5194  * @return 1
5195  **/
5196 GLuint TestBase::getTestCaseNumber()
5197 {
5198         return 1;
5199 }
5200
5201 /** Check if flat qualifier is required for given type, stage and storage
5202  *
5203  * @param stage        Shader stage
5204  * @param type         Input type
5205  * @param storage      Storage of variable
5206  *
5207  * @return Last location index
5208  **/
5209 bool TestBase::isFlatRequired(Utils::Shader::STAGES stage, const Utils::Type& type,
5210                                                           Utils::Variable::STORAGE storage) const
5211 {
5212         /* Float types do not need flat at all */
5213         if (Utils::Type::Float == type.m_basic_type)
5214         {
5215                 return false;
5216         }
5217
5218         /* Inputs to fragment shader */
5219         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_INPUT == storage))
5220         {
5221                 return true;
5222         }
5223
5224         /* Outputs from geometry shader */
5225         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Variable::VARYING_OUTPUT == storage))
5226         {
5227                 return true;
5228         }
5229
5230         return false;
5231 }
5232
5233 /** Basic implementation of testInit method
5234  *
5235  **/
5236 void TestBase::testInit()
5237 {
5238 }
5239
5240 /** Calculate stride for interface
5241  *
5242  * @param interface Interface
5243  *
5244  * @return Calculated value
5245  **/
5246 GLuint TestBase::calculateStride(const Utils::Interface& interface) const
5247 {
5248         const size_t n_members = interface.m_members.size();
5249
5250         GLuint stride = 0;
5251
5252         for (size_t i = 0; i < n_members; ++i)
5253         {
5254                 const Utils::Variable::Descriptor& member                 = interface.m_members[i];
5255                 const GLuint                                       member_offset  = member.m_offset;
5256                 const GLuint                                       member_stride  = member.m_expected_stride_of_element;
5257                 const GLuint                                       member_ends_at = member_offset + member_stride;
5258
5259                 stride = std::max(stride, member_ends_at);
5260         }
5261
5262         return stride;
5263 }
5264
5265 /** Generate data for interface. This routine is recursive
5266  *
5267  * @param interface Interface
5268  * @param offset    Offset in out_data
5269  * @param out_data  Buffer to be filled
5270  **/
5271 void TestBase::generateData(const Utils::Interface& interface, GLuint offset, std::vector<GLubyte>& out_data) const
5272 {
5273         const size_t n_members = interface.m_members.size();
5274         GLubyte*         ptr       = &out_data[offset];
5275
5276         for (size_t i = 0; i < n_members; ++i)
5277         {
5278                 const Utils::Variable::Descriptor& member                = interface.m_members[i];
5279                 const GLuint                                       member_offset = member.m_offset;
5280                 const GLuint n_elements = (0 == member.m_n_array_elements) ? 1 : member.m_n_array_elements;
5281
5282                 for (GLuint element = 0; element < n_elements; ++element)
5283                 {
5284                         const GLuint element_offset = element * member.m_expected_stride_of_element;
5285                         const GLuint data_offfset   = member_offset + element_offset;
5286
5287                         if (Utils::Variable::BUILTIN == member.m_type)
5288                         {
5289                                 const std::vector<GLubyte>& data = member.m_builtin.GenerateData();
5290
5291                                 memcpy(ptr + data_offfset, &data[0], data.size());
5292                         }
5293                         else
5294                         {
5295                                 generateData(*member.m_interface, offset + data_offfset, out_data);
5296                         }
5297                 }
5298         }
5299 }
5300
5301 /** Get type at index
5302  *
5303  * @param index Index of requested type
5304  *
5305  * @return Type
5306  **/
5307 Utils::Type TestBase::getType(GLuint index) const
5308 {
5309         Utils::Type type;
5310
5311         switch (index)
5312         {
5313         case 0:
5314                 type = Utils::Type::_double;
5315                 break;
5316         case 1:
5317                 type = Utils::Type::dmat2;
5318                 break;
5319         case 2:
5320                 type = Utils::Type::dmat2x3;
5321                 break;
5322         case 3:
5323                 type = Utils::Type::dmat2x4;
5324                 break;
5325         case 4:
5326                 type = Utils::Type::dmat3;
5327                 break;
5328         case 5:
5329                 type = Utils::Type::dmat3x2;
5330                 break;
5331         case 6:
5332                 type = Utils::Type::dmat3x4;
5333                 break;
5334         case 7:
5335                 type = Utils::Type::dmat4;
5336                 break;
5337         case 8:
5338                 type = Utils::Type::dmat4x2;
5339                 break;
5340         case 9:
5341                 type = Utils::Type::dmat4x3;
5342                 break;
5343         case 10:
5344                 type = Utils::Type::dvec2;
5345                 break;
5346         case 11:
5347                 type = Utils::Type::dvec3;
5348                 break;
5349         case 12:
5350                 type = Utils::Type::dvec4;
5351                 break;
5352         case 13:
5353                 type = Utils::Type::_float;
5354                 break;
5355         case 14:
5356                 type = Utils::Type::mat2;
5357                 break;
5358         case 15:
5359                 type = Utils::Type::mat2x3;
5360                 break;
5361         case 16:
5362                 type = Utils::Type::mat2x4;
5363                 break;
5364         case 17:
5365                 type = Utils::Type::mat3;
5366                 break;
5367         case 18:
5368                 type = Utils::Type::mat3x2;
5369                 break;
5370         case 19:
5371                 type = Utils::Type::mat3x4;
5372                 break;
5373         case 20:
5374                 type = Utils::Type::mat4;
5375                 break;
5376         case 21:
5377                 type = Utils::Type::mat4x2;
5378                 break;
5379         case 22:
5380                 type = Utils::Type::mat4x3;
5381                 break;
5382         case 23:
5383                 type = Utils::Type::vec2;
5384                 break;
5385         case 24:
5386                 type = Utils::Type::vec3;
5387                 break;
5388         case 25:
5389                 type = Utils::Type::vec4;
5390                 break;
5391         case 26:
5392                 type = Utils::Type::_int;
5393                 break;
5394         case 27:
5395                 type = Utils::Type::ivec2;
5396                 break;
5397         case 28:
5398                 type = Utils::Type::ivec3;
5399                 break;
5400         case 29:
5401                 type = Utils::Type::ivec4;
5402                 break;
5403         case 30:
5404                 type = Utils::Type::uint;
5405                 break;
5406         case 31:
5407                 type = Utils::Type::uvec2;
5408                 break;
5409         case 32:
5410                 type = Utils::Type::uvec3;
5411                 break;
5412         case 33:
5413                 type = Utils::Type::uvec4;
5414                 break;
5415         default:
5416                 TCU_FAIL("invalid enum");
5417         }
5418
5419         return type;
5420 }
5421
5422 /** Get name of type at index
5423  *
5424  * @param index Index of type
5425  *
5426  * @return Name
5427  **/
5428 std::string TestBase::getTypeName(GLuint index) const
5429 {
5430         std::string name = getType(index).GetGLSLTypeName();
5431
5432         return name;
5433 }
5434
5435 /** Get number of types
5436  *
5437  * @return 34
5438  **/
5439 glw::GLuint TestBase::getTypesNumber() const
5440 {
5441         return 34;
5442 }
5443
5444 /** Execute test
5445  *
5446  * @return true if test pass, false otherwise
5447  **/
5448 bool TestBase::test()
5449 {
5450         bool   result           = true;
5451         GLuint n_test_cases = 0;
5452
5453         /* Prepare test */
5454         testInit();
5455
5456         /* GL entry points */
5457         const Functions& gl = m_context.getRenderContext().getFunctions();
5458
5459         /* Tessellation patch set up */
5460         gl.patchParameteri(GL_PATCH_VERTICES, 1);
5461         GLU_EXPECT_NO_ERROR(gl.getError(), "PatchParameteri");
5462
5463         /* Get number of test cases */
5464         n_test_cases = getTestCaseNumber();
5465
5466 #if DEBUG_REPEAT_TEST_CASE
5467
5468         while (1)
5469         {
5470                 GLuint test_case = DEBUG_REPEATED_TEST_CASE;
5471
5472 #else /* DEBUG_REPEAT_TEST_CASE */
5473
5474         for (GLuint test_case = 0; test_case < n_test_cases; ++test_case)
5475         {
5476
5477 #endif /* DEBUG_REPEAT_TEST_CASE */
5478
5479                 bool case_result = true;
5480
5481                 /* Execute case */
5482                 if (false == testCase(test_case))
5483                 {
5484                         case_result = false;
5485                 }
5486
5487                 /* Log failure */
5488                 if (false == case_result)
5489                 {
5490                         const std::string& test_case_name = getTestCaseName(test_case);
5491
5492                         if (false == test_case_name.empty())
5493                         {
5494                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case_name
5495                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5496                         }
5497                         else
5498                         {
5499                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "Test case (" << test_case
5500                                                                                                         << ") failed." << tcu::TestLog::EndMessage;
5501                         }
5502
5503                         result = false;
5504                 }
5505         }
5506
5507         /* Done */
5508         return result;
5509 }
5510
5511 /* Constants used by BufferTestBase */
5512 const GLuint BufferTestBase::bufferDescriptor::m_non_indexed = -1;
5513
5514 /** Constructor
5515  *
5516  * @param context          Test context
5517  * @param test_name        Name of test
5518  * @param test_description Description of test
5519  **/
5520 BufferTestBase::BufferTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
5521         : TestBase(context, test_name, test_description)
5522 {
5523 }
5524
5525 /** Execute drawArrays for single vertex
5526  *
5527  * @param ignored
5528  *
5529  * @return true
5530  **/
5531 bool BufferTestBase::executeDrawCall(bool tesEnabled, GLuint /* test_case_index */)
5532 {
5533         const Functions& gl = m_context.getRenderContext().getFunctions();
5534
5535         gl.disable(GL_RASTERIZER_DISCARD);
5536         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
5537
5538         gl.beginTransformFeedback(GL_POINTS);
5539         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
5540
5541         // Only TES is existed, glDrawArray can use the parameter GL_PATCHES
5542         if (tesEnabled == false)
5543         {
5544                 gl.drawArrays(GL_POINTS, 0 /* first */, 1 /* count */);
5545         }
5546         else
5547         {
5548                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
5549         }
5550
5551         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
5552
5553         gl.endTransformFeedback();
5554         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
5555
5556         return true;
5557 }
5558
5559 /** Get descriptors of buffers necessary for test
5560  *
5561  * @param ignored
5562  * @param ignored
5563  **/
5564 void BufferTestBase::getBufferDescriptors(glw::GLuint /* test_case_index */,
5565                                                                                   bufferDescriptor::Vector& /* out_descriptors */)
5566 {
5567         /* Nothhing to be done */
5568 }
5569
5570 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
5571  *
5572  * @param ignored
5573  * @param ignored
5574  **/
5575 void BufferTestBase::getCapturedVaryings(glw::GLuint /* test_case_index */,
5576                                                                                  Utils::Program::NameVector& /* captured_varyings */)
5577 {
5578         /* Nothing to be done */
5579 }
5580
5581 /** Get body of main function for given shader stage
5582  *
5583  * @param ignored
5584  * @param ignored
5585  * @param out_assignments  Set to empty
5586  * @param out_calculations Set to empty
5587  **/
5588 void BufferTestBase::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5589                                                                    std::string& out_assignments, std::string& out_calculations)
5590 {
5591         out_assignments  = "";
5592         out_calculations = "";
5593 }
5594
5595 /** Get interface of shader
5596  *
5597  * @param ignored
5598  * @param ignored
5599  * @param out_interface Set to ""
5600  **/
5601 void BufferTestBase::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES /* stage */,
5602                                                                                 std::string& out_interface)
5603 {
5604         out_interface = "";
5605 }
5606
5607 /** Get source code of shader
5608  *
5609  * @param test_case_index Index of test case
5610  * @param stage           Shader stage
5611  *
5612  * @return Source
5613  **/
5614 std::string BufferTestBase::getShaderSource(glw::GLuint test_case_index, Utils::Shader::STAGES stage)
5615 {
5616         std::string assignments;
5617         std::string calculations;
5618         std::string interface;
5619
5620         /* */
5621         getShaderBody(test_case_index, stage, assignments, calculations);
5622         getShaderInterface(test_case_index, stage, interface);
5623
5624         /* */
5625         std::string source = getShaderTemplate(stage);
5626
5627         /* */
5628         size_t position = 0;
5629         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
5630         Utils::replaceToken("CALCULATIONS", position, calculations.c_str(), source);
5631         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
5632
5633         /* */
5634         return source;
5635 }
5636
5637 /** Inspects program to check if all resources are as expected
5638  *
5639  * @param ignored
5640  * @param ignored
5641  * @param ignored
5642  *
5643  * @return true
5644  **/
5645 bool BufferTestBase::inspectProgram(GLuint /* test_case_index */, Utils::Program& /* program */,
5646                                                                         std::stringstream& /* out_stream */)
5647 {
5648         return true;
5649 }
5650
5651 /** Runs test case
5652  *
5653  * @param test_case_index Id of test case
5654  *
5655  * @return true if test case pass, false otherwise
5656  **/
5657 bool BufferTestBase::testCase(GLuint test_case_index)
5658 {
5659         try
5660         {
5661                 bufferCollection                   buffers;
5662                 Utils::Program::NameVector captured_varyings;
5663                 bufferDescriptor::Vector   descriptors;
5664                 Utils::Program                     program(m_context);
5665                 Utils::VertexArray                 vao(m_context);
5666
5667                 /* Get captured varyings */
5668                 getCapturedVaryings(test_case_index, captured_varyings);
5669
5670                 /* Get shader sources */
5671                 const std::string& fragment_shader  = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
5672                 const std::string& geometry_shader  = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
5673                 const std::string& tess_ctrl_shader = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
5674                 const std::string& tess_eval_shader = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
5675                 const std::string& vertex_shader        = getShaderSource(test_case_index, Utils::Shader::VERTEX);
5676
5677                 /* Set up program */
5678                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
5679                                          vertex_shader, captured_varyings, true, false /* is_separable */);
5680
5681                 /* Inspection */
5682                 {
5683                         std::stringstream stream;
5684                         if (false == inspectProgram(test_case_index, program, stream))
5685                         {
5686                                 m_context.getTestContext().getLog()
5687                                         << tcu::TestLog::Message
5688                                         << "Program inspection failed. Test case: " << getTestCaseName(test_case_index)
5689                                         << ". Reason: " << stream.str() << tcu::TestLog::EndMessage
5690                                         << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5691                                         << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5692                                         << tcu::TestLog::KernelSource(fragment_shader);
5693
5694                                 return false;
5695                         }
5696                 }
5697
5698                 program.Use();
5699
5700                 /* Set up buffers */
5701                 getBufferDescriptors(test_case_index, descriptors);
5702                 cleanBuffers();
5703                 prepareBuffers(descriptors, buffers);
5704
5705                 /* Set up vao */
5706                 vao.Init();
5707                 vao.Bind();
5708
5709                 /* Draw */
5710                 bool result = executeDrawCall((program.m_tess_eval.m_id != 0), test_case_index);
5711
5712 #if USE_NSIGHT
5713                 m_context.getRenderContext().postIterate();
5714 #endif
5715
5716                 if (false == result)
5717                 {
5718                         m_context.getTestContext().getLog()
5719                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5720                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5721                                 << tcu::TestLog::KernelSource(fragment_shader);
5722
5723                         return false;
5724                 }
5725
5726                 /* Verify result */
5727                 if (false == verifyBuffers(buffers))
5728                 {
5729                         m_context.getTestContext().getLog()
5730                                 << tcu::TestLog::KernelSource(vertex_shader) << tcu::TestLog::KernelSource(tess_ctrl_shader)
5731                                 << tcu::TestLog::KernelSource(tess_eval_shader) << tcu::TestLog::KernelSource(geometry_shader)
5732                                 << tcu::TestLog::KernelSource(fragment_shader);
5733
5734                         return false;
5735                 }
5736         }
5737         catch (Utils::Shader::InvalidSourceException& exc)
5738         {
5739                 exc.log(m_context);
5740                 TCU_FAIL(exc.what());
5741         }
5742         catch (Utils::Program::BuildException& exc)
5743         {
5744                 exc.log(m_context);
5745                 TCU_FAIL(exc.what());
5746         }
5747
5748         /* Done */
5749         return true;
5750 }
5751
5752 /** Verify contents of buffers
5753  *
5754  * @param buffers Collection of buffers to be verified
5755  *
5756  * @return true if everything is as expected, false otherwise
5757  **/
5758 bool BufferTestBase::verifyBuffers(bufferCollection& buffers)
5759 {
5760         bool result = true;
5761
5762         for (bufferCollection::Vector::iterator it = buffers.m_vector.begin(), end = buffers.m_vector.end(); end != it;
5763                  ++it)
5764         {
5765                 bufferCollection::pair& pair       = *it;
5766                 Utils::Buffer*                  buffer   = pair.m_buffer;
5767                 bufferDescriptor*               descriptor = pair.m_descriptor;
5768                 size_t                                  size       = descriptor->m_expected_data.size();
5769
5770                 /* Skip buffers that have no expected data */
5771                 if (0 == size)
5772                 {
5773                         continue;
5774                 }
5775
5776                 /* Get pointer to contents of buffer */
5777                 buffer->Bind();
5778                 GLvoid* buffer_data = buffer->Map(Utils::Buffer::ReadOnly);
5779
5780                 /* Get pointer to expected data */
5781                 GLvoid* expected_data = &descriptor->m_expected_data[0];
5782
5783                 /* Compare */
5784                 int res = memcmp(buffer_data, expected_data, size);
5785
5786                 if (0 != res)
5787                 {
5788                         m_context.getTestContext().getLog()
5789                                 << tcu::TestLog::Message
5790                                 << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
5791                                 << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
5792
5793                         result = false;
5794                 }
5795
5796                 /* Release buffer mapping */
5797                 buffer->UnMap();
5798         }
5799
5800         return result;
5801 }
5802
5803 /** Unbinds all uniforms and xfb
5804  *
5805  **/
5806 void BufferTestBase::cleanBuffers()
5807 {
5808         const Functions& gl = m_context.getRenderContext().getFunctions();
5809
5810         GLint max_uni = 0;
5811         GLint max_xfb = 0;
5812
5813         gl.getIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, &max_uni);
5814         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
5815         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
5816
5817         for (GLint i = 0; i < max_uni; ++i)
5818         {
5819                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Uniform, i);
5820         }
5821
5822         for (GLint i = 0; i < max_xfb; ++i)
5823         {
5824                 Utils::Buffer::BindBase(gl, 0, Utils::Buffer::Transform_feedback, i);
5825         }
5826 }
5827
5828 /** Get template of shader for given stage
5829  *
5830  * @param stage Stage
5831  *
5832  * @return Template of shader source
5833  **/
5834 std::string BufferTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
5835 {
5836         static const GLchar* compute_shader_template = "#version 430 core\n"
5837                                                                                                    "#extension GL_ARB_enhanced_layouts : require\n"
5838                                                                                                    "\n"
5839                                                                                                    "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
5840                                                                                                    "\n"
5841                                                                                                    "writeonly uniform uimage2D uni_image;\n"
5842                                                                                                    "\n"
5843                                                                                                    "INTERFACE"
5844                                                                                                    "\n"
5845                                                                                                    "void main()\n"
5846                                                                                                    "{\n"
5847                                                                                                    "CALCULATIONS"
5848                                                                                                    "\n"
5849                                                                                                    "ASSIGNMENTS"
5850                                                                                                    "}\n"
5851                                                                                                    "\n";
5852
5853         static const GLchar* fragment_shader_template = "#version 430 core\n"
5854                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5855                                                                                                         "\n"
5856                                                                                                         "INTERFACE"
5857                                                                                                         "\n"
5858                                                                                                         "void main()\n"
5859                                                                                                         "{\n"
5860                                                                                                         "CALCULATIONS"
5861                                                                                                         "\n"
5862                                                                                                         "ASSIGNMENTS"
5863                                                                                                         "}\n"
5864                                                                                                         "\n";
5865
5866         // max_vertices is set to 3 for the test case "xfb_vertex_streams" declares 3 streams in geometry shader,
5867         // according to spec, max_vertices should be no less than 3 if there are 3 streams in GS.
5868         static const GLchar* geometry_shader_template = "#version 430 core\n"
5869                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
5870                                                                                                         "\n"
5871                                                                                                         "layout(points)                   in;\n"
5872                                                                                                         "layout(points, max_vertices = 3) out;\n"
5873                                                                                                         "\n"
5874                                                                                                         "INTERFACE"
5875                                                                                                         "\n"
5876                                                                                                         "void main()\n"
5877                                                                                                         "{\n"
5878                                                                                                         "CALCULATIONS"
5879                                                                                                         "\n"
5880                                                                                                         "\n"
5881                                                                                                         "ASSIGNMENTS"
5882                                                                                                         "    gl_Position  = vec4(0, 0, 0, 1);\n"
5883                                                                                                         "    EmitVertex();\n"
5884                                                                                                         "}\n"
5885                                                                                                         "\n";
5886
5887         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
5888                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5889                                                                                                          "\n"
5890                                                                                                          "layout(vertices = 1) out;\n"
5891                                                                                                          "\n"
5892                                                                                                          "INTERFACE"
5893                                                                                                          "\n"
5894                                                                                                          "void main()\n"
5895                                                                                                          "{\n"
5896                                                                                                          "CALCULATIONS"
5897                                                                                                          "\n"
5898                                                                                                          "ASSIGNMENTS"
5899                                                                                                          "\n"
5900                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
5901                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
5902                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
5903                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
5904                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
5905                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
5906                                                                                                          "}\n"
5907                                                                                                          "\n";
5908
5909         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
5910                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
5911                                                                                                          "\n"
5912                                                                                                          "layout(isolines, point_mode) in;\n"
5913                                                                                                          "\n"
5914                                                                                                          "INTERFACE"
5915                                                                                                          "\n"
5916                                                                                                          "void main()\n"
5917                                                                                                          "{\n"
5918                                                                                                          "CALCULATIONS"
5919                                                                                                          "\n"
5920                                                                                                          "ASSIGNMENTS"
5921                                                                                                          "}\n"
5922                                                                                                          "\n";
5923
5924         static const GLchar* vertex_shader_template = "#version 430 core\n"
5925                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
5926                                                                                                   "\n"
5927                                                                                                   "INTERFACE"
5928                                                                                                   "\n"
5929                                                                                                   "void main()\n"
5930                                                                                                   "{\n"
5931                                                                                                   "CALCULATIONS"
5932                                                                                                   "\n"
5933                                                                                                   "ASSIGNMENTS"
5934                                                                                                   "}\n"
5935                                                                                                   "\n";
5936
5937         const GLchar* result = 0;
5938
5939         switch (stage)
5940         {
5941         case Utils::Shader::COMPUTE:
5942                 result = compute_shader_template;
5943                 break;
5944         case Utils::Shader::FRAGMENT:
5945                 result = fragment_shader_template;
5946                 break;
5947         case Utils::Shader::GEOMETRY:
5948                 result = geometry_shader_template;
5949                 break;
5950         case Utils::Shader::TESS_CTRL:
5951                 result = tess_ctrl_shader_template;
5952                 break;
5953         case Utils::Shader::TESS_EVAL:
5954                 result = tess_eval_shader_template;
5955                 break;
5956         case Utils::Shader::VERTEX:
5957                 result = vertex_shader_template;
5958                 break;
5959         default:
5960                 TCU_FAIL("Invalid enum");
5961         }
5962
5963         return result;
5964 }
5965
5966 /** Prepare buffer according to descriptor
5967  *
5968  * @param buffer Buffer to prepare
5969  * @param desc   Descriptor
5970  **/
5971 void BufferTestBase::prepareBuffer(Utils::Buffer& buffer, bufferDescriptor& desc)
5972 {
5973         GLsizeiptr size = 0;
5974         GLvoid* data = 0;
5975
5976         if (false == desc.m_initial_data.empty())
5977         {
5978                 size = desc.m_initial_data.size();
5979                 data = &desc.m_initial_data[0];
5980         }
5981         else if (false == desc.m_expected_data.empty())
5982         {
5983                 size = desc.m_expected_data.size();
5984         }
5985
5986         buffer.Init(desc.m_target, Utils::Buffer::StaticDraw, size, data);
5987
5988         if (bufferDescriptor::m_non_indexed != desc.m_index)
5989         {
5990                 buffer.BindBase(desc.m_index);
5991         }
5992         else
5993         {
5994                 buffer.Bind();
5995         }
5996 }
5997
5998 /** Prepare collection of buffer
5999  *
6000  * @param descriptors Collection of descriptors
6001  * @param out_buffers Collection of buffers
6002  **/
6003 void BufferTestBase::prepareBuffers(bufferDescriptor::Vector& descriptors, bufferCollection& out_buffers)
6004 {
6005         for (bufferDescriptor::Vector::iterator it = descriptors.begin(), end = descriptors.end(); end != it; ++it)
6006         {
6007                 bufferCollection::pair pair;
6008
6009                 pair.m_buffer = new Utils::Buffer(m_context);
6010                 if (0 == pair.m_buffer)
6011                 {
6012                         TCU_FAIL("Memory allocation failed");
6013                 }
6014
6015                 pair.m_descriptor = &(*it);
6016
6017                 prepareBuffer(*pair.m_buffer, *pair.m_descriptor);
6018
6019                 out_buffers.m_vector.push_back(pair);
6020         }
6021 }
6022
6023 /** Destructor
6024  *
6025  **/
6026 BufferTestBase::bufferCollection::~bufferCollection()
6027 {
6028         for (Vector::iterator it = m_vector.begin(), end = m_vector.end(); end != it; ++it)
6029         {
6030                 if (0 != it->m_buffer)
6031                 {
6032                         delete it->m_buffer;
6033                         it->m_buffer = 0;
6034                 }
6035         }
6036 }
6037
6038 /** Constructor
6039  *
6040  * @param context          Test context
6041  * @param test_name        Name of test
6042  * @param test_description Description of test
6043  **/
6044 NegativeTestBase::NegativeTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6045         : TestBase(context, test_name, test_description)
6046 {
6047 }
6048
6049 /** Selects if "compute" stage is relevant for test
6050  *
6051  * @param ignored
6052  *
6053  * @return true
6054  **/
6055 bool NegativeTestBase::isComputeRelevant(GLuint /* test_case_index */)
6056 {
6057         return true;
6058 }
6059
6060 /** Selects if compilation failure is expected result
6061  *
6062  * @param ignored
6063  *
6064  * @return true
6065  **/
6066 bool NegativeTestBase::isFailureExpected(GLuint /* test_case_index */)
6067 {
6068         return true;
6069 }
6070
6071 /** Runs test case
6072  *
6073  * @param test_case_index Id of test case
6074  *
6075  * @return true if test case pass, false otherwise
6076  **/
6077 bool NegativeTestBase::testCase(GLuint test_case_index)
6078 {
6079         bool test_case_result = true;
6080
6081         /* Compute */
6082         if (true == isComputeRelevant(test_case_index))
6083         {
6084                 const std::string& cs_source               = getShaderSource(test_case_index, Utils::Shader::COMPUTE);
6085                 bool                       is_build_error         = false;
6086                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6087                 Utils::Program   program(m_context);
6088
6089                 try
6090                 {
6091                         program.Init(cs_source, "" /* fs */, "" /* gs */, "" /* tcs */, "" /* tes */, "" /* vs */,
6092                                                  false /* separable */);
6093                 }
6094                 catch (Utils::Shader::InvalidSourceException& exc)
6095                 {
6096                         if (false == is_failure_expected)
6097                         {
6098                                 m_context.getTestContext().getLog()
6099                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6100                                 exc.log(m_context);
6101                         }
6102
6103 #if DEBUG_NEG_LOG_ERROR
6104
6105                         else
6106                         {
6107                                 m_context.getTestContext().getLog()
6108                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6109                                         << tcu::TestLog::EndMessage;
6110                                 exc.log(m_context);
6111                         }
6112
6113 #endif /* DEBUG_NEG_LOG_ERROR */
6114
6115                         is_build_error = true;
6116                 }
6117                 catch (Utils::Program::BuildException& exc)
6118                 {
6119                         if (false == is_failure_expected)
6120                         {
6121                                 m_context.getTestContext().getLog()
6122                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6123                                 exc.log(m_context);
6124                         }
6125
6126 #if DEBUG_NEG_LOG_ERROR
6127
6128                         else
6129                         {
6130                                 m_context.getTestContext().getLog()
6131                                         << tcu::TestLog::Message
6132                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6133                                 exc.log(m_context);
6134                         }
6135
6136 #endif /* DEBUG_NEG_LOG_ERROR */
6137
6138                         is_build_error = true;
6139                 }
6140
6141                 if (is_build_error != is_failure_expected)
6142                 {
6143                         if (!is_build_error)
6144                         {
6145                                 m_context.getTestContext().getLog()
6146                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6147                                 Utils::Shader::LogSource(m_context, cs_source, Utils::Shader::COMPUTE);
6148                         }
6149                         test_case_result = false;
6150                 }
6151         }
6152         else /* Draw */
6153         {
6154                 const std::string& fs_source               = getShaderSource(test_case_index, Utils::Shader::FRAGMENT);
6155                 const std::string& gs_source               = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
6156                 bool                       is_build_error         = false;
6157                 const bool                 is_failure_expected = isFailureExpected(test_case_index);
6158                 Utils::Program   program(m_context);
6159                 const std::string& tcs_source = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
6160                 const std::string& tes_source = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
6161                 const std::string& vs_source  = getShaderSource(test_case_index, Utils::Shader::VERTEX);
6162
6163                 try
6164                 {
6165                         program.Init("" /* cs */, fs_source, gs_source, tcs_source, tes_source, vs_source, false /* separable */);
6166                 }
6167                 catch (Utils::Shader::InvalidSourceException& exc)
6168                 {
6169                         if (false == is_failure_expected)
6170                         {
6171                                 m_context.getTestContext().getLog()
6172                                         << tcu::TestLog::Message << "Unexpected error in shader compilation: " << tcu::TestLog::EndMessage;
6173                                 exc.log(m_context);
6174                         }
6175
6176 #if DEBUG_NEG_LOG_ERROR
6177
6178                         else
6179                         {
6180                                 m_context.getTestContext().getLog()
6181                                         << tcu::TestLog::Message << "Error in shader compilation was expected, logged for verification: "
6182                                         << tcu::TestLog::EndMessage;
6183                                 exc.log(m_context);
6184                         }
6185
6186 #endif /* DEBUG_NEG_LOG_ERROR */
6187
6188                         is_build_error = true;
6189                 }
6190                 catch (Utils::Program::BuildException& exc)
6191                 {
6192                         if (false == is_failure_expected)
6193                         {
6194                                 m_context.getTestContext().getLog()
6195                                         << tcu::TestLog::Message << "Unexpected error in program linking: " << tcu::TestLog::EndMessage;
6196                                 exc.log(m_context);
6197                         }
6198
6199 #if DEBUG_NEG_LOG_ERROR
6200
6201                         else
6202                         {
6203                                 m_context.getTestContext().getLog()
6204                                         << tcu::TestLog::Message
6205                                         << "Error in program linking was expected, logged for verification: " << tcu::TestLog::EndMessage;
6206                                 exc.log(m_context);
6207                         }
6208
6209 #endif /* DEBUG_NEG_LOG_ERROR */
6210
6211                         is_build_error = true;
6212                 }
6213
6214                 if (is_build_error != is_failure_expected)
6215                 {
6216                         if (!is_build_error)
6217                         {
6218                                 m_context.getTestContext().getLog()
6219                                         << tcu::TestLog::Message << "Unexpected success: " << tcu::TestLog::EndMessage;
6220                                 Utils::Shader::LogSource(m_context, vs_source, Utils::Shader::VERTEX);
6221                                 Utils::Shader::LogSource(m_context, tcs_source, Utils::Shader::TESS_CTRL);
6222                                 Utils::Shader::LogSource(m_context, tes_source, Utils::Shader::TESS_EVAL);
6223                                 Utils::Shader::LogSource(m_context, gs_source, Utils::Shader::GEOMETRY);
6224                                 Utils::Shader::LogSource(m_context, fs_source, Utils::Shader::FRAGMENT);
6225                         }
6226                         test_case_result = false;
6227                 }
6228         }
6229
6230         return test_case_result;
6231 }
6232
6233 /* Constants used by TextureTestBase */
6234 const glw::GLuint TextureTestBase::m_width  = 16;
6235 const glw::GLuint TextureTestBase::m_height = 16;
6236
6237 /** Constructor
6238  *
6239  * @param context          Test context
6240  * @param test_name        Name of test
6241  * @param test_description Description of test
6242  **/
6243 TextureTestBase::TextureTestBase(deqp::Context& context, const GLchar* test_name, const GLchar* test_description)
6244         : TestBase(context, test_name, test_description)
6245 {
6246 }
6247
6248 /** Get locations for all inputs with automatic_location
6249  *
6250  * @param program           Program object
6251  * @param program_interface Interface of program
6252  **/
6253 void TextureTestBase::prepareAttribLocation(Utils::Program& program, Utils::ProgramInterface& program_interface)
6254 {
6255         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6256
6257         Utils::Variable::PtrVector& inputs = si.m_inputs;
6258
6259         for (Utils::Variable::PtrVector::iterator it = inputs.begin(); inputs.end() != it; ++it)
6260         {
6261                 /* Test does not specify location, query value and set */
6262                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6263                 {
6264                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_INPUT);
6265                         GLint  location = 0;
6266
6267                         program.GetResource(GL_PROGRAM_INPUT, index, GL_LOCATION, 1 /* size */, &location);
6268
6269                         (*it)->m_descriptor.m_expected_location = location;
6270                 }
6271         }
6272 }
6273
6274 /** Verifies contents of drawn image
6275  *
6276  * @param ignored
6277  * @param color_0 Verified image
6278  *
6279  * @return true if image is filled with 1, false otherwise
6280  **/
6281 bool TextureTestBase::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& color_0)
6282 {
6283         static const GLuint size                   = m_width * m_height;
6284         static const GLuint expected_color = 1;
6285
6286         std::vector<GLuint> data;
6287         data.resize(size);
6288
6289         color_0.Get(GL_RED_INTEGER, GL_UNSIGNED_INT, &data[0]);
6290
6291         for (GLuint i = 0; i < size; ++i)
6292         {
6293                 const GLuint color = data[i];
6294
6295                 if (expected_color != color)
6296                 {
6297                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "R32UI[" << i << "]:" << color
6298                                                                                                 << tcu::TestLog::EndMessage;
6299                         return false;
6300                 }
6301         }
6302
6303         return true;
6304 }
6305
6306 /** Execute dispatch compute for 16x16x1
6307  *
6308  * @param ignored
6309  **/
6310 void TextureTestBase::executeDispatchCall(GLuint /* test_case_index */)
6311 {
6312         const Functions& gl = m_context.getRenderContext().getFunctions();
6313
6314         gl.dispatchCompute(16 /* x */, 16 /* y */, 1 /* z */);
6315         GLU_EXPECT_NO_ERROR(gl.getError(), "DispatchCompute");
6316 }
6317
6318 /** Execute drawArrays for single vertex
6319  *
6320  * @param ignored
6321  **/
6322 void TextureTestBase::executeDrawCall(GLuint /* test_case_index */)
6323 {
6324         const Functions& gl = m_context.getRenderContext().getFunctions();
6325
6326         gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
6327         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
6328 }
6329
6330 /** Prepare code snippet that will pass in variables to out variables
6331  *
6332  * @param ignored
6333  * @param varying_passthrough Collection of connections between in and out variables
6334  * @param stage               Shader stage
6335  *
6336  * @return Code that pass in variables to next stage
6337  **/
6338 std::string TextureTestBase::getPassSnippet(GLuint /* test_case_index */,
6339                                                                                         Utils::VaryingPassthrough& varying_passthrough, Utils::Shader::STAGES stage)
6340 {
6341         static const GLchar* separator = "\n    ";
6342
6343         /* Skip for compute shader */
6344         if (Utils::Shader::COMPUTE == stage)
6345         {
6346                 return "";
6347         }
6348
6349         Utils::VaryingConnection::Vector& vector = varying_passthrough.Get(stage);
6350
6351         std::string result   = Utils::g_list;
6352         size_t          position = 0;
6353
6354         for (GLuint i = 0; i < vector.size(); ++i)
6355         {
6356
6357                 Utils::VaryingConnection& connection = vector[i];
6358
6359                 Utils::Variable* in  = connection.m_in;
6360                 Utils::Variable* out = connection.m_out;
6361
6362                 Utils::Variable::FLAVOUR in_flavour  = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6363                 Utils::Variable::FLAVOUR out_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::OUTPUT);
6364
6365                 const std::string passthrough =
6366                         getVariablePassthrough("", in->m_descriptor, in_flavour, "", out->m_descriptor, out_flavour);
6367
6368                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6369         }
6370
6371         Utils::endList("", position, result);
6372
6373         return result;
6374 }
6375
6376 /** Basic implementation of method getProgramInterface
6377  *
6378  * @param ignored
6379  * @param ignored
6380  * @param ignored
6381  **/
6382 void TextureTestBase::getProgramInterface(GLuint /* test_case_index */,
6383                                                                                   Utils::ProgramInterface& /* program_interface */,
6384                                                                                   Utils::VaryingPassthrough& /* varying_passthrough */)
6385 {
6386 }
6387
6388 /** Prepare code snippet that will verify in and uniform variables
6389  *
6390  * @param ignored
6391  * @param program_interface Interface of program
6392  * @param stage             Shader stage
6393  *
6394  * @return Code that verify variables
6395  **/
6396 std::string TextureTestBase::getVerificationSnippet(GLuint /* test_case_index */,
6397                                                                                                         Utils::ProgramInterface& program_interface,
6398                                                                                                         Utils::Shader::STAGES   stage)
6399 {
6400         static const GLchar* separator = " ||\n        ";
6401
6402         std::string verification = "if (LIST)\n"
6403                                                            "    {\n"
6404                                                            "        result = 0u;\n"
6405                                                            "    }\n";
6406
6407         /* Get flavour of in and out variables */
6408         Utils::Variable::FLAVOUR in_flavour = Utils::Variable::GetFlavour(stage, Utils::Variable::INPUT);
6409
6410         /* Get interface for shader stage */
6411         Utils::ShaderInterface& si = program_interface.GetShaderInterface(stage);
6412
6413         /* There are no varialbes to verify */
6414         if ((0 == si.m_inputs.size()) && (0 == si.m_uniforms.size()) && (0 == si.m_ssb_blocks.size()))
6415         {
6416                 return "";
6417         }
6418
6419         /* For each in variable insert verification code */
6420         size_t position = 0;
6421
6422         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6423         {
6424                 const Utils::Variable& var                              = *si.m_inputs[i];
6425                 const std::string&       var_verification = getVariableVerifcation("", var.m_data, var.m_descriptor, in_flavour);
6426
6427                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6428         }
6429
6430         /* For each unifrom variable insert verification code */
6431         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6432         {
6433                 const Utils::Variable& var = *si.m_uniforms[i];
6434                 const std::string&       var_verification =
6435                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6436
6437                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6438         }
6439
6440         /* For each ssb variable insert verification code */
6441         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6442         {
6443                 const Utils::Variable& var = *si.m_ssb_blocks[i];
6444                 const std::string&       var_verification =
6445                         getVariableVerifcation("", var.m_data, var.m_descriptor, Utils::Variable::BASIC);
6446
6447                 Utils::insertElementOfList(var_verification.c_str(), separator, position, verification);
6448         }
6449
6450         Utils::endList("", position, verification);
6451
6452 #if DEBUG_TTB_VERIFICATION_SNIPPET_STAGE
6453
6454         {
6455                 GLchar buffer[16];
6456                 sprintf(buffer, "%d", stage + 10);
6457                 Utils::replaceToken("0u", position, buffer, verification);
6458         }
6459
6460 #elif DEBUG_TTB_VERIFICATION_SNIPPET_VARIABLE
6461
6462         if (Utils::Shader::VERTEX == stage)
6463         {
6464                 Utils::replaceToken("0u", position, "in_vs_first.x", verification);
6465         }
6466         else
6467         {
6468                 Utils::replaceToken("0u", position, "31u", verification);
6469         }
6470
6471 #endif
6472
6473         /* Done */
6474         return verification;
6475 }
6476
6477 /** Selects if "compute" stage is relevant for test
6478  *
6479  * @param ignored
6480  *
6481  * @return true
6482  **/
6483 bool TextureTestBase::isComputeRelevant(GLuint /* test_case_index */)
6484 {
6485         return true;
6486 }
6487
6488 /** Selects if "draw" stages are relevant for test
6489  *
6490  * @param ignored
6491  *
6492  * @return true
6493  **/
6494 bool TextureTestBase::isDrawRelevant(GLuint /* test_case_index */)
6495 {
6496         return true;
6497 }
6498
6499 /** Prepare code that will do assignment of single in to single out
6500  *
6501  * @param in_parent_name  Name of parent in variable
6502  * @param in_variable     Descriptor of in variable
6503  * @param in_flavour      Flavoud of in variable
6504  * @param out_parent_name Name of parent out variable
6505  * @param out_variable    Descriptor of out variable
6506  * @param out_flavour     Flavoud of out variable
6507  *
6508  * @return Code that does OUT = IN
6509  **/
6510 std::string TextureTestBase::getVariablePassthrough(const std::string&                             in_parent_name,
6511                                                                                                         const Utils::Variable::Descriptor& in_variable,
6512                                                                                                         Utils::Variable::FLAVOUR                   in_flavour,
6513                                                                                                         const std::string&                                 out_parent_name,
6514                                                                                                         const Utils::Variable::Descriptor& out_variable,
6515                                                                                                         Utils::Variable::FLAVOUR                   out_flavour)
6516 {
6517         bool                             done             = false;
6518         GLuint                           index            = 0;
6519         GLuint                           member_index = 0;
6520         size_t                           position        = 0;
6521         std::string                      result           = Utils::g_list;
6522         static const GLchar* separator  = ";\n    ";
6523
6524         /* For each member of each array element */
6525         do
6526         {
6527                 const std::string in_name  = Utils::Variable::GetReference(in_parent_name, in_variable, in_flavour, index);
6528                 const std::string out_name = Utils::Variable::GetReference(out_parent_name, out_variable, out_flavour, index);
6529                 std::string               passthrough;
6530
6531                 /* Prepare verification */
6532                 if (Utils::Variable::BUILTIN == in_variable.m_type)
6533                 {
6534                         size_t pass_position = 0;
6535
6536                         passthrough = "OUT = IN;";
6537
6538                         Utils::replaceToken("OUT", pass_position, out_name.c_str(), passthrough);
6539                         Utils::replaceToken("IN", pass_position, in_name.c_str(), passthrough);
6540
6541                         /* Increment index */
6542                         ++index;
6543                 }
6544                 else
6545                 {
6546                         const Utils::Interface* in_interface  = in_variable.m_interface;
6547                         const Utils::Interface* out_interface = out_variable.m_interface;
6548
6549                         if ((0 == in_interface) || (0 == out_interface))
6550                         {
6551                                 TCU_FAIL("Nullptr");
6552                         }
6553
6554                         const Utils::Variable::Descriptor& in_member  = in_interface->m_members[member_index];
6555                         const Utils::Variable::Descriptor& out_member = out_interface->m_members[member_index];
6556
6557                         passthrough = getVariablePassthrough(in_name, in_member, Utils::Variable::BASIC, out_name, out_member,
6558                                                                                                  Utils::Variable::BASIC);
6559
6560                         /* Increment member_index */
6561                         ++member_index;
6562
6563                         /* Increment index and reset member_index if all members were processed */
6564                         if (in_interface->m_members.size() == member_index)
6565                         {
6566                                 ++index;
6567                                 member_index = 0;
6568                         }
6569                 }
6570
6571                 /* Check if loop should end */
6572                 if ((index >= in_variable.m_n_array_elements) && (0 == member_index))
6573                 {
6574                         done = true;
6575                 }
6576
6577                 Utils::insertElementOfList(passthrough.c_str(), separator, position, result);
6578
6579         } while (true != done);
6580
6581         Utils::endList("", position, result);
6582
6583         /* Done */
6584         return result;
6585 }
6586
6587 /** Get verification of single variable
6588  *
6589  * @param parent_name Name of parent variable
6590  * @param data        Data that should be used as EXPECTED
6591  * @param variable    Descriptor of variable
6592  * @param flavour     Flavour of variable
6593  *
6594  * @return Code that does (EXPECTED != VALUE) ||
6595  **/
6596 std::string TextureTestBase::getVariableVerifcation(const std::string& parent_name, const GLvoid* data,
6597                                                                                                         const Utils::Variable::Descriptor& variable,
6598                                                                                                         Utils::Variable::FLAVOUR                   flavour)
6599 {
6600         static const GLchar* logic_op   = " ||\n        ";
6601         const GLuint             n_elements = (0 == variable.m_n_array_elements) ? 1 : variable.m_n_array_elements;
6602         size_t                           position   = 0;
6603         std::string                      result         = Utils::g_list;
6604         GLint                            stride         = variable.m_expected_stride_of_element;
6605
6606         /* For each each array element */
6607         for (GLuint element = 0; element < n_elements; ++element)
6608         {
6609                 const std::string name = Utils::Variable::GetReference(parent_name, variable, flavour, element);
6610
6611                 /* Calculate data pointer */
6612                 GLvoid* data_ptr = (GLvoid*)((GLubyte*)data + element * stride);
6613
6614                 /* Prepare verification */
6615                 if (Utils::Variable::BUILTIN == variable.m_type)
6616                 {
6617                         const std::string& expected = variable.m_builtin.GetGLSLConstructor(data_ptr);
6618                         std::string                verification;
6619                         size_t                     verification_position = 0;
6620
6621                         verification = "(EXPECTED != NAME)";
6622
6623                         Utils::replaceToken("EXPECTED", verification_position, expected.c_str(), verification);
6624                         Utils::replaceToken("NAME", verification_position, name.c_str(), verification);
6625
6626                         Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6627                 }
6628                 else
6629                 {
6630                         const Utils::Interface* interface = variable.m_interface;
6631
6632                         if (0 == interface)
6633                         {
6634                                 TCU_FAIL("Nullptr");
6635                         }
6636
6637                         const GLuint n_members = static_cast<GLuint>(interface->m_members.size());
6638
6639                         /* for each member */
6640                         for (GLuint member_index = 0; member_index < n_members; ++member_index)
6641                         {
6642                                 const Utils::Variable::Descriptor& member = interface->m_members[member_index];
6643
6644                                 /* Get verification of member */
6645                                 const std::string& verification =
6646                                         getVariableVerifcation(name, (GLubyte*)data_ptr + member.m_offset, member, Utils::Variable::BASIC);
6647
6648                                 Utils::insertElementOfList(verification.c_str(), logic_op, position, result);
6649                         }
6650                 }
6651         }
6652
6653         Utils::endList("", position, result);
6654
6655         return result;
6656 }
6657
6658 /** Prepare attributes, vertex array object and array buffer
6659  *
6660  * @param test_case_index   Index of test case
6661  * @param program_interface Interface of program
6662  * @param buffer            Array buffer
6663  * @param vao               Vertex array object
6664  **/
6665 void TextureTestBase::prepareAttributes(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6666                                                                                 Utils::Buffer& buffer, Utils::VertexArray& vao)
6667 {
6668         bool use_component_qualifier = useComponentQualifier(test_case_index);
6669
6670         /* Get shader interface */
6671         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6672
6673         /* Bind vao and buffer */
6674         vao.Bind();
6675         buffer.Bind();
6676
6677         /* Skip if there are no input variables in vertex shader */
6678         if (0 == si.m_inputs.size())
6679         {
6680                 return;
6681         }
6682
6683         /* Calculate vertex stride and check */
6684         GLint vertex_stride = 0;
6685
6686         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6687         {
6688                 Utils::Variable& variable = *si.m_inputs[i];
6689
6690                 GLint variable_size = static_cast<GLuint>(variable.m_data_size);
6691
6692                 GLint ends_at = variable_size + variable.m_descriptor.m_offset;
6693
6694                 vertex_stride = std::max(vertex_stride, ends_at);
6695         }
6696
6697         /* Prepare buffer data and set up vao */
6698         std::vector<GLubyte> buffer_data;
6699         buffer_data.resize(vertex_stride);
6700
6701         GLubyte* ptr = &buffer_data[0];
6702
6703         for (GLuint i = 0; i < si.m_inputs.size(); ++i)
6704         {
6705                 Utils::Variable& variable = *si.m_inputs[i];
6706
6707                 memcpy(ptr + variable.m_descriptor.m_offset, variable.m_data, variable.m_data_size);
6708
6709                 if (false == use_component_qualifier)
6710                 {
6711                         vao.Attribute(variable.m_descriptor.m_expected_location, variable.m_descriptor.m_builtin,
6712                                                   variable.m_descriptor.m_n_array_elements, variable.m_descriptor.m_normalized,
6713                                                   variable.GetStride(), (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6714                 }
6715                 else if (0 == variable.m_descriptor.m_expected_component)
6716                 {
6717                         /* Components can only be applied to vectors.
6718                          Assumption that test use all 4 components */
6719                         const Utils::Type& type =
6720                                 Utils::Type::GetType(variable.m_descriptor.m_builtin.m_basic_type, 1 /* n_columns */, 4 /* n_rows */);
6721
6722                         vao.Attribute(variable.m_descriptor.m_expected_location, type, variable.m_descriptor.m_n_array_elements,
6723                                                   variable.m_descriptor.m_normalized, variable.GetStride(),
6724                                                   (GLvoid*)(intptr_t)variable.m_descriptor.m_offset);
6725                 }
6726         }
6727
6728         /* Update buffer */
6729         buffer.Data(Utils::Buffer::StaticDraw, vertex_stride, ptr);
6730 }
6731
6732 /** Get locations for all outputs with automatic_location
6733  *
6734  * @param program           Program object
6735  * @param program_interface Interface of program
6736  **/
6737 void TextureTestBase::prepareFragmentDataLoc(Utils::Program& program, Utils::ProgramInterface& program_interface)
6738 {
6739         Utils::ShaderInterface&         si              = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6740         Utils::Variable::PtrVector& outputs = si.m_outputs;
6741
6742         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
6743         {
6744                 /* Test does not specify location, query value and set */
6745                 if (Utils::Variable::m_automatic_location == (*it)->m_descriptor.m_expected_location)
6746                 {
6747                         GLuint index    = program.GetResourceIndex((*it)->m_descriptor.m_name, GL_PROGRAM_OUTPUT);
6748                         GLint  location = 0;
6749
6750                         program.GetResource(GL_PROGRAM_OUTPUT, index, GL_LOCATION, 1 /* size */, &location);
6751
6752                         (*it)->m_descriptor.m_expected_location = location;
6753                 }
6754         }
6755 }
6756
6757 /** Prepare framebuffer with single texture as color attachment
6758  *
6759  * @param framebuffer     Framebuffer
6760  * @param color_0_texture Texture that will used as color attachment
6761  **/
6762 void TextureTestBase::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
6763 {
6764         /* Prepare data */
6765         std::vector<GLuint> texture_data;
6766         texture_data.resize(m_width * m_height);
6767
6768         for (GLuint i = 0; i < texture_data.size(); ++i)
6769         {
6770                 texture_data[i] = 0x20406080;
6771         }
6772
6773         /* Prepare texture */
6774         color_0_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6775                                                  &texture_data[0]);
6776
6777         /* Prepare framebuffer */
6778         framebuffer.Init();
6779         framebuffer.Bind();
6780         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0, color_0_texture.m_id, m_width, m_height);
6781
6782         framebuffer.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
6783         framebuffer.Clear(GL_COLOR_BUFFER_BIT);
6784 }
6785
6786 /** Prepare iamge unit for compute shader
6787  *
6788  * @param location      Uniform location
6789  * @param image_texture Texture that will used as color attachment
6790  **/
6791 void TextureTestBase::prepareImage(GLint location, Utils::Texture& image_texture) const
6792 {
6793         static const GLuint image_unit = 0;
6794
6795         std::vector<GLuint> texture_data;
6796         texture_data.resize(m_width * m_height);
6797
6798         for (GLuint i = 0; i < texture_data.size(); ++i)
6799         {
6800                 texture_data[i] = 0x20406080;
6801         }
6802
6803         image_texture.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT,
6804                                            &texture_data[0]);
6805
6806         const Functions& gl = m_context.getRenderContext().getFunctions();
6807
6808         gl.bindImageTexture(image_unit, image_texture.m_id, 0 /* level */, GL_FALSE /* layered */, 0 /* Layer */,
6809                                                 GL_WRITE_ONLY, GL_R32UI);
6810         GLU_EXPECT_NO_ERROR(gl.getError(), "BindImageTexture");
6811
6812         Utils::Program::Uniform(gl, Utils::Type::_int, 1 /* count */, location, &image_unit);
6813 }
6814
6815 /** Basic implementation
6816  *
6817  * @param ignored
6818  * @param si        Shader interface
6819  * @param program   Program
6820  * @param cs_buffer Buffer for ssb blocks
6821  **/
6822 void TextureTestBase::prepareSSBs(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6823                                                                   Utils::Buffer& buffer)
6824 {
6825         /* Skip if there are no input variables in vertex shader */
6826         if (0 == si.m_ssb_blocks.size())
6827         {
6828                 return;
6829         }
6830
6831         /* Calculate vertex stride */
6832         GLint ssbs_stride = 0;
6833
6834         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6835         {
6836                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6837
6838                 if (false == variable.IsBlock())
6839                 {
6840                         continue;
6841                 }
6842
6843                 GLint variable_stride = variable.GetStride();
6844
6845                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6846
6847                 ssbs_stride = std::max(ssbs_stride, ends_at);
6848         }
6849
6850         /* Set active program */
6851         program.Use();
6852
6853         /* Allocate */
6854         buffer.Bind();
6855         buffer.Data(Utils::Buffer::StaticDraw, ssbs_stride, 0);
6856
6857         /* Set up uniforms */
6858         for (GLuint i = 0; i < si.m_ssb_blocks.size(); ++i)
6859         {
6860                 Utils::Variable& variable = *si.m_ssb_blocks[i];
6861
6862                 /* prepareUnifor should work fine for ssb blocks */
6863                 prepareUniform(program, variable, buffer);
6864         }
6865 }
6866
6867 /** Basic implementation
6868  *
6869  * @param test_case_index   Test case index
6870  * @param program_interface Program interface
6871  * @param program           Program
6872  * @param cs_buffer         Buffer for compute shader stage
6873  **/
6874 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6875                                                                   Utils::Program& program, Utils::Buffer& cs_buffer)
6876 {
6877         cs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6878
6879         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
6880
6881         prepareSSBs(test_case_index, cs, program, cs_buffer);
6882
6883         cs_buffer.BindBase(Utils::Shader::COMPUTE);
6884 }
6885
6886 /** Basic implementation
6887  *
6888  * @param test_case_index   Test case index
6889  * @param program_interface Program interface
6890  * @param program           Program
6891  * @param fs_buffer         Buffer for fragment shader stage
6892  * @param gs_buffer         Buffer for geometry shader stage
6893  * @param tcs_buffer        Buffer for tessellation control shader stage
6894  * @param tes_buffer        Buffer for tessellation evaluation shader stage
6895  * @param vs_buffer         Buffer for vertex shader stage
6896  **/
6897 void TextureTestBase::prepareSSBs(GLuint test_case_index, Utils::ProgramInterface& program_interface,
6898                                                                   Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
6899                                                                   Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
6900 {
6901         fs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6902         gs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6903         tcs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6904         tes_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6905         vs_buffer.Init(Utils::Buffer::Shader_Storage, Utils::Buffer::StaticDraw, 0, 0);
6906
6907         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
6908         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
6909         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
6910         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
6911         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
6912
6913         prepareSSBs(test_case_index, fs, program, fs_buffer);
6914         prepareSSBs(test_case_index, gs, program, gs_buffer);
6915         prepareSSBs(test_case_index, tcs, program, tcs_buffer);
6916         prepareSSBs(test_case_index, tes, program, tes_buffer);
6917         prepareSSBs(test_case_index, vs, program, vs_buffer);
6918
6919         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
6920         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
6921         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
6922         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
6923         vs_buffer.BindBase(Utils::Shader::VERTEX);
6924 }
6925
6926 /** Updates buffer data with variable
6927  *
6928  * @param program  Program object
6929  * @param variable Variable
6930  * @param buffer   Buffer
6931  **/
6932 void TextureTestBase::prepareUniform(Utils::Program& program, Utils::Variable& variable, Utils::Buffer& buffer)
6933 {
6934         const Functions& gl = m_context.getRenderContext().getFunctions();
6935
6936         GLsizei count = variable.m_descriptor.m_n_array_elements;
6937         if (0 == count)
6938         {
6939                 count = 1;
6940         }
6941
6942         if (Utils::Variable::BUILTIN == variable.m_descriptor.m_type)
6943         {
6944                 program.Uniform(gl, variable.m_descriptor.m_builtin, count, variable.m_descriptor.m_expected_location,
6945                                                 variable.m_data);
6946         }
6947         else
6948         {
6949                 const bool is_block = variable.IsBlock();
6950
6951                 if (false == is_block)
6952                 {
6953                         TCU_FAIL("Not implemented");
6954                 }
6955                 else
6956                 {
6957                         buffer.SubData(variable.m_descriptor.m_offset, variable.m_descriptor.m_expected_stride_of_element * count,
6958                                                    variable.m_data);
6959                 }
6960         }
6961 }
6962
6963 /** Basic implementation
6964  *
6965  * @param ignored
6966  * @param si        Shader interface
6967  * @param program   Program
6968  * @param cs_buffer Buffer for uniform blocks
6969  **/
6970 void TextureTestBase::prepareUniforms(GLuint /* test_case_index */, Utils::ShaderInterface& si, Utils::Program& program,
6971                                                                           Utils::Buffer& buffer)
6972 {
6973         /* Skip if there are no input variables in vertex shader */
6974         if (0 == si.m_uniforms.size())
6975         {
6976                 return;
6977         }
6978
6979         /* Calculate vertex stride */
6980         GLint uniforms_stride = 0;
6981
6982         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
6983         {
6984                 Utils::Variable& variable = *si.m_uniforms[i];
6985
6986                 if (false == variable.IsBlock())
6987                 {
6988                         continue;
6989                 }
6990
6991                 GLint variable_stride = variable.GetStride();
6992
6993                 GLint ends_at = variable_stride + variable.m_descriptor.m_offset;
6994
6995                 uniforms_stride = std::max(uniforms_stride, ends_at);
6996         }
6997
6998         /* Set active program */
6999         program.Use();
7000
7001         /* Allocate */
7002         buffer.Bind();
7003         buffer.Data(Utils::Buffer::StaticDraw, uniforms_stride, 0);
7004
7005         /* Set up uniforms */
7006         for (GLuint i = 0; i < si.m_uniforms.size(); ++i)
7007         {
7008                 Utils::Variable& variable = *si.m_uniforms[i];
7009
7010                 prepareUniform(program, variable, buffer);
7011         }
7012 }
7013
7014 /** Basic implementation
7015  *
7016  * @param test_case_index   Test case index
7017  * @param program_interface Program interface
7018  * @param program           Program
7019  * @param cs_buffer         Buffer for compute shader stage
7020  **/
7021 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7022                                                                           Utils::Program& program, Utils::Buffer& cs_buffer)
7023 {
7024         cs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7025
7026         Utils::ShaderInterface& cs = program_interface.GetShaderInterface(Utils::Shader::COMPUTE);
7027
7028         prepareUniforms(test_case_index, cs, program, cs_buffer);
7029
7030         cs_buffer.BindBase(Utils::Shader::COMPUTE);
7031 }
7032
7033 /** Basic implementation
7034  *
7035  * @param test_case_index   Test case index
7036  * @param program_interface Program interface
7037  * @param program           Program
7038  * @param fs_buffer         Buffer for fragment shader stage
7039  * @param gs_buffer         Buffer for geometry shader stage
7040  * @param tcs_buffer        Buffer for tessellation control shader stage
7041  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7042  * @param vs_buffer         Buffer for vertex shader stage
7043  **/
7044 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7045                                                                           Utils::Program& program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7046                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7047 {
7048         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7049         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7050         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7051         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7052         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7053
7054         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7055         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7056         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7057         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7058         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7059
7060         prepareUniforms(test_case_index, fs, program, fs_buffer);
7061         prepareUniforms(test_case_index, gs, program, gs_buffer);
7062         prepareUniforms(test_case_index, tcs, program, tcs_buffer);
7063         prepareUniforms(test_case_index, tes, program, tes_buffer);
7064         prepareUniforms(test_case_index, vs, program, vs_buffer);
7065
7066         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7067         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7068         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7069         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7070         vs_buffer.BindBase(Utils::Shader::VERTEX);
7071 }
7072
7073 /** Basic implementation
7074  *
7075  * @param test_case_index   Test case index
7076  * @param program_interface Program interface
7077  * @param program           Program
7078  * @param fs_buffer         Buffer for fragment shader stage
7079  * @param gs_buffer         Buffer for geometry shader stage
7080  * @param tcs_buffer        Buffer for tessellation control shader stage
7081  * @param tes_buffer        Buffer for tessellation evaluation shader stage
7082  * @param vs_buffer         Buffer for vertex shader stage
7083  **/
7084 void TextureTestBase::prepareUniforms(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7085                                                                           Utils::Program& fs_program, Utils::Program& gs_program,
7086                                                                           Utils::Program& tcs_program, Utils::Program& tes_program,
7087                                                                           Utils::Program& vs_program, Utils::Buffer& fs_buffer, Utils::Buffer& gs_buffer,
7088                                                                           Utils::Buffer& tcs_buffer, Utils::Buffer& tes_buffer, Utils::Buffer& vs_buffer)
7089 {
7090         fs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7091         gs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7092         tcs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7093         tes_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7094         vs_buffer.Init(Utils::Buffer::Uniform, Utils::Buffer::StaticDraw, 0, 0);
7095
7096         Utils::ShaderInterface& fs  = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
7097         Utils::ShaderInterface& gs  = program_interface.GetShaderInterface(Utils::Shader::GEOMETRY);
7098         Utils::ShaderInterface& tcs = program_interface.GetShaderInterface(Utils::Shader::TESS_CTRL);
7099         Utils::ShaderInterface& tes = program_interface.GetShaderInterface(Utils::Shader::TESS_EVAL);
7100         Utils::ShaderInterface& vs  = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
7101
7102         prepareUniforms(test_case_index, fs, fs_program, fs_buffer);
7103         fs_buffer.BindBase(Utils::Shader::FRAGMENT);
7104
7105         prepareUniforms(test_case_index, gs, gs_program, gs_buffer);
7106         gs_buffer.BindBase(Utils::Shader::GEOMETRY);
7107
7108         prepareUniforms(test_case_index, tcs, tcs_program, tcs_buffer);
7109         tcs_buffer.BindBase(Utils::Shader::TESS_CTRL);
7110
7111         prepareUniforms(test_case_index, tes, tes_program, tes_buffer);
7112         tes_buffer.BindBase(Utils::Shader::TESS_EVAL);
7113
7114         prepareUniforms(test_case_index, vs, vs_program, vs_buffer);
7115         vs_buffer.BindBase(Utils::Shader::VERTEX);
7116 }
7117
7118 /** Prepare source for shader
7119  *
7120  * @param test_case_index     Index of test case
7121  * @param program_interface   Interface of program
7122  * @param varying_passthrough Collection of connection between in and out variables
7123  * @param stage               Shader stage
7124  *
7125  * @return Source of shader
7126  **/
7127 std::string TextureTestBase::getShaderSource(GLuint test_case_index, Utils::ProgramInterface& program_interface,
7128                                                                                          Utils::VaryingPassthrough& varying_passthrough,
7129                                                                                          Utils::Shader::STAGES          stage)
7130 {
7131         /* Get strings */
7132         const GLchar*     shader_template  = getShaderTemplate(stage);
7133         const std::string& shader_interface = program_interface.GetInterfaceForStage(stage);
7134
7135         const std::string& verification = getVerificationSnippet(test_case_index, program_interface, stage);
7136
7137         const std::string& passthrough = getPassSnippet(test_case_index, varying_passthrough, stage);
7138
7139         const GLchar* per_vertex = "";
7140
7141         std::string source   = shader_template;
7142         size_t          position = 0;
7143
7144         /* Replace tokens in template */
7145         if (Utils::Shader::GEOMETRY == stage)
7146         {
7147                 if (false == useMonolithicProgram(test_case_index))
7148                 {
7149                         per_vertex = "out gl_PerVertex {\n"
7150                                                  "vec4 gl_Position;\n"
7151                                                  "};\n"
7152                                                  "\n";
7153                 }
7154
7155                 Utils::replaceToken("PERVERTEX", position, per_vertex, source);
7156         }
7157
7158         Utils::replaceToken("INTERFACE", position, shader_interface.c_str(), source);
7159         Utils::replaceToken("VERIFICATION", position, verification.c_str(), source);
7160
7161         if (false == verification.empty())
7162         {
7163                 Utils::replaceAllTokens("ELSE", "    else ", source);
7164         }
7165         else
7166         {
7167                 Utils::replaceAllTokens("ELSE", "", source);
7168         }
7169
7170         Utils::replaceAllTokens("PASSTHROUGH", passthrough.c_str(), source);
7171
7172         /* Done */
7173         return source;
7174 }
7175
7176 /** Returns template of shader for given stage
7177  *
7178  * @param stage Shade stage
7179  *
7180  * @return Proper template
7181  **/
7182 const GLchar* TextureTestBase::getShaderTemplate(Utils::Shader::STAGES stage)
7183 {
7184
7185         static const GLchar* compute_shader_template =
7186                 "#version 430 core\n"
7187                 "#extension GL_ARB_enhanced_layouts : require\n"
7188                 "\n"
7189                 "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
7190                 "\n"
7191                 "writeonly uniform uimage2D uni_image;\n"
7192                 "\n"
7193                 "INTERFACE"
7194                 "\n"
7195                 "void main()\n"
7196                 "{\n"
7197                 "    uint result = 1u;\n"
7198                 "\n"
7199                 "    VERIFICATION"
7200                 "\n"
7201                 "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
7202                 "}\n"
7203                 "\n";
7204
7205         static const GLchar* fragment_shader_template = "#version 430 core\n"
7206                                                                                                         "#extension GL_ARB_enhanced_layouts : require\n"
7207                                                                                                         "\n"
7208                                                                                                         "flat in  uint gs_fs_result;\n"
7209                                                                                                         "     out uint fs_out_result;\n"
7210                                                                                                         "\n"
7211                                                                                                         "INTERFACE"
7212                                                                                                         "\n"
7213                                                                                                         "void main()\n"
7214                                                                                                         "{\n"
7215                                                                                                         "    uint result = 1u;\n"
7216                                                                                                         "\n"
7217                                                                                                         "    if (1u != gs_fs_result)\n"
7218                                                                                                         "    {\n"
7219                                                                                                         "         result = gs_fs_result;\n"
7220                                                                                                         "    }\n"
7221                                                                                                         "ELSEVERIFICATION"
7222                                                                                                         "\n"
7223                                                                                                         "    fs_out_result = result;\n"
7224                                                                                                         "    PASSTHROUGH\n"
7225                                                                                                         "}\n"
7226                                                                                                         "\n";
7227
7228         static const GLchar* geometry_shader_template =
7229                 "#version 430 core\n"
7230                 "#extension GL_ARB_enhanced_layouts : require\n"
7231                 "\n"
7232                 "layout(points)                           in;\n"
7233                 "layout(triangle_strip, max_vertices = 4) out;\n"
7234                 "\n"
7235                 "     in  uint tes_gs_result[];\n"
7236                 "flat out uint gs_fs_result;\n"
7237                 "\n"
7238                 "PERVERTEX" /* Separable programs require explicit declaration of gl_PerVertex */
7239                 "INTERFACE"
7240                 "\n"
7241                 "void main()\n"
7242                 "{\n"
7243                 "    uint result = 1u;\n"
7244                 "\n"
7245                 "    if (1u != tes_gs_result[0])\n"
7246                 "    {\n"
7247                 "         result = tes_gs_result[0];\n"
7248                 "    }\n"
7249                 "ELSEVERIFICATION"
7250                 "\n"
7251                 "    gs_fs_result = result;\n"
7252                 "    PASSTHROUGH\n"
7253                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
7254                 "    EmitVertex();\n"
7255                 "    gs_fs_result = result;\n"
7256                 "    PASSTHROUGH\n"
7257                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
7258                 "    EmitVertex();\n"
7259                 "    gs_fs_result = result;\n"
7260                 "    PASSTHROUGH\n"
7261                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
7262                 "    EmitVertex();\n"
7263                 "    gs_fs_result = result;\n"
7264                 "    PASSTHROUGH\n"
7265                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
7266                 "    EmitVertex();\n"
7267                 "}\n"
7268                 "\n";
7269
7270         static const GLchar* tess_ctrl_shader_template = "#version 430 core\n"
7271                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7272                                                                                                          "\n"
7273                                                                                                          "layout(vertices = 1) out;\n"
7274                                                                                                          "\n"
7275                                                                                                          "in  uint vs_tcs_result[];\n"
7276                                                                                                          "out uint tcs_tes_result[];\n"
7277                                                                                                          "\n"
7278                                                                                                          "INTERFACE"
7279                                                                                                          "\n"
7280                                                                                                          "void main()\n"
7281                                                                                                          "{\n"
7282                                                                                                          "    uint result = 1u;\n"
7283                                                                                                          "\n"
7284                                                                                                          "    if (1u != vs_tcs_result[gl_InvocationID])\n"
7285                                                                                                          "    {\n"
7286                                                                                                          "         result = vs_tcs_result[gl_InvocationID];\n"
7287                                                                                                          "    }\n"
7288                                                                                                          "ELSEVERIFICATION"
7289                                                                                                          "\n"
7290                                                                                                          "    tcs_tes_result[gl_InvocationID] = result;\n"
7291                                                                                                          "\n"
7292                                                                                                          "    PASSTHROUGH\n"
7293                                                                                                          "\n"
7294                                                                                                          "    gl_TessLevelOuter[0] = 1.0;\n"
7295                                                                                                          "    gl_TessLevelOuter[1] = 1.0;\n"
7296                                                                                                          "    gl_TessLevelOuter[2] = 1.0;\n"
7297                                                                                                          "    gl_TessLevelOuter[3] = 1.0;\n"
7298                                                                                                          "    gl_TessLevelInner[0] = 1.0;\n"
7299                                                                                                          "    gl_TessLevelInner[1] = 1.0;\n"
7300                                                                                                          "}\n"
7301                                                                                                          "\n";
7302
7303         static const GLchar* tess_eval_shader_template = "#version 430 core\n"
7304                                                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
7305                                                                                                          "\n"
7306                                                                                                          "layout(isolines, point_mode) in;\n"
7307                                                                                                          "\n"
7308                                                                                                          "in  uint tcs_tes_result[];\n"
7309                                                                                                          "out uint tes_gs_result;\n"
7310                                                                                                          "\n"
7311                                                                                                          "INTERFACE"
7312                                                                                                          "\n"
7313                                                                                                          "void main()\n"
7314                                                                                                          "{\n"
7315                                                                                                          "    uint result = 1u;\n"
7316                                                                                                          "\n"
7317                                                                                                          "    if (1 != tcs_tes_result[0])\n"
7318                                                                                                          "    {\n"
7319                                                                                                          "         result = tcs_tes_result[0];\n"
7320                                                                                                          "    }\n"
7321                                                                                                          "ELSEVERIFICATION"
7322                                                                                                          "\n"
7323                                                                                                          "    tes_gs_result = result;\n"
7324                                                                                                          "\n"
7325                                                                                                          "    PASSTHROUGH\n"
7326                                                                                                          "}\n"
7327                                                                                                          "\n";
7328
7329         static const GLchar* vertex_shader_template = "#version 430 core\n"
7330                                                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7331                                                                                                   "\n"
7332                                                                                                   "out uint vs_tcs_result;\n"
7333                                                                                                   "\n"
7334                                                                                                   "INTERFACE"
7335                                                                                                   "\n"
7336                                                                                                   "void main()\n"
7337                                                                                                   "{\n"
7338                                                                                                   "    uint result = 1u;\n"
7339                                                                                                   "\n"
7340                                                                                                   "    VERIFICATION\n"
7341                                                                                                   "\n"
7342                                                                                                   "    vs_tcs_result = result;\n"
7343                                                                                                   "\n"
7344                                                                                                   "    PASSTHROUGH\n"
7345                                                                                                   "}\n"
7346                                                                                                   "\n";
7347
7348         const GLchar* result = 0;
7349
7350         switch (stage)
7351         {
7352         case Utils::Shader::COMPUTE:
7353                 result = compute_shader_template;
7354                 break;
7355         case Utils::Shader::FRAGMENT:
7356                 result = fragment_shader_template;
7357                 break;
7358         case Utils::Shader::GEOMETRY:
7359                 result = geometry_shader_template;
7360                 break;
7361         case Utils::Shader::TESS_CTRL:
7362                 result = tess_ctrl_shader_template;
7363                 break;
7364         case Utils::Shader::TESS_EVAL:
7365                 result = tess_eval_shader_template;
7366                 break;
7367         case Utils::Shader::VERTEX:
7368                 result = vertex_shader_template;
7369                 break;
7370         default:
7371                 TCU_FAIL("Invalid enum");
7372         }
7373
7374         return result;
7375 }
7376
7377 /** Runs test case
7378  *
7379  * @param test_case_index Id of test case
7380  *
7381  * @return true if test case pass, false otherwise
7382  **/
7383 bool TextureTestBase::testCase(GLuint test_case_index)
7384 {
7385         try
7386         {
7387                 if (true == useMonolithicProgram(test_case_index))
7388                 {
7389                         return testMonolithic(test_case_index);
7390                 }
7391                 else
7392                 {
7393                         return testSeparable(test_case_index);
7394                 }
7395         }
7396         catch (Utils::Shader::InvalidSourceException& exc)
7397         {
7398                 exc.log(m_context);
7399                 TCU_FAIL(exc.what());
7400         }
7401         catch (Utils::Program::BuildException& exc)
7402         {
7403                 TCU_FAIL(exc.what());
7404         }
7405 }
7406
7407 /** Runs "draw" test with monolithic program
7408  *
7409  * @param test_case_index Id of test case
7410  **/
7411 bool TextureTestBase::testMonolithic(GLuint test_case_index)
7412 {
7413         Utils::ProgramInterface   program_interface;
7414         Utils::VaryingPassthrough varying_passthrough;
7415
7416         /* */
7417         const std::string& test_name = getTestCaseName(test_case_index);
7418
7419         /* */
7420         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7421
7422         bool result = true;
7423         /* Draw */
7424         if (true == isDrawRelevant(test_case_index))
7425         {
7426                 Utils::Buffer     buffer_attr(m_context);
7427                 Utils::Buffer     buffer_ssb_fs(m_context);
7428                 Utils::Buffer     buffer_ssb_gs(m_context);
7429                 Utils::Buffer     buffer_ssb_tcs(m_context);
7430                 Utils::Buffer     buffer_ssb_tes(m_context);
7431                 Utils::Buffer     buffer_ssb_vs(m_context);
7432                 Utils::Buffer     buffer_u_fs(m_context);
7433                 Utils::Buffer     buffer_u_gs(m_context);
7434                 Utils::Buffer     buffer_u_tcs(m_context);
7435                 Utils::Buffer     buffer_u_tes(m_context);
7436                 Utils::Buffer     buffer_u_vs(m_context);
7437                 Utils::Framebuffer framebuffer(m_context);
7438                 Utils::Program   program(m_context);
7439                 Utils::Texture   texture_fb(m_context);
7440                 Utils::VertexArray vao(m_context);
7441
7442                 /* */
7443                 const std::string& fragment_shader =
7444                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7445                 const std::string& geometry_shader =
7446                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7447                 const std::string& tess_ctrl_shader =
7448                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7449                 const std::string& tess_eval_shader =
7450                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7451                 const std::string& vertex_shader =
7452                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7453
7454                 program.Init("" /* compute_shader */, fragment_shader, geometry_shader, tess_ctrl_shader, tess_eval_shader,
7455                                          vertex_shader, false /* is_separable */);
7456
7457                 /* */
7458                 prepareAttribLocation(program, program_interface);
7459                 prepareFragmentDataLoc(program, program_interface);
7460
7461                 /* */
7462                 std::stringstream stream;
7463                 if (false == Utils::checkMonolithicDrawProgramInterface(program, program_interface, stream))
7464                 {
7465                         m_context.getTestContext().getLog()
7466                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7467                                 << ". Inspection of draw program interface failed:\n"
7468                                 << stream.str() << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7469                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7470                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7471
7472                         return false;
7473                 }
7474
7475                 /* */
7476                 program.Use();
7477
7478                 /* */
7479                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7480                 vao.Init();
7481                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7482
7483                 /* */
7484                 prepareUniforms(test_case_index, program_interface, program, buffer_u_fs, buffer_u_gs, buffer_u_tcs,
7485                                                 buffer_u_tes, buffer_u_vs);
7486
7487                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_fs, buffer_ssb_gs, buffer_ssb_tcs,
7488                                         buffer_ssb_tes, buffer_ssb_vs);
7489
7490                 /* */
7491                 prepareFramebuffer(framebuffer, texture_fb);
7492
7493                 /* Draw */
7494                 executeDrawCall(test_case_index);
7495
7496 #if USE_NSIGHT
7497                 m_context.getRenderContext().postIterate();
7498 #endif
7499
7500                 /* Check results */
7501                 if (false == checkResults(test_case_index, texture_fb))
7502                 {
7503                         m_context.getTestContext().getLog()
7504                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7505                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vertex_shader)
7506                                 << tcu::TestLog::KernelSource(tess_ctrl_shader) << tcu::TestLog::KernelSource(tess_eval_shader)
7507                                 << tcu::TestLog::KernelSource(geometry_shader) << tcu::TestLog::KernelSource(fragment_shader);
7508
7509                         result = false;
7510                 }
7511         }
7512
7513         /* Compute */
7514         if (true == isComputeRelevant(test_case_index))
7515         {
7516                 Utils::Buffer     buffer_ssb_cs(m_context);
7517                 Utils::Buffer     buffer_u_cs(m_context);
7518                 Utils::Program   program(m_context);
7519                 Utils::Texture   texture_im(m_context);
7520                 Utils::VertexArray vao(m_context);
7521
7522                 /* */
7523                 const std::string& compute_shader =
7524                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7525
7526                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7527                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7528
7529                 /* */
7530                 {
7531                         std::stringstream stream;
7532
7533                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7534                         {
7535                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7536                                                                                                         << ". Inspection of compute program interface failed:\n"
7537                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7538
7539                                 return false;
7540                         }
7541                 }
7542
7543                 /* */
7544                 program.Use();
7545
7546                 /* */
7547                 vao.Init();
7548                 vao.Bind();
7549
7550                 /* */
7551                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7552
7553                 prepareSSBs(test_case_index, program_interface, program, buffer_ssb_cs);
7554
7555                 /* */
7556                 GLint image_location = program.GetUniformLocation("uni_image");
7557                 prepareImage(image_location, texture_im);
7558
7559                 /* Draw */
7560                 executeDispatchCall(test_case_index);
7561
7562 #if USE_NSIGHT
7563                 m_context.getRenderContext().postIterate();
7564 #endif
7565
7566                 /* Check results */
7567                 if (false == checkResults(test_case_index, texture_im))
7568                 {
7569                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7570                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7571                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7572
7573                         result = false;
7574                 }
7575         }
7576
7577         return result;
7578 }
7579
7580 /** Runs "draw" test with separable program
7581  *
7582  * @param test_case_index Id of test case
7583  **/
7584 bool TextureTestBase::testSeparable(GLuint test_case_index)
7585 {
7586         Utils::ProgramInterface   program_interface;
7587         Utils::VaryingPassthrough varying_passthrough;
7588
7589         /* */
7590         const std::string& test_name = getTestCaseName(test_case_index);
7591
7592         /* */
7593         getProgramInterface(test_case_index, program_interface, varying_passthrough);
7594
7595         bool result = true;
7596         /* Draw */
7597         if (true == isDrawRelevant(test_case_index))
7598         {
7599                 Utils::Buffer     buffer_attr(m_context);
7600                 Utils::Buffer     buffer_u_fs(m_context);
7601                 Utils::Buffer     buffer_u_gs(m_context);
7602                 Utils::Buffer     buffer_u_tcs(m_context);
7603                 Utils::Buffer     buffer_u_tes(m_context);
7604                 Utils::Buffer     buffer_u_vs(m_context);
7605                 Utils::Framebuffer framebuffer(m_context);
7606                 Utils::Pipeline pipeline(m_context);
7607                 Utils::Program   program_fs(m_context);
7608                 Utils::Program   program_gs(m_context);
7609                 Utils::Program   program_tcs(m_context);
7610                 Utils::Program   program_tes(m_context);
7611                 Utils::Program   program_vs(m_context);
7612                 Utils::Texture   texture_fb(m_context);
7613                 Utils::VertexArray vao(m_context);
7614
7615                 /* */
7616                 const std::string& fs =
7617                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::FRAGMENT);
7618                 const std::string& gs =
7619                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::GEOMETRY);
7620                 const std::string& tcs =
7621                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_CTRL);
7622                 const std::string& tes =
7623                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::TESS_EVAL);
7624                 const std::string& vs =
7625                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::VERTEX);
7626
7627                 program_fs.Init("" /*cs*/, fs, "" /*gs*/, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7628                 program_gs.Init("" /*cs*/, "" /*fs*/, gs, "" /*tcs*/, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7629                 program_tcs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, tcs, "" /*tes*/, "" /*vs*/, true /* is_separable */);
7630                 program_tes.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, tes, "" /*vs*/, true /* is_separable */);
7631                 program_vs.Init("" /*cs*/, "" /*fs*/, "" /*gs*/, "" /*tcs*/, "" /*tes*/, vs, true /* is_separable */);
7632
7633                 /* */
7634                 prepareAttribLocation(program_vs, program_interface);
7635                 prepareFragmentDataLoc(program_vs, program_interface);
7636
7637                 /* */
7638                 std::stringstream stream;
7639                 if ((false ==
7640                          Utils::checkSeparableDrawProgramInterface(program_vs, program_interface, Utils::Shader::VERTEX, stream)) ||
7641                         (false == Utils::checkSeparableDrawProgramInterface(program_fs, program_interface, Utils::Shader::FRAGMENT,
7642                                                                                                                                 stream)) ||
7643                         (false == Utils::checkSeparableDrawProgramInterface(program_gs, program_interface, Utils::Shader::GEOMETRY,
7644                                                                                                                                 stream)) ||
7645                         (false == Utils::checkSeparableDrawProgramInterface(program_tcs, program_interface,
7646                                                                                                                                 Utils::Shader::TESS_CTRL, stream)) ||
7647                         (false == Utils::checkSeparableDrawProgramInterface(program_tes, program_interface,
7648                                                                                                                                 Utils::Shader::TESS_EVAL, stream)))
7649                 {
7650                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7651                                                                                                 << ". Inspection of separable draw program interface failed:\n"
7652                                                                                                 << stream.str() << tcu::TestLog::EndMessage
7653                                                                                                 << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7654                                                                                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs)
7655                                                                                                 << tcu::TestLog::KernelSource(fs);
7656
7657                         return false;
7658                 }
7659
7660                 /* */
7661                 pipeline.Init();
7662                 pipeline.UseProgramStages(program_fs.m_id, GL_FRAGMENT_SHADER_BIT);
7663                 pipeline.UseProgramStages(program_gs.m_id, GL_GEOMETRY_SHADER_BIT);
7664                 pipeline.UseProgramStages(program_tcs.m_id, GL_TESS_CONTROL_SHADER_BIT);
7665                 pipeline.UseProgramStages(program_tes.m_id, GL_TESS_EVALUATION_SHADER_BIT);
7666                 pipeline.UseProgramStages(program_vs.m_id, GL_VERTEX_SHADER_BIT);
7667                 pipeline.Bind();
7668
7669                 /* */
7670
7671                 buffer_attr.Init(Utils::Buffer::Array, Utils::Buffer::StaticDraw, 0, 0);
7672                 vao.Init();
7673                 prepareAttributes(test_case_index, program_interface, buffer_attr, vao);
7674
7675                 /* */
7676                 prepareUniforms(test_case_index, program_interface, program_fs, program_gs, program_tcs, program_tes,
7677                                                 program_vs, buffer_u_fs, buffer_u_gs, buffer_u_tcs, buffer_u_tes, buffer_u_vs);
7678
7679                 Utils::Program::Use(m_context.getRenderContext().getFunctions(), Utils::Program::m_invalid_id);
7680
7681                 /* */
7682                 prepareFramebuffer(framebuffer, texture_fb);
7683
7684                 /* Draw */
7685                 executeDrawCall(test_case_index);
7686
7687 #if USE_NSIGHT
7688                 m_context.getRenderContext().postIterate();
7689 #endif
7690
7691                 /* Check results */
7692                 if (false == checkResults(test_case_index, texture_fb))
7693                 {
7694                         m_context.getTestContext().getLog()
7695                                 << tcu::TestLog::Message << "FAILURE. Test case: " << test_name << ". Draw - invalid results."
7696                                 << tcu::TestLog::EndMessage << tcu::TestLog::KernelSource(vs) << tcu::TestLog::KernelSource(tcs)
7697                                 << tcu::TestLog::KernelSource(tes) << tcu::TestLog::KernelSource(gs) << tcu::TestLog::KernelSource(fs);
7698
7699                         result = false;
7700                 }
7701         }
7702
7703         /* Compute */
7704         if (true == isComputeRelevant(test_case_index))
7705         {
7706                 Utils::Buffer     buffer_u_cs(m_context);
7707                 Utils::Program   program(m_context);
7708                 Utils::Texture   texture_im(m_context);
7709                 Utils::VertexArray vao(m_context);
7710
7711                 /* */
7712                 const std::string& compute_shader =
7713                         getShaderSource(test_case_index, program_interface, varying_passthrough, Utils::Shader::COMPUTE);
7714
7715                 program.Init(compute_shader, "" /* fragment_shader */, "" /* geometry_shader */, "" /* tess_ctrl_shader */,
7716                                          "" /* tess_eval_shader */, "" /* vertex_shader */, false /* is_separable */);
7717
7718                 /* */
7719                 {
7720                         std::stringstream stream;
7721
7722                         if (false == Utils::checkMonolithicComputeProgramInterface(program, program_interface, stream))
7723                         {
7724                                 m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7725                                                                                                         << ". Inspection of compute program interface failed:\n"
7726                                                                                                         << stream.str() << tcu::TestLog::EndMessage;
7727
7728                                 return false;
7729                         }
7730                 }
7731
7732                 /* */
7733                 program.Use();
7734
7735                 /* */
7736                 vao.Init();
7737                 vao.Bind();
7738
7739                 /* */
7740                 prepareUniforms(test_case_index, program_interface, program, buffer_u_cs);
7741
7742                 /* */
7743                 GLint image_location = program.GetUniformLocation("uni_image");
7744                 prepareImage(image_location, texture_im);
7745
7746                 /* Draw */
7747                 executeDispatchCall(test_case_index);
7748
7749 #if USE_NSIGHT
7750                 m_context.getRenderContext().postIterate();
7751 #endif
7752
7753                 /* Check results */
7754                 if (false == checkResults(test_case_index, texture_im))
7755                 {
7756                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "FAILURE. Test case: " << test_name
7757                                                                                                 << ". Compute - invalid results." << tcu::TestLog::EndMessage
7758                                                                                                 << tcu::TestLog::KernelSource(compute_shader);
7759
7760                         result = false;
7761                 }
7762         }
7763
7764         return result;
7765 }
7766
7767 /** Basic implementation
7768  *
7769  * @param ignored
7770  *
7771  * @return false
7772  **/
7773 bool TextureTestBase::useComponentQualifier(glw::GLuint /* test_case_index */)
7774 {
7775         return false;
7776 }
7777
7778 /** Basic implementation
7779  *
7780  * @param ignored
7781  *
7782  * @return true
7783  **/
7784 bool TextureTestBase::useMonolithicProgram(GLuint /* test_case_index */)
7785 {
7786         return true;
7787 }
7788
7789 /** Constructor
7790  *
7791  * @param context Test framework context
7792  **/
7793 APIConstantValuesTest::APIConstantValuesTest(deqp::Context& context)
7794         : TestCase(context, "api_constant_values", "Test verifies values of api constants")
7795 {
7796         /* Nothing to be done here */
7797 }
7798
7799 /** Execute test
7800  *
7801  * @return tcu::TestNode::STOP otherwise
7802  **/
7803 tcu::TestNode::IterateResult APIConstantValuesTest::iterate()
7804 {
7805         static const GLuint expected_comp = 64;
7806         static const GLuint expected_xfb  = 4;
7807         static const GLuint expected_sep  = 4;
7808         GLint                           max_comp          = 0;
7809         GLint                           max_xfb           = 0;
7810         GLint                           max_sep           = 0;
7811         bool                            test_result   = true;
7812
7813         const Functions& gl = m_context.getRenderContext().getFunctions();
7814
7815         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_xfb);
7816         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7817         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_comp);
7818         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7819         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_sep);
7820         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
7821
7822         if (expected_xfb > (GLuint)max_xfb)
7823         {
7824                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7825                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_BUFFERS. Got " << max_xfb
7826                                                                                         << " Expected at least " << expected_xfb << tcu::TestLog::EndMessage;
7827
7828                 test_result = false;
7829         }
7830
7831         if (expected_comp > (GLuint)max_comp)
7832         {
7833                 m_context.getTestContext().getLog()
7834                         << tcu::TestLog::Message << "Invalid GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS. Got " << max_comp
7835                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7836
7837                 test_result = false;
7838         }
7839
7840         if (expected_sep > (GLuint)max_sep)
7841         {
7842                 m_context.getTestContext().getLog() << tcu::TestLog::Message
7843                                                                                         << "Invalid GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS. Got " << max_comp
7844                                                                                         << " Expected at least " << expected_comp << tcu::TestLog::EndMessage;
7845
7846                 test_result = false;
7847         }
7848
7849         /* Set result */
7850         if (true == test_result)
7851         {
7852                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7853         }
7854         else
7855         {
7856                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7857         }
7858
7859         /* Done */
7860         return tcu::TestNode::STOP;
7861 }
7862
7863 /** Constructor
7864  *
7865  * @param context Test framework context
7866  **/
7867 APIErrorsTest::APIErrorsTest(deqp::Context& context)
7868         : TestCase(context, "api_errors", "Test verifies errors reeturned by api")
7869 {
7870         /* Nothing to be done here */
7871 }
7872
7873 /** Execute test
7874  *
7875  * @return tcu::TestNode::STOP otherwise
7876  **/
7877 tcu::TestNode::IterateResult APIErrorsTest::iterate()
7878 {
7879         GLint              length = 0;
7880         GLchar             name[64];
7881         GLint              param = 0;
7882         Utils::Program program(m_context);
7883         bool               test_result = true;
7884
7885         const Functions& gl = m_context.getRenderContext().getFunctions();
7886
7887         try
7888         {
7889                 program.Init("" /* cs */, "#version 430 core\n"
7890                                                                   "#extension GL_ARB_enhanced_layouts : require\n"
7891                                                                   "\n"
7892                                                                   "in  vec4 vs_fs;\n"
7893                                                                   "out vec4 fs_out;\n"
7894                                                                   "\n"
7895                                                                   "void main()\n"
7896                                                                   "{\n"
7897                                                                   "    fs_out = vs_fs;\n"
7898                                                                   "}\n"
7899                                                                   "\n" /* fs */,
7900                                          "" /* gs */, "" /* tcs */, "" /* tes */, "#version 430 core\n"
7901                                                                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
7902                                                                                                                           "\n"
7903                                                                                                                           "in  vec4 in_vs;\n"
7904                                                                                                                           "layout (xfb_offset = 16) out vec4 vs_fs;\n"
7905                                                                                                                           "\n"
7906                                                                                                                           "void main()\n"
7907                                                                                                                           "{\n"
7908                                                                                                                           "    vs_fs = in_vs;\n"
7909                                                                                                                           "}\n"
7910                                                                                                                           "\n" /* vs */,
7911                                          false /* separable */);
7912         }
7913         catch (Utils::Shader::InvalidSourceException& exc)
7914         {
7915                 exc.log(m_context);
7916                 TCU_FAIL(exc.what());
7917         }
7918         catch (Utils::Program::BuildException& exc)
7919         {
7920                 TCU_FAIL(exc.what());
7921         }
7922
7923         /*
7924          * - GetProgramInterfaceiv should generate INVALID_OPERATION when
7925          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER and <pname> is one of the
7926          * following:
7927          *   * MAX_NAME_LENGTH,
7928          *   * MAX_NUM_ACTIVE_VARIABLES;
7929          */
7930         gl.getProgramInterfaceiv(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH, &param);
7931         checkError(GL_INVALID_OPERATION, "GetProgramInterfaceiv(GL_TRANSFORM_FEEDBACK_BUFFER, GL_MAX_NAME_LENGTH)",
7932                            test_result);
7933
7934         /*
7935          * - GetProgramResourceIndex should generate INVALID_ENUM when
7936          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7937          */
7938         gl.getProgramResourceIndex(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, "0");
7939         checkError(GL_INVALID_ENUM, "GetProgramResourceIndex(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7940         /*
7941          * - GetProgramResourceName should generate INVALID_ENUM when
7942          * <programInterface> is TRANSFORM_FEEDBACK_BUFFER;
7943          */
7944         gl.getProgramResourceName(program.m_id, GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, 64 /* bufSize */, &length,
7945                                                           name);
7946         checkError(GL_INVALID_ENUM, "GetProgramResourceName(GL_TRANSFORM_FEEDBACK_BUFFER)", test_result);
7947
7948         /* Set result */
7949         if (true == test_result)
7950         {
7951                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_PASS, "Pass");
7952         }
7953         else
7954         {
7955                 m_context.getTestContext().setTestResult(QP_TEST_RESULT_FAIL, "Fail");
7956         }
7957
7958         /* Done */
7959         return tcu::TestNode::STOP;
7960 }
7961
7962 /** Check if error is the expected one.
7963  *
7964  * @param expected_error Expected error
7965  * @param message        Message to log in case of error
7966  * @param test_result    Test result, set to false in case of invalid error
7967  **/
7968 void APIErrorsTest::checkError(GLenum expected_error, const GLchar* message, bool& test_result)
7969 {
7970         const Functions& gl = m_context.getRenderContext().getFunctions();
7971
7972         GLenum error = gl.getError();
7973
7974         if (error != expected_error)
7975         {
7976                 m_context.getTestContext().getLog()
7977                         << tcu::TestLog::Message << "Failure. Invalid error. Got " << glu::getErrorStr(error) << " expected "
7978                         << glu::getErrorStr(expected_error) << " Msg: " << message << tcu::TestLog::EndMessage;
7979
7980                 test_result = false;
7981         }
7982 }
7983
7984 /** Constructor
7985  *
7986  * @param context Test framework context
7987  **/
7988 GLSLContantImmutablityTest::GLSLContantImmutablityTest(deqp::Context& context)
7989         : NegativeTestBase(context, "glsl_contant_immutablity", "Test verifies that glsl constants cannot be modified")
7990 {
7991         /* Nothing to be done here */
7992 }
7993
7994 /** Source for given test case and stage
7995  *
7996  * @param test_case_index Index of test case
7997  * @param stage           Shader stage
7998  *
7999  * @return Shader source
8000  **/
8001 std::string GLSLContantImmutablityTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
8002 {
8003         static const GLchar* cs = "#version 430 core\n"
8004                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8005                                                           "\n"
8006                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8007                                                           "\n"
8008                                                           "writeonly uniform uimage2D uni_image;\n"
8009                                                           "\n"
8010                                                           "void main()\n"
8011                                                           "{\n"
8012                                                           "    uint result = 1u;\n"
8013                                                           "    CONSTANT = 3;\n"
8014                                                           "\n"
8015                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), uvec4(result, 0, 0, 0));\n"
8016                                                           "}\n"
8017                                                           "\n";
8018         static const GLchar* fs = "#version 430 core\n"
8019                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8020                                                           "\n"
8021                                                           "in  vec4 gs_fs;\n"
8022                                                           "out vec4 fs_out;\n"
8023                                                           "\n"
8024                                                           "void main()\n"
8025                                                           "{\n"
8026                                                           "ASSIGNMENT"
8027                                                           "    fs_out = gs_fs;\n"
8028                                                           "}\n"
8029                                                           "\n";
8030         static const GLchar* gs = "#version 430 core\n"
8031                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8032                                                           "\n"
8033                                                           "layout(points)                           in;\n"
8034                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8035                                                           "\n"
8036                                                           "in  vec4 tes_gs[];\n"
8037                                                           "out vec4 gs_fs;\n"
8038                                                           "\n"
8039                                                           "void main()\n"
8040                                                           "{\n"
8041                                                           "ASSIGNMENT"
8042                                                           "    gs_fs = tes_gs[0];\n"
8043                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8044                                                           "    EmitVertex();\n"
8045                                                           "    gs_fs = tes_gs[0];\n"
8046                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8047                                                           "    EmitVertex();\n"
8048                                                           "    gs_fs = tes_gs[0];\n"
8049                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8050                                                           "    EmitVertex();\n"
8051                                                           "    gs_fs = tes_gs[0];\n"
8052                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
8053                                                           "    EmitVertex();\n"
8054                                                           "}\n"
8055                                                           "\n";
8056         static const GLchar* tcs = "#version 430 core\n"
8057                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8058                                                            "\n"
8059                                                            "layout(vertices = 1) out;\n"
8060                                                            "\n"
8061                                                            "in  vec4 vs_tcs[];\n"
8062                                                            "out vec4 tcs_tes[];\n"
8063                                                            "\n"
8064                                                            "void main()\n"
8065                                                            "{\n"
8066                                                            "\n"
8067                                                            "ASSIGNMENT"
8068                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
8069                                                            "\n"
8070                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
8071                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
8072                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
8073                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
8074                                                            "    gl_TessLevelInner[0] = 1.0;\n"
8075                                                            "    gl_TessLevelInner[1] = 1.0;\n"
8076                                                            "}\n"
8077                                                            "\n";
8078         static const GLchar* tes = "#version 430 core\n"
8079                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8080                                                            "\n"
8081                                                            "layout(isolines, point_mode) in;\n"
8082                                                            "\n"
8083                                                            "in  vec4 tcs_tes[];\n"
8084                                                            "out vec4 tes_gs;\n"
8085                                                            "\n"
8086                                                            "void main()\n"
8087                                                            "{\n"
8088                                                            "ASSIGNMENT"
8089                                                            "    tes_gs = tcs_tes[0];\n"
8090                                                            "}\n"
8091                                                            "\n";
8092         static const GLchar* vs = "#version 430 core\n"
8093                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8094                                                           "\n"
8095                                                           "in  vec4 in_vs;\n"
8096                                                           "out vec4 vs_tcs;\n"
8097                                                           "\n"
8098                                                           "void main()\n"
8099                                                           "{\n"
8100                                                           "ASSIGNMENT"
8101                                                           "    vs_tcs = in_vs;\n"
8102                                                           "}\n"
8103                                                           "\n";
8104
8105         std::string source;
8106         testCase&   test_case = m_test_cases[test_case_index];
8107
8108         if (Utils::Shader::COMPUTE == test_case.m_stage)
8109         {
8110                 size_t position = 0;
8111
8112                 source = cs;
8113
8114                 Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), source);
8115         }
8116         else
8117         {
8118                 std::string assignment = "    CONSTANT = 3;\n";
8119                 size_t          position   = 0;
8120
8121                 switch (stage)
8122                 {
8123                 case Utils::Shader::FRAGMENT:
8124                         source = fs;
8125                         break;
8126                 case Utils::Shader::GEOMETRY:
8127                         source = gs;
8128                         break;
8129                 case Utils::Shader::TESS_CTRL:
8130                         source = tcs;
8131                         break;
8132                 case Utils::Shader::TESS_EVAL:
8133                         source = tes;
8134                         break;
8135                 case Utils::Shader::VERTEX:
8136                         source = vs;
8137                         break;
8138                 default:
8139                         TCU_FAIL("Invalid enum");
8140                 }
8141
8142                 if (test_case.m_stage == stage)
8143                 {
8144                         Utils::replaceToken("CONSTANT", position, getConstantName(test_case.m_constant), assignment);
8145                 }
8146                 else
8147                 {
8148                         assignment = "";
8149                 }
8150
8151                 position = 0;
8152                 Utils::replaceToken("ASSIGNMENT", position, assignment.c_str(), source);
8153         }
8154
8155         return source;
8156 }
8157
8158 /** Get description of test case
8159  *
8160  * @param test_case_index Index of test case
8161  *
8162  * @return Constant name
8163  **/
8164 std::string GLSLContantImmutablityTest::getTestCaseName(GLuint test_case_index)
8165 {
8166         std::string result = getConstantName(m_test_cases[test_case_index].m_constant);
8167
8168         return result;
8169 }
8170
8171 /** Get number of test cases
8172  *
8173  * @return Number of test cases
8174  **/
8175 GLuint GLSLContantImmutablityTest::getTestCaseNumber()
8176 {
8177         return static_cast<GLuint>(m_test_cases.size());
8178 }
8179
8180 /** Selects if "compute" stage is relevant for test
8181  *
8182  * @param test_case_index Index of test case
8183  *
8184  * @return true when tested stage is compute
8185  **/
8186 bool GLSLContantImmutablityTest::isComputeRelevant(GLuint test_case_index)
8187 {
8188         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8189 }
8190
8191 /** Prepare all test cases
8192  *
8193  **/
8194 void GLSLContantImmutablityTest::testInit()
8195 {
8196         for (GLuint constant = 0; constant < CONSTANTS_MAX; ++constant)
8197         {
8198                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8199                 {
8200                         testCase test_case = { (CONSTANTS)constant, (Utils::Shader::STAGES)stage };
8201
8202                         m_test_cases.push_back(test_case);
8203                 }
8204         }
8205 }
8206
8207 /** Get name of glsl constant
8208  *
8209  * @param Constant id
8210  *
8211  * @return Name of constant used in GLSL
8212  **/
8213 const GLchar* GLSLContantImmutablityTest::getConstantName(CONSTANTS constant)
8214 {
8215         const GLchar* name = "";
8216
8217         switch (constant)
8218         {
8219         case GL_ARB_ENHANCED_LAYOUTS:
8220                 name = "GL_ARB_enhanced_layouts";
8221                 break;
8222         case GL_MAX_XFB:
8223                 name = "gl_MaxTransformFeedbackBuffers";
8224                 break;
8225         case GL_MAX_XFB_INT_COMP:
8226                 name = "gl_MaxTransformFeedbackInterleavedComponents";
8227                 break;
8228         default:
8229                 TCU_FAIL("Invalid enum");
8230         }
8231
8232         return name;
8233 }
8234
8235 /** Constructor
8236  *
8237  * @param context Test framework context
8238  **/
8239 GLSLContantValuesTest::GLSLContantValuesTest(deqp::Context& context)
8240         : TextureTestBase(context, "glsl_contant_values", "Test verifies values of constant symbols")
8241 {
8242 }
8243
8244 /** Selects if "compute" stage is relevant for test
8245  *
8246  * @param ignored
8247  *
8248  * @return false
8249  **/
8250 bool GLSLContantValuesTest::isComputeRelevant(GLuint /* test_case_index */)
8251 {
8252         return false;
8253 }
8254
8255 /** Prepare code snippet that will verify in and uniform variables
8256  *
8257  * @param ignored
8258  * @param ignored
8259  * @param stage   Shader stage
8260  *
8261  * @return Code that verify variables
8262  **/
8263 std::string GLSLContantValuesTest::getVerificationSnippet(GLuint /* test_case_index */,
8264                                                                                                                   Utils::ProgramInterface& /* program_interface */,
8265                                                                                                                   Utils::Shader::STAGES stage)
8266 {
8267         /* Get constants */
8268         const Functions& gl = m_context.getRenderContext().getFunctions();
8269
8270         GLint max_transform_feedback_buffers                            = 0;
8271         GLint max_transform_feedback_interleaved_components = 0;
8272
8273         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8274         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8275         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8276         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8277
8278         std::string verification;
8279
8280         if (Utils::Shader::VERTEX == stage)
8281         {
8282                 verification = "if (1 != GL_ARB_enhanced_layouts)\n"
8283                                            "    {\n"
8284                                            "        result = 0;\n"
8285                                            "    }\n"
8286                                            "    else if (MAX_TRANSFORM_FEEDBACK_BUFFERS\n"
8287                                            "        != gl_MaxTransformFeedbackBuffers)\n"
8288                                            "    {\n"
8289                                            "        result = 0;\n"
8290                                            "    }\n"
8291                                            "    else if (MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS \n"
8292                                            "        != gl_MaxTransformFeedbackInterleavedComponents)\n"
8293                                            "    {\n"
8294                                            "        result = 0;\n"
8295                                            "    }\n";
8296
8297                 size_t position = 0;
8298                 GLchar buffer[16];
8299
8300                 sprintf(buffer, "%d", max_transform_feedback_buffers);
8301                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_BUFFERS", position, buffer, verification);
8302
8303                 sprintf(buffer, "%d", max_transform_feedback_interleaved_components);
8304                 Utils::replaceToken("MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", position, buffer, verification);
8305         }
8306         else
8307         {
8308                 verification = "";
8309         }
8310
8311         return verification;
8312 }
8313
8314 /** Constructor
8315  *
8316  * @param context Test framework context
8317  **/
8318 GLSLConstantIntegralExpressionTest::GLSLConstantIntegralExpressionTest(deqp::Context& context)
8319         : TextureTestBase(context, "glsl_constant_integral_expression",
8320                                           "Test verifies that symbols can be used as constant integral expressions")
8321 {
8322 }
8323
8324 /** Get interface of program
8325  *
8326  * @param ignored
8327  * @param program_interface Interface of program
8328  * @param ignored
8329  **/
8330 void GLSLConstantIntegralExpressionTest::getProgramInterface(GLuint /* test_case_index */,
8331                                                                                                                          Utils::ProgramInterface& program_interface,
8332                                                                                                                          Utils::VaryingPassthrough& /* varying_passthrough */)
8333 {
8334         /* Get constants */
8335         const Functions& gl = m_context.getRenderContext().getFunctions();
8336
8337         GLint max_transform_feedback_buffers                            = 0;
8338         GLint max_transform_feedback_interleaved_components = 0;
8339
8340         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_transform_feedback_buffers);
8341         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8342         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_transform_feedback_interleaved_components);
8343         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
8344
8345         GLuint gohan_div = std::max(1, max_transform_feedback_buffers / 16);
8346         GLuint goten_div = std::max(1, max_transform_feedback_interleaved_components / 16);
8347
8348         m_gohan_length = max_transform_feedback_buffers / gohan_div;
8349         m_goten_length = max_transform_feedback_interleaved_components / goten_div;
8350
8351         /* Globals */
8352         std::string globals = "uniform uint goku [GL_ARB_enhanced_layouts / 1];\n"
8353                                                   "uniform uint gohan[gl_MaxTransformFeedbackBuffers / GOHAN_DIV];\n"
8354                                                   "uniform uint goten[gl_MaxTransformFeedbackInterleavedComponents / GOTEN_DIV];\n";
8355
8356         size_t position = 0;
8357         GLchar buffer[16];
8358
8359         sprintf(buffer, "%d", gohan_div);
8360         Utils::replaceToken("GOHAN_DIV", position, buffer, globals);
8361
8362         sprintf(buffer, "%d", goten_div);
8363         Utils::replaceToken("GOTEN_DIV", position, buffer, globals);
8364
8365         program_interface.m_vertex.m_globals    = globals;
8366         program_interface.m_tess_ctrl.m_globals = globals;
8367         program_interface.m_tess_eval.m_globals = globals;
8368         program_interface.m_geometry.m_globals  = globals;
8369         program_interface.m_fragment.m_globals  = globals;
8370         program_interface.m_compute.m_globals   = globals;
8371 }
8372
8373 /** Prepare code snippet that will verify in and uniform variables
8374  *
8375  * @param ignored
8376  * @param ignored
8377  * @param ignored
8378  *
8379  * @return Code that verify variables
8380  **/
8381 std::string GLSLConstantIntegralExpressionTest::getVerificationSnippet(GLuint /* test_case_index */,
8382                                                                                                                                            Utils::ProgramInterface& /* program_interface */,
8383                                                                                                                                            Utils::Shader::STAGES /* stage */)
8384 {
8385         std::string verification = "{\n"
8386                                                            "        uint goku_sum = 0;\n"
8387                                                            "        uint gohan_sum = 0;\n"
8388                                                            "        uint goten_sum = 0;\n"
8389                                                            "\n"
8390                                                            "        for (uint i = 0u; i < goku.length(); ++i)\n"
8391                                                            "        {\n"
8392                                                            "            goku_sum += goku[i];\n"
8393                                                            "        }\n"
8394                                                            "\n"
8395                                                            "        for (uint i = 0u; i < gohan.length(); ++i)\n"
8396                                                            "        {\n"
8397                                                            "            gohan_sum += gohan[i];\n"
8398                                                            "        }\n"
8399                                                            "\n"
8400                                                            "        for (uint i = 0u; i < goten.length(); ++i)\n"
8401                                                            "        {\n"
8402                                                            "            goten_sum += goten[i];\n"
8403                                                            "        }\n"
8404                                                            "\n"
8405                                                            "        if ( (1u != goku_sum)  &&\n"
8406                                                            "             (EXPECTED_GOHAN_SUMu != gohan_sum) ||\n"
8407                                                            "             (EXPECTED_GOTEN_SUMu != goten_sum) )\n"
8408                                                            "        {\n"
8409                                                            "            result = 0u;\n"
8410                                                            "        }\n"
8411                                                            "    }\n";
8412
8413         size_t position = 0;
8414         GLchar buffer[16];
8415
8416         sprintf(buffer, "%d", m_gohan_length);
8417         Utils::replaceToken("EXPECTED_GOHAN_SUM", position, buffer, verification);
8418
8419         sprintf(buffer, "%d", m_goten_length);
8420         Utils::replaceToken("EXPECTED_GOTEN_SUM", position, buffer, verification);
8421
8422         return verification;
8423 }
8424
8425 /** Prepare unifroms
8426  *
8427  * @param ignored
8428  * @param ignored
8429  * @param program Program object
8430  * @param ignored
8431  **/
8432 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint /* test_case_index */,
8433                                                                                                                  Utils::ProgramInterface& /* program_interface */,
8434                                                                                                                  Utils::Program& program, Utils::Buffer& /* cs_buffer */)
8435 {
8436         static const GLuint uniform_data[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
8437
8438         const Functions& gl = m_context.getRenderContext().getFunctions();
8439
8440         GLint goku_location  = program.GetUniformLocation("goku");
8441         GLint gohan_location = program.GetUniformLocation("gohan");
8442         GLint goten_location = program.GetUniformLocation("goten");
8443
8444         program.Uniform(gl, Utils::Type::uint, 1 /* count */, goku_location, uniform_data);
8445         program.Uniform(gl, Utils::Type::uint, m_gohan_length, gohan_location, uniform_data);
8446         program.Uniform(gl, Utils::Type::uint, m_goten_length, goten_location, uniform_data);
8447 }
8448
8449 /** Prepare unifroms
8450  *
8451  * @param test_case_index   Pass as param to first implemetnation
8452  * @param program_interface Pass as param to first implemetnation
8453  * @param program           Pass as param to first implemetnation
8454  * @param ignored
8455  * @param ignored
8456  * @param ignored
8457  * @param ignored
8458  * @param vs_buffer         Pass as param to first implemetnation
8459  **/
8460 void GLSLConstantIntegralExpressionTest::prepareUniforms(GLuint                                   test_case_index,
8461                                                                                                                  Utils::ProgramInterface& program_interface,
8462                                                                                                                  Utils::Program& program, Utils::Buffer& /* fs_buffer */,
8463                                                                                                                  Utils::Buffer& /* gs_buffer */,
8464                                                                                                                  Utils::Buffer& /* tcs_buffer */,
8465                                                                                                                  Utils::Buffer& /* tes_buffer */, Utils::Buffer& vs_buffer)
8466 {
8467         /* Call first implementation */
8468         prepareUniforms(test_case_index, program_interface, program, vs_buffer);
8469 }
8470
8471 /** Constructor
8472  *
8473  * @param context Test framework context
8474  **/
8475 UniformBlockMemberOffsetAndAlignTest::UniformBlockMemberOffsetAndAlignTest(deqp::Context& context)
8476         : TextureTestBase(context, "uniform_block_member_offset_and_align",
8477                                           "Test verifies offsets and alignment of uniform buffer members")
8478 {
8479 }
8480
8481 /** Get interface of program
8482  *
8483  * @param test_case_index     Test case index
8484  * @param program_interface   Interface of program
8485  * @param varying_passthrough Collection of connections between in and out variables
8486  **/
8487 void UniformBlockMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
8488                                                                                                                            Utils::ProgramInterface&   program_interface,
8489                                                                                                                            Utils::VaryingPassthrough& varying_passthrough)
8490 {
8491         std::string globals = "const int basic_size = BASIC_SIZE;\n"
8492                                                   "const int type_align = TYPE_ALIGN;\n"
8493                                                   "const int type_size  = TYPE_SIZE;\n";
8494
8495         Utils::Type  type                = getType(test_case_index);
8496         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
8497         const GLuint base_align  = type.GetBaseAlignment(false);
8498         const GLuint array_align = type.GetBaseAlignment(true);
8499         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
8500         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
8501
8502         /* Calculate offsets */
8503         const GLuint first_offset  = 0;
8504         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
8505
8506 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
8507
8508         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
8509         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
8510         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
8511         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
8512         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
8513         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
8514
8515 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8516
8517         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
8518         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + 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, 8 * basic_size);
8523
8524 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
8525
8526         /* Prepare data */
8527         const std::vector<GLubyte>& first  = type.GenerateData();
8528         const std::vector<GLubyte>& second = type.GenerateData();
8529         const std::vector<GLubyte>& third  = type.GenerateData();
8530         const std::vector<GLubyte>& fourth = type.GenerateData();
8531
8532         m_data.resize(eigth_offset + base_stride);
8533         GLubyte* ptr = &m_data[0];
8534         memcpy(ptr + first_offset, &first[0], first.size());
8535         memcpy(ptr + second_offset, &second[0], second.size());
8536         memcpy(ptr + third_offset, &third[0], third.size());
8537         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
8538         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
8539         memcpy(ptr + sixth_offset, &third[0], third.size());
8540         memcpy(ptr + seventh_offset, &second[0], second.size());
8541         memcpy(ptr + eigth_offset, &first[0], first.size());
8542
8543         /* Prepare globals */
8544         size_t position = 0;
8545         GLchar buffer[16];
8546
8547         sprintf(buffer, "%d", basic_size);
8548         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
8549
8550         sprintf(buffer, "%d", type_align);
8551         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
8552
8553         sprintf(buffer, "%d", base_stride);
8554         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
8555
8556         /* Prepare Block */
8557         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
8558
8559         vs_uni_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
8560                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8561                                                  first_offset);
8562
8563         vs_uni_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
8564                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
8565                                                  0 /* n_array_elements */, base_stride, second_offset);
8566
8567         vs_uni_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
8568                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8569                                                  third_offset);
8570
8571         vs_uni_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
8572                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8573                                                  fourth_offset);
8574
8575         vs_uni_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8576                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
8577
8578         vs_uni_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
8579                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
8580
8581         vs_uni_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
8582                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
8583                                                  eigth_offset);
8584
8585         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
8586
8587         /* Add globals */
8588         vs_si.m_globals = globals;
8589
8590         /* Add uniform BLOCK */
8591         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
8592                                   static_cast<glw::GLint>(m_data.size()), 0, &m_data[0], m_data.size());
8593
8594         /* */
8595         program_interface.CloneVertexInterface(varying_passthrough);
8596 }
8597
8598 /** Get type name
8599  *
8600  * @param test_case_index Index of test case
8601  *
8602  * @return Name of type test in test_case_index
8603  **/
8604 std::string UniformBlockMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
8605 {
8606         return getTypeName(test_case_index);
8607 }
8608
8609 /** Returns number of types to test
8610  *
8611  * @return Number of types, 34
8612  **/
8613 glw::GLuint UniformBlockMemberOffsetAndAlignTest::getTestCaseNumber()
8614 {
8615         return getTypesNumber();
8616 }
8617
8618 /** Prepare code snippet that will verify in and uniform variables
8619  *
8620  * @param ignored
8621  * @param ignored
8622  * @param stage   Shader stage
8623  *
8624  * @return Code that verify variables
8625  **/
8626 std::string UniformBlockMemberOffsetAndAlignTest::getVerificationSnippet(
8627         GLuint /* test_case_index */, Utils::ProgramInterface& /* program_interface */, Utils::Shader::STAGES stage)
8628 {
8629         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
8630                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
8631                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
8632                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
8633                                                            "    {\n"
8634                                                            "        result = 0;\n"
8635                                                            "    }";
8636
8637         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::UNIFORM);
8638
8639         Utils::replaceAllTokens("PREFIX", prefix, verification);
8640
8641         return verification;
8642 }
8643
8644 /** Constructor
8645  *
8646  * @param context Test framework context
8647  **/
8648 UniformBlockLayoutQualifierConflictTest::UniformBlockLayoutQualifierConflictTest(deqp::Context& context)
8649         : NegativeTestBase(
8650                   context, "uniform_block_layout_qualifier_conflict",
8651                   "Test verifies that std140 is required when offset and/or align qualifiers are used with uniform block")
8652 {
8653         /* Nothing to be done here */
8654 }
8655
8656 /** Source for given test case and stage
8657  *
8658  * @param test_case_index Index of test case
8659  * @param stage           Shader stage
8660  *
8661  * @return Shader source
8662  **/
8663 std::string UniformBlockLayoutQualifierConflictTest::getShaderSource(GLuint                                test_case_index,
8664                                                                                                                                          Utils::Shader::STAGES stage)
8665 {
8666         static const GLchar* cs = "#version 430 core\n"
8667                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8668                                                           "\n"
8669                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8670                                                           "\n"
8671                                                           "LAYOUTuniform Block {\n"
8672                                                           "    layout(offset = 16) vec4 boy;\n"
8673                                                           "    layout(align  = 64) vec4 man;\n"
8674                                                           "} uni_block;\n"
8675                                                           "\n"
8676                                                           "writeonly uniform image2D uni_image;\n"
8677                                                           "\n"
8678                                                           "void main()\n"
8679                                                           "{\n"
8680                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
8681                                                           "\n"
8682                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8683                                                           "}\n"
8684                                                           "\n";
8685         static const GLchar* fs = "#version 430 core\n"
8686                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8687                                                           "\n"
8688                                                           "LAYOUTuniform Block {\n"
8689                                                           "    layout(offset = 16) vec4 boy;\n"
8690                                                           "    layout(align  = 64) vec4 man;\n"
8691                                                           "} uni_block;\n"
8692                                                           "\n"
8693                                                           "in  vec4 gs_fs;\n"
8694                                                           "out vec4 fs_out;\n"
8695                                                           "\n"
8696                                                           "void main()\n"
8697                                                           "{\n"
8698                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
8699                                                           "}\n"
8700                                                           "\n";
8701         static const GLchar* gs = "#version 430 core\n"
8702                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8703                                                           "\n"
8704                                                           "layout(points)                           in;\n"
8705                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
8706                                                           "\n"
8707                                                           "LAYOUTuniform Block {\n"
8708                                                           "    layout(offset = 16) vec4 boy;\n"
8709                                                           "    layout(align  = 64) vec4 man;\n"
8710                                                           "} uni_block;\n"
8711                                                           "\n"
8712                                                           "in  vec4 tes_gs[];\n"
8713                                                           "out vec4 gs_fs;\n"
8714                                                           "\n"
8715                                                           "void main()\n"
8716                                                           "{\n"
8717                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8718                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
8719                                                           "    EmitVertex();\n"
8720                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8721                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
8722                                                           "    EmitVertex();\n"
8723                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
8724                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
8725                                                           "    EmitVertex();\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                                                           "}\n"
8730                                                           "\n";
8731         static const GLchar* tcs =
8732                 "#version 430 core\n"
8733                 "#extension GL_ARB_enhanced_layouts : require\n"
8734                 "\n"
8735                 "layout(vertices = 1) out;\n"
8736                 "\n"
8737                 "LAYOUTuniform Block {\n"
8738                 "    layout(offset = 16) vec4 boy;\n"
8739                 "    layout(align  = 64) vec4 man;\n"
8740                 "} uni_block;\n"
8741                 "\n"
8742                 "in  vec4 vs_tcs[];\n"
8743                 "out vec4 tcs_tes[];\n"
8744                 "\n"
8745                 "void main()\n"
8746                 "{\n"
8747                 "\n"
8748                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
8749                 "\n"
8750                 "    gl_TessLevelOuter[0] = 1.0;\n"
8751                 "    gl_TessLevelOuter[1] = 1.0;\n"
8752                 "    gl_TessLevelOuter[2] = 1.0;\n"
8753                 "    gl_TessLevelOuter[3] = 1.0;\n"
8754                 "    gl_TessLevelInner[0] = 1.0;\n"
8755                 "    gl_TessLevelInner[1] = 1.0;\n"
8756                 "}\n"
8757                 "\n";
8758         static const GLchar* tes = "#version 430 core\n"
8759                                                            "#extension GL_ARB_enhanced_layouts : require\n"
8760                                                            "\n"
8761                                                            "layout(isolines, point_mode) in;\n"
8762                                                            "\n"
8763                                                            "LAYOUTuniform Block {\n"
8764                                                            "    layout(offset = 16) vec4 boy;\n"
8765                                                            "    layout(align  = 64) vec4 man;\n"
8766                                                            "} uni_block;\n"
8767                                                            "\n"
8768                                                            "in  vec4 tcs_tes[];\n"
8769                                                            "out vec4 tes_gs;\n"
8770                                                            "\n"
8771                                                            "void main()\n"
8772                                                            "{\n"
8773                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
8774                                                            "}\n"
8775                                                            "\n";
8776         static const GLchar* vs = "#version 430 core\n"
8777                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8778                                                           "\n"
8779                                                           "LAYOUTuniform Block {\n"
8780                                                           "    layout(offset = 16) vec4 boy;\n"
8781                                                           "    layout(align  = 64) vec4 man;\n"
8782                                                           "} uni_block;\n"
8783                                                           "\n"
8784                                                           "in  vec4 in_vs;\n"
8785                                                           "out vec4 vs_tcs;\n"
8786                                                           "\n"
8787                                                           "void main()\n"
8788                                                           "{\n"
8789                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
8790                                                           "}\n"
8791                                                           "\n";
8792
8793         std::string   layout    = "";
8794         size_t            position  = 0;
8795         testCase&        test_case = m_test_cases[test_case_index];
8796         const GLchar* qualifier = getQualifierName(test_case.m_qualifier);
8797         std::string   source;
8798
8799         if (0 != qualifier[0])
8800         {
8801                 size_t layout_position = 0;
8802
8803                 layout = "layout (QUALIFIER) ";
8804
8805                 Utils::replaceToken("QUALIFIER", layout_position, qualifier, layout);
8806         }
8807
8808         switch (stage)
8809         {
8810         case Utils::Shader::COMPUTE:
8811                 source = cs;
8812                 break;
8813         case Utils::Shader::FRAGMENT:
8814                 source = fs;
8815                 break;
8816         case Utils::Shader::GEOMETRY:
8817                 source = gs;
8818                 break;
8819         case Utils::Shader::TESS_CTRL:
8820                 source = tcs;
8821                 break;
8822         case Utils::Shader::TESS_EVAL:
8823                 source = tes;
8824                 break;
8825         case Utils::Shader::VERTEX:
8826                 source = vs;
8827                 break;
8828         default:
8829                 TCU_FAIL("Invalid enum");
8830         }
8831
8832         if (test_case.m_stage == stage)
8833         {
8834                 Utils::replaceToken("LAYOUT", position, layout.c_str(), source);
8835         }
8836         else
8837         {
8838                 Utils::replaceToken("LAYOUT", position, "layout (std140) ", source);
8839         }
8840
8841         return source;
8842 }
8843
8844 /** Get description of test case
8845  *
8846  * @param test_case_index Index of test case
8847  *
8848  * @return Qualifier name
8849  **/
8850 std::string UniformBlockLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
8851 {
8852         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
8853
8854         return result;
8855 }
8856
8857 /** Get number of test cases
8858  *
8859  * @return Number of test cases
8860  **/
8861 GLuint UniformBlockLayoutQualifierConflictTest::getTestCaseNumber()
8862 {
8863         return static_cast<GLuint>(m_test_cases.size());
8864 }
8865
8866 /** Selects if "compute" stage is relevant for test
8867  *
8868  * @param test_case_index Index of test case
8869  *
8870  * @return true when tested stage is compute
8871  **/
8872 bool UniformBlockLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
8873 {
8874         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
8875 }
8876
8877 /** Selects if compilation failure is expected result
8878  *
8879  * @param test_case_index Index of test case
8880  *
8881  * @return false for STD140 cases, true otherwise
8882  **/
8883 bool UniformBlockLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
8884 {
8885         return (STD140 != m_test_cases[test_case_index].m_qualifier);
8886 }
8887
8888 /** Prepare all test cases
8889  *
8890  **/
8891 void UniformBlockLayoutQualifierConflictTest::testInit()
8892 {
8893         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
8894         {
8895                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
8896                 {
8897                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
8898
8899                         m_test_cases.push_back(test_case);
8900                 }
8901         }
8902 }
8903
8904 /** Get name of glsl constant
8905  *
8906  * @param Constant id
8907  *
8908  * @return Name of constant used in GLSL
8909  **/
8910 const GLchar* UniformBlockLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
8911 {
8912         const GLchar* name = "";
8913
8914         switch (qualifier)
8915         {
8916         case DEFAULT:
8917                 name = "";
8918                 break;
8919         case STD140:
8920                 name = "std140";
8921                 break;
8922         case SHARED:
8923                 name = "shared";
8924                 break;
8925         case PACKED:
8926                 name = "packed";
8927                 break;
8928         default:
8929                 TCU_FAIL("Invalid enum");
8930         }
8931
8932         return name;
8933 }
8934
8935 /** Constructor
8936  *
8937  * @param context Test framework context
8938  **/
8939 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(deqp::Context& context)
8940         : NegativeTestBase(context, "uniform_block_member_invalid_offset_alignment",
8941                                            "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
8942 {
8943         /* Nothing to be done here */
8944 }
8945
8946 /** Constructor
8947  *
8948  * @param context     Test framework context
8949  * @param name        Test name
8950  * @param description Test description
8951  **/
8952 UniformBlockMemberInvalidOffsetAlignmentTest::UniformBlockMemberInvalidOffsetAlignmentTest(
8953         deqp::Context& context, const glw::GLchar* name, const glw::GLchar* description)
8954         : NegativeTestBase(context, name, description)
8955 {
8956         /* Nothing to be done here */
8957 }
8958
8959 /** Source for given test case and stage
8960  *
8961  * @param test_case_index Index of test case
8962  * @param stage           Shader stage
8963  *
8964  * @return Shader source
8965  **/
8966 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint                                test_case_index,
8967                                                                                                                                                   Utils::Shader::STAGES stage)
8968 {
8969         static const GLchar* cs = "#version 430 core\n"
8970                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8971                                                           "\n"
8972                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
8973                                                           "\n"
8974                                                           "layout (std140) uniform Block {\n"
8975                                                           "    layout (offset = OFFSET) TYPE member;\n"
8976                                                           "} block;\n"
8977                                                           "\n"
8978                                                           "writeonly uniform image2D uni_image;\n"
8979                                                           "\n"
8980                                                           "void main()\n"
8981                                                           "{\n"
8982                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
8983                                                           "\n"
8984                                                           "    if (TYPE(1) == block.member)\n"
8985                                                           "    {\n"
8986                                                           "        result = vec4(1, 1, 1, 1);\n"
8987                                                           "    }\n"
8988                                                           "\n"
8989                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
8990                                                           "}\n"
8991                                                           "\n";
8992         static const GLchar* fs = "#version 430 core\n"
8993                                                           "#extension GL_ARB_enhanced_layouts : require\n"
8994                                                           "\n"
8995                                                           "in  vec4 gs_fs;\n"
8996                                                           "out vec4 fs_out;\n"
8997                                                           "\n"
8998                                                           "void main()\n"
8999                                                           "{\n"
9000                                                           "    fs_out = gs_fs;\n"
9001                                                           "}\n"
9002                                                           "\n";
9003         static const GLchar* fs_tested = "#version 430 core\n"
9004                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9005                                                                          "\n"
9006                                                                          "layout (std140) uniform Block {\n"
9007                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9008                                                                          "} block;\n"
9009                                                                          "\n"
9010                                                                          "in  vec4 gs_fs;\n"
9011                                                                          "out vec4 fs_out;\n"
9012                                                                          "\n"
9013                                                                          "void main()\n"
9014                                                                          "{\n"
9015                                                                          "    if (TYPE(1) == block.member)\n"
9016                                                                          "    {\n"
9017                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9018                                                                          "    }\n"
9019                                                                          "\n"
9020                                                                          "    fs_out += gs_fs;\n"
9021                                                                          "}\n"
9022                                                                          "\n";
9023         static const GLchar* gs = "#version 430 core\n"
9024                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9025                                                           "\n"
9026                                                           "layout(points)                           in;\n"
9027                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9028                                                           "\n"
9029                                                           "in  vec4 tes_gs[];\n"
9030                                                           "out vec4 gs_fs;\n"
9031                                                           "\n"
9032                                                           "void main()\n"
9033                                                           "{\n"
9034                                                           "    gs_fs = tes_gs[0];\n"
9035                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9036                                                           "    EmitVertex();\n"
9037                                                           "    gs_fs = tes_gs[0];\n"
9038                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9039                                                           "    EmitVertex();\n"
9040                                                           "    gs_fs = tes_gs[0];\n"
9041                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9042                                                           "    EmitVertex();\n"
9043                                                           "    gs_fs = tes_gs[0];\n"
9044                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9045                                                           "    EmitVertex();\n"
9046                                                           "}\n"
9047                                                           "\n";
9048         static const GLchar* gs_tested = "#version 430 core\n"
9049                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9050                                                                          "\n"
9051                                                                          "layout(points)                           in;\n"
9052                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9053                                                                          "\n"
9054                                                                          "layout (std140) uniform Block {\n"
9055                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9056                                                                          "} block;\n"
9057                                                                          "\n"
9058                                                                          "in  vec4 tes_gs[];\n"
9059                                                                          "out vec4 gs_fs;\n"
9060                                                                          "\n"
9061                                                                          "void main()\n"
9062                                                                          "{\n"
9063                                                                          "    if (TYPE(1) == block.member)\n"
9064                                                                          "    {\n"
9065                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9066                                                                          "    }\n"
9067                                                                          "\n"
9068                                                                          "    gs_fs += tes_gs[0];\n"
9069                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9070                                                                          "    EmitVertex();\n"
9071                                                                          "    gs_fs += tes_gs[0];\n"
9072                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9073                                                                          "    EmitVertex();\n"
9074                                                                          "    gs_fs += tes_gs[0];\n"
9075                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9076                                                                          "    EmitVertex();\n"
9077                                                                          "    gs_fs += tes_gs[0];\n"
9078                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9079                                                                          "    EmitVertex();\n"
9080                                                                          "}\n"
9081                                                                          "\n";
9082         static const GLchar* tcs = "#version 430 core\n"
9083                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9084                                                            "\n"
9085                                                            "layout(vertices = 1) out;\n"
9086                                                            "\n"
9087                                                            "in  vec4 vs_tcs[];\n"
9088                                                            "out vec4 tcs_tes[];\n"
9089                                                            "\n"
9090                                                            "void main()\n"
9091                                                            "{\n"
9092                                                            "\n"
9093                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9094                                                            "\n"
9095                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9096                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9097                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9098                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9099                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9100                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9101                                                            "}\n"
9102                                                            "\n";
9103         static const GLchar* tcs_tested = "#version 430 core\n"
9104                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9105                                                                           "\n"
9106                                                                           "layout(vertices = 1) out;\n"
9107                                                                           "\n"
9108                                                                           "layout (std140) uniform Block {\n"
9109                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9110                                                                           "} block;\n"
9111                                                                           "\n"
9112                                                                           "in  vec4 vs_tcs[];\n"
9113                                                                           "out vec4 tcs_tes[];\n"
9114                                                                           "\n"
9115                                                                           "void main()\n"
9116                                                                           "{\n"
9117                                                                           "    if (TYPE(1) == block.member)\n"
9118                                                                           "    {\n"
9119                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9120                                                                           "    }\n"
9121                                                                           "\n"
9122                                                                           "\n"
9123                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9124                                                                           "\n"
9125                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9126                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9127                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9128                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9129                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9130                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9131                                                                           "}\n"
9132                                                                           "\n";
9133         static const GLchar* tes = "#version 430 core\n"
9134                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9135                                                            "\n"
9136                                                            "layout(isolines, point_mode) in;\n"
9137                                                            "\n"
9138                                                            "in  vec4 tcs_tes[];\n"
9139                                                            "out vec4 tes_gs;\n"
9140                                                            "\n"
9141                                                            "void main()\n"
9142                                                            "{\n"
9143                                                            "    tes_gs = tcs_tes[0];\n"
9144                                                            "}\n"
9145                                                            "\n";
9146         static const GLchar* tes_tested = "#version 430 core\n"
9147                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9148                                                                           "\n"
9149                                                                           "layout(isolines, point_mode) in;\n"
9150                                                                           "\n"
9151                                                                           "layout (std140) uniform Block {\n"
9152                                                                           "    layout (offset = OFFSET) TYPE member;\n"
9153                                                                           "} block;\n"
9154                                                                           "\n"
9155                                                                           "in  vec4 tcs_tes[];\n"
9156                                                                           "out vec4 tes_gs;\n"
9157                                                                           "\n"
9158                                                                           "void main()\n"
9159                                                                           "{\n"
9160                                                                           "    if (TYPE(1) == block.member)\n"
9161                                                                           "    {\n"
9162                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9163                                                                           "    }\n"
9164                                                                           "\n"
9165                                                                           "    tes_gs += tcs_tes[0];\n"
9166                                                                           "}\n"
9167                                                                           "\n";
9168         static const GLchar* vs = "#version 430 core\n"
9169                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9170                                                           "\n"
9171                                                           "in  vec4 in_vs;\n"
9172                                                           "out vec4 vs_tcs;\n"
9173                                                           "\n"
9174                                                           "void main()\n"
9175                                                           "{\n"
9176                                                           "    vs_tcs = in_vs;\n"
9177                                                           "}\n"
9178                                                           "\n";
9179         static const GLchar* vs_tested = "#version 430 core\n"
9180                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9181                                                                          "\n"
9182                                                                          "layout (std140) uniform Block {\n"
9183                                                                          "    layout (offset = OFFSET) TYPE member;\n"
9184                                                                          "} block;\n"
9185                                                                          "\n"
9186                                                                          "in  vec4 in_vs;\n"
9187                                                                          "out vec4 vs_tcs;\n"
9188                                                                          "\n"
9189                                                                          "void main()\n"
9190                                                                          "{\n"
9191                                                                          "    if (TYPE(1) == block.member)\n"
9192                                                                          "    {\n"
9193                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9194                                                                          "    }\n"
9195                                                                          "\n"
9196                                                                          "    vs_tcs += in_vs;\n"
9197                                                                          "}\n"
9198                                                                          "\n";
9199
9200         std::string source;
9201         testCase&   test_case = m_test_cases[test_case_index];
9202
9203         if (test_case.m_stage == stage)
9204         {
9205                 GLchar                     buffer[16];
9206                 const GLuint       offset       = test_case.m_offset;
9207                 size_t                     position  = 0;
9208                 const Utils::Type& type          = test_case.m_type;
9209                 const GLchar*     type_name = type.GetGLSLTypeName();
9210
9211                 sprintf(buffer, "%d", offset);
9212
9213                 switch (stage)
9214                 {
9215                 case Utils::Shader::COMPUTE:
9216                         source = cs;
9217                         break;
9218                 case Utils::Shader::FRAGMENT:
9219                         source = fs_tested;
9220                         break;
9221                 case Utils::Shader::GEOMETRY:
9222                         source = gs_tested;
9223                         break;
9224                 case Utils::Shader::TESS_CTRL:
9225                         source = tcs_tested;
9226                         break;
9227                 case Utils::Shader::TESS_EVAL:
9228                         source = tes_tested;
9229                         break;
9230                 case Utils::Shader::VERTEX:
9231                         source = vs_tested;
9232                         break;
9233                 default:
9234                         TCU_FAIL("Invalid enum");
9235                 }
9236
9237                 Utils::replaceToken("OFFSET", position, buffer, source);
9238                 Utils::replaceToken("TYPE", position, type_name, source);
9239                 Utils::replaceToken("TYPE", position, type_name, source);
9240         }
9241         else
9242         {
9243                 switch (stage)
9244                 {
9245                 case Utils::Shader::FRAGMENT:
9246                         source = fs;
9247                         break;
9248                 case Utils::Shader::GEOMETRY:
9249                         source = gs;
9250                         break;
9251                 case Utils::Shader::TESS_CTRL:
9252                         source = tcs;
9253                         break;
9254                 case Utils::Shader::TESS_EVAL:
9255                         source = tes;
9256                         break;
9257                 case Utils::Shader::VERTEX:
9258                         source = vs;
9259                         break;
9260                 default:
9261                         TCU_FAIL("Invalid enum");
9262                 }
9263         }
9264
9265         return source;
9266 }
9267
9268 /** Get description of test case
9269  *
9270  * @param test_case_index Index of test case
9271  *
9272  * @return Type name and offset
9273  **/
9274 std::string UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
9275 {
9276         std::stringstream stream;
9277         testCase&                 test_case = m_test_cases[test_case_index];
9278
9279         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
9280
9281         return stream.str();
9282 }
9283
9284 /** Get number of test cases
9285  *
9286  * @return Number of test cases
9287  **/
9288 GLuint UniformBlockMemberInvalidOffsetAlignmentTest::getTestCaseNumber()
9289 {
9290         return static_cast<GLuint>(m_test_cases.size());
9291 }
9292
9293 /** Selects if "compute" stage is relevant for test
9294  *
9295  * @param test_case_index Index of test case
9296  *
9297  * @return true when tested stage is compute
9298  **/
9299 bool UniformBlockMemberInvalidOffsetAlignmentTest::isComputeRelevant(GLuint test_case_index)
9300 {
9301         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9302 }
9303
9304 /** Selects if compilation failure is expected result
9305  *
9306  * @param test_case_index Index of test case
9307  *
9308  * @return should_fail field from testCase
9309  **/
9310 bool UniformBlockMemberInvalidOffsetAlignmentTest::isFailureExpected(GLuint test_case_index)
9311 {
9312         return m_test_cases[test_case_index].m_should_fail;
9313 }
9314
9315 /** Checks if stage is supported
9316  *
9317  * @param stage ignored
9318  *
9319  * @return true
9320  **/
9321 bool UniformBlockMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9322 {
9323         return true;
9324 }
9325
9326 /** Prepare all test cases
9327  *
9328  **/
9329 void UniformBlockMemberInvalidOffsetAlignmentTest::testInit()
9330 {
9331         const Functions& gl               = m_context.getRenderContext().getFunctions();
9332         GLint                    max_size = 0;
9333         const GLuint     n_types  = getTypesNumber();
9334         bool                     stage_support[Utils::Shader::STAGE_MAX];
9335
9336         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9337         {
9338                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9339         }
9340
9341         gl.getIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
9342         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
9343
9344         for (GLuint i = 0; i < n_types; ++i)
9345         {
9346                 const Utils::Type& type           = getType(i);
9347                 const GLuint       alignment  = type.GetBaseAlignment(false);
9348                 const GLuint       type_size  = type.GetSize();
9349                 const GLuint       sec_to_end = max_size - 2 * type_size;
9350
9351                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9352                 {
9353                         if (false == stage_support[stage])
9354                         {
9355                                 continue;
9356                         }
9357
9358                         for (GLuint offset = 0; offset <= type_size; ++offset)
9359                         {
9360                                 const GLuint modulo              = offset % alignment;
9361                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9362                                 const bool   should_fail = !is_aligned;
9363
9364                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9365
9366                                 m_test_cases.push_back(test_case);
9367                         }
9368
9369                         for (GLuint offset = sec_to_end; offset <= sec_to_end + type_size; ++offset)
9370                         {
9371                                 const GLuint modulo              = offset % alignment;
9372                                 const bool   is_aligned  = (0 == modulo) ? true : false;
9373                                 const bool   should_fail = !is_aligned;
9374
9375                                 testCase test_case = { offset, should_fail, (Utils::Shader::STAGES)stage, type };
9376
9377                                 m_test_cases.push_back(test_case);
9378                         }
9379                 }
9380         }
9381 }
9382
9383 /** Constructor
9384  *
9385  * @param context Test framework context
9386  **/
9387 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context& context)
9388         : NegativeTestBase(context, "uniform_block_member_overlapping_offsets",
9389                                            "Test verifies that overlapping offsets qualifiers cause compilation failure")
9390 {
9391         /* Nothing to be done here */
9392 }
9393
9394 /** Constructor
9395  *
9396  * @param context Test framework context
9397  * @param name        Test name
9398  * @param description Test description
9399  **/
9400 UniformBlockMemberOverlappingOffsetsTest::UniformBlockMemberOverlappingOffsetsTest(deqp::Context&        context,
9401                                                                                                                                                                    const glw::GLchar* name,
9402                                                                                                                                                                    const glw::GLchar* description)
9403         : NegativeTestBase(context, name, description)
9404 {
9405         /* Nothing to be done here */
9406 }
9407
9408 /** Source for given test case and stage
9409  *
9410  * @param test_case_index Index of test case
9411  * @param stage           Shader stage
9412  *
9413  * @return Shader source
9414  **/
9415 std::string UniformBlockMemberOverlappingOffsetsTest::getShaderSource(GLuint                            test_case_index,
9416                                                                                                                                           Utils::Shader::STAGES stage)
9417 {
9418         static const GLchar* cs = "#version 430 core\n"
9419                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9420                                                           "\n"
9421                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9422                                                           "\n"
9423                                                           "layout (std140) uniform Block {\n"
9424                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9425                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9426                                                           "} block;\n"
9427                                                           "\n"
9428                                                           "writeonly uniform image2D uni_image;\n"
9429                                                           "\n"
9430                                                           "void main()\n"
9431                                                           "{\n"
9432                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9433                                                           "\n"
9434                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9435                                                           "        (MAN_TYPE(0) == block.man) )\n"
9436                                                           "    {\n"
9437                                                           "        result = vec4(1, 1, 1, 1);\n"
9438                                                           "    }\n"
9439                                                           "\n"
9440                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9441                                                           "}\n"
9442                                                           "\n";
9443         static const GLchar* fs = "#version 430 core\n"
9444                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9445                                                           "\n"
9446                                                           "in  vec4 gs_fs;\n"
9447                                                           "out vec4 fs_out;\n"
9448                                                           "\n"
9449                                                           "void main()\n"
9450                                                           "{\n"
9451                                                           "    fs_out = gs_fs;\n"
9452                                                           "}\n"
9453                                                           "\n";
9454         static const GLchar* fs_tested = "#version 430 core\n"
9455                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9456                                                                          "\n"
9457                                                                          "layout (std140) uniform Block {\n"
9458                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9459                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9460                                                                          "} block;\n"
9461                                                                          "\n"
9462                                                                          "in  vec4 gs_fs;\n"
9463                                                                          "out vec4 fs_out;\n"
9464                                                                          "\n"
9465                                                                          "void main()\n"
9466                                                                          "{\n"
9467                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9468                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9469                                                                          "    {\n"
9470                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
9471                                                                          "    }\n"
9472                                                                          "\n"
9473                                                                          "    fs_out += gs_fs;\n"
9474                                                                          "}\n"
9475                                                                          "\n";
9476         static const GLchar* gs = "#version 430 core\n"
9477                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9478                                                           "\n"
9479                                                           "layout(points)                           in;\n"
9480                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9481                                                           "\n"
9482                                                           "in  vec4 tes_gs[];\n"
9483                                                           "out vec4 gs_fs;\n"
9484                                                           "\n"
9485                                                           "void main()\n"
9486                                                           "{\n"
9487                                                           "    gs_fs = tes_gs[0];\n"
9488                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9489                                                           "    EmitVertex();\n"
9490                                                           "    gs_fs = tes_gs[0];\n"
9491                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9492                                                           "    EmitVertex();\n"
9493                                                           "    gs_fs = tes_gs[0];\n"
9494                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9495                                                           "    EmitVertex();\n"
9496                                                           "    gs_fs = tes_gs[0];\n"
9497                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9498                                                           "    EmitVertex();\n"
9499                                                           "}\n"
9500                                                           "\n";
9501         static const GLchar* gs_tested = "#version 430 core\n"
9502                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9503                                                                          "\n"
9504                                                                          "layout(points)                           in;\n"
9505                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9506                                                                          "\n"
9507                                                                          "layout (std140) uniform Block {\n"
9508                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9509                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9510                                                                          "} block;\n"
9511                                                                          "\n"
9512                                                                          "in  vec4 tes_gs[];\n"
9513                                                                          "out vec4 gs_fs;\n"
9514                                                                          "\n"
9515                                                                          "void main()\n"
9516                                                                          "{\n"
9517                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9518                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9519                                                                          "    {\n"
9520                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
9521                                                                          "    }\n"
9522                                                                          "\n"
9523                                                                          "    gs_fs += tes_gs[0];\n"
9524                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9525                                                                          "    EmitVertex();\n"
9526                                                                          "    gs_fs += tes_gs[0];\n"
9527                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9528                                                                          "    EmitVertex();\n"
9529                                                                          "    gs_fs += tes_gs[0];\n"
9530                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
9531                                                                          "    EmitVertex();\n"
9532                                                                          "    gs_fs += tes_gs[0];\n"
9533                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
9534                                                                          "    EmitVertex();\n"
9535                                                                          "}\n"
9536                                                                          "\n";
9537         static const GLchar* tcs = "#version 430 core\n"
9538                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9539                                                            "\n"
9540                                                            "layout(vertices = 1) out;\n"
9541                                                            "\n"
9542                                                            "in  vec4 vs_tcs[];\n"
9543                                                            "out vec4 tcs_tes[];\n"
9544                                                            "\n"
9545                                                            "void main()\n"
9546                                                            "{\n"
9547                                                            "\n"
9548                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
9549                                                            "\n"
9550                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
9551                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
9552                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
9553                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
9554                                                            "    gl_TessLevelInner[0] = 1.0;\n"
9555                                                            "    gl_TessLevelInner[1] = 1.0;\n"
9556                                                            "}\n"
9557                                                            "\n";
9558         static const GLchar* tcs_tested = "#version 430 core\n"
9559                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9560                                                                           "\n"
9561                                                                           "layout(vertices = 1) out;\n"
9562                                                                           "\n"
9563                                                                           "layout (std140) uniform Block {\n"
9564                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9565                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9566                                                                           "} block;\n"
9567                                                                           "\n"
9568                                                                           "in  vec4 vs_tcs[];\n"
9569                                                                           "out vec4 tcs_tes[];\n"
9570                                                                           "\n"
9571                                                                           "void main()\n"
9572                                                                           "{\n"
9573                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9574                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9575                                                                           "    {\n"
9576                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
9577                                                                           "    }\n"
9578                                                                           "\n"
9579                                                                           "\n"
9580                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
9581                                                                           "\n"
9582                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
9583                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
9584                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
9585                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
9586                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
9587                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
9588                                                                           "}\n"
9589                                                                           "\n";
9590         static const GLchar* tes = "#version 430 core\n"
9591                                                            "#extension GL_ARB_enhanced_layouts : require\n"
9592                                                            "\n"
9593                                                            "layout(isolines, point_mode) in;\n"
9594                                                            "\n"
9595                                                            "in  vec4 tcs_tes[];\n"
9596                                                            "out vec4 tes_gs;\n"
9597                                                            "\n"
9598                                                            "void main()\n"
9599                                                            "{\n"
9600                                                            "    tes_gs = tcs_tes[0];\n"
9601                                                            "}\n"
9602                                                            "\n";
9603         static const GLchar* tes_tested = "#version 430 core\n"
9604                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9605                                                                           "\n"
9606                                                                           "layout(isolines, point_mode) in;\n"
9607                                                                           "\n"
9608                                                                           "layout (std140) uniform Block {\n"
9609                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9610                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9611                                                                           "} block;\n"
9612                                                                           "\n"
9613                                                                           "in  vec4 tcs_tes[];\n"
9614                                                                           "out vec4 tes_gs;\n"
9615                                                                           "\n"
9616                                                                           "void main()\n"
9617                                                                           "{\n"
9618                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
9619                                                                           "        (MAN_TYPE(0) == block.man) )\n"
9620                                                                           "    {\n"
9621                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
9622                                                                           "    }\n"
9623                                                                           "\n"
9624                                                                           "    tes_gs += tcs_tes[0];\n"
9625                                                                           "}\n"
9626                                                                           "\n";
9627         static const GLchar* vs = "#version 430 core\n"
9628                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9629                                                           "\n"
9630                                                           "in  vec4 in_vs;\n"
9631                                                           "out vec4 vs_tcs;\n"
9632                                                           "\n"
9633                                                           "void main()\n"
9634                                                           "{\n"
9635                                                           "    vs_tcs = in_vs;\n"
9636                                                           "}\n"
9637                                                           "\n";
9638         static const GLchar* vs_tested = "#version 430 core\n"
9639                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9640                                                                          "\n"
9641                                                                          "layout (std140) uniform Block {\n"
9642                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
9643                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
9644                                                                          "} block;\n"
9645                                                                          "\n"
9646                                                                          "in  vec4 in_vs;\n"
9647                                                                          "out vec4 vs_tcs;\n"
9648                                                                          "\n"
9649                                                                          "void main()\n"
9650                                                                          "{\n"
9651                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
9652                                                                          "        (MAN_TYPE(0) == block.man) )\n"
9653                                                                          "    {\n"
9654                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
9655                                                                          "    }\n"
9656                                                                          "\n"
9657                                                                          "    vs_tcs += in_vs;\n"
9658                                                                          "}\n"
9659                                                                          "\n";
9660
9661         std::string source;
9662         testCase&   test_case = m_test_cases[test_case_index];
9663
9664         if (test_case.m_stage == stage)
9665         {
9666                 GLchar                     buffer[16];
9667                 const GLuint       boy_offset   = test_case.m_boy_offset;
9668                 const Utils::Type& boy_type              = test_case.m_boy_type;
9669                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
9670                 const GLuint       man_offset   = test_case.m_man_offset;
9671                 const Utils::Type& man_type              = test_case.m_man_type;
9672                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
9673                 size_t                     position              = 0;
9674
9675                 switch (stage)
9676                 {
9677                 case Utils::Shader::COMPUTE:
9678                         source = cs;
9679                         break;
9680                 case Utils::Shader::FRAGMENT:
9681                         source = fs_tested;
9682                         break;
9683                 case Utils::Shader::GEOMETRY:
9684                         source = gs_tested;
9685                         break;
9686                 case Utils::Shader::TESS_CTRL:
9687                         source = tcs_tested;
9688                         break;
9689                 case Utils::Shader::TESS_EVAL:
9690                         source = tes_tested;
9691                         break;
9692                 case Utils::Shader::VERTEX:
9693                         source = vs_tested;
9694                         break;
9695                 default:
9696                         TCU_FAIL("Invalid enum");
9697                 }
9698
9699                 sprintf(buffer, "%d", boy_offset);
9700                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
9701                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9702                 sprintf(buffer, "%d", man_offset);
9703                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
9704                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9705                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
9706                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
9707         }
9708         else
9709         {
9710                 switch (stage)
9711                 {
9712                 case Utils::Shader::FRAGMENT:
9713                         source = fs;
9714                         break;
9715                 case Utils::Shader::GEOMETRY:
9716                         source = gs;
9717                         break;
9718                 case Utils::Shader::TESS_CTRL:
9719                         source = tcs;
9720                         break;
9721                 case Utils::Shader::TESS_EVAL:
9722                         source = tes;
9723                         break;
9724                 case Utils::Shader::VERTEX:
9725                         source = vs;
9726                         break;
9727                 default:
9728                         TCU_FAIL("Invalid enum");
9729                 }
9730         }
9731
9732         return source;
9733 }
9734
9735 /** Get description of test case
9736  *
9737  * @param test_case_index Index of test case
9738  *
9739  * @return Type name and offset
9740  **/
9741 std::string UniformBlockMemberOverlappingOffsetsTest::getTestCaseName(GLuint test_case_index)
9742 {
9743         std::stringstream stream;
9744         testCase&                 test_case = m_test_cases[test_case_index];
9745
9746         stream << "Type: " << test_case.m_boy_type.GetGLSLTypeName() << ", offset: " << test_case.m_boy_offset
9747                    << ". Type: " << test_case.m_man_type.GetGLSLTypeName() << ", offset: " << test_case.m_man_offset;
9748
9749         return stream.str();
9750 }
9751
9752 /** Get number of test cases
9753  *
9754  * @return Number of test cases
9755  **/
9756 GLuint UniformBlockMemberOverlappingOffsetsTest::getTestCaseNumber()
9757 {
9758         return static_cast<GLuint>(m_test_cases.size());
9759 }
9760
9761 /** Selects if "compute" stage is relevant for test
9762  *
9763  * @param test_case_index Index of test case
9764  *
9765  * @return true when tested stage is compute
9766  **/
9767 bool UniformBlockMemberOverlappingOffsetsTest::isComputeRelevant(GLuint test_case_index)
9768 {
9769         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
9770 }
9771
9772 /** Checks if stage is supported
9773  *
9774  * @param stage ignored
9775  *
9776  * @return true
9777  **/
9778 bool UniformBlockMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES /* stage */)
9779 {
9780         return true;
9781 }
9782
9783 /** Prepare all test cases
9784  *
9785  **/
9786 void UniformBlockMemberOverlappingOffsetsTest::testInit()
9787 {
9788         const GLuint n_types = getTypesNumber();
9789         bool             stage_support[Utils::Shader::STAGE_MAX];
9790
9791         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9792         {
9793                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
9794         }
9795
9796         for (GLuint i = 0; i < n_types; ++i)
9797         {
9798                 const Utils::Type& boy_type = getType(i);
9799                 const GLuint       boy_size = boy_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9800
9801                 for (GLuint j = 0; j < n_types; ++j)
9802                 {
9803                         const Utils::Type& man_type  = getType(j);
9804                         const GLuint       man_align = man_type.GetBaseAlignment(false);
9805                         const GLuint       man_size  = man_type.GetActualAlignment(1 /* align */, false /* is_array*/);
9806
9807                         const GLuint boy_offset           = lcm(boy_size, man_size);
9808                         const GLuint man_after_start  = boy_offset + 1;
9809                         const GLuint man_after_off      = man_type.GetActualOffset(man_after_start, man_size);
9810                         const GLuint man_before_start = boy_offset - man_align;
9811                         const GLuint man_before_off   = man_type.GetActualOffset(man_before_start, man_size);
9812
9813                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
9814                         {
9815                                 if (false == stage_support[stage])
9816                                 {
9817                                         continue;
9818                                 }
9819
9820                                 if ((boy_offset > man_before_off) && (boy_offset < man_before_off + man_size))
9821                                 {
9822                                         testCase test_case = { boy_offset, boy_type, man_before_off, man_type,
9823                                                                                    (Utils::Shader::STAGES)stage };
9824
9825                                         m_test_cases.push_back(test_case);
9826                                 }
9827
9828                                 if ((boy_offset < man_after_off) && (boy_offset + boy_size > man_after_off))
9829                                 {
9830                                         testCase test_case = { boy_offset, boy_type, man_after_off, man_type,
9831                                                                                    (Utils::Shader::STAGES)stage };
9832
9833                                         m_test_cases.push_back(test_case);
9834                                 }
9835
9836                                 /* Boy offset, should be fine for both types */
9837                                 testCase test_case = { boy_offset, boy_type, boy_offset, man_type, (Utils::Shader::STAGES)stage };
9838
9839                                 m_test_cases.push_back(test_case);
9840                         }
9841                 }
9842         }
9843 }
9844
9845 /** Find greatest common divisor for a and b
9846  *
9847  * @param a A argument
9848  * @param b B argument
9849  *
9850  * @return Found gcd value
9851  **/
9852 GLuint UniformBlockMemberOverlappingOffsetsTest::gcd(GLuint a, GLuint b)
9853 {
9854         if ((0 != a) && (0 == b))
9855         {
9856                 return a;
9857         }
9858         else
9859         {
9860                 GLuint greater = std::max(a, b);
9861                 GLuint lesser  = std::min(a, b);
9862
9863                 return gcd(lesser, greater % lesser);
9864         }
9865 }
9866
9867 /** Find lowest common multiple for a and b
9868  *
9869  * @param a A argument
9870  * @param b B argument
9871  *
9872  * @return Found gcd value
9873  **/
9874 GLuint UniformBlockMemberOverlappingOffsetsTest::lcm(GLuint a, GLuint b)
9875 {
9876         return (a * b) / gcd(a, b);
9877 }
9878
9879 /** Constructor
9880  *
9881  * @param context Test framework context
9882  **/
9883 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context& context)
9884         : NegativeTestBase(context, "uniform_block_member_align_non_power_of_2",
9885                                            "Test verifies that align qualifier requires value that is a power of 2")
9886 {
9887         /* Nothing to be done here */
9888 }
9889
9890 /** Constructor
9891  *
9892  * @param context Test framework context
9893  * @param name        Test name
9894  * @param description Test description
9895  **/
9896 UniformBlockMemberAlignNonPowerOf2Test::UniformBlockMemberAlignNonPowerOf2Test(deqp::Context&    context,
9897                                                                                                                                                            const glw::GLchar* name,
9898                                                                                                                                                            const glw::GLchar* description)
9899         : NegativeTestBase(context, name, description)
9900 {
9901         /* Nothing to be done here */
9902 }
9903
9904 /** Source for given test case and stage
9905  *
9906  * @param test_case_index Index of test case
9907  * @param stage           Shader stage
9908  *
9909  * @return Shader source
9910  **/
9911 std::string UniformBlockMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
9912 {
9913         static const GLchar* cs = "#version 430 core\n"
9914                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9915                                                           "\n"
9916                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
9917                                                           "\n"
9918                                                           "layout (std140) uniform Block {\n"
9919                                                           "    vec4 boy;\n"
9920                                                           "    layout (align = ALIGN) TYPE man;\n"
9921                                                           "} block;\n"
9922                                                           "\n"
9923                                                           "writeonly uniform image2D uni_image;\n"
9924                                                           "\n"
9925                                                           "void main()\n"
9926                                                           "{\n"
9927                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
9928                                                           "\n"
9929                                                           "    if (TYPE(0) == block.man)\n"
9930                                                           "    {\n"
9931                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
9932                                                           "    }\n"
9933                                                           "\n"
9934                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
9935                                                           "}\n"
9936                                                           "\n";
9937         static const GLchar* fs = "#version 430 core\n"
9938                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9939                                                           "\n"
9940                                                           "in  vec4 gs_fs;\n"
9941                                                           "out vec4 fs_out;\n"
9942                                                           "\n"
9943                                                           "void main()\n"
9944                                                           "{\n"
9945                                                           "    fs_out = gs_fs;\n"
9946                                                           "}\n"
9947                                                           "\n";
9948         static const GLchar* fs_tested = "#version 430 core\n"
9949                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9950                                                                          "\n"
9951                                                                          "layout (std140) uniform Block {\n"
9952                                                                          "    vec4 boy;\n"
9953                                                                          "    layout (align = ALIGN) TYPE man;\n"
9954                                                                          "} block;\n"
9955                                                                          "\n"
9956                                                                          "in  vec4 gs_fs;\n"
9957                                                                          "out vec4 fs_out;\n"
9958                                                                          "\n"
9959                                                                          "void main()\n"
9960                                                                          "{\n"
9961                                                                          "    if (TYPE(0) == block.man)\n"
9962                                                                          "    {\n"
9963                                                                          "        fs_out = block.boy;\n"
9964                                                                          "    }\n"
9965                                                                          "\n"
9966                                                                          "    fs_out += gs_fs;\n"
9967                                                                          "}\n"
9968                                                                          "\n";
9969         static const GLchar* gs = "#version 430 core\n"
9970                                                           "#extension GL_ARB_enhanced_layouts : require\n"
9971                                                           "\n"
9972                                                           "layout(points)                           in;\n"
9973                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
9974                                                           "\n"
9975                                                           "in  vec4 tes_gs[];\n"
9976                                                           "out vec4 gs_fs;\n"
9977                                                           "\n"
9978                                                           "void main()\n"
9979                                                           "{\n"
9980                                                           "    gs_fs = tes_gs[0];\n"
9981                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
9982                                                           "    EmitVertex();\n"
9983                                                           "    gs_fs = tes_gs[0];\n"
9984                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
9985                                                           "    EmitVertex();\n"
9986                                                           "    gs_fs = tes_gs[0];\n"
9987                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
9988                                                           "    EmitVertex();\n"
9989                                                           "    gs_fs = tes_gs[0];\n"
9990                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
9991                                                           "    EmitVertex();\n"
9992                                                           "}\n"
9993                                                           "\n";
9994         static const GLchar* gs_tested = "#version 430 core\n"
9995                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
9996                                                                          "\n"
9997                                                                          "layout(points)                           in;\n"
9998                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
9999                                                                          "\n"
10000                                                                          "layout (std140) uniform Block {\n"
10001                                                                          "    vec4 boy;\n"
10002                                                                          "    layout (align = ALIGN) TYPE man;\n"
10003                                                                          "} block;\n"
10004                                                                          "\n"
10005                                                                          "in  vec4 tes_gs[];\n"
10006                                                                          "out vec4 gs_fs;\n"
10007                                                                          "\n"
10008                                                                          "void main()\n"
10009                                                                          "{\n"
10010                                                                          "    if (TYPE(0) == block.man)\n"
10011                                                                          "    {\n"
10012                                                                          "        gs_fs = block.boy;\n"
10013                                                                          "    }\n"
10014                                                                          "\n"
10015                                                                          "    gs_fs += tes_gs[0];\n"
10016                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10017                                                                          "    EmitVertex();\n"
10018                                                                          "    gs_fs += tes_gs[0];\n"
10019                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10020                                                                          "    EmitVertex();\n"
10021                                                                          "    gs_fs += tes_gs[0];\n"
10022                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
10023                                                                          "    EmitVertex();\n"
10024                                                                          "    gs_fs += tes_gs[0];\n"
10025                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
10026                                                                          "    EmitVertex();\n"
10027                                                                          "}\n"
10028                                                                          "\n";
10029         static const GLchar* tcs = "#version 430 core\n"
10030                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10031                                                            "\n"
10032                                                            "layout(vertices = 1) out;\n"
10033                                                            "\n"
10034                                                            "in  vec4 vs_tcs[];\n"
10035                                                            "out vec4 tcs_tes[];\n"
10036                                                            "\n"
10037                                                            "void main()\n"
10038                                                            "{\n"
10039                                                            "\n"
10040                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
10041                                                            "\n"
10042                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
10043                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
10044                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
10045                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
10046                                                            "    gl_TessLevelInner[0] = 1.0;\n"
10047                                                            "    gl_TessLevelInner[1] = 1.0;\n"
10048                                                            "}\n"
10049                                                            "\n";
10050         static const GLchar* tcs_tested = "#version 430 core\n"
10051                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10052                                                                           "\n"
10053                                                                           "layout(vertices = 1) out;\n"
10054                                                                           "\n"
10055                                                                           "layout (std140) uniform Block {\n"
10056                                                                           "    vec4 boy;\n"
10057                                                                           "    layout (align = ALIGN) TYPE man;\n"
10058                                                                           "} block;\n"
10059                                                                           "\n"
10060                                                                           "in  vec4 vs_tcs[];\n"
10061                                                                           "out vec4 tcs_tes[];\n"
10062                                                                           "\n"
10063                                                                           "void main()\n"
10064                                                                           "{\n"
10065                                                                           "    if (TYPE(0) == block.man)\n"
10066                                                                           "    {\n"
10067                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
10068                                                                           "    }\n"
10069                                                                           "\n"
10070                                                                           "\n"
10071                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
10072                                                                           "\n"
10073                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
10074                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
10075                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
10076                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
10077                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
10078                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
10079                                                                           "}\n"
10080                                                                           "\n";
10081         static const GLchar* tes = "#version 430 core\n"
10082                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10083                                                            "\n"
10084                                                            "layout(isolines, point_mode) in;\n"
10085                                                            "\n"
10086                                                            "in  vec4 tcs_tes[];\n"
10087                                                            "out vec4 tes_gs;\n"
10088                                                            "\n"
10089                                                            "void main()\n"
10090                                                            "{\n"
10091                                                            "    tes_gs = tcs_tes[0];\n"
10092                                                            "}\n"
10093                                                            "\n";
10094         static const GLchar* tes_tested = "#version 430 core\n"
10095                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10096                                                                           "\n"
10097                                                                           "layout(isolines, point_mode) in;\n"
10098                                                                           "\n"
10099                                                                           "layout (std140) uniform Block {\n"
10100                                                                           "    vec4 boy;\n"
10101                                                                           "    layout (align = ALIGN) TYPE man;\n"
10102                                                                           "} block;\n"
10103                                                                           "\n"
10104                                                                           "in  vec4 tcs_tes[];\n"
10105                                                                           "out vec4 tes_gs;\n"
10106                                                                           "\n"
10107                                                                           "void main()\n"
10108                                                                           "{\n"
10109                                                                           "    if (TYPE(0) == block.man)\n"
10110                                                                           "    {\n"
10111                                                                           "        tes_gs = block.boy;\n"
10112                                                                           "    }\n"
10113                                                                           "\n"
10114                                                                           "    tes_gs += tcs_tes[0];\n"
10115                                                                           "}\n"
10116                                                                           "\n";
10117         static const GLchar* vs = "#version 430 core\n"
10118                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10119                                                           "\n"
10120                                                           "in  vec4 in_vs;\n"
10121                                                           "out vec4 vs_tcs;\n"
10122                                                           "\n"
10123                                                           "void main()\n"
10124                                                           "{\n"
10125                                                           "    vs_tcs = in_vs;\n"
10126                                                           "}\n"
10127                                                           "\n";
10128         static const GLchar* vs_tested = "#version 430 core\n"
10129                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
10130                                                                          "\n"
10131                                                                          "layout (std140) uniform Block {\n"
10132                                                                          "    vec4 boy;\n"
10133                                                                          "    layout (align = ALIGN) TYPE man;\n"
10134                                                                          "} block;\n"
10135                                                                          "\n"
10136                                                                          "in  vec4 in_vs;\n"
10137                                                                          "out vec4 vs_tcs;\n"
10138                                                                          "\n"
10139                                                                          "void main()\n"
10140                                                                          "{\n"
10141                                                                          "    if (TYPE(0) == block.man)\n"
10142                                                                          "    {\n"
10143                                                                          "        vs_tcs = block.boy;\n"
10144                                                                          "    }\n"
10145                                                                          "\n"
10146                                                                          "    vs_tcs += in_vs;\n"
10147                                                                          "}\n"
10148                                                                          "\n";
10149
10150         std::string source;
10151         testCase&   test_case = m_test_cases[test_case_index];
10152
10153         if (test_case.m_stage == stage)
10154         {
10155                 GLchar                     buffer[16];
10156                 const GLuint       alignment = test_case.m_alignment;
10157                 const Utils::Type& type          = test_case.m_type;
10158                 const GLchar*     type_name = type.GetGLSLTypeName();
10159                 size_t                     position  = 0;
10160
10161                 switch (stage)
10162                 {
10163                 case Utils::Shader::COMPUTE:
10164                         source = cs;
10165                         break;
10166                 case Utils::Shader::FRAGMENT:
10167                         source = fs_tested;
10168                         break;
10169                 case Utils::Shader::GEOMETRY:
10170                         source = gs_tested;
10171                         break;
10172                 case Utils::Shader::TESS_CTRL:
10173                         source = tcs_tested;
10174                         break;
10175                 case Utils::Shader::TESS_EVAL:
10176                         source = tes_tested;
10177                         break;
10178                 case Utils::Shader::VERTEX:
10179                         source = vs_tested;
10180                         break;
10181                 default:
10182                         TCU_FAIL("Invalid enum");
10183                 }
10184
10185                 sprintf(buffer, "%d", alignment);
10186                 Utils::replaceToken("ALIGN", position, buffer, source);
10187                 Utils::replaceToken("TYPE", position, type_name, source);
10188                 Utils::replaceToken("TYPE", position, type_name, source);
10189         }
10190         else
10191         {
10192                 switch (stage)
10193                 {
10194                 case Utils::Shader::FRAGMENT:
10195                         source = fs;
10196                         break;
10197                 case Utils::Shader::GEOMETRY:
10198                         source = gs;
10199                         break;
10200                 case Utils::Shader::TESS_CTRL:
10201                         source = tcs;
10202                         break;
10203                 case Utils::Shader::TESS_EVAL:
10204                         source = tes;
10205                         break;
10206                 case Utils::Shader::VERTEX:
10207                         source = vs;
10208                         break;
10209                 default:
10210                         TCU_FAIL("Invalid enum");
10211                 }
10212         }
10213
10214         return source;
10215 }
10216
10217 /** Get description of test case
10218  *
10219  * @param test_case_index Index of test case
10220  *
10221  * @return Type name and offset
10222  **/
10223 std::string UniformBlockMemberAlignNonPowerOf2Test::getTestCaseName(GLuint test_case_index)
10224 {
10225         std::stringstream stream;
10226         testCase&                 test_case = m_test_cases[test_case_index];
10227
10228         stream << "Type: " << test_case.m_type.GetGLSLTypeName() << ", align: " << test_case.m_alignment;
10229
10230         return stream.str();
10231 }
10232
10233 /** Get number of test cases
10234  *
10235  * @return Number of test cases
10236  **/
10237 GLuint UniformBlockMemberAlignNonPowerOf2Test::getTestCaseNumber()
10238 {
10239         return static_cast<GLuint>(m_test_cases.size());
10240 }
10241
10242 /** Selects if "compute" stage is relevant for test
10243  *
10244  * @param test_case_index Index of test case
10245  *
10246  * @return true when tested stage is compute
10247  **/
10248 bool UniformBlockMemberAlignNonPowerOf2Test::isComputeRelevant(GLuint test_case_index)
10249 {
10250         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10251 }
10252
10253 /** Checks if stage is supported
10254  *
10255  * @param ignored
10256  *
10257  * @return true
10258  **/
10259 bool UniformBlockMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES /* stage */)
10260 {
10261         return true;
10262 }
10263
10264 /** Selects if compilation failure is expected result
10265  *
10266  * @param test_case_index Index of test case
10267  *
10268  * @return should_fail field from testCase
10269  **/
10270 bool UniformBlockMemberAlignNonPowerOf2Test::isFailureExpected(GLuint test_case_index)
10271 {
10272         return m_test_cases[test_case_index].m_should_fail;
10273 }
10274
10275 /** Prepare all test cases
10276  *
10277  **/
10278 void UniformBlockMemberAlignNonPowerOf2Test::testInit()
10279 {
10280         static const GLuint dmat4_size = 128;
10281         const GLuint            n_types = getTypesNumber();
10282         bool                            stage_support[Utils::Shader::STAGE_MAX];
10283
10284         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10285         {
10286                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10287         }
10288
10289         for (GLuint j = 0; j < n_types; ++j)
10290         {
10291                 const Utils::Type& type = getType(j);
10292
10293                 for (GLuint align = 0; align <= dmat4_size; ++align)
10294                 {
10295
10296 #if WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST
10297
10298                         const bool should_fail = (0 == align) ? false : !isPowerOf2(align);
10299
10300 #else /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10301
10302                         const bool should_fail = !isPowerOf2(align);
10303
10304 #endif /* WRKARD_UNIFORMBLOCKMEMBERALIGNNONPOWEROF2TEST */
10305
10306                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10307                         {
10308                                 if (false == stage_support[stage])
10309                                 {
10310                                         continue;
10311                                 }
10312
10313                                 testCase test_case = { align, type, should_fail, (Utils::Shader::STAGES)stage };
10314
10315                                 m_test_cases.push_back(test_case);
10316                         }
10317                 }
10318         }
10319 }
10320
10321 /** Check if value is power of 2
10322  *
10323  * @param val Tested value
10324  *
10325  * @return true if val is power of 2, false otherwise
10326  **/
10327 bool UniformBlockMemberAlignNonPowerOf2Test::isPowerOf2(GLuint val)
10328 {
10329         if (0 == val)
10330         {
10331                 return false;
10332         }
10333
10334         return (0 == (val & (val - 1)));
10335 }
10336
10337 /** Constructor
10338  *
10339  * @param context Test framework context
10340  **/
10341 UniformBlockAlignmentTest::UniformBlockAlignmentTest(deqp::Context& context)
10342         : TextureTestBase(context, "uniform_block_alignment", "Test verifies offset and alignment of uniform buffer")
10343 {
10344 }
10345
10346 /** Get interface of program
10347  *
10348  * @param ignored
10349  * @param program_interface Interface of program
10350  * @param varying_passthrough Collection of connections between in and out variables
10351  **/
10352 void UniformBlockAlignmentTest::getProgramInterface(GLuint /* test_case_index */,
10353                                                                                                         Utils::ProgramInterface&   program_interface,
10354                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
10355 {
10356         static const Utils::Type vec4 = Utils::Type::vec4;
10357
10358 #if WRKARD_UNIFORMBLOCKALIGNMENT
10359
10360         static const GLuint block_align = 16;
10361
10362 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
10363
10364         static const GLuint block_align = 64;
10365
10366 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10367
10368         static const GLuint vec4_stride = 16;
10369         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
10370
10371         /*Fixed a test issue, the fifth_offset should be calculated by block_align, instead of fifth_align, according to spec, the actual
10372          alignment of a member will be the greater of the specified alignment and the base aligment for the member type
10373          */
10374         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
10375         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
10376         const GLuint third_offset =
10377                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
10378         const GLuint fourth_offset =
10379                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
10380         const GLuint fifth_offset =
10381                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, block_align); /* vec4[2] at 160 */
10382         const GLuint sixth_offset =
10383                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
10384
10385         Utils::Interface* structure = program_interface.Structure("Data");
10386
10387         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10388                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
10389
10390         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
10391                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
10392                                           Utils::Type::vec4.GetSize() /* offset */);
10393
10394         /* Prepare Block */
10395         Utils::Interface* vs_uni_block = program_interface.Block("vs_uni_Block");
10396
10397         vs_uni_block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
10398                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
10399
10400         vs_uni_block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10401                                                  0 /* n_array_elements */, data_stride, second_offset);
10402
10403         vs_uni_block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10404                                                  2 /* n_array_elements */, data_stride, third_offset);
10405
10406         vs_uni_block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
10407                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
10408
10409         vs_uni_block->Member("fifth", "layout(align = 64)", 0 /* expected_component */, 0 /* expected_location */, vec4,
10410                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
10411
10412         vs_uni_block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
10413                                                  0 /* n_array_elements */, data_stride, sixth_offset);
10414
10415         const GLuint stride = calculateStride(*vs_uni_block);
10416         m_data.resize(stride);
10417         generateData(*vs_uni_block, 0, m_data);
10418
10419         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10420
10421 /* Add uniform BLOCK */
10422 #if WRKARD_UNIFORMBLOCKALIGNMENT
10423         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING)", 0, 0, vs_uni_block, 0,
10424                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10425 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
10426         vs_si.Uniform("vs_uni_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_uni_block, 0,
10427                                   static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10428 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
10429
10430         program_interface.CloneVertexInterface(varying_passthrough);
10431 }
10432
10433 /** Constructor
10434  *
10435  * @param context Test framework context
10436  **/
10437 SSBMemberOffsetAndAlignTest::SSBMemberOffsetAndAlignTest(deqp::Context& context)
10438         : TextureTestBase(context, "ssb_member_offset_and_align",
10439                                           "Test verifies offsets and alignment of storage buffer members")
10440 {
10441 }
10442
10443 /** Get interface of program
10444  *
10445  * @param test_case_index     Test case index
10446  * @param program_interface   Interface of program
10447  * @param varying_passthrough Collection of connections between in and out variables
10448  **/
10449 void SSBMemberOffsetAndAlignTest::getProgramInterface(GLuint                                     test_case_index,
10450                                                                                                           Utils::ProgramInterface&   program_interface,
10451                                                                                                           Utils::VaryingPassthrough& varying_passthrough)
10452 {
10453         std::string globals = "const int basic_size = BASIC_SIZE;\n"
10454                                                   "const int type_align = TYPE_ALIGN;\n"
10455                                                   "const int type_size  = TYPE_SIZE;\n";
10456
10457         Utils::Type  type                = getType(test_case_index);
10458         GLuint           basic_size  = Utils::Type::GetTypeSize(type.m_basic_type);
10459         const GLuint base_align  = type.GetBaseAlignment(false);
10460         const GLuint array_align = type.GetBaseAlignment(true);
10461         const GLuint base_stride = Utils::Type::CalculateStd140Stride(base_align, type.m_n_columns, 0);
10462         const GLuint type_align  = Utils::roundUpToPowerOf2(base_stride);
10463
10464         /* Calculate offsets */
10465         const GLuint first_offset  = 0;
10466         const GLuint second_offset = type.GetActualOffset(base_stride, basic_size / 2);
10467
10468 #if WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST
10469
10470         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, base_align);
10471         const GLuint fourth_offset  = type.GetActualOffset(third_offset + base_stride, base_align);
10472         const GLuint fifth_offset   = type.GetActualOffset(fourth_offset + base_stride, base_align);
10473         const GLuint sixth_offset   = type.GetActualOffset(fifth_offset + base_stride, array_align);
10474         const GLuint seventh_offset = type.GetActualOffset(sixth_offset + base_stride, array_align);
10475         const GLuint eigth_offset   = type.GetActualOffset(seventh_offset + base_stride, array_align);
10476
10477 #else /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10478
10479         const GLuint third_offset   = type.GetActualOffset(second_offset + base_stride, 2 * type_align);
10480         const GLuint fourth_offset  = type.GetActualOffset(3 * type_align + 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, 8 * basic_size);
10485
10486 #endif /* WRKARD_UNIFORMBLOCKMEMBEROFFSETANDALIGNTEST */
10487
10488         /* Prepare data */
10489         const std::vector<GLubyte>& first  = type.GenerateData();
10490         const std::vector<GLubyte>& second = type.GenerateData();
10491         const std::vector<GLubyte>& third  = type.GenerateData();
10492         const std::vector<GLubyte>& fourth = type.GenerateData();
10493
10494         m_data.resize(eigth_offset + base_stride);
10495         GLubyte* ptr = &m_data[0];
10496         memcpy(ptr + first_offset, &first[0], first.size());
10497         memcpy(ptr + second_offset, &second[0], second.size());
10498         memcpy(ptr + third_offset, &third[0], third.size());
10499         memcpy(ptr + fourth_offset, &fourth[0], fourth.size());
10500         memcpy(ptr + fifth_offset, &fourth[0], fourth.size());
10501         memcpy(ptr + sixth_offset, &third[0], third.size());
10502         memcpy(ptr + seventh_offset, &second[0], second.size());
10503         memcpy(ptr + eigth_offset, &first[0], first.size());
10504
10505         /* Prepare globals */
10506         size_t position = 0;
10507         GLchar buffer[16];
10508
10509         sprintf(buffer, "%d", basic_size);
10510         Utils::replaceToken("BASIC_SIZE", position, buffer, globals);
10511
10512         sprintf(buffer, "%d", type_align);
10513         Utils::replaceToken("TYPE_ALIGN", position, buffer, globals);
10514
10515         sprintf(buffer, "%d", base_stride);
10516         Utils::replaceToken("TYPE_SIZE", position, buffer, globals);
10517
10518         /* Prepare Block */
10519         Utils::Interface* vs_buf_block = program_interface.Block("vs_buf_Block");
10520
10521         vs_buf_block->Member("at_first_offset", "layout(offset = 0, align = 8 * basic_size)", 0 /* expected_component */,
10522                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10523                                                  first_offset);
10524
10525         vs_buf_block->Member("at_second_offset", "layout(offset = type_size, align = basic_size / 2)",
10526                                                  0 /* expected_component */, 0 /* expected_location */, type, false /* normalized */,
10527                                                  0 /* n_array_elements */, base_stride, second_offset);
10528
10529         vs_buf_block->Member("at_third_offset", "layout(align = 2 * type_align)", 0 /* expected_component */,
10530                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10531                                                  third_offset);
10532
10533         vs_buf_block->Member("at_fourth_offset", "layout(offset = 3 * type_align + type_size)", 0 /* expected_component */,
10534                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10535                                                  fourth_offset);
10536
10537         vs_buf_block->Member("at_fifth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10538                                                  false /* normalized */, 0 /* n_array_elements */, base_stride, fifth_offset);
10539
10540         vs_buf_block->Member("at_sixth_offset", "", 0 /* expected_component */, 0 /* expected_location */, type,
10541                                                  false /* normalized */, 2 /* n_array_elements */, array_align * 2, sixth_offset);
10542
10543         vs_buf_block->Member("at_eigth_offset", "layout(align = 8 * basic_size)", 0 /* expected_component */,
10544                                                  0 /* expected_location */, type, false /* normalized */, 0 /* n_array_elements */, base_stride,
10545                                                  eigth_offset);
10546
10547         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
10548
10549         /* Add globals */
10550         vs_si.m_globals = globals;
10551
10552         /* Add uniform BLOCK */
10553         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_block, 0,
10554                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
10555
10556         /* */
10557         program_interface.CloneVertexInterface(varying_passthrough);
10558 }
10559
10560 /** Get type name
10561  *
10562  * @param test_case_index Index of test case
10563  *
10564  * @return Name of type test in test_case_index
10565  **/
10566 std::string SSBMemberOffsetAndAlignTest::getTestCaseName(glw::GLuint test_case_index)
10567 {
10568         return getTypeName(test_case_index);
10569 }
10570
10571 /** Returns number of types to test
10572  *
10573  * @return Number of types, 34
10574  **/
10575 glw::GLuint SSBMemberOffsetAndAlignTest::getTestCaseNumber()
10576 {
10577         return getTypesNumber();
10578 }
10579
10580 /** Prepare code snippet that will verify in and uniform variables
10581  *
10582  * @param ignored
10583  * @param ignored
10584  * @param stage   Shader stage
10585  *
10586  * @return Code that verify variables
10587  **/
10588 std::string SSBMemberOffsetAndAlignTest::getVerificationSnippet(GLuint /* test_case_index */,
10589                                                                                                                                 Utils::ProgramInterface& /* program_interface */,
10590                                                                                                                                 Utils::Shader::STAGES stage)
10591 {
10592         std::string verification = "if ( (PREFIXblock.at_first_offset  != PREFIXblock.at_eigth_offset   ) ||\n"
10593                                                            "         (PREFIXblock.at_second_offset != PREFIXblock.at_sixth_offset[1]) ||\n"
10594                                                            "         (PREFIXblock.at_third_offset  != PREFIXblock.at_sixth_offset[0]) ||\n"
10595                                                            "         (PREFIXblock.at_fourth_offset != PREFIXblock.at_fifth_offset   )  )\n"
10596                                                            "    {\n"
10597                                                            "        result = 0;\n"
10598                                                            "    }";
10599
10600         const GLchar* prefix = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::SSB);
10601
10602         Utils::replaceAllTokens("PREFIX", prefix, verification);
10603
10604         return verification;
10605 }
10606
10607 /** Selects if "draw" stages are relevant for test
10608  *
10609  * @param ignored
10610  *
10611  * @return true if all stages support shader storage buffers, false otherwise
10612  **/
10613 bool SSBMemberOffsetAndAlignTest::isDrawRelevant(GLuint /* test_case_index */)
10614 {
10615         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10616         GLint                    gs_supported_buffers  = 0;
10617         GLint                    tcs_supported_buffers = 0;
10618         GLint                    tes_supported_buffers = 0;
10619         GLint                    vs_supported_buffers  = 0;
10620
10621         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
10622         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
10623         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
10624         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
10625
10626         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10627
10628         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
10629                         (1 <= vs_supported_buffers));
10630 }
10631
10632 /** Constructor
10633  *
10634  * @param context Test framework context
10635  **/
10636 SSBLayoutQualifierConflictTest::SSBLayoutQualifierConflictTest(deqp::Context& context)
10637         : NegativeTestBase(context, "ssb_layout_qualifier_conflict", "Test verifies that std140 or std430 is required when "
10638                                                                                                                                  "offset and/or align qualifiers are used with storage "
10639                                                                                                                                  "block")
10640 {
10641         /* Nothing to be done here */
10642 }
10643
10644 /** Source for given test case and stage
10645  *
10646  * @param test_case_index Index of test case
10647  * @param stage           Shader stage
10648  *
10649  * @return Shader source
10650  **/
10651 std::string SSBLayoutQualifierConflictTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
10652 {
10653         static const GLchar* cs = "#version 430 core\n"
10654                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10655                                                           "\n"
10656                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
10657                                                           "\n"
10658                                                           "layout (QUALIFIERbinding = BINDING) buffer cs_Block {\n"
10659                                                           "    layout(offset = 16) vec4 boy;\n"
10660                                                           "    layout(align  = 64) vec4 man;\n"
10661                                                           "} uni_block;\n"
10662                                                           "\n"
10663                                                           "writeonly uniform image2D uni_image;\n"
10664                                                           "\n"
10665                                                           "void main()\n"
10666                                                           "{\n"
10667                                                           "    vec4 result = uni_block.boy + uni_block.man;\n"
10668                                                           "\n"
10669                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
10670                                                           "}\n"
10671                                                           "\n";
10672         static const GLchar* fs = "#version 430 core\n"
10673                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10674                                                           "\n"
10675                                                           "layout (QUALIFIERbinding = BINDING) buffer Block {\n"
10676                                                           "    layout(offset = 16) vec4 boy;\n"
10677                                                           "    layout(align  = 64) vec4 man;\n"
10678                                                           "} uni_block;\n"
10679                                                           "\n"
10680                                                           "in  vec4 gs_fs;\n"
10681                                                           "out vec4 fs_out;\n"
10682                                                           "\n"
10683                                                           "void main()\n"
10684                                                           "{\n"
10685                                                           "    fs_out = gs_fs + uni_block.boy + uni_block.man;\n"
10686                                                           "}\n"
10687                                                           "\n";
10688         static const GLchar* gs = "#version 430 core\n"
10689                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10690                                                           "\n"
10691                                                           "layout(points)                           in;\n"
10692                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
10693                                                           "\n"
10694                                                           "layout (QUALIFIERbinding = BINDING) buffer gs_Block {\n"
10695                                                           "    layout(offset = 16) vec4 boy;\n"
10696                                                           "    layout(align  = 64) vec4 man;\n"
10697                                                           "} uni_block;\n"
10698                                                           "\n"
10699                                                           "in  vec4 tes_gs[];\n"
10700                                                           "out vec4 gs_fs;\n"
10701                                                           "\n"
10702                                                           "void main()\n"
10703                                                           "{\n"
10704                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10705                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
10706                                                           "    EmitVertex();\n"
10707                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10708                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
10709                                                           "    EmitVertex();\n"
10710                                                           "    gs_fs = tes_gs[0] + uni_block.boy + uni_block.man;\n"
10711                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
10712                                                           "    EmitVertex();\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                                                           "}\n"
10717                                                           "\n";
10718         static const GLchar* tcs =
10719                 "#version 430 core\n"
10720                 "#extension GL_ARB_enhanced_layouts : require\n"
10721                 "\n"
10722                 "layout(vertices = 1) out;\n"
10723                 "\n"
10724                 "layout (QUALIFIERbinding = BINDING) buffer tcs_Block {\n"
10725                 "    layout(offset = 16) vec4 boy;\n"
10726                 "    layout(align  = 64) vec4 man;\n"
10727                 "} uni_block;\n"
10728                 "\n"
10729                 "in  vec4 vs_tcs[];\n"
10730                 "out vec4 tcs_tes[];\n"
10731                 "\n"
10732                 "void main()\n"
10733                 "{\n"
10734                 "\n"
10735                 "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID] + uni_block.boy + uni_block.man;\n"
10736                 "\n"
10737                 "    gl_TessLevelOuter[0] = 1.0;\n"
10738                 "    gl_TessLevelOuter[1] = 1.0;\n"
10739                 "    gl_TessLevelOuter[2] = 1.0;\n"
10740                 "    gl_TessLevelOuter[3] = 1.0;\n"
10741                 "    gl_TessLevelInner[0] = 1.0;\n"
10742                 "    gl_TessLevelInner[1] = 1.0;\n"
10743                 "}\n"
10744                 "\n";
10745         static const GLchar* tes = "#version 430 core\n"
10746                                                            "#extension GL_ARB_enhanced_layouts : require\n"
10747                                                            "\n"
10748                                                            "layout(isolines, point_mode) in;\n"
10749                                                            "\n"
10750                                                            "layout (QUALIFIERbinding = BINDING) buffer tes_Block {\n"
10751                                                            "    layout(offset = 16) vec4 boy;\n"
10752                                                            "    layout(align  = 64) vec4 man;\n"
10753                                                            "} uni_block;\n"
10754                                                            "\n"
10755                                                            "in  vec4 tcs_tes[];\n"
10756                                                            "out vec4 tes_gs;\n"
10757                                                            "\n"
10758                                                            "void main()\n"
10759                                                            "{\n"
10760                                                            "    tes_gs = tcs_tes[0] + uni_block.boy + uni_block.man;\n"
10761                                                            "}\n"
10762                                                            "\n";
10763         static const GLchar* vs = "#version 430 core\n"
10764                                                           "#extension GL_ARB_enhanced_layouts : require\n"
10765                                                           "\n"
10766                                                           "layout (QUALIFIERbinding = BINDING) buffer vs_Block {\n"
10767                                                           "    layout(offset = 16) vec4 boy;\n"
10768                                                           "    layout(align  = 64) vec4 man;\n"
10769                                                           "} uni_block;\n"
10770                                                           "\n"
10771                                                           "in  vec4 in_vs;\n"
10772                                                           "out vec4 vs_tcs;\n"
10773                                                           "\n"
10774                                                           "void main()\n"
10775                                                           "{\n"
10776                                                           "    vs_tcs = in_vs + uni_block.boy + uni_block.man;\n"
10777                                                           "}\n"
10778                                                           "\n";
10779
10780         GLchar          buffer[16];
10781         size_t          position = 0;
10782         std::string source;
10783         testCase&   test_case = m_test_cases[test_case_index];
10784         std::string qualifier = getQualifierName(test_case.m_qualifier);
10785
10786         if (false == qualifier.empty())
10787         {
10788                 qualifier.append(", ");
10789         }
10790
10791         sprintf(buffer, "%d", stage);
10792
10793         switch (stage)
10794         {
10795         case Utils::Shader::COMPUTE:
10796                 source = cs;
10797                 break;
10798         case Utils::Shader::FRAGMENT:
10799                 source = fs;
10800                 break;
10801         case Utils::Shader::GEOMETRY:
10802                 source = gs;
10803                 break;
10804         case Utils::Shader::TESS_CTRL:
10805                 source = tcs;
10806                 break;
10807         case Utils::Shader::TESS_EVAL:
10808                 source = tes;
10809                 break;
10810         case Utils::Shader::VERTEX:
10811                 source = vs;
10812                 break;
10813         default:
10814                 TCU_FAIL("Invalid enum");
10815         }
10816
10817         if (test_case.m_stage == stage)
10818         {
10819                 Utils::replaceToken("QUALIFIER", position, qualifier.c_str(), source);
10820         }
10821         else
10822         {
10823                 Utils::replaceToken("QUALIFIER", position, "std140, ", source);
10824         }
10825
10826         Utils::replaceToken("BINDING", position, buffer, source);
10827
10828         return source;
10829 }
10830
10831 /** Get description of test case
10832  *
10833  * @param test_case_index Index of test case
10834  *
10835  * @return Qualifier name
10836  **/
10837 std::string SSBLayoutQualifierConflictTest::getTestCaseName(GLuint test_case_index)
10838 {
10839         std::string result = getQualifierName(m_test_cases[test_case_index].m_qualifier);
10840
10841         return result;
10842 }
10843
10844 /** Get number of test cases
10845  *
10846  * @return Number of test cases
10847  **/
10848 GLuint SSBLayoutQualifierConflictTest::getTestCaseNumber()
10849 {
10850         return static_cast<GLuint>(m_test_cases.size());
10851 }
10852
10853 /** Selects if "compute" stage is relevant for test
10854  *
10855  * @param test_case_index Index of test case
10856  *
10857  * @return true when tested stage is compute
10858  **/
10859 bool SSBLayoutQualifierConflictTest::isComputeRelevant(GLuint test_case_index)
10860 {
10861         return (Utils::Shader::COMPUTE == m_test_cases[test_case_index].m_stage);
10862 }
10863
10864 /** Selects if compilation failure is expected result
10865  *
10866  * @param test_case_index Index of test case
10867  *
10868  * @return false for STD140 and STD430 cases, true otherwise
10869  **/
10870 bool SSBLayoutQualifierConflictTest::isFailureExpected(GLuint test_case_index)
10871 {
10872         const QUALIFIERS qualifier = m_test_cases[test_case_index].m_qualifier;
10873
10874         return !((STD140 == qualifier) || (STD430 == qualifier));
10875 }
10876
10877 /** Checks if stage is supported
10878  *
10879  * @param stage Shader stage
10880  *
10881  * @return true if supported, false otherwise
10882  **/
10883 bool SSBLayoutQualifierConflictTest::isStageSupported(Utils::Shader::STAGES stage)
10884 {
10885         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
10886         GLint                    max_supported_buffers = 0;
10887         GLenum                   pname                             = 0;
10888
10889         switch (stage)
10890         {
10891         case Utils::Shader::COMPUTE:
10892                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
10893                 break;
10894         case Utils::Shader::FRAGMENT:
10895                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
10896                 break;
10897         case Utils::Shader::GEOMETRY:
10898                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
10899                 break;
10900         case Utils::Shader::TESS_CTRL:
10901                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
10902                 break;
10903         case Utils::Shader::TESS_EVAL:
10904                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
10905                 break;
10906         case Utils::Shader::VERTEX:
10907                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
10908                 break;
10909         default:
10910                 TCU_FAIL("Invalid enum");
10911         }
10912
10913         gl.getIntegerv(pname, &max_supported_buffers);
10914         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
10915
10916         return 1 <= max_supported_buffers;
10917 }
10918
10919 /** Prepare all test cases
10920  *
10921  **/
10922 void SSBLayoutQualifierConflictTest::testInit()
10923 {
10924         bool stage_support[Utils::Shader::STAGE_MAX];
10925
10926         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10927         {
10928                 stage_support[stage] = isStageSupported((Utils::Shader::STAGES)stage);
10929         }
10930
10931         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
10932         {
10933                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
10934                 {
10935                         if (false == stage_support[stage])
10936                         {
10937                                 continue;
10938                         }
10939
10940                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
10941
10942                         m_test_cases.push_back(test_case);
10943                 }
10944         }
10945 }
10946
10947 /** Get name of glsl constant
10948  *
10949  * @param Constant id
10950  *
10951  * @return Name of constant used in GLSL
10952  **/
10953 const GLchar* SSBLayoutQualifierConflictTest::getQualifierName(QUALIFIERS qualifier)
10954 {
10955         const GLchar* name = "";
10956
10957         switch (qualifier)
10958         {
10959         case DEFAULT:
10960                 name = "";
10961                 break;
10962         case STD140:
10963                 name = "std140";
10964                 break;
10965         case STD430:
10966                 name = "std430";
10967                 break;
10968         case SHARED:
10969                 name = "shared";
10970                 break;
10971         case PACKED:
10972                 name = "packed";
10973                 break;
10974         default:
10975                 TCU_FAIL("Invalid enum");
10976         }
10977
10978         return name;
10979 }
10980
10981 /** Constructor
10982  *
10983  * @param context Test framework context
10984  **/
10985 SSBMemberInvalidOffsetAlignmentTest::SSBMemberInvalidOffsetAlignmentTest(deqp::Context& context)
10986         : UniformBlockMemberInvalidOffsetAlignmentTest(
10987                   context, "ssb_member_invalid_offset_alignment",
10988                   "Test verifies that invalid alignment of offset qualifiers cause compilation failure")
10989 {
10990         /* Nothing to be done here */
10991 }
10992
10993 /** Source for given test case and stage
10994  *
10995  * @param test_case_index Index of test case
10996  * @param stage           Shader stage
10997  *
10998  * @return Shader source
10999  **/
11000 std::string SSBMemberInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11001 {
11002         static const GLchar* cs = "#version 430 core\n"
11003                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11004                                                           "\n"
11005                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11006                                                           "\n"
11007                                                           "layout (std140) buffer Block {\n"
11008                                                           "    layout (offset = OFFSET) TYPE member;\n"
11009                                                           "} block;\n"
11010                                                           "\n"
11011                                                           "writeonly uniform image2D uni_image;\n"
11012                                                           "\n"
11013                                                           "void main()\n"
11014                                                           "{\n"
11015                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11016                                                           "\n"
11017                                                           "    if (TYPE(1) == block.member)\n"
11018                                                           "    {\n"
11019                                                           "        result = vec4(1, 1, 1, 1);\n"
11020                                                           "    }\n"
11021                                                           "\n"
11022                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11023                                                           "}\n"
11024                                                           "\n";
11025         static const GLchar* fs = "#version 430 core\n"
11026                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11027                                                           "\n"
11028                                                           "in  vec4 gs_fs;\n"
11029                                                           "out vec4 fs_out;\n"
11030                                                           "\n"
11031                                                           "void main()\n"
11032                                                           "{\n"
11033                                                           "    fs_out = gs_fs;\n"
11034                                                           "}\n"
11035                                                           "\n";
11036         static const GLchar* fs_tested = "#version 430 core\n"
11037                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11038                                                                          "\n"
11039                                                                          "layout (std140) buffer Block {\n"
11040                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11041                                                                          "} block;\n"
11042                                                                          "\n"
11043                                                                          "in  vec4 gs_fs;\n"
11044                                                                          "out vec4 fs_out;\n"
11045                                                                          "\n"
11046                                                                          "void main()\n"
11047                                                                          "{\n"
11048                                                                          "    if (TYPE(1) == block.member)\n"
11049                                                                          "    {\n"
11050                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11051                                                                          "    }\n"
11052                                                                          "\n"
11053                                                                          "    fs_out += gs_fs;\n"
11054                                                                          "}\n"
11055                                                                          "\n";
11056         static const GLchar* gs = "#version 430 core\n"
11057                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11058                                                           "\n"
11059                                                           "layout(points)                           in;\n"
11060                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11061                                                           "\n"
11062                                                           "in  vec4 tes_gs[];\n"
11063                                                           "out vec4 gs_fs;\n"
11064                                                           "\n"
11065                                                           "void main()\n"
11066                                                           "{\n"
11067                                                           "    gs_fs = tes_gs[0];\n"
11068                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11069                                                           "    EmitVertex();\n"
11070                                                           "    gs_fs = tes_gs[0];\n"
11071                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11072                                                           "    EmitVertex();\n"
11073                                                           "    gs_fs = tes_gs[0];\n"
11074                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11075                                                           "    EmitVertex();\n"
11076                                                           "    gs_fs = tes_gs[0];\n"
11077                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11078                                                           "    EmitVertex();\n"
11079                                                           "}\n"
11080                                                           "\n";
11081         static const GLchar* gs_tested = "#version 430 core\n"
11082                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11083                                                                          "\n"
11084                                                                          "layout(points)                           in;\n"
11085                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11086                                                                          "\n"
11087                                                                          "layout (std140) buffer Block {\n"
11088                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11089                                                                          "} block;\n"
11090                                                                          "\n"
11091                                                                          "in  vec4 tes_gs[];\n"
11092                                                                          "out vec4 gs_fs;\n"
11093                                                                          "\n"
11094                                                                          "void main()\n"
11095                                                                          "{\n"
11096                                                                          "    if (TYPE(1) == block.member)\n"
11097                                                                          "    {\n"
11098                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11099                                                                          "    }\n"
11100                                                                          "\n"
11101                                                                          "    gs_fs += tes_gs[0];\n"
11102                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11103                                                                          "    EmitVertex();\n"
11104                                                                          "    gs_fs += tes_gs[0];\n"
11105                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11106                                                                          "    EmitVertex();\n"
11107                                                                          "    gs_fs += tes_gs[0];\n"
11108                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11109                                                                          "    EmitVertex();\n"
11110                                                                          "    gs_fs += tes_gs[0];\n"
11111                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11112                                                                          "    EmitVertex();\n"
11113                                                                          "}\n"
11114                                                                          "\n";
11115         static const GLchar* tcs = "#version 430 core\n"
11116                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11117                                                            "\n"
11118                                                            "layout(vertices = 1) out;\n"
11119                                                            "\n"
11120                                                            "in  vec4 vs_tcs[];\n"
11121                                                            "out vec4 tcs_tes[];\n"
11122                                                            "\n"
11123                                                            "void main()\n"
11124                                                            "{\n"
11125                                                            "\n"
11126                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11127                                                            "\n"
11128                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11129                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11130                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11131                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11132                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11133                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11134                                                            "}\n"
11135                                                            "\n";
11136         static const GLchar* tcs_tested = "#version 430 core\n"
11137                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11138                                                                           "\n"
11139                                                                           "layout(vertices = 1) out;\n"
11140                                                                           "\n"
11141                                                                           "layout (std140) buffer Block {\n"
11142                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11143                                                                           "} block;\n"
11144                                                                           "\n"
11145                                                                           "in  vec4 vs_tcs[];\n"
11146                                                                           "out vec4 tcs_tes[];\n"
11147                                                                           "\n"
11148                                                                           "void main()\n"
11149                                                                           "{\n"
11150                                                                           "    if (TYPE(1) == block.member)\n"
11151                                                                           "    {\n"
11152                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11153                                                                           "    }\n"
11154                                                                           "\n"
11155                                                                           "\n"
11156                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11157                                                                           "\n"
11158                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11159                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11160                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11161                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11162                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11163                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11164                                                                           "}\n"
11165                                                                           "\n";
11166         static const GLchar* tes = "#version 430 core\n"
11167                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11168                                                            "\n"
11169                                                            "layout(isolines, point_mode) in;\n"
11170                                                            "\n"
11171                                                            "in  vec4 tcs_tes[];\n"
11172                                                            "out vec4 tes_gs;\n"
11173                                                            "\n"
11174                                                            "void main()\n"
11175                                                            "{\n"
11176                                                            "    tes_gs = tcs_tes[0];\n"
11177                                                            "}\n"
11178                                                            "\n";
11179         static const GLchar* tes_tested = "#version 430 core\n"
11180                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11181                                                                           "\n"
11182                                                                           "layout(isolines, point_mode) in;\n"
11183                                                                           "\n"
11184                                                                           "layout (std140) buffer Block {\n"
11185                                                                           "    layout (offset = OFFSET) TYPE member;\n"
11186                                                                           "} block;\n"
11187                                                                           "\n"
11188                                                                           "in  vec4 tcs_tes[];\n"
11189                                                                           "out vec4 tes_gs;\n"
11190                                                                           "\n"
11191                                                                           "void main()\n"
11192                                                                           "{\n"
11193                                                                           "    if (TYPE(1) == block.member)\n"
11194                                                                           "    {\n"
11195                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11196                                                                           "    }\n"
11197                                                                           "\n"
11198                                                                           "    tes_gs += tcs_tes[0];\n"
11199                                                                           "}\n"
11200                                                                           "\n";
11201         static const GLchar* vs = "#version 430 core\n"
11202                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11203                                                           "\n"
11204                                                           "in  vec4 in_vs;\n"
11205                                                           "out vec4 vs_tcs;\n"
11206                                                           "\n"
11207                                                           "void main()\n"
11208                                                           "{\n"
11209                                                           "    vs_tcs = in_vs;\n"
11210                                                           "}\n"
11211                                                           "\n";
11212         static const GLchar* vs_tested = "#version 430 core\n"
11213                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11214                                                                          "\n"
11215                                                                          "layout (std140) buffer Block {\n"
11216                                                                          "    layout (offset = OFFSET) TYPE member;\n"
11217                                                                          "} block;\n"
11218                                                                          "\n"
11219                                                                          "in  vec4 in_vs;\n"
11220                                                                          "out vec4 vs_tcs;\n"
11221                                                                          "\n"
11222                                                                          "void main()\n"
11223                                                                          "{\n"
11224                                                                          "    if (TYPE(1) == block.member)\n"
11225                                                                          "    {\n"
11226                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11227                                                                          "    }\n"
11228                                                                          "\n"
11229                                                                          "    vs_tcs += in_vs;\n"
11230                                                                          "}\n"
11231                                                                          "\n";
11232
11233         std::string source;
11234         testCase&   test_case = m_test_cases[test_case_index];
11235
11236         if (test_case.m_stage == stage)
11237         {
11238                 GLchar                     buffer[16];
11239                 const GLuint       offset       = test_case.m_offset;
11240                 size_t                     position  = 0;
11241                 const Utils::Type& type          = test_case.m_type;
11242                 const GLchar*     type_name = type.GetGLSLTypeName();
11243
11244                 sprintf(buffer, "%d", offset);
11245
11246                 switch (stage)
11247                 {
11248                 case Utils::Shader::COMPUTE:
11249                         source = cs;
11250                         break;
11251                 case Utils::Shader::FRAGMENT:
11252                         source = fs_tested;
11253                         break;
11254                 case Utils::Shader::GEOMETRY:
11255                         source = gs_tested;
11256                         break;
11257                 case Utils::Shader::TESS_CTRL:
11258                         source = tcs_tested;
11259                         break;
11260                 case Utils::Shader::TESS_EVAL:
11261                         source = tes_tested;
11262                         break;
11263                 case Utils::Shader::VERTEX:
11264                         source = vs_tested;
11265                         break;
11266                 default:
11267                         TCU_FAIL("Invalid enum");
11268                 }
11269
11270                 Utils::replaceToken("OFFSET", position, buffer, source);
11271                 Utils::replaceToken("TYPE", position, type_name, source);
11272                 Utils::replaceToken("TYPE", position, type_name, source);
11273         }
11274         else
11275         {
11276                 switch (stage)
11277                 {
11278                 case Utils::Shader::FRAGMENT:
11279                         source = fs;
11280                         break;
11281                 case Utils::Shader::GEOMETRY:
11282                         source = gs;
11283                         break;
11284                 case Utils::Shader::TESS_CTRL:
11285                         source = tcs;
11286                         break;
11287                 case Utils::Shader::TESS_EVAL:
11288                         source = tes;
11289                         break;
11290                 case Utils::Shader::VERTEX:
11291                         source = vs;
11292                         break;
11293                 default:
11294                         TCU_FAIL("Invalid enum");
11295                 }
11296         }
11297
11298         return source;
11299 }
11300
11301 /** Checks if stage is supported
11302  *
11303  * @param stage Shader stage
11304  *
11305  * @return true if supported, false otherwise
11306  **/
11307 bool SSBMemberInvalidOffsetAlignmentTest::isStageSupported(Utils::Shader::STAGES stage)
11308 {
11309         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11310         GLint                    max_supported_buffers = 0;
11311         GLenum                   pname                             = 0;
11312
11313         switch (stage)
11314         {
11315         case Utils::Shader::COMPUTE:
11316                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11317                 break;
11318         case Utils::Shader::FRAGMENT:
11319                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11320                 break;
11321         case Utils::Shader::GEOMETRY:
11322                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11323                 break;
11324         case Utils::Shader::TESS_CTRL:
11325                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11326                 break;
11327         case Utils::Shader::TESS_EVAL:
11328                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11329                 break;
11330         case Utils::Shader::VERTEX:
11331                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11332                 break;
11333         default:
11334                 TCU_FAIL("Invalid enum");
11335         }
11336
11337         gl.getIntegerv(pname, &max_supported_buffers);
11338         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11339
11340         return 1 <= max_supported_buffers;
11341 }
11342
11343 /** Constructor
11344  *
11345  * @param context Test framework context
11346  **/
11347 SSBMemberOverlappingOffsetsTest::SSBMemberOverlappingOffsetsTest(deqp::Context& context)
11348         : UniformBlockMemberOverlappingOffsetsTest(
11349                   context, "ssb_member_overlapping_offsets",
11350                   "Test verifies that overlapping offsets qualifiers cause compilation failure")
11351 {
11352         /* Nothing to be done here */
11353 }
11354
11355 /** Source for given test case and stage
11356  *
11357  * @param test_case_index Index of test case
11358  * @param stage           Shader stage
11359  *
11360  * @return Shader source
11361  **/
11362 std::string SSBMemberOverlappingOffsetsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11363 {
11364         static const GLchar* cs = "#version 430 core\n"
11365                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11366                                                           "\n"
11367                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11368                                                           "\n"
11369                                                           "layout (std140) buffer Block {\n"
11370                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11371                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11372                                                           "} block;\n"
11373                                                           "\n"
11374                                                           "writeonly uniform image2D uni_image;\n"
11375                                                           "\n"
11376                                                           "void main()\n"
11377                                                           "{\n"
11378                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11379                                                           "\n"
11380                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11381                                                           "        (MAN_TYPE(0) == block.man) )\n"
11382                                                           "    {\n"
11383                                                           "        result = vec4(1, 1, 1, 1);\n"
11384                                                           "    }\n"
11385                                                           "\n"
11386                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11387                                                           "}\n"
11388                                                           "\n";
11389         static const GLchar* fs = "#version 430 core\n"
11390                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11391                                                           "\n"
11392                                                           "in  vec4 gs_fs;\n"
11393                                                           "out vec4 fs_out;\n"
11394                                                           "\n"
11395                                                           "void main()\n"
11396                                                           "{\n"
11397                                                           "    fs_out = gs_fs;\n"
11398                                                           "}\n"
11399                                                           "\n";
11400         static const GLchar* fs_tested = "#version 430 core\n"
11401                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11402                                                                          "\n"
11403                                                                          "layout (std140) buffer Block {\n"
11404                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11405                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11406                                                                          "} block;\n"
11407                                                                          "\n"
11408                                                                          "in  vec4 gs_fs;\n"
11409                                                                          "out vec4 fs_out;\n"
11410                                                                          "\n"
11411                                                                          "void main()\n"
11412                                                                          "{\n"
11413                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11414                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11415                                                                          "    {\n"
11416                                                                          "        fs_out = vec4(1, 1, 1, 1);\n"
11417                                                                          "    }\n"
11418                                                                          "\n"
11419                                                                          "    fs_out += gs_fs;\n"
11420                                                                          "}\n"
11421                                                                          "\n";
11422         static const GLchar* gs = "#version 430 core\n"
11423                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11424                                                           "\n"
11425                                                           "layout(points)                           in;\n"
11426                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11427                                                           "\n"
11428                                                           "in  vec4 tes_gs[];\n"
11429                                                           "out vec4 gs_fs;\n"
11430                                                           "\n"
11431                                                           "void main()\n"
11432                                                           "{\n"
11433                                                           "    gs_fs = tes_gs[0];\n"
11434                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11435                                                           "    EmitVertex();\n"
11436                                                           "    gs_fs = tes_gs[0];\n"
11437                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11438                                                           "    EmitVertex();\n"
11439                                                           "    gs_fs = tes_gs[0];\n"
11440                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11441                                                           "    EmitVertex();\n"
11442                                                           "    gs_fs = tes_gs[0];\n"
11443                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11444                                                           "    EmitVertex();\n"
11445                                                           "}\n"
11446                                                           "\n";
11447         static const GLchar* gs_tested = "#version 430 core\n"
11448                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11449                                                                          "\n"
11450                                                                          "layout(points)                           in;\n"
11451                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11452                                                                          "\n"
11453                                                                          "layout (std140) buffer Block {\n"
11454                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11455                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11456                                                                          "} block;\n"
11457                                                                          "\n"
11458                                                                          "in  vec4 tes_gs[];\n"
11459                                                                          "out vec4 gs_fs;\n"
11460                                                                          "\n"
11461                                                                          "void main()\n"
11462                                                                          "{\n"
11463                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11464                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11465                                                                          "    {\n"
11466                                                                          "        gs_fs = vec4(1, 1, 1, 1);\n"
11467                                                                          "    }\n"
11468                                                                          "\n"
11469                                                                          "    gs_fs += tes_gs[0];\n"
11470                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11471                                                                          "    EmitVertex();\n"
11472                                                                          "    gs_fs += tes_gs[0];\n"
11473                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11474                                                                          "    EmitVertex();\n"
11475                                                                          "    gs_fs += tes_gs[0];\n"
11476                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11477                                                                          "    EmitVertex();\n"
11478                                                                          "    gs_fs += tes_gs[0];\n"
11479                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11480                                                                          "    EmitVertex();\n"
11481                                                                          "}\n"
11482                                                                          "\n";
11483         static const GLchar* tcs = "#version 430 core\n"
11484                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11485                                                            "\n"
11486                                                            "layout(vertices = 1) out;\n"
11487                                                            "\n"
11488                                                            "in  vec4 vs_tcs[];\n"
11489                                                            "out vec4 tcs_tes[];\n"
11490                                                            "\n"
11491                                                            "void main()\n"
11492                                                            "{\n"
11493                                                            "\n"
11494                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11495                                                            "\n"
11496                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11497                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11498                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11499                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11500                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11501                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11502                                                            "}\n"
11503                                                            "\n";
11504         static const GLchar* tcs_tested = "#version 430 core\n"
11505                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11506                                                                           "\n"
11507                                                                           "layout(vertices = 1) out;\n"
11508                                                                           "\n"
11509                                                                           "layout (std140) buffer Block {\n"
11510                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11511                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11512                                                                           "} block;\n"
11513                                                                           "\n"
11514                                                                           "in  vec4 vs_tcs[];\n"
11515                                                                           "out vec4 tcs_tes[];\n"
11516                                                                           "\n"
11517                                                                           "void main()\n"
11518                                                                           "{\n"
11519                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11520                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11521                                                                           "    {\n"
11522                                                                           "        tcs_tes[gl_InvocationID] = vec4(1, 1, 1, 1);\n"
11523                                                                           "    }\n"
11524                                                                           "\n"
11525                                                                           "\n"
11526                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11527                                                                           "\n"
11528                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11529                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11530                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11531                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11532                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11533                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11534                                                                           "}\n"
11535                                                                           "\n";
11536         static const GLchar* tes = "#version 430 core\n"
11537                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11538                                                            "\n"
11539                                                            "layout(isolines, point_mode) in;\n"
11540                                                            "\n"
11541                                                            "in  vec4 tcs_tes[];\n"
11542                                                            "out vec4 tes_gs;\n"
11543                                                            "\n"
11544                                                            "void main()\n"
11545                                                            "{\n"
11546                                                            "    tes_gs = tcs_tes[0];\n"
11547                                                            "}\n"
11548                                                            "\n";
11549         static const GLchar* tes_tested = "#version 430 core\n"
11550                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11551                                                                           "\n"
11552                                                                           "layout(isolines, point_mode) in;\n"
11553                                                                           "\n"
11554                                                                           "layout (std140) buffer Block {\n"
11555                                                                           "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11556                                                                           "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11557                                                                           "} block;\n"
11558                                                                           "\n"
11559                                                                           "in  vec4 tcs_tes[];\n"
11560                                                                           "out vec4 tes_gs;\n"
11561                                                                           "\n"
11562                                                                           "void main()\n"
11563                                                                           "{\n"
11564                                                                           "    if ((BOY_TYPE(1) == block.boy) ||\n"
11565                                                                           "        (MAN_TYPE(0) == block.man) )\n"
11566                                                                           "    {\n"
11567                                                                           "        tes_gs = vec4(1, 1, 1, 1);\n"
11568                                                                           "    }\n"
11569                                                                           "\n"
11570                                                                           "    tes_gs += tcs_tes[0];\n"
11571                                                                           "}\n"
11572                                                                           "\n";
11573         static const GLchar* vs = "#version 430 core\n"
11574                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11575                                                           "\n"
11576                                                           "in  vec4 in_vs;\n"
11577                                                           "out vec4 vs_tcs;\n"
11578                                                           "\n"
11579                                                           "void main()\n"
11580                                                           "{\n"
11581                                                           "    vs_tcs = in_vs;\n"
11582                                                           "}\n"
11583                                                           "\n";
11584         static const GLchar* vs_tested = "#version 430 core\n"
11585                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11586                                                                          "\n"
11587                                                                          "layout (std140) buffer Block {\n"
11588                                                                          "    layout (offset = BOY_OFFSET) BOY_TYPE boy;\n"
11589                                                                          "    layout (offset = MAN_OFFSET) MAN_TYPE man;\n"
11590                                                                          "} block;\n"
11591                                                                          "\n"
11592                                                                          "in  vec4 in_vs;\n"
11593                                                                          "out vec4 vs_tcs;\n"
11594                                                                          "\n"
11595                                                                          "void main()\n"
11596                                                                          "{\n"
11597                                                                          "    if ((BOY_TYPE(1) == block.boy) ||\n"
11598                                                                          "        (MAN_TYPE(0) == block.man) )\n"
11599                                                                          "    {\n"
11600                                                                          "        vs_tcs = vec4(1, 1, 1, 1);\n"
11601                                                                          "    }\n"
11602                                                                          "\n"
11603                                                                          "    vs_tcs += in_vs;\n"
11604                                                                          "}\n"
11605                                                                          "\n";
11606
11607         std::string source;
11608         testCase&   test_case = m_test_cases[test_case_index];
11609
11610         if (test_case.m_stage == stage)
11611         {
11612                 GLchar                     buffer[16];
11613                 const GLuint       boy_offset   = test_case.m_boy_offset;
11614                 const Utils::Type& boy_type              = test_case.m_boy_type;
11615                 const GLchar*     boy_type_name = boy_type.GetGLSLTypeName();
11616                 const GLuint       man_offset   = test_case.m_man_offset;
11617                 const Utils::Type& man_type              = test_case.m_man_type;
11618                 const GLchar*     man_type_name = man_type.GetGLSLTypeName();
11619                 size_t                     position              = 0;
11620
11621                 switch (stage)
11622                 {
11623                 case Utils::Shader::COMPUTE:
11624                         source = cs;
11625                         break;
11626                 case Utils::Shader::FRAGMENT:
11627                         source = fs_tested;
11628                         break;
11629                 case Utils::Shader::GEOMETRY:
11630                         source = gs_tested;
11631                         break;
11632                 case Utils::Shader::TESS_CTRL:
11633                         source = tcs_tested;
11634                         break;
11635                 case Utils::Shader::TESS_EVAL:
11636                         source = tes_tested;
11637                         break;
11638                 case Utils::Shader::VERTEX:
11639                         source = vs_tested;
11640                         break;
11641                 default:
11642                         TCU_FAIL("Invalid enum");
11643                 }
11644
11645                 sprintf(buffer, "%d", boy_offset);
11646                 Utils::replaceToken("BOY_OFFSET", position, buffer, source);
11647                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11648                 sprintf(buffer, "%d", man_offset);
11649                 Utils::replaceToken("MAN_OFFSET", position, buffer, source);
11650                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11651                 Utils::replaceToken("BOY_TYPE", position, boy_type_name, source);
11652                 Utils::replaceToken("MAN_TYPE", position, man_type_name, source);
11653         }
11654         else
11655         {
11656                 switch (stage)
11657                 {
11658                 case Utils::Shader::FRAGMENT:
11659                         source = fs;
11660                         break;
11661                 case Utils::Shader::GEOMETRY:
11662                         source = gs;
11663                         break;
11664                 case Utils::Shader::TESS_CTRL:
11665                         source = tcs;
11666                         break;
11667                 case Utils::Shader::TESS_EVAL:
11668                         source = tes;
11669                         break;
11670                 case Utils::Shader::VERTEX:
11671                         source = vs;
11672                         break;
11673                 default:
11674                         TCU_FAIL("Invalid enum");
11675                 }
11676         }
11677
11678         return source;
11679 }
11680
11681 /** Checks if stage is supported
11682  *
11683  * @param stage Shader stage
11684  *
11685  * @return true if supported, false otherwise
11686  **/
11687 bool SSBMemberOverlappingOffsetsTest::isStageSupported(Utils::Shader::STAGES stage)
11688 {
11689         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
11690         GLint                    max_supported_buffers = 0;
11691         GLenum                   pname                             = 0;
11692
11693         switch (stage)
11694         {
11695         case Utils::Shader::COMPUTE:
11696                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
11697                 break;
11698         case Utils::Shader::FRAGMENT:
11699                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
11700                 break;
11701         case Utils::Shader::GEOMETRY:
11702                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
11703                 break;
11704         case Utils::Shader::TESS_CTRL:
11705                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
11706                 break;
11707         case Utils::Shader::TESS_EVAL:
11708                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
11709                 break;
11710         case Utils::Shader::VERTEX:
11711                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
11712                 break;
11713         default:
11714                 TCU_FAIL("Invalid enum");
11715         }
11716
11717         gl.getIntegerv(pname, &max_supported_buffers);
11718         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
11719
11720         return 1 <= max_supported_buffers;
11721 }
11722
11723 /** Constructor
11724  *
11725  * @param context Test framework context
11726  **/
11727 SSBMemberAlignNonPowerOf2Test::SSBMemberAlignNonPowerOf2Test(deqp::Context& context)
11728         : UniformBlockMemberAlignNonPowerOf2Test(context, "ssb_member_align_non_power_of_2",
11729                                                                                          "Test verifies that align qualifier requires value that is a power of 2")
11730 {
11731         /* Nothing to be done here */
11732 }
11733
11734 /** Source for given test case and stage
11735  *
11736  * @param test_case_index Index of test case
11737  * @param stage           Shader stage
11738  *
11739  * @return Shader source
11740  **/
11741 std::string SSBMemberAlignNonPowerOf2Test::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
11742 {
11743         static const GLchar* cs = "#version 430 core\n"
11744                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11745                                                           "\n"
11746                                                           "layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;\n"
11747                                                           "\n"
11748                                                           "layout (std140) buffer Block {\n"
11749                                                           "    vec4 boy;\n"
11750                                                           "    layout (align = ALIGN) TYPE man;\n"
11751                                                           "} block;\n"
11752                                                           "\n"
11753                                                           "writeonly uniform image2D uni_image;\n"
11754                                                           "\n"
11755                                                           "void main()\n"
11756                                                           "{\n"
11757                                                           "    vec4 result = vec4(1, 0, 0.5, 1);\n"
11758                                                           "\n"
11759                                                           "    if (TYPE(0) == block.man)\n"
11760                                                           "    {\n"
11761                                                           "        result = vec4(1, 1, 1, 1) - block.boy;\n"
11762                                                           "    }\n"
11763                                                           "\n"
11764                                                           "    imageStore(uni_image, ivec2(gl_GlobalInvocationID.xy), result);\n"
11765                                                           "}\n"
11766                                                           "\n";
11767         static const GLchar* fs = "#version 430 core\n"
11768                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11769                                                           "\n"
11770                                                           "in  vec4 gs_fs;\n"
11771                                                           "out vec4 fs_out;\n"
11772                                                           "\n"
11773                                                           "void main()\n"
11774                                                           "{\n"
11775                                                           "    fs_out = gs_fs;\n"
11776                                                           "}\n"
11777                                                           "\n";
11778         static const GLchar* fs_tested = "#version 430 core\n"
11779                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11780                                                                          "\n"
11781                                                                          "layout (std140) buffer Block {\n"
11782                                                                          "    vec4 boy;\n"
11783                                                                          "    layout (align = ALIGN) TYPE man;\n"
11784                                                                          "} block;\n"
11785                                                                          "\n"
11786                                                                          "in  vec4 gs_fs;\n"
11787                                                                          "out vec4 fs_out;\n"
11788                                                                          "\n"
11789                                                                          "void main()\n"
11790                                                                          "{\n"
11791                                                                          "    if (TYPE(0) == block.man)\n"
11792                                                                          "    {\n"
11793                                                                          "        fs_out = block.boy;\n"
11794                                                                          "    }\n"
11795                                                                          "\n"
11796                                                                          "    fs_out += gs_fs;\n"
11797                                                                          "}\n"
11798                                                                          "\n";
11799         static const GLchar* gs = "#version 430 core\n"
11800                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11801                                                           "\n"
11802                                                           "layout(points)                           in;\n"
11803                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
11804                                                           "\n"
11805                                                           "in  vec4 tes_gs[];\n"
11806                                                           "out vec4 gs_fs;\n"
11807                                                           "\n"
11808                                                           "void main()\n"
11809                                                           "{\n"
11810                                                           "    gs_fs = tes_gs[0];\n"
11811                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11812                                                           "    EmitVertex();\n"
11813                                                           "    gs_fs = tes_gs[0];\n"
11814                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11815                                                           "    EmitVertex();\n"
11816                                                           "    gs_fs = tes_gs[0];\n"
11817                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
11818                                                           "    EmitVertex();\n"
11819                                                           "    gs_fs = tes_gs[0];\n"
11820                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
11821                                                           "    EmitVertex();\n"
11822                                                           "}\n"
11823                                                           "\n";
11824         static const GLchar* gs_tested = "#version 430 core\n"
11825                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11826                                                                          "\n"
11827                                                                          "layout(points)                           in;\n"
11828                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
11829                                                                          "\n"
11830                                                                          "layout (std140) buffer Block {\n"
11831                                                                          "    vec4 boy;\n"
11832                                                                          "    layout (align = ALIGN) TYPE man;\n"
11833                                                                          "} block;\n"
11834                                                                          "\n"
11835                                                                          "in  vec4 tes_gs[];\n"
11836                                                                          "out vec4 gs_fs;\n"
11837                                                                          "\n"
11838                                                                          "void main()\n"
11839                                                                          "{\n"
11840                                                                          "    if (TYPE(0) == block.man)\n"
11841                                                                          "    {\n"
11842                                                                          "        gs_fs = block.boy;\n"
11843                                                                          "    }\n"
11844                                                                          "\n"
11845                                                                          "    gs_fs += tes_gs[0];\n"
11846                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
11847                                                                          "    EmitVertex();\n"
11848                                                                          "    gs_fs += tes_gs[0];\n"
11849                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
11850                                                                          "    EmitVertex();\n"
11851                                                                          "    gs_fs += tes_gs[0];\n"
11852                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
11853                                                                          "    EmitVertex();\n"
11854                                                                          "    gs_fs += tes_gs[0];\n"
11855                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
11856                                                                          "    EmitVertex();\n"
11857                                                                          "}\n"
11858                                                                          "\n";
11859         static const GLchar* tcs = "#version 430 core\n"
11860                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11861                                                            "\n"
11862                                                            "layout(vertices = 1) out;\n"
11863                                                            "\n"
11864                                                            "in  vec4 vs_tcs[];\n"
11865                                                            "out vec4 tcs_tes[];\n"
11866                                                            "\n"
11867                                                            "void main()\n"
11868                                                            "{\n"
11869                                                            "\n"
11870                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
11871                                                            "\n"
11872                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
11873                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
11874                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
11875                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
11876                                                            "    gl_TessLevelInner[0] = 1.0;\n"
11877                                                            "    gl_TessLevelInner[1] = 1.0;\n"
11878                                                            "}\n"
11879                                                            "\n";
11880         static const GLchar* tcs_tested = "#version 430 core\n"
11881                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11882                                                                           "\n"
11883                                                                           "layout(vertices = 1) out;\n"
11884                                                                           "\n"
11885                                                                           "layout (std140) buffer Block {\n"
11886                                                                           "    vec4 boy;\n"
11887                                                                           "    layout (align = ALIGN) TYPE man;\n"
11888                                                                           "} block;\n"
11889                                                                           "\n"
11890                                                                           "in  vec4 vs_tcs[];\n"
11891                                                                           "out vec4 tcs_tes[];\n"
11892                                                                           "\n"
11893                                                                           "void main()\n"
11894                                                                           "{\n"
11895                                                                           "    if (TYPE(0) == block.man)\n"
11896                                                                           "    {\n"
11897                                                                           "        tcs_tes[gl_InvocationID] = block.boy;\n"
11898                                                                           "    }\n"
11899                                                                           "\n"
11900                                                                           "\n"
11901                                                                           "    tcs_tes[gl_InvocationID] += vs_tcs[gl_InvocationID];\n"
11902                                                                           "\n"
11903                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
11904                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
11905                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
11906                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
11907                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
11908                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
11909                                                                           "}\n"
11910                                                                           "\n";
11911         static const GLchar* tes = "#version 430 core\n"
11912                                                            "#extension GL_ARB_enhanced_layouts : require\n"
11913                                                            "\n"
11914                                                            "layout(isolines, point_mode) in;\n"
11915                                                            "\n"
11916                                                            "in  vec4 tcs_tes[];\n"
11917                                                            "out vec4 tes_gs;\n"
11918                                                            "\n"
11919                                                            "void main()\n"
11920                                                            "{\n"
11921                                                            "    tes_gs = tcs_tes[0];\n"
11922                                                            "}\n"
11923                                                            "\n";
11924         static const GLchar* tes_tested = "#version 430 core\n"
11925                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11926                                                                           "\n"
11927                                                                           "layout(isolines, point_mode) in;\n"
11928                                                                           "\n"
11929                                                                           "layout (std140) buffer Block {\n"
11930                                                                           "    vec4 boy;\n"
11931                                                                           "    layout (align = ALIGN) TYPE man;\n"
11932                                                                           "} block;\n"
11933                                                                           "\n"
11934                                                                           "in  vec4 tcs_tes[];\n"
11935                                                                           "out vec4 tes_gs;\n"
11936                                                                           "\n"
11937                                                                           "void main()\n"
11938                                                                           "{\n"
11939                                                                           "    if (TYPE(0) == block.man)\n"
11940                                                                           "    {\n"
11941                                                                           "        tes_gs = block.boy;\n"
11942                                                                           "    }\n"
11943                                                                           "\n"
11944                                                                           "    tes_gs += tcs_tes[0];\n"
11945                                                                           "}\n"
11946                                                                           "\n";
11947         static const GLchar* vs = "#version 430 core\n"
11948                                                           "#extension GL_ARB_enhanced_layouts : require\n"
11949                                                           "\n"
11950                                                           "in  vec4 in_vs;\n"
11951                                                           "out vec4 vs_tcs;\n"
11952                                                           "\n"
11953                                                           "void main()\n"
11954                                                           "{\n"
11955                                                           "    vs_tcs = in_vs;\n"
11956                                                           "}\n"
11957                                                           "\n";
11958         static const GLchar* vs_tested = "#version 430 core\n"
11959                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
11960                                                                          "\n"
11961                                                                          "layout (std140) buffer Block {\n"
11962                                                                          "    vec4 boy;\n"
11963                                                                          "    layout (align = ALIGN) TYPE man;\n"
11964                                                                          "} block;\n"
11965                                                                          "\n"
11966                                                                          "in  vec4 in_vs;\n"
11967                                                                          "out vec4 vs_tcs;\n"
11968                                                                          "\n"
11969                                                                          "void main()\n"
11970                                                                          "{\n"
11971                                                                          "    if (TYPE(0) == block.man)\n"
11972                                                                          "    {\n"
11973                                                                          "        vs_tcs = block.boy;\n"
11974                                                                          "    }\n"
11975                                                                          "\n"
11976                                                                          "    vs_tcs += in_vs;\n"
11977                                                                          "}\n"
11978                                                                          "\n";
11979
11980         std::string source;
11981         testCase&   test_case = m_test_cases[test_case_index];
11982
11983         if (test_case.m_stage == stage)
11984         {
11985                 GLchar                     buffer[16];
11986                 const GLuint       alignment = test_case.m_alignment;
11987                 const Utils::Type& type          = test_case.m_type;
11988                 const GLchar*     type_name = type.GetGLSLTypeName();
11989                 size_t                     position  = 0;
11990
11991                 switch (stage)
11992                 {
11993                 case Utils::Shader::COMPUTE:
11994                         source = cs;
11995                         break;
11996                 case Utils::Shader::FRAGMENT:
11997                         source = fs_tested;
11998                         break;
11999                 case Utils::Shader::GEOMETRY:
12000                         source = gs_tested;
12001                         break;
12002                 case Utils::Shader::TESS_CTRL:
12003                         source = tcs_tested;
12004                         break;
12005                 case Utils::Shader::TESS_EVAL:
12006                         source = tes_tested;
12007                         break;
12008                 case Utils::Shader::VERTEX:
12009                         source = vs_tested;
12010                         break;
12011                 default:
12012                         TCU_FAIL("Invalid enum");
12013                 }
12014
12015                 sprintf(buffer, "%d", alignment);
12016                 Utils::replaceToken("ALIGN", position, buffer, source);
12017                 Utils::replaceToken("TYPE", position, type_name, source);
12018                 Utils::replaceToken("TYPE", position, type_name, source);
12019         }
12020         else
12021         {
12022                 switch (stage)
12023                 {
12024                 case Utils::Shader::FRAGMENT:
12025                         source = fs;
12026                         break;
12027                 case Utils::Shader::GEOMETRY:
12028                         source = gs;
12029                         break;
12030                 case Utils::Shader::TESS_CTRL:
12031                         source = tcs;
12032                         break;
12033                 case Utils::Shader::TESS_EVAL:
12034                         source = tes;
12035                         break;
12036                 case Utils::Shader::VERTEX:
12037                         source = vs;
12038                         break;
12039                 default:
12040                         TCU_FAIL("Invalid enum");
12041                 }
12042         }
12043
12044         return source;
12045 }
12046
12047 /** Checks if stage is supported
12048  *
12049  * @param stage Shader stage
12050  *
12051  * @return true if supported, false otherwise
12052  **/
12053 bool SSBMemberAlignNonPowerOf2Test::isStageSupported(Utils::Shader::STAGES stage)
12054 {
12055         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12056         GLint                    max_supported_buffers = 0;
12057         GLenum                   pname                             = 0;
12058
12059         switch (stage)
12060         {
12061         case Utils::Shader::COMPUTE:
12062                 pname = GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS;
12063                 break;
12064         case Utils::Shader::FRAGMENT:
12065                 pname = GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS;
12066                 break;
12067         case Utils::Shader::GEOMETRY:
12068                 pname = GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS;
12069                 break;
12070         case Utils::Shader::TESS_CTRL:
12071                 pname = GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS;
12072                 break;
12073         case Utils::Shader::TESS_EVAL:
12074                 pname = GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS;
12075                 break;
12076         case Utils::Shader::VERTEX:
12077                 pname = GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS;
12078                 break;
12079         default:
12080                 TCU_FAIL("Invalid enum");
12081         }
12082
12083         gl.getIntegerv(pname, &max_supported_buffers);
12084         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12085
12086         return 1 <= max_supported_buffers;
12087 }
12088
12089 /** Constructor
12090  *
12091  * @param context Test framework context
12092  **/
12093 SSBAlignmentTest::SSBAlignmentTest(deqp::Context& context)
12094         : TextureTestBase(context, "ssb_alignment", "Test verifies offset and alignment of ssb buffer")
12095 {
12096 }
12097
12098 /** Get interface of program
12099  *
12100  * @param ignored
12101  * @param program_interface Interface of program
12102  * @param varying_passthrough Collection of connections between in and out variables
12103  **/
12104 void SSBAlignmentTest::getProgramInterface(GLuint /* test_case_index */, Utils::ProgramInterface& program_interface,
12105                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12106 {
12107         static const Utils::Type vec4 = Utils::Type::vec4;
12108
12109 #if WRKARD_UNIFORMBLOCKALIGNMENT
12110
12111         static const GLuint block_align = 16;
12112
12113 #else /* WRKARD_UNIFORMBLOCKALIGNMENT */
12114
12115         static const GLuint block_align = 64;
12116
12117 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12118
12119         static const GLuint fifth_align = 16;
12120         static const GLuint vec4_stride = 16;
12121         static const GLuint data_stride = vec4_stride * 2; /* one vec4 + one scalar aligned to 16 */
12122
12123         const GLuint first_offset  = 0;                                                                                                                                         /* vec4 at 0 */
12124         const GLuint second_offset = Utils::Type::GetActualOffset(first_offset + vec4_stride, block_align); /* Data at 32 */
12125         const GLuint third_offset =
12126                 Utils::Type::GetActualOffset(second_offset + data_stride, block_align); /* Data[2] at 64 */
12127         const GLuint fourth_offset =
12128                 Utils::Type::GetActualOffset(third_offset + data_stride * 2, block_align); /* vec4[3] at 96 */
12129         const GLuint fifth_offset =
12130                 Utils::Type::GetActualOffset(fourth_offset + vec4_stride * 3, fifth_align); /* vec4[2] at 160 */
12131         const GLuint sixth_offset =
12132                 Utils::Type::GetActualOffset(fifth_offset + vec4_stride * 2, block_align); /* Data at 192 */
12133
12134         Utils::Interface* structure = program_interface.Structure("Data");
12135
12136         structure->Member("vector", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12137                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::vec4.GetSize(), 0 /* offset */);
12138
12139         structure->Member("scalar", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::_float,
12140                                           false /* normalized */, 0 /* n_array_elements */, Utils::Type::_float.GetSize(),
12141                                           Utils::Type::vec4.GetSize() /* offset */);
12142
12143         /* Prepare Block */
12144         Utils::Interface* vs_buf_Block = program_interface.Block("vs_buf_Block");
12145
12146         vs_buf_Block->Member("first", "", 0 /* expected_component */, 0 /* expected_location */, Utils::Type::vec4,
12147                                                  false /* normalized */, 0 /* n_array_elements */, vec4_stride, first_offset /* offset */);
12148
12149         vs_buf_Block->Member("second", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12150                                                  0 /* n_array_elements */, data_stride, second_offset);
12151
12152         vs_buf_Block->Member("third", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12153                                                  2 /* n_array_elements */, data_stride, third_offset);
12154
12155         vs_buf_Block->Member("fourth", "", 0 /* expected_component */, 0 /* expected_location */, vec4,
12156                                                  false /* normalized */, 3 /* n_array_elements */, vec4_stride, fourth_offset);
12157
12158         vs_buf_Block->Member("fifth", "layout(align = 16)", 0 /* expected_component */, 0 /* expected_location */, vec4,
12159                                                  false /* normalized */, 2 /* n_array_elements */, vec4_stride, fifth_offset);
12160
12161         vs_buf_Block->Member("sixth", "", 0 /* expected_component */, 0 /* expected_location */, structure,
12162                                                  0 /* n_array_elements */, data_stride, sixth_offset);
12163
12164         const GLuint stride = calculateStride(*vs_buf_Block);
12165         m_data.resize(stride);
12166         generateData(*vs_buf_Block, 0, m_data);
12167
12168         Utils::ShaderInterface& vs_si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12169
12170 /* Add uniform BLOCK */
12171 #if WRKARD_UNIFORMBLOCKALIGNMENT
12172         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING)", 0, 0, vs_buf_Block, 0,
12173                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12174 #else  /* WRKARD_UNIFORMBLOCKALIGNMENT */
12175         vs_si.SSB("vs_buf_block", "layout (std140, binding = BINDING, align = 64)", 0, 0, vs_buf_Block, 0,
12176                           static_cast<GLuint>(m_data.size()), 0, &m_data[0], m_data.size());
12177 #endif /* WRKARD_UNIFORMBLOCKALIGNMENT */
12178
12179         program_interface.CloneVertexInterface(varying_passthrough);
12180 }
12181
12182 /** Selects if "draw" stages are relevant for test
12183  *
12184  * @param ignored
12185  *
12186  * @return true if all stages support shader storage buffers, false otherwise
12187  **/
12188 bool SSBAlignmentTest::isDrawRelevant(GLuint /* test_case_index */)
12189 {
12190         const Functions& gl                                        = m_context.getRenderContext().getFunctions();
12191         GLint                    gs_supported_buffers  = 0;
12192         GLint                    tcs_supported_buffers = 0;
12193         GLint                    tes_supported_buffers = 0;
12194         GLint                    vs_supported_buffers  = 0;
12195
12196         gl.getIntegerv(GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS, &gs_supported_buffers);
12197         gl.getIntegerv(GL_MAX_TESS_CONTROL_SHADER_STORAGE_BLOCKS, &tcs_supported_buffers);
12198         gl.getIntegerv(GL_MAX_TESS_EVALUATION_SHADER_STORAGE_BLOCKS, &tes_supported_buffers);
12199         gl.getIntegerv(GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS, &vs_supported_buffers);
12200
12201         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
12202
12203         return ((1 <= gs_supported_buffers) && (1 <= tcs_supported_buffers) && (1 <= tes_supported_buffers) &&
12204                         (1 <= vs_supported_buffers));
12205 }
12206
12207 /** Constructor
12208  *
12209  * @param context Test framework context
12210  **/
12211 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context)
12212         : TextureTestBase(context, "varying_locations", "Test verifies that input and output locations are respected")
12213 {
12214 }
12215
12216 /** Constructor
12217  *
12218  * @param context          Test context
12219  * @param test_name        Name of test
12220  * @param test_description Description of test
12221  **/
12222 VaryingLocationsTest::VaryingLocationsTest(deqp::Context& context, const glw::GLchar* test_name,
12223                                                                                    const glw::GLchar* test_description)
12224         : TextureTestBase(context, test_name, test_description)
12225 {
12226 }
12227
12228 /** Get interface of program
12229  *
12230  * @param test_case_index     Test case
12231  * @param program_interface   Interface of program
12232  * @param varying_passthrough Collection of connections between in and out variables
12233  **/
12234 void VaryingLocationsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
12235                                                                                            Utils::VaryingPassthrough& varying_passthrough)
12236 {
12237         const Utils::Type type = getType(test_case_index);
12238
12239         m_first_data = type.GenerateDataPacked();
12240         m_last_data  = type.GenerateDataPacked();
12241
12242         prepareShaderStage(Utils::Shader::FRAGMENT, type, program_interface, varying_passthrough);
12243         prepareShaderStage(Utils::Shader::GEOMETRY, type, program_interface, varying_passthrough);
12244         prepareShaderStage(Utils::Shader::TESS_CTRL, type, program_interface, varying_passthrough);
12245         prepareShaderStage(Utils::Shader::TESS_EVAL, type, program_interface, varying_passthrough);
12246         prepareShaderStage(Utils::Shader::VERTEX, type, program_interface, varying_passthrough);
12247 }
12248
12249 /** Get type name
12250  *
12251  * @param test_case_index Index of test case
12252  *
12253  * @return Name of type test in test_case_index
12254  **/
12255 std::string VaryingLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12256 {
12257         return getTypeName(test_case_index);
12258 }
12259
12260 /** Returns number of types to test
12261  *
12262  * @return Number of types, 34
12263  **/
12264 glw::GLuint VaryingLocationsTest::getTestCaseNumber()
12265 {
12266         return getTypesNumber();
12267 }
12268
12269 /** Selects if "compute" stage is relevant for test
12270  *
12271  * @param ignored
12272  *
12273  * @return false
12274  **/
12275 bool VaryingLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12276 {
12277         return false;
12278 }
12279
12280 /**
12281  *
12282  *
12283  **/
12284 std::string VaryingLocationsTest::prepareGlobals(GLint last_in_loc, GLint last_out_loc)
12285 {
12286         GLchar          buffer[16];
12287         std::string globals = "const uint first_input_location  = 0u;\n"
12288                                                   "const uint first_output_location = 0u;\n"
12289                                                   "const uint last_input_location   = LAST_INPUTu;\n"
12290                                                   "const uint last_output_location  = LAST_OUTPUTu;\n";
12291         size_t position = 100; /* Skip first part */
12292
12293         sprintf(buffer, "%d", last_in_loc);
12294         Utils::replaceToken("LAST_INPUT", position, buffer, globals);
12295
12296         sprintf(buffer, "%d", last_out_loc);
12297         Utils::replaceToken("LAST_OUTPUT", position, buffer, globals);
12298
12299         return globals;
12300 }
12301
12302 /**
12303  *
12304  **/
12305 void VaryingLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12306                                                                                           Utils::ProgramInterface&   program_interface,
12307                                                                                           Utils::VaryingPassthrough& varying_passthrough)
12308 {
12309         const GLuint array_length  = 1;
12310         const GLuint first_in_loc  = 0;
12311         const GLuint first_out_loc = 0;
12312         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12313         size_t           position         = 0;
12314
12315         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12316
12317         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12318
12319         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12320         const GLchar* qual_first_out = "layout (location = first_output_location)";
12321         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12322         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12323
12324         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12325         const GLuint                    type_size = type.GetSize();
12326
12327         std::string first_in_name  = "PREFIXfirst";
12328         std::string first_out_name = "PREFIXfirst";
12329         std::string last_in_name   = "PREFIXlast";
12330         std::string last_out_name  = "PREFIXlast";
12331
12332         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12333         position = 0;
12334         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12335         position = 0;
12336         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12337         position = 0;
12338         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12339
12340         if (Utils::Shader::FRAGMENT == stage)
12341         {
12342                 qual_first_in = "layout (location = first_input_location) flat";
12343                 qual_last_in  = "layout (location = last_input_location)  flat";
12344         }
12345         if (Utils::Shader::GEOMETRY == stage)
12346         {
12347                 qual_first_out = "layout (location = first_output_location) flat";
12348                 qual_last_out  = "layout (location = last_output_location)  flat";
12349         }
12350
12351         Utils::Variable* first_in = si.Input(
12352                 first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12353                 first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12354                 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12355
12356         Utils::Variable* last_in =
12357                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12358                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12359                                  0u /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12360                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12361
12362         if (Utils::Shader::FRAGMENT != stage)
12363         {
12364                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12365
12366                 Utils::Variable* first_out =
12367                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12368                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12369                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_first_data[0] /* data */,
12370                                           m_first_data.size() /* data_size */);
12371
12372                 Utils::Variable* last_out = si.Output(
12373                         last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12374                         last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */, 0u /* n_array_elements */,
12375                         0u /* stride */, 0u /* offset */, (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12376
12377                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12378
12379                 varying_passthrough.Add(stage, first_in, first_out);
12380                 varying_passthrough.Add(stage, last_in, last_out);
12381         }
12382         else
12383         {
12384                 /* No outputs for fragment shader, so last_output_location can be 0 */
12385                 si.m_globals = prepareGlobals(last_in_loc, 0);
12386         }
12387 }
12388
12389 /** This test should be run with separable programs
12390  *
12391  * @param ignored
12392  *
12393  * @return true
12394  **/
12395 bool VaryingLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12396 {
12397         return false;
12398 }
12399
12400 /* Constants used by VertexAttribLocationsTest */
12401 const GLuint VertexAttribLocationsTest::m_base_vertex   = 4;
12402 const GLuint VertexAttribLocationsTest::m_base_instance = 2;
12403 const GLuint VertexAttribLocationsTest::m_loc_vertex    = 2;
12404 const GLuint VertexAttribLocationsTest::m_loc_instance  = 5;
12405 const GLuint VertexAttribLocationsTest::m_n_instances   = 4;
12406
12407 /** Constructor
12408  *
12409  * @param context Test framework context
12410  **/
12411 VertexAttribLocationsTest::VertexAttribLocationsTest(deqp::Context& context)
12412         : TextureTestBase(context, "vertex_attrib_locations",
12413                                           "Test verifies that attribute locations are respected by drawing operations")
12414 {
12415 }
12416
12417 /** Execute proper draw command for test case
12418  *
12419  * @param test_case_index Index of test case
12420  **/
12421 void VertexAttribLocationsTest::executeDrawCall(GLuint test_case_index)
12422 {
12423         const Functions& gl = m_context.getRenderContext().getFunctions();
12424
12425         switch (test_case_index)
12426         {
12427         case DRAWARRAYS:
12428                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
12429                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
12430                 break;
12431         case DRAWARRAYSINSTANCED:
12432                 gl.drawArraysInstanced(GL_PATCHES, 0 /* first */, 1 /* count */, m_n_instances);
12433                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArraysInstanced");
12434                 break;
12435         case DRAWELEMENTS:
12436                 gl.drawElements(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL);
12437                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElements");
12438                 break;
12439         case DRAWELEMENTSBASEVERTEX:
12440                 gl.drawElementsBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_base_vertex);
12441                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsBaseVertex");
12442                 break;
12443         case DRAWELEMENTSINSTANCED:
12444                 gl.drawElementsInstanced(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances);
12445                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstanced");
12446                 break;
12447         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12448                 gl.drawElementsInstancedBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12449                                                                                          m_base_instance);
12450                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseInstance");
12451                 break;
12452         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12453                 gl.drawElementsInstancedBaseVertex(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL, m_n_instances,
12454                                                                                    m_base_vertex);
12455                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertex");
12456                 break;
12457         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12458                 gl.drawElementsInstancedBaseVertexBaseInstance(GL_PATCHES, 1 /* count */, GL_UNSIGNED_BYTE, DE_NULL,
12459                                                                                                            m_n_instances, m_base_vertex, m_base_instance);
12460                 GLU_EXPECT_NO_ERROR(gl.getError(), "DrawElementsInstancedBaseVertexBaseInstance");
12461                 break;
12462         default:
12463                 TCU_FAIL("Invalid enum");
12464         }
12465 }
12466
12467 /** Get interface of program
12468  *
12469  * @param ignored
12470  * @param program_interface   Interface of program
12471  * @param ignored
12472  **/
12473 void VertexAttribLocationsTest::getProgramInterface(GLuint /* test_case_index */,
12474                                                                                                         Utils::ProgramInterface& program_interface,
12475                                                                                                         Utils::VaryingPassthrough& /* varying_passthrough */)
12476 {
12477         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12478
12479         /* Globals */
12480         si.m_globals = "const uint vertex_index_location   = 2;\n"
12481                                    "const uint instance_index_location = 5;\n";
12482
12483         /* Attributes */
12484         si.Input("vertex_index" /* name */, "layout (location = vertex_index_location)" /* qualifiers */,
12485                          0 /* expected_componenet */, m_loc_vertex /* expected_location */, Utils::Type::uint /* type */,
12486                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 0u /* offset */,
12487                          (GLvoid*)0 /* data */, 0 /* data_size */);
12488         si.Input("instance_index" /* name */, "layout (location = instance_index_location)" /* qualifiers */,
12489                          0 /* expected_componenet */, m_loc_instance /* expected_location */, Utils::Type::uint /* type */,
12490                          GL_FALSE /* normalized */, 0u /* n_array_elements */, 16 /* stride */, 16u /* offset */,
12491                          (GLvoid*)0 /* data */, 0 /* data_size */);
12492 }
12493
12494 /** Get name of test case
12495  *
12496  * @param test_case_index Index of test case
12497  *
12498  * @return Name of test case
12499  **/
12500 std::string VertexAttribLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12501 {
12502         std::string result;
12503
12504         switch (test_case_index)
12505         {
12506         case DRAWARRAYS:
12507                 result = "DrawArrays";
12508                 break;
12509         case DRAWARRAYSINSTANCED:
12510                 result = "DrawArraysInstanced";
12511                 break;
12512         case DRAWELEMENTS:
12513                 result = "DrawElements";
12514                 break;
12515         case DRAWELEMENTSBASEVERTEX:
12516                 result = "DrawElementsBaseVertex";
12517                 break;
12518         case DRAWELEMENTSINSTANCED:
12519                 result = "DrawElementsInstanced";
12520                 break;
12521         case DRAWELEMENTSINSTANCEDBASEINSTANCE:
12522                 result = "DrawElementsInstancedBaseInstance";
12523                 break;
12524         case DRAWELEMENTSINSTANCEDBASEVERTEX:
12525                 result = "DrawElementsInstancedBaseVertex";
12526                 break;
12527         case DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE:
12528                 result = "DrawElementsInstancedBaseVertexBaseInstance";
12529                 break;
12530         default:
12531                 TCU_FAIL("Invalid enum");
12532         }
12533
12534         return result;
12535 }
12536
12537 /** Get number of test cases
12538  *
12539  * @return Number of test cases
12540  **/
12541 GLuint VertexAttribLocationsTest::getTestCaseNumber()
12542 {
12543         return TESTCASES_MAX;
12544 }
12545
12546 /** Prepare code snippet that will verify in and uniform variables
12547  *
12548  * @param ignored
12549  * @param ignored
12550  * @param stage   Shader stage
12551  *
12552  * @return Code that verify variables
12553  **/
12554 std::string VertexAttribLocationsTest::getVerificationSnippet(GLuint /* test_case_index */,
12555                                                                                                                           Utils::ProgramInterface& /* program_interface */,
12556                                                                                                                           Utils::Shader::STAGES stage)
12557 {
12558         std::string verification;
12559
12560         if (Utils::Shader::VERTEX == stage)
12561         {
12562
12563 #if DEBUG_VERTEX_ATTRIB_LOCATIONS_TEST_VARIABLE
12564
12565                 verification = "if (gl_InstanceID != instance_index)\n"
12566                                            "    {\n"
12567                                            "        result = 12u;\n"
12568                                            "    }\n"
12569                                            "    else if (gl_VertexID != vertex_index)\n"
12570                                            "    {\n"
12571                                            "        result = 11u;\n"
12572                                            "    }\n";
12573
12574 #else
12575
12576                 verification = "if ((gl_VertexID   != vertex_index)  ||\n"
12577                                            "        (gl_InstanceID != instance_index) )\n"
12578                                            "    {\n"
12579                                            "        result = 0u;\n"
12580                                            "    }\n";
12581
12582 #endif
12583         }
12584         else
12585         {
12586                 verification = "";
12587         }
12588
12589         return verification;
12590 }
12591
12592 /** Selects if "compute" stage is relevant for test
12593  *
12594  * @param ignored
12595  *
12596  * @return false
12597  **/
12598 bool VertexAttribLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12599 {
12600         return false;
12601 }
12602
12603 /** Prepare attributes, vertex array object and array buffer
12604  *
12605  * @param ignored
12606  * @param ignored Interface of program
12607  * @param buffer  Array buffer
12608  * @param vao     Vertex array object
12609  **/
12610 void VertexAttribLocationsTest::prepareAttributes(GLuint test_case_index /* test_case_index */,
12611                                                                                                   Utils::ProgramInterface& /* program_interface */,
12612                                                                                                   Utils::Buffer& buffer, Utils::VertexArray& vao)
12613 {
12614         static const GLuint vertex_index_data[8]   = { 0, 1, 2, 3, 4, 5, 6, 7 };
12615         static const GLuint instance_index_data[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };
12616
12617         std::vector<GLuint> buffer_data;
12618         buffer_data.resize(8 + 8); /* vertex_index_data + instance_index_data */
12619
12620         GLubyte* ptr = (GLubyte*)&buffer_data[0];
12621
12622         /*
12623          When case index >=2, the test calls glDrawElement*(), such as glDrawElementsBaseVertex(), glDrawElementsInstanced(), glDrawElementsInstancedBaseInstance() and so on,
12624          So we need to change the buffer type as GL_ELEMENT_ARRAY_BUFFER
12625          */
12626         if (test_case_index >= 2)
12627         {
12628                 buffer.m_buffer = Utils::Buffer::Element;
12629         }
12630         vao.Bind();
12631         buffer.Bind();
12632
12633         vao.Attribute(m_loc_vertex /* vertex_index */, Utils::Type::uint, 0 /* array_elements */, false /* normalized */,
12634                                   0 /* stride */, 0 /* offset */);
12635
12636         vao.Attribute(m_loc_instance /* instance_index */, Utils::Type::uint, 0 /* array_elements */,
12637                                   false /* normalized */, 0 /* stride */, (GLvoid*)sizeof(vertex_index_data) /* offset */);
12638         // when test_case_index is 5 or 7, the draw call is glDrawElementsInstancedBaseInstance, glDrawElementsInstancedBaseVertexBaseInstance
12639         // the instancecount is 4, the baseinstance is 2, the divisor should be set 2
12640         bool isBaseInstanced = (test_case_index == DRAWELEMENTSINSTANCEDBASEINSTANCE ||
12641                                                         test_case_index == DRAWELEMENTSINSTANCEDBASEVERTEXBASEINSTANCE);
12642         vao.Divisor(m_context.getRenderContext().getFunctions() /* gl */, m_loc_instance /* instance_index */,
12643                                 isBaseInstanced ? 2 : 1 /* divisor. 1 - advance once per instance */);
12644
12645         memcpy(ptr + 0, vertex_index_data, sizeof(vertex_index_data));
12646         memcpy(ptr + sizeof(vertex_index_data), instance_index_data, sizeof(instance_index_data));
12647
12648         buffer.Data(Utils::Buffer::StaticDraw, buffer_data.size() * sizeof(GLuint), ptr);
12649 }
12650
12651 /** This test should be run with separable programs
12652  *
12653  * @param ignored
12654  *
12655  * @return true
12656  **/
12657 bool VertexAttribLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12658 {
12659         return false;
12660 }
12661
12662 /** Constructor
12663  *
12664  * @param context Test framework context
12665  **/
12666 VaryingArrayLocationsTest::VaryingArrayLocationsTest(deqp::Context& context)
12667         : VaryingLocationsTest(context, "varying_array_locations",
12668                                                    "Test verifies that input and output locations are respected for arrays")
12669 {
12670 }
12671
12672 /**
12673  *
12674  **/
12675 void VaryingArrayLocationsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& type,
12676                                                                                                    Utils::ProgramInterface&   program_interface,
12677                                                                                                    Utils::VaryingPassthrough& varying_passthrough)
12678 {
12679         const GLuint array_length  = 1u;
12680         const GLuint first_in_loc  = 0;
12681         const GLuint first_out_loc = 0;
12682         const GLuint last_in_loc   = getLastInputLocation(stage, type, array_length);
12683         size_t           position         = 0;
12684
12685         const GLchar* prefix_in = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_INPUT);
12686
12687         const GLchar* prefix_out = Utils::ProgramInterface::GetStagePrefix(stage, Utils::Variable::VARYING_OUTPUT);
12688
12689         const GLchar* qual_first_in  = "layout (location = first_input_location)";
12690         const GLchar* qual_first_out = "layout (location = first_output_location)";
12691         const GLchar* qual_last_in   = "layout (location = last_input_location)";
12692         const GLchar* qual_last_out  = "layout (location = last_output_location)";
12693
12694         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(stage);
12695         const GLuint                    type_size = type.GetSize();
12696
12697         std::string first_in_name  = "PREFIXfirst";
12698         std::string first_out_name = "PREFIXfirst";
12699         std::string last_in_name   = "PREFIXlast";
12700         std::string last_out_name  = "PREFIXlast";
12701
12702         Utils::replaceToken("PREFIX", position, prefix_in, first_in_name);
12703         position = 0;
12704         Utils::replaceToken("PREFIX", position, prefix_out, first_out_name);
12705         position = 0;
12706         Utils::replaceToken("PREFIX", position, prefix_in, last_in_name);
12707         position = 0;
12708         Utils::replaceToken("PREFIX", position, prefix_out, last_out_name);
12709
12710         if (Utils::Shader::FRAGMENT == stage)
12711         {
12712                 qual_first_in = "layout (location = first_input_location) flat";
12713                 qual_last_in  = "layout (location = last_input_location)  flat";
12714         }
12715         if (Utils::Shader::GEOMETRY == stage)
12716         {
12717                 qual_first_out = "layout (location = first_output_location) flat";
12718                 qual_last_out  = "layout (location = last_output_location)  flat";
12719         }
12720
12721         Utils::Variable* first_in =
12722                 si.Input(first_in_name.c_str(), qual_first_in /* qualifiers */, 0 /* expected_componenet */,
12723                                  first_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12724                                  array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12725                                  (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12726
12727         Utils::Variable* last_in =
12728                 si.Input(last_in_name.c_str(), qual_last_in /* qualifiers */, 0 /* expected_componenet */,
12729                                  last_in_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12730                                  array_length /* n_array_elements */, 0u /* stride */, type_size /* offset */,
12731                                  (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12732
12733         if (Utils::Shader::FRAGMENT != stage)
12734         {
12735                 const GLuint last_out_loc = getLastOutputLocation(stage, type, array_length);
12736
12737                 Utils::Variable* first_out =
12738                         si.Output(first_out_name.c_str(), qual_first_out /* qualifiers */, 0 /* expected_componenet */,
12739                                           first_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12740                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12741                                           (GLvoid*)&m_first_data[0] /* data */, m_first_data.size() /* data_size */);
12742
12743                 Utils::Variable* last_out =
12744                         si.Output(last_out_name.c_str(), qual_last_out /* qualifiers */, 0 /* expected_componenet */,
12745                                           last_out_loc /* expected_location */, type /* type */, GL_FALSE /* normalized */,
12746                                           array_length /* n_array_elements */, 0u /* stride */, 0u /* offset */,
12747                                           (GLvoid*)&m_last_data[0] /* data */, m_last_data.size() /* data_size */);
12748
12749                 si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
12750
12751                 varying_passthrough.Add(stage, first_in, first_out);
12752                 varying_passthrough.Add(stage, last_in, last_out);
12753         }
12754         else
12755         {
12756                 /* No outputs for fragment shader, so last_output_location can be 0 */
12757                 si.m_globals = prepareGlobals(last_in_loc, 0);
12758         }
12759 }
12760
12761 /** Constructor
12762  *
12763  * @param context Test framework context
12764  **/
12765 VaryingStructureLocationsTest::VaryingStructureLocationsTest(deqp::Context& context)
12766         : TextureTestBase(context, "varying_structure_locations",
12767                                           "Test verifies that locations are respected when structures are used as in and out ")
12768 {
12769 }
12770
12771 /** Prepare code snippet that will pass in variables to out variables
12772  *
12773  * @param ignored
12774  * @param varying_passthrough Collection of connections between in and out variables
12775  * @param stage               Shader stage
12776  *
12777  * @return Code that pass in variables to next stage
12778  **/
12779 std::string VaryingStructureLocationsTest::getPassSnippet(GLuint /* test_case_index */,
12780                                                                                                                   Utils::VaryingPassthrough& varying_passthrough,
12781                                                                                                                   Utils::Shader::STAGES          stage)
12782 {
12783         std::string result;
12784
12785         if (Utils::Shader::VERTEX != stage)
12786         {
12787                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
12788         }
12789         else
12790         {
12791                 result = "    vs_tcs_output[0].single   = vs_in_single[0];\n"
12792                                  "    vs_tcs_output[0].array[0] = vs_in_array[0];\n";
12793         }
12794
12795         return result;
12796 }
12797
12798 /** Get interface of program
12799  *
12800  * @param test_case_index     Test case
12801  * @param program_interface   Interface of program
12802  * @param varying_passthrough Collection of connections between in and out variables
12803  **/
12804 void VaryingStructureLocationsTest::getProgramInterface(GLuint                                     test_case_index,
12805                                                                                                                 Utils::ProgramInterface&   program_interface,
12806                                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
12807 {
12808         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
12809         const Utils::Type               type = getType(test_case_index);
12810
12811         /* Prepare data */
12812         // We should call GenerateDataPacked() to generate data, which can make sure the data in shader is correct
12813         m_single_data = type.GenerateDataPacked();
12814         m_array_data  = type.GenerateDataPacked();
12815
12816         m_data.resize(m_single_data.size() + m_array_data.size());
12817         GLubyte* ptr = (GLubyte*)&m_data[0];
12818         memcpy(ptr, &m_single_data[0], m_single_data.size());
12819         memcpy(ptr + m_single_data.size(), &m_array_data[0], m_array_data.size());
12820
12821         Utils::Interface* structure = program_interface.Structure("Data");
12822
12823         structure->Member("single", "" /* qualifiers */, 0 /* component */, 0 /* location */, type, false /* normalized */,
12824                                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */);
12825
12826         // the second struct member 's location should not be 0, it is based on by how many the locations the first struct member consumed.
12827         structure->Member("array", "" /* qualifiers */, 0 /* component */, type.GetLocations() /* location */, type,
12828                                           false /* normalized */, 1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */);
12829
12830         si.Input("vs_in_single", "layout (location = 0)", 0 /* component */, 0 /* location */, type, false /* normalized */,
12831                          1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_single_data[0] /* data */,
12832                          m_single_data.size() /* data_size */);
12833
12834         si.Input("vs_in_array", "layout (location = 8)", 0 /* component */, 8 /* location */, type, false /* normalized */,
12835                          1u /* n_array_elements */, 0u /* stride */, type.GetSize() /* offset */,
12836                          (GLvoid*)&m_array_data[0] /* data */, m_array_data.size() /* data_size */);
12837
12838         si.Output("vs_tcs_output", "layout (location = 0)", 0 /* component */, 0 /* location */, structure,
12839                           1u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
12840                           m_data.size() /* data_size */);
12841
12842         program_interface.CloneVertexInterface(varying_passthrough);
12843 }
12844
12845 /** Get type name
12846  *
12847  * @param test_case_index Index of test case
12848  *
12849  * @return Name of type test in test_case_index
12850  **/
12851 std::string VaryingStructureLocationsTest::getTestCaseName(glw::GLuint test_case_index)
12852 {
12853         return getTypeName(test_case_index);
12854 }
12855
12856 /** Returns number of types to test
12857  *
12858  * @return Number of types, 34
12859  **/
12860 glw::GLuint VaryingStructureLocationsTest::getTestCaseNumber()
12861 {
12862         return getTypesNumber();
12863 }
12864
12865 /** Selects if "compute" stage is relevant for test
12866  *
12867  * @param ignored
12868  *
12869  * @return false
12870  **/
12871 bool VaryingStructureLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
12872 {
12873         return false;
12874 }
12875
12876 /** This test should be run with separable programs
12877  *
12878  * @param ignored
12879  *
12880  * @return true
12881  **/
12882 bool VaryingStructureLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
12883 {
12884         return false;
12885 }
12886
12887 /** Constructor
12888  *
12889  * @param context          Test context
12890  * @param test_name        Name of test
12891  * @param test_description Description of test
12892  **/
12893 VaryingStructureMemberLocationTest::VaryingStructureMemberLocationTest(deqp::Context& context)
12894         : NegativeTestBase(context, "varying_structure_member_location",
12895                                            "Test verifies that compiler does not allow location qualifier on member of strucure")
12896 {
12897 }
12898
12899 /** Source for given test case and stage
12900  *
12901  * @param test_case_index Index of test case
12902  * @param stage           Shader stage
12903  *
12904  * @return Shader source
12905  **/
12906 std::string VaryingStructureMemberLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
12907 {
12908         static const GLchar* struct_definition = "struct Data {\n"
12909                                                                                          "    vec4 gohan;\n"
12910                                                                                          "    layout (location = 4) vec4 goten;\n"
12911                                                                                          "};\n";
12912         static const GLchar* input_var  = "in Data data;\n";
12913         static const GLchar* output_var = "out Data data;\n";
12914         static const GLchar* input_use  = "    result += data.gohan + data.goten;\n";
12915         static const GLchar* output_use = "    data.gohan = result / 2;\n"
12916                                                                           "    data.goten = result / 4 - data.gohan;\n";
12917         static const GLchar* fs = "#version 430 core\n"
12918                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12919                                                           "\n"
12920                                                           "in  vec4 gs_fs;\n"
12921                                                           "out vec4 fs_out;\n"
12922                                                           "\n"
12923                                                           "void main()\n"
12924                                                           "{\n"
12925                                                           "    fs_out = gs_fs;\n"
12926                                                           "}\n"
12927                                                           "\n";
12928         static const GLchar* fs_tested = "#version 430 core\n"
12929                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12930                                                                          "\n"
12931                                                                          "STRUCT_DEFINITION"
12932                                                                          "\n"
12933                                                                          "VARIABLE_DEFINITION"
12934                                                                          "\n"
12935                                                                          "in  vec4 gs_fs;\n"
12936                                                                          "out vec4 fs_out;\n"
12937                                                                          "\n"
12938                                                                          "void main()\n"
12939                                                                          "{\n"
12940                                                                          "    vec4 result = gs_fs;\n"
12941                                                                          "\n"
12942                                                                          "VARIABLE_USE"
12943                                                                          "\n"
12944                                                                          "    fs_out += result;\n"
12945                                                                          "}\n"
12946                                                                          "\n";
12947         static const GLchar* gs = "#version 430 core\n"
12948                                                           "#extension GL_ARB_enhanced_layouts : require\n"
12949                                                           "\n"
12950                                                           "layout(points)                           in;\n"
12951                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
12952                                                           "\n"
12953                                                           "in  vec4 tes_gs[];\n"
12954                                                           "out vec4 gs_fs;\n"
12955                                                           "\n"
12956                                                           "void main()\n"
12957                                                           "{\n"
12958                                                           "    gs_fs = tes_gs[0];\n"
12959                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12960                                                           "    EmitVertex();\n"
12961                                                           "    gs_fs = tes_gs[0];\n"
12962                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12963                                                           "    EmitVertex();\n"
12964                                                           "    gs_fs = tes_gs[0];\n"
12965                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
12966                                                           "    EmitVertex();\n"
12967                                                           "    gs_fs = tes_gs[0];\n"
12968                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
12969                                                           "    EmitVertex();\n"
12970                                                           "}\n"
12971                                                           "\n";
12972         static const GLchar* gs_tested = "#version 430 core\n"
12973                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
12974                                                                          "\n"
12975                                                                          "layout(points)                           in;\n"
12976                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
12977                                                                          "\n"
12978                                                                          "STRUCT_DEFINITION"
12979                                                                          "\n"
12980                                                                          "VARIABLE_DEFINITION"
12981                                                                          "\n"
12982                                                                          "in  vec4 tes_gs[];\n"
12983                                                                          "out vec4 gs_fs;\n"
12984                                                                          "\n"
12985                                                                          "void main()\n"
12986                                                                          "{\n"
12987                                                                          "    vec4 result = tes_gs[0];\n"
12988                                                                          "\n"
12989                                                                          "VARIABLE_USE"
12990                                                                          "\n"
12991                                                                          "    gs_fs = result;\n"
12992                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
12993                                                                          "    EmitVertex();\n"
12994                                                                          "    gs_fs = result;\n"
12995                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
12996                                                                          "    EmitVertex();\n"
12997                                                                          "    gs_fs = result;\n"
12998                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
12999                                                                          "    EmitVertex();\n"
13000                                                                          "    gs_fs = result;\n"
13001                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13002                                                                          "    EmitVertex();\n"
13003                                                                          "}\n"
13004                                                                          "\n";
13005         static const GLchar* tcs = "#version 430 core\n"
13006                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13007                                                            "\n"
13008                                                            "layout(vertices = 1) out;\n"
13009                                                            "\n"
13010                                                            "in  vec4 vs_tcs[];\n"
13011                                                            "out vec4 tcs_tes[];\n"
13012                                                            "\n"
13013                                                            "void main()\n"
13014                                                            "{\n"
13015                                                            "\n"
13016                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13017                                                            "\n"
13018                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13019                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13020                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13021                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13022                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13023                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13024                                                            "}\n"
13025                                                            "\n";
13026         static const GLchar* tcs_tested = "#version 430 core\n"
13027                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13028                                                                           "\n"
13029                                                                           "layout(vertices = 1) out;\n"
13030                                                                           "\n"
13031                                                                           "STRUCT_DEFINITION"
13032                                                                           "\n"
13033                                                                           "VARIABLE_DEFINITION"
13034                                                                           "\n"
13035                                                                           "in  vec4 vs_tcs[];\n"
13036                                                                           "out vec4 tcs_tes[];\n"
13037                                                                           "\n"
13038                                                                           "void main()\n"
13039                                                                           "{\n"
13040                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13041                                                                           "\n"
13042                                                                           "VARIABLE_USE"
13043                                                                           "\n"
13044                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13045                                                                           "\n"
13046                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13047                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13048                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13049                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13050                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13051                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13052                                                                           "}\n"
13053                                                                           "\n";
13054         static const GLchar* tes = "#version 430 core\n"
13055                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13056                                                            "\n"
13057                                                            "layout(isolines, point_mode) in;\n"
13058                                                            "\n"
13059                                                            "in  vec4 tcs_tes[];\n"
13060                                                            "out vec4 tes_gs;\n"
13061                                                            "\n"
13062                                                            "void main()\n"
13063                                                            "{\n"
13064                                                            "    tes_gs = tcs_tes[0];\n"
13065                                                            "}\n"
13066                                                            "\n";
13067         static const GLchar* tes_tested = "#version 430 core\n"
13068                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13069                                                                           "\n"
13070                                                                           "layout(isolines, point_mode) in;\n"
13071                                                                           "\n"
13072                                                                           "STRUCT_DEFINITION"
13073                                                                           "\n"
13074                                                                           "VARIABLE_DEFINITION"
13075                                                                           "\n"
13076                                                                           "in  vec4 tcs_tes[];\n"
13077                                                                           "out vec4 tes_gs;\n"
13078                                                                           "\n"
13079                                                                           "void main()\n"
13080                                                                           "{\n"
13081                                                                           "    vec4 result = tcs_tes[0];\n"
13082                                                                           "\n"
13083                                                                           "VARIABLE_USE"
13084                                                                           "\n"
13085                                                                           "    tes_gs += result;\n"
13086                                                                           "}\n"
13087                                                                           "\n";
13088         static const GLchar* vs = "#version 430 core\n"
13089                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13090                                                           "\n"
13091                                                           "in  vec4 in_vs;\n"
13092                                                           "out vec4 vs_tcs;\n"
13093                                                           "\n"
13094                                                           "void main()\n"
13095                                                           "{\n"
13096                                                           "    vs_tcs = in_vs;\n"
13097                                                           "}\n"
13098                                                           "\n";
13099         static const GLchar* vs_tested = "#version 430 core\n"
13100                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13101                                                                          "\n"
13102                                                                          "STRUCT_DEFINITION"
13103                                                                          "\n"
13104                                                                          "VARIABLE_DEFINITION"
13105                                                                          "\n"
13106                                                                          "in  vec4 in_vs;\n"
13107                                                                          "out vec4 vs_tcs;\n"
13108                                                                          "\n"
13109                                                                          "void main()\n"
13110                                                                          "{\n"
13111                                                                          "    vec4 result = in_vs;\n"
13112                                                                          "\n"
13113                                                                          "VARIABLE_USE"
13114                                                                          "\n"
13115                                                                          "    vs_tcs += result;\n"
13116                                                                          "}\n"
13117                                                                          "\n";
13118
13119         std::string   source;
13120         testCase&        test_case               = m_test_cases[test_case_index];
13121         const GLchar* var_definition = 0;
13122         const GLchar* var_use            = 0;
13123
13124         if (true == test_case.m_is_input)
13125         {
13126                 var_definition = input_var;
13127                 var_use            = input_use;
13128         }
13129         else
13130         {
13131                 var_definition = output_var;
13132                 var_use            = output_use;
13133         }
13134
13135         if (test_case.m_stage == stage)
13136         {
13137                 size_t position = 0;
13138
13139                 switch (stage)
13140                 {
13141                 case Utils::Shader::FRAGMENT:
13142                         source = fs_tested;
13143                         break;
13144                 case Utils::Shader::GEOMETRY:
13145                         source = gs_tested;
13146                         break;
13147                 case Utils::Shader::TESS_CTRL:
13148                         source = tcs_tested;
13149                         break;
13150                 case Utils::Shader::TESS_EVAL:
13151                         source = tes_tested;
13152                         break;
13153                 case Utils::Shader::VERTEX:
13154                         source = vs_tested;
13155                         break;
13156                 default:
13157                         TCU_FAIL("Invalid enum");
13158                 }
13159
13160                 Utils::replaceToken("STRUCT_DEFINITION", position, struct_definition, source);
13161                 Utils::replaceToken("VARIABLE_DEFINITION", position, var_definition, source);
13162                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13163         }
13164         else
13165         {
13166                 switch (stage)
13167                 {
13168                 case Utils::Shader::FRAGMENT:
13169                         source = fs;
13170                         break;
13171                 case Utils::Shader::GEOMETRY:
13172                         source = gs;
13173                         break;
13174                 case Utils::Shader::TESS_CTRL:
13175                         source = tcs;
13176                         break;
13177                 case Utils::Shader::TESS_EVAL:
13178                         source = tes;
13179                         break;
13180                 case Utils::Shader::VERTEX:
13181                         source = vs;
13182                         break;
13183                 default:
13184                         TCU_FAIL("Invalid enum");
13185                 }
13186         }
13187
13188         return source;
13189 }
13190
13191 /** Get description of test case
13192  *
13193  * @param test_case_index Index of test case
13194  *
13195  * @return Test case description
13196  **/
13197 std::string VaryingStructureMemberLocationTest::getTestCaseName(GLuint test_case_index)
13198 {
13199         std::stringstream stream;
13200         testCase&                 test_case = m_test_cases[test_case_index];
13201
13202         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13203
13204         if (true == test_case.m_is_input)
13205         {
13206                 stream << "input";
13207         }
13208         else
13209         {
13210                 stream << "output";
13211         }
13212
13213         return stream.str();
13214 }
13215
13216 /** Get number of test cases
13217  *
13218  * @return Number of test cases
13219  **/
13220 GLuint VaryingStructureMemberLocationTest::getTestCaseNumber()
13221 {
13222         return static_cast<GLuint>(m_test_cases.size());
13223 }
13224
13225 /** Selects if "compute" stage is relevant for test
13226  *
13227  * @param ignored
13228  *
13229  * @return false
13230  **/
13231 bool VaryingStructureMemberLocationTest::isComputeRelevant(GLuint /* test_case_index */)
13232 {
13233         return false;
13234 }
13235
13236 /** Prepare all test cases
13237  *
13238  **/
13239 void VaryingStructureMemberLocationTest::testInit()
13240 {
13241         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13242         {
13243                 if (Utils::Shader::COMPUTE == stage)
13244                 {
13245                         continue;
13246                 }
13247
13248                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
13249                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
13250
13251                 m_test_cases.push_back(test_case_in);
13252
13253                 if (Utils::Shader::FRAGMENT != stage)
13254                 {
13255                         m_test_cases.push_back(test_case_out);
13256                 }
13257         }
13258 }
13259
13260 /** Constructor
13261  *
13262  * @param context Test framework context
13263  **/
13264 VaryingBlockLocationsTest::VaryingBlockLocationsTest(deqp::Context& context)
13265         : TextureTestBase(context, "varying_block_locations",
13266                                           "Test verifies that locations are respected when blocks are used as in and out ")
13267 {
13268 }
13269
13270 /** Prepare code snippet that will pass in variables to out variables
13271  *
13272  * @param ignored
13273  * @param varying_passthrough Collection of connections between in and out variables
13274  * @param stage               Shader stage
13275  *
13276  * @return Code that pass in variables to next stage
13277  **/
13278 std::string VaryingBlockLocationsTest::getPassSnippet(GLuint /* test_case_index */,
13279                                                                                                           Utils::VaryingPassthrough& varying_passthrough,
13280                                                                                                           Utils::Shader::STAGES          stage)
13281 {
13282         std::string result;
13283
13284         if (Utils::Shader::VERTEX != stage)
13285         {
13286                 result = TextureTestBase::getPassSnippet(0, varying_passthrough, stage);
13287         }
13288         else
13289         {
13290                 result = "vs_tcs_block.third  = vs_in_third;\n"
13291                                  "    vs_tcs_block.fourth = vs_in_fourth;\n"
13292                                  "    vs_tcs_block.fifth  = vs_in_fifth;\n";
13293         }
13294
13295         return result;
13296 }
13297
13298 /** Get interface of program
13299  *
13300  * @param ignored
13301  * @param program_interface   Interface of program
13302  * @param varying_passthrough Collection of connections between in and out variables
13303  **/
13304 void VaryingBlockLocationsTest::getProgramInterface(GLuint /* test_case_index */,
13305                                                                                                         Utils::ProgramInterface&   program_interface,
13306                                                                                                         Utils::VaryingPassthrough& varying_passthrough)
13307 {
13308         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
13309         const Utils::Type               vec4 = Utils::Type::vec4;
13310
13311         /* Prepare data */
13312         m_third_data  = vec4.GenerateData();
13313         m_fourth_data = vec4.GenerateData();
13314         m_fifth_data  = vec4.GenerateData();
13315
13316         /* Memory layout is different from location layout */
13317         const GLuint fifth_offset  = 0u;
13318         const GLuint third_offset  = static_cast<GLuint>(fifth_offset + m_fifth_data.size());
13319         const GLuint fourth_offset = static_cast<GLuint>(third_offset + m_fourth_data.size());
13320
13321         m_data.resize(fourth_offset + m_fourth_data.size());
13322         GLubyte* ptr = (GLubyte*)&m_data[0];
13323         memcpy(ptr + third_offset, &m_third_data[0], m_third_data.size());
13324         memcpy(ptr + fourth_offset, &m_fourth_data[0], m_fourth_data.size());
13325         memcpy(ptr + fifth_offset, &m_fifth_data[0], m_fifth_data.size());
13326
13327         Utils::Interface* block = program_interface.Block("vs_tcs_Block");
13328
13329         block->Member("fifth", "" /* qualifiers */, 0 /* component */, 4 /* location */, vec4, false /* normalized */,
13330                                   0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */);
13331
13332         block->Member("third", "layout (location = 2)" /* qualifiers */, 0 /* component */, 2 /* location */, vec4,
13333                                   false /* normalized */, 0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */);
13334
13335         block->Member("fourth", "" /* qualifiers */, 0 /* component */, 3 /* location */, vec4, false /* normalized */,
13336                                   0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */);
13337
13338         si.Output("vs_tcs_block", "layout (location = 4)", 0 /* component */, 4 /* location */, block,
13339                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)&m_data[0] /* data */,
13340                           m_data.size() /* data_size */);
13341
13342         si.Input("vs_in_third", "layout (location = 0)", 0 /* component */, 0 /* location */, vec4, false /* normalized */,
13343                          0u /* n_array_elements */, 0u /* stride */, third_offset /* offset */,
13344                          (GLvoid*)&m_third_data[0] /* data */, m_third_data.size() /* data_size */);
13345
13346         si.Input("vs_in_fourth", "layout (location = 1)", 0 /* component */, 1 /* location */, vec4, false /* normalized */,
13347                          0u /* n_array_elements */, 0u /* stride */, fourth_offset /* offset */,
13348                          (GLvoid*)&m_fourth_data[0] /* data */, m_fourth_data.size() /* data_size */);
13349
13350         si.Input("vs_in_fifth", "layout (location = 2)", 0 /* component */, 2 /* location */, vec4, false /* normalized */,
13351                          0u /* n_array_elements */, 0u /* stride */, fifth_offset /* offset */,
13352                          (GLvoid*)&m_fifth_data[0] /* data */, m_fifth_data.size() /* data_size */);
13353
13354         program_interface.CloneVertexInterface(varying_passthrough);
13355 }
13356
13357 /** Selects if "compute" stage is relevant for test
13358  *
13359  * @param ignored
13360  *
13361  * @return false
13362  **/
13363 bool VaryingBlockLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13364 {
13365         return false;
13366 }
13367
13368 /** This test should be run with separable programs
13369  *
13370  * @param ignored
13371  *
13372  * @return true
13373  **/
13374 bool VaryingBlockLocationsTest::useMonolithicProgram(GLuint /* test_case_index */)
13375 {
13376         return false;
13377 }
13378
13379 /** Constructor
13380  *
13381  * @param context Test framework context
13382  **/
13383 VaryingBlockMemberLocationsTest::VaryingBlockMemberLocationsTest(deqp::Context& context)
13384         : NegativeTestBase(
13385                   context, "varying_block_member_locations",
13386                   "Test verifies that compilation error is reported when not all members of block are qualified with location")
13387 {
13388 }
13389
13390 /** Source for given test case and stage
13391  *
13392  * @param test_case_index Index of test case
13393  * @param stage           Shader stage
13394  *
13395  * @return Shader source
13396  **/
13397 std::string VaryingBlockMemberLocationsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
13398 {
13399         static const GLchar* block_definition_all = "Goku {\n"
13400                                                                                                 "    layout (location = 2) vec4 gohan;\n"
13401                                                                                                 "    layout (location = 4) vec4 goten;\n"
13402                                                                                                 "    layout (location = 6) vec4 chichi;\n"
13403                                                                                                 "} gokuARRAY;\n";
13404         static const GLchar* block_definition_default = "Goku {\n"
13405                                                                                                         "    vec4 gohan;\n"
13406                                                                                                         "    vec4 goten;\n"
13407                                                                                                         "    vec4 chichi;\n"
13408                                                                                                         "} gokuARRAY;\n";
13409         static const GLchar* block_definition_one = "Goku {\n"
13410                                                                                                 "    vec4 gohan;\n"
13411                                                                                                 "    layout (location = 4) vec4 goten;\n"
13412                                                                                                 "    vec4 chichi;\n"
13413                                                                                                 "} gokuARRAY;\n";
13414         static const GLchar* input_use  = "    result += gokuINDEX.gohan + gokuINDEX.goten + gokuINDEX.chichi;\n";
13415         static const GLchar* output_use = "    gokuINDEX.gohan  = result / 2;\n"
13416                                                                           "    gokuINDEX.goten  = result / 4 - gokuINDEX.gohan;\n"
13417                                                                           "    gokuINDEX.chichi = result / 8 - gokuINDEX.goten;\n";
13418         static const GLchar* fs = "#version 430 core\n"
13419                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13420                                                           "\n"
13421                                                           "in  vec4 gs_fs;\n"
13422                                                           "out vec4 fs_out;\n"
13423                                                           "\n"
13424                                                           "void main()\n"
13425                                                           "{\n"
13426                                                           "    fs_out = gs_fs;\n"
13427                                                           "}\n"
13428                                                           "\n";
13429         static const GLchar* fs_tested = "#version 430 core\n"
13430                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13431                                                                          "\n"
13432                                                                          "DIRECTION BLOCK_DEFINITION"
13433                                                                          "\n"
13434                                                                          "in  vec4 gs_fs;\n"
13435                                                                          "out vec4 fs_out;\n"
13436                                                                          "\n"
13437                                                                          "void main()\n"
13438                                                                          "{\n"
13439                                                                          "    vec4 result = gs_fs;\n"
13440                                                                          "\n"
13441                                                                          "VARIABLE_USE"
13442                                                                          "\n"
13443                                                                          "    fs_out = result;\n"
13444                                                                          "}\n"
13445                                                                          "\n";
13446         static const GLchar* gs = "#version 430 core\n"
13447                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13448                                                           "\n"
13449                                                           "layout(points)                           in;\n"
13450                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13451                                                           "\n"
13452                                                           "in  vec4 tes_gs[];\n"
13453                                                           "out vec4 gs_fs;\n"
13454                                                           "\n"
13455                                                           "void main()\n"
13456                                                           "{\n"
13457                                                           "    gs_fs = tes_gs[0];\n"
13458                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13459                                                           "    EmitVertex();\n"
13460                                                           "    gs_fs = tes_gs[0];\n"
13461                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13462                                                           "    EmitVertex();\n"
13463                                                           "    gs_fs = tes_gs[0];\n"
13464                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13465                                                           "    EmitVertex();\n"
13466                                                           "    gs_fs = tes_gs[0];\n"
13467                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13468                                                           "    EmitVertex();\n"
13469                                                           "}\n"
13470                                                           "\n";
13471         static const GLchar* gs_tested = "#version 430 core\n"
13472                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13473                                                                          "\n"
13474                                                                          "layout(points)                           in;\n"
13475                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13476                                                                          "\n"
13477                                                                          "DIRECTION BLOCK_DEFINITION"
13478                                                                          "\n"
13479                                                                          "in  vec4 tes_gs[];\n"
13480                                                                          "out vec4 gs_fs;\n"
13481                                                                          "\n"
13482                                                                          "void main()\n"
13483                                                                          "{\n"
13484                                                                          "    vec4 result = tes_gs[0];\n"
13485                                                                          "\n"
13486                                                                          "VARIABLE_USE"
13487                                                                          "\n"
13488                                                                          "    gs_fs = result;\n"
13489                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13490                                                                          "    EmitVertex();\n"
13491                                                                          "    gs_fs = result;\n"
13492                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13493                                                                          "    EmitVertex();\n"
13494                                                                          "    gs_fs = result;\n"
13495                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13496                                                                          "    EmitVertex();\n"
13497                                                                          "    gs_fs = result;\n"
13498                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13499                                                                          "    EmitVertex();\n"
13500                                                                          "}\n"
13501                                                                          "\n";
13502         static const GLchar* tcs = "#version 430 core\n"
13503                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13504                                                            "\n"
13505                                                            "layout(vertices = 1) out;\n"
13506                                                            "\n"
13507                                                            "in  vec4 vs_tcs[];\n"
13508                                                            "out vec4 tcs_tes[];\n"
13509                                                            "\n"
13510                                                            "void main()\n"
13511                                                            "{\n"
13512                                                            "\n"
13513                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13514                                                            "\n"
13515                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13516                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13517                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13518                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13519                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13520                                                            "    gl_TessLevelInner[1] = 1.0;\n"
13521                                                            "}\n"
13522                                                            "\n";
13523         static const GLchar* tcs_tested = "#version 430 core\n"
13524                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13525                                                                           "\n"
13526                                                                           "layout(vertices = 1) out;\n"
13527                                                                           "\n"
13528                                                                           "DIRECTION BLOCK_DEFINITION"
13529                                                                           "\n"
13530                                                                           "in  vec4 vs_tcs[];\n"
13531                                                                           "out vec4 tcs_tes[];\n"
13532                                                                           "\n"
13533                                                                           "void main()\n"
13534                                                                           "{\n"
13535                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
13536                                                                           "\n"
13537                                                                           "VARIABLE_USE"
13538                                                                           "\n"
13539                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
13540                                                                           "\n"
13541                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
13542                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
13543                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
13544                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
13545                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
13546                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
13547                                                                           "}\n"
13548                                                                           "\n";
13549         static const GLchar* tes = "#version 430 core\n"
13550                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13551                                                            "\n"
13552                                                            "layout(isolines, point_mode) in;\n"
13553                                                            "\n"
13554                                                            "in  vec4 tcs_tes[];\n"
13555                                                            "out vec4 tes_gs;\n"
13556                                                            "\n"
13557                                                            "void main()\n"
13558                                                            "{\n"
13559                                                            "    tes_gs = tcs_tes[0];\n"
13560                                                            "}\n"
13561                                                            "\n";
13562         static const GLchar* tes_tested = "#version 430 core\n"
13563                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13564                                                                           "\n"
13565                                                                           "layout(isolines, point_mode) in;\n"
13566                                                                           "\n"
13567                                                                           "DIRECTION BLOCK_DEFINITION"
13568                                                                           "\n"
13569                                                                           "in  vec4 tcs_tes[];\n"
13570                                                                           "out vec4 tes_gs;\n"
13571                                                                           "\n"
13572                                                                           "void main()\n"
13573                                                                           "{\n"
13574                                                                           "    vec4 result = tcs_tes[0];\n"
13575                                                                           "\n"
13576                                                                           "VARIABLE_USE"
13577                                                                           "\n"
13578                                                                           "    tes_gs = result;\n"
13579                                                                           "}\n"
13580                                                                           "\n";
13581         static const GLchar* vs = "#version 430 core\n"
13582                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13583                                                           "\n"
13584                                                           "in  vec4 in_vs;\n"
13585                                                           "out vec4 vs_tcs;\n"
13586                                                           "\n"
13587                                                           "void main()\n"
13588                                                           "{\n"
13589                                                           "    vs_tcs = in_vs;\n"
13590                                                           "}\n"
13591                                                           "\n";
13592         static const GLchar* vs_tested = "#version 430 core\n"
13593                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13594                                                                          "\n"
13595                                                                          "DIRECTION BLOCK_DEFINITION"
13596                                                                          "\n"
13597                                                                          "in  vec4 in_vs;\n"
13598                                                                          "out vec4 vs_tcs;\n"
13599                                                                          "\n"
13600                                                                          "void main()\n"
13601                                                                          "{\n"
13602                                                                          "    vec4 result = in_vs;\n"
13603                                                                          "\n"
13604                                                                          "VARIABLE_USE"
13605                                                                          "\n"
13606                                                                          "    vs_tcs = result;\n"
13607                                                                          "}\n"
13608                                                                          "\n";
13609
13610         static const GLchar* shaders_in[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13611                                                                                           /* vs  */ { 0, vs_tested, tcs, tes, gs, fs },
13612                                                                                           /* tcs */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13613                                                                                           /* tes */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13614                                                                                           /* gs  */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13615                                                                                           /* fs  */ { 0, vs, tcs, tes, gs_tested, fs_tested } };
13616
13617         static const GLchar* shaders_out[6][6] = { /* cs  */ { 0, 0, 0, 0, 0, 0 },
13618                                                                                            /* vs  */ { 0, vs_tested, tcs_tested, tes, gs, fs },
13619                                                                                            /* tcs */ { 0, vs, tcs_tested, tes_tested, gs, fs },
13620                                                                                            /* tes */ { 0, vs, tcs, tes_tested, gs_tested, fs },
13621                                                                                            /* gs  */ { 0, vs, tcs, tes, gs_tested, fs_tested },
13622                                                                                            /* fs  */ { 0, 0, 0, 0, 0, 0 } };
13623
13624         static const bool require_modifications_in[6][6] = {
13625                 /* cs  */ { false, false, false, false, false, false },
13626                 /* vs  */ { false, true, false, false, false, false },
13627                 /* tcs */ { false, true, true, false, false, false },
13628                 /* tes */ { false, false, true, true, false, false },
13629                 /* gs  */ { false, false, false, true, true, false },
13630                 /* fs  */ { false, false, false, false, true, true }
13631         };
13632
13633         static const bool require_modifications_out[6][6] = {
13634                 /* cs  */ { false, false, false, false, false, false },
13635                 /* vs  */ { false, true, true, false, false, false },
13636                 /* tcs */ { false, false, true, true, false, false },
13637                 /* tes */ { false, false, false, true, true, false },
13638                 /* gs  */ { false, false, false, false, true, true },
13639                 /* fs  */ { false, false, false, false, false, false }
13640         };
13641
13642         const GLchar* array                                     = "";
13643         const GLchar* definition                        = block_definition_default;
13644         const GLchar* direction                         = "out";
13645         const GLchar* index                                     = "";
13646         bool              require_modifications = false;
13647         std::string   source;
13648         testCase&        test_case = m_test_cases[test_case_index];
13649         const GLchar* var_use   = output_use;
13650
13651         if (true == test_case.m_is_input)
13652         {
13653                 require_modifications = require_modifications_in[test_case.m_stage][stage];
13654                 source                            = shaders_in[test_case.m_stage][stage];
13655
13656                 if (test_case.m_stage == stage)
13657                 {
13658                         direction = "in";
13659                         var_use   = input_use;
13660                 }
13661         }
13662         else
13663         {
13664                 require_modifications = require_modifications_out[test_case.m_stage][stage];
13665                 source                            = shaders_out[test_case.m_stage][stage];
13666
13667                 if (test_case.m_stage != stage)
13668                 {
13669                         direction = "in";
13670                         var_use   = input_use;
13671                 }
13672         }
13673
13674         if (test_case.m_stage == stage)
13675         {
13676                 if (true == test_case.m_qualify_all)
13677                 {
13678                         definition = block_definition_all;
13679                 }
13680                 else
13681                 {
13682                         definition = block_definition_one;
13683                 }
13684         }
13685
13686         switch (stage)
13687         {
13688         case Utils::Shader::FRAGMENT:
13689                 break;
13690         case Utils::Shader::GEOMETRY:
13691                 array = "[]";
13692                 index = "[0]";
13693                 break;
13694         case Utils::Shader::TESS_CTRL:
13695                 array = "[]";
13696                 index = "[gl_InvocationID]";
13697                 break;
13698         // geometry shader's input must have one more dimension than tessellation evaluation shader's output,
13699         // the GS input block is an array, so the DS output can't be declared as an array
13700         case Utils::Shader::TESS_EVAL:
13701         {
13702                 if (std::string(direction) == std::string("in")) // match HS output and DS input
13703                 {
13704                         array = "[]";
13705                         index = "[0]";
13706                 }
13707                 else // match DS output and GS input
13708                 {
13709                         array = "";
13710                         index = "";
13711                 }
13712         }
13713         break;
13714         case Utils::Shader::VERTEX:
13715                 break;
13716         default:
13717                 TCU_FAIL("Invalid enum");
13718         }
13719
13720         if (true == require_modifications)
13721         {
13722                 size_t position = 0;
13723                 size_t temp;
13724
13725                 Utils::replaceToken("DIRECTION", position, direction, source);
13726                 temp = position;
13727                 Utils::replaceToken("BLOCK_DEFINITION", position, definition, source);
13728                 position = temp;
13729                 Utils::replaceToken("ARRAY", position, array, source);
13730                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
13731
13732                 Utils::replaceAllTokens("INDEX", index, source);
13733         }
13734         else
13735         {
13736                 switch (stage)
13737                 {
13738                 case Utils::Shader::FRAGMENT:
13739                         source = fs;
13740                         break;
13741                 case Utils::Shader::GEOMETRY:
13742                         source = gs;
13743                         break;
13744                 case Utils::Shader::TESS_CTRL:
13745                         source = tcs;
13746                         break;
13747                 case Utils::Shader::TESS_EVAL:
13748                         source = tes;
13749                         break;
13750                 case Utils::Shader::VERTEX:
13751                         source = vs;
13752                         break;
13753                 default:
13754                         TCU_FAIL("Invalid enum");
13755                 }
13756         }
13757
13758         return source;
13759 }
13760
13761 /** Get description of test case
13762  *
13763  * @param test_case_index Index of test case
13764  *
13765  * @return Test case description
13766  **/
13767 std::string VaryingBlockMemberLocationsTest::getTestCaseName(GLuint test_case_index)
13768 {
13769         std::stringstream stream;
13770         testCase&                 test_case = m_test_cases[test_case_index];
13771
13772         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
13773
13774         if (true == test_case.m_is_input)
13775         {
13776                 stream << "input";
13777         }
13778         else
13779         {
13780                 stream << "output";
13781         }
13782
13783         if (true == test_case.m_qualify_all)
13784         {
13785                 stream << ", all members qualified";
13786         }
13787         else
13788         {
13789                 stream << ", not all members qualified";
13790         }
13791
13792         return stream.str();
13793 }
13794
13795 /** Get number of test cases
13796  *
13797  * @return Number of test cases
13798  **/
13799 GLuint VaryingBlockMemberLocationsTest::getTestCaseNumber()
13800 {
13801         return static_cast<GLuint>(m_test_cases.size());
13802 }
13803
13804 /** Selects if "compute" stage is relevant for test
13805  *
13806  * @param ignored
13807  *
13808  * @return false
13809  **/
13810 bool VaryingBlockMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
13811 {
13812         return false;
13813 }
13814
13815 /** Selects if compilation failure is expected result
13816  *
13817  * @param test_case_index Index of test case
13818  *
13819  * @return false when all members are qualified, true otherwise
13820  **/
13821 bool VaryingBlockMemberLocationsTest::isFailureExpected(GLuint test_case_index)
13822 {
13823         return (true != m_test_cases[test_case_index].m_qualify_all);
13824 }
13825
13826 /** Prepare all test cases
13827  *
13828  **/
13829 void VaryingBlockMemberLocationsTest::testInit()
13830 {
13831         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
13832         {
13833                 if (Utils::Shader::COMPUTE == stage)
13834                 {
13835                         continue;
13836                 }
13837
13838                 testCase test_case_in_all  = { true, true, (Utils::Shader::STAGES)stage };
13839                 testCase test_case_in_one  = { true, false, (Utils::Shader::STAGES)stage };
13840                 testCase test_case_out_all = { false, true, (Utils::Shader::STAGES)stage };
13841                 testCase test_case_out_one = { false, false, (Utils::Shader::STAGES)stage };
13842
13843                 if (Utils::Shader::VERTEX != stage)
13844                 {
13845                         m_test_cases.push_back(test_case_in_all);
13846                         m_test_cases.push_back(test_case_in_one);
13847                 }
13848
13849                 if (Utils::Shader::FRAGMENT != stage)
13850                 {
13851                         m_test_cases.push_back(test_case_out_all);
13852                         m_test_cases.push_back(test_case_out_one);
13853                 }
13854         }
13855 }
13856
13857 /** Constructor
13858  *
13859  * @param context Test framework context
13860  **/
13861 VaryingBlockAutomaticMemberLocationsTest::VaryingBlockAutomaticMemberLocationsTest(deqp::Context& context)
13862         : NegativeTestBase(
13863                   context, "varying_block_automatic_member_locations",
13864                   "Test verifies that compiler assigns subsequent locations to block members, even if this causes errors")
13865 {
13866 }
13867
13868 /** Source for given test case and stage
13869  *
13870  * @param test_case_index Index of test case
13871  * @param stage           Shader stage
13872  *
13873  * @return Shader source
13874  **/
13875 std::string VaryingBlockAutomaticMemberLocationsTest::getShaderSource(GLuint                            test_case_index,
13876                                                                                                                                           Utils::Shader::STAGES stage)
13877 {
13878         static const GLchar* block_definition = "layout (location = 2) DIRECTION DBZ {\n"
13879                                                                                         "    vec4 goku;\n"
13880                                                                                         "    vec4 gohan[4];\n"
13881                                                                                         "    vec4 goten;\n"
13882                                                                                         "    layout (location = 1) vec4 chichi;\n"
13883                                                                                         "    vec4 pan;\n"
13884                                                                                         "} dbzARRAY;\n";
13885         static const GLchar* input_use = "    result += dbzINDEX.goku + dbzINDEX.gohan[0] + dbzINDEX.gohan[1] + "
13886                                                                          "dbzINDEX.gohan[3] + dbzINDEX.gohan[2] + dbzINDEX.goten + dbzINDEX.chichi + "
13887                                                                          "dbzINDEX.pan;\n";
13888         static const GLchar* output_use = "    dbzINDEX.goku     = result;\n"
13889                                                                           "    dbzINDEX.gohan[0] = result / 2;\n"
13890                                                                           "    dbzINDEX.gohan[1] = result / 2.25;\n"
13891                                                                           "    dbzINDEX.gohan[2] = result / 2.5;\n"
13892                                                                           "    dbzINDEX.gohan[3] = result / 2.75;\n"
13893                                                                           "    dbzINDEX.goten    = result / 4  - dbzINDEX.gohan[0] - dbzINDEX.gohan[1] - "
13894                                                                           "dbzINDEX.gohan[2] - dbzINDEX.gohan[3];\n"
13895                                                                           "    dbzINDEX.chichi   = result / 8  - dbzINDEX.goten;\n"
13896                                                                           "    dbzINDEX.pan      = result / 16 - dbzINDEX.chichi;\n";
13897         static const GLchar* fs = "#version 430 core\n"
13898                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13899                                                           "\n"
13900                                                           "in  vec4 gs_fs;\n"
13901                                                           "out vec4 fs_out;\n"
13902                                                           "\n"
13903                                                           "void main()\n"
13904                                                           "{\n"
13905                                                           "    fs_out = gs_fs;\n"
13906                                                           "}\n"
13907                                                           "\n";
13908         static const GLchar* fs_tested = "#version 430 core\n"
13909                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13910                                                                          "\n"
13911                                                                          "BLOCK_DEFINITION"
13912                                                                          "\n"
13913                                                                          "in  vec4 gs_fs;\n"
13914                                                                          "out vec4 fs_out;\n"
13915                                                                          "\n"
13916                                                                          "void main()\n"
13917                                                                          "{\n"
13918                                                                          "    vec4 result = gs_fs;\n"
13919                                                                          "\n"
13920                                                                          "VARIABLE_USE"
13921                                                                          "\n"
13922                                                                          "    fs_out += result;\n"
13923                                                                          "}\n"
13924                                                                          "\n";
13925         static const GLchar* gs = "#version 430 core\n"
13926                                                           "#extension GL_ARB_enhanced_layouts : require\n"
13927                                                           "\n"
13928                                                           "layout(points)                           in;\n"
13929                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
13930                                                           "\n"
13931                                                           "in  vec4 tes_gs[];\n"
13932                                                           "out vec4 gs_fs;\n"
13933                                                           "\n"
13934                                                           "void main()\n"
13935                                                           "{\n"
13936                                                           "    gs_fs = tes_gs[0];\n"
13937                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13938                                                           "    EmitVertex();\n"
13939                                                           "    gs_fs = tes_gs[0];\n"
13940                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13941                                                           "    EmitVertex();\n"
13942                                                           "    gs_fs = tes_gs[0];\n"
13943                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
13944                                                           "    EmitVertex();\n"
13945                                                           "    gs_fs = tes_gs[0];\n"
13946                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
13947                                                           "    EmitVertex();\n"
13948                                                           "}\n"
13949                                                           "\n";
13950         static const GLchar* gs_tested = "#version 430 core\n"
13951                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
13952                                                                          "\n"
13953                                                                          "layout(points)                           in;\n"
13954                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
13955                                                                          "\n"
13956                                                                          "BLOCK_DEFINITION"
13957                                                                          "\n"
13958                                                                          "in  vec4 tes_gs[];\n"
13959                                                                          "out vec4 gs_fs;\n"
13960                                                                          "\n"
13961                                                                          "void main()\n"
13962                                                                          "{\n"
13963                                                                          "    vec4 result = tes_gs[0];\n"
13964                                                                          "\n"
13965                                                                          "VARIABLE_USE"
13966                                                                          "\n"
13967                                                                          "    gs_fs = result;\n"
13968                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
13969                                                                          "    EmitVertex();\n"
13970                                                                          "    gs_fs = result;\n"
13971                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
13972                                                                          "    EmitVertex();\n"
13973                                                                          "    gs_fs = result;\n"
13974                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
13975                                                                          "    EmitVertex();\n"
13976                                                                          "    gs_fs = result;\n"
13977                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
13978                                                                          "    EmitVertex();\n"
13979                                                                          "}\n"
13980                                                                          "\n";
13981         static const GLchar* tcs = "#version 430 core\n"
13982                                                            "#extension GL_ARB_enhanced_layouts : require\n"
13983                                                            "\n"
13984                                                            "layout(vertices = 1) out;\n"
13985                                                            "\n"
13986                                                            "in  vec4 vs_tcs[];\n"
13987                                                            "out vec4 tcs_tes[];\n"
13988                                                            "\n"
13989                                                            "void main()\n"
13990                                                            "{\n"
13991                                                            "\n"
13992                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
13993                                                            "\n"
13994                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
13995                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
13996                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
13997                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
13998                                                            "    gl_TessLevelInner[0] = 1.0;\n"
13999                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14000                                                            "}\n"
14001                                                            "\n";
14002         static const GLchar* tcs_tested = "#version 430 core\n"
14003                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14004                                                                           "\n"
14005                                                                           "layout(vertices = 1) out;\n"
14006                                                                           "\n"
14007                                                                           "BLOCK_DEFINITION"
14008                                                                           "\n"
14009                                                                           "in  vec4 vs_tcs[];\n"
14010                                                                           "out vec4 tcs_tes[];\n"
14011                                                                           "\n"
14012                                                                           "void main()\n"
14013                                                                           "{\n"
14014                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14015                                                                           "\n"
14016                                                                           "VARIABLE_USE"
14017                                                                           "\n"
14018                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14019                                                                           "\n"
14020                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14021                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14022                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14023                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14024                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14025                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14026                                                                           "}\n"
14027                                                                           "\n";
14028         static const GLchar* tes = "#version 430 core\n"
14029                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14030                                                            "\n"
14031                                                            "layout(isolines, point_mode) in;\n"
14032                                                            "\n"
14033                                                            "in  vec4 tcs_tes[];\n"
14034                                                            "out vec4 tes_gs;\n"
14035                                                            "\n"
14036                                                            "void main()\n"
14037                                                            "{\n"
14038                                                            "    tes_gs = tcs_tes[0];\n"
14039                                                            "}\n"
14040                                                            "\n";
14041         static const GLchar* tes_tested = "#version 430 core\n"
14042                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14043                                                                           "\n"
14044                                                                           "layout(isolines, point_mode) in;\n"
14045                                                                           "\n"
14046                                                                           "BLOCK_DEFINITION"
14047                                                                           "\n"
14048                                                                           "in  vec4 tcs_tes[];\n"
14049                                                                           "out vec4 tes_gs;\n"
14050                                                                           "\n"
14051                                                                           "void main()\n"
14052                                                                           "{\n"
14053                                                                           "    vec4 result = tcs_tes[0];\n"
14054                                                                           "\n"
14055                                                                           "VARIABLE_USE"
14056                                                                           "\n"
14057                                                                           "    tes_gs += result;\n"
14058                                                                           "}\n"
14059                                                                           "\n";
14060         static const GLchar* vs = "#version 430 core\n"
14061                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14062                                                           "\n"
14063                                                           "in  vec4 in_vs;\n"
14064                                                           "out vec4 vs_tcs;\n"
14065                                                           "\n"
14066                                                           "void main()\n"
14067                                                           "{\n"
14068                                                           "    vs_tcs = in_vs;\n"
14069                                                           "}\n"
14070                                                           "\n";
14071         static const GLchar* vs_tested = "#version 430 core\n"
14072                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14073                                                                          "\n"
14074                                                                          "BLOCK_DEFINITION"
14075                                                                          "\n"
14076                                                                          "in  vec4 in_vs;\n"
14077                                                                          "out vec4 vs_tcs;\n"
14078                                                                          "\n"
14079                                                                          "void main()\n"
14080                                                                          "{\n"
14081                                                                          "    vec4 result = in_vs;\n"
14082                                                                          "\n"
14083                                                                          "VARIABLE_USE"
14084                                                                          "\n"
14085                                                                          "    vs_tcs += result;\n"
14086                                                                          "}\n"
14087                                                                          "\n";
14088
14089         const GLchar* array             = "";
14090         const GLchar* direction = "out";
14091         const GLchar* index             = "";
14092         std::string   source;
14093         testCase&        test_case = m_test_cases[test_case_index];
14094         const GLchar* var_use   = output_use;
14095
14096         if (true == test_case.m_is_input)
14097         {
14098                 direction = "in ";
14099                 var_use   = input_use;
14100         }
14101
14102         if (test_case.m_stage == stage)
14103         {
14104                 size_t position = 0;
14105                 size_t temp;
14106
14107                 switch (stage)
14108                 {
14109                 case Utils::Shader::FRAGMENT:
14110                         source = fs_tested;
14111                         break;
14112                 case Utils::Shader::GEOMETRY:
14113                         source = gs_tested;
14114                         array  = "[]";
14115                         index  = "[0]";
14116                         break;
14117                 case Utils::Shader::TESS_CTRL:
14118                         source = tcs_tested;
14119                         array  = "[]";
14120                         index  = "[gl_InvocationID]";
14121                         break;
14122                 case Utils::Shader::TESS_EVAL:
14123                         source = tes_tested;
14124                         array  = "[]";
14125                         index  = "[0]";
14126                         break;
14127                 case Utils::Shader::VERTEX:
14128                         source = vs_tested;
14129                         break;
14130                 default:
14131                         TCU_FAIL("Invalid enum");
14132                 }
14133
14134                 temp = position;
14135                 Utils::replaceToken("BLOCK_DEFINITION", position, block_definition, source);
14136                 position = temp;
14137                 Utils::replaceToken("DIRECTION", position, direction, source);
14138                 Utils::replaceToken("ARRAY", position, array, source);
14139                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14140
14141                 Utils::replaceAllTokens("INDEX", index, source);
14142         }
14143         else
14144         {
14145                 switch (stage)
14146                 {
14147                 case Utils::Shader::FRAGMENT:
14148                         source = fs;
14149                         break;
14150                 case Utils::Shader::GEOMETRY:
14151                         source = gs;
14152                         break;
14153                 case Utils::Shader::TESS_CTRL:
14154                         source = tcs;
14155                         break;
14156                 case Utils::Shader::TESS_EVAL:
14157                         source = tes;
14158                         break;
14159                 case Utils::Shader::VERTEX:
14160                         source = vs;
14161                         break;
14162                 default:
14163                         TCU_FAIL("Invalid enum");
14164                 }
14165         }
14166
14167         return source;
14168 }
14169
14170 /** Get description of test case
14171  *
14172  * @param test_case_index Index of test case
14173  *
14174  * @return Test case description
14175  **/
14176 std::string VaryingBlockAutomaticMemberLocationsTest::getTestCaseName(GLuint test_case_index)
14177 {
14178         std::stringstream stream;
14179         testCase&                 test_case = m_test_cases[test_case_index];
14180
14181         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", direction: ";
14182
14183         if (true == test_case.m_is_input)
14184         {
14185                 stream << "input";
14186         }
14187         else
14188         {
14189                 stream << "output";
14190         }
14191
14192         return stream.str();
14193 }
14194
14195 /** Get number of test cases
14196  *
14197  * @return Number of test cases
14198  **/
14199 GLuint VaryingBlockAutomaticMemberLocationsTest::getTestCaseNumber()
14200 {
14201         return static_cast<GLuint>(m_test_cases.size());
14202 }
14203
14204 /** Selects if "compute" stage is relevant for test
14205  *
14206  * @param ignored
14207  *
14208  * @return false
14209  **/
14210 bool VaryingBlockAutomaticMemberLocationsTest::isComputeRelevant(GLuint /* test_case_index */)
14211 {
14212         return false;
14213 }
14214
14215 /** Prepare all test cases
14216  *
14217  **/
14218 void VaryingBlockAutomaticMemberLocationsTest::testInit()
14219 {
14220         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14221         {
14222                 if (Utils::Shader::COMPUTE == stage)
14223                 {
14224                         continue;
14225                 }
14226
14227                 testCase test_case_in  = { true, (Utils::Shader::STAGES)stage };
14228                 testCase test_case_out = { false, (Utils::Shader::STAGES)stage };
14229
14230                 if (Utils::Shader::VERTEX != stage)
14231                 {
14232                         m_test_cases.push_back(test_case_in);
14233                 }
14234
14235                 if (Utils::Shader::FRAGMENT != stage)
14236                 {
14237                         m_test_cases.push_back(test_case_out);
14238                 }
14239         }
14240 }
14241
14242 /** Constructor
14243  *
14244  * @param context Test framework context
14245  **/
14246 VaryingLocationLimitTest::VaryingLocationLimitTest(deqp::Context& context)
14247         : NegativeTestBase(context, "varying_location_limit",
14248                                            "Test verifies that compiler reports error when location qualifier exceed limits")
14249 {
14250 }
14251
14252 /** Source for given test case and stage
14253  *
14254  * @param test_case_index Index of test case
14255  * @param stage           Shader stage
14256  *
14257  * @return Shader source
14258  **/
14259 std::string VaryingLocationLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
14260 {
14261         static const GLchar* var_definition = "layout (location = LAST + 1) FLAT DIRECTION TYPE gokuARRAY;\n";
14262         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
14263                                                                          "    {\n"
14264                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
14265                                                                          "    }\n";
14266         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
14267                                                                           "    if (vec4(0) == result)\n"
14268                                                                           "    {\n"
14269                                                                           "        gokuINDEX = TYPE(1);\n"
14270                                                                           "    }\n";
14271         static const GLchar* fs = "#version 430 core\n"
14272                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14273                                                           "\n"
14274                                                           "in  vec4 gs_fs;\n"
14275                                                           "out vec4 fs_out;\n"
14276                                                           "\n"
14277                                                           "void main()\n"
14278                                                           "{\n"
14279                                                           "    fs_out = gs_fs;\n"
14280                                                           "}\n"
14281                                                           "\n";
14282         static const GLchar* fs_tested = "#version 430 core\n"
14283                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14284                                                                          "\n"
14285                                                                          "VAR_DEFINITION"
14286                                                                          "\n"
14287                                                                          "in  vec4 gs_fs;\n"
14288                                                                          "out vec4 fs_out;\n"
14289                                                                          "\n"
14290                                                                          "void main()\n"
14291                                                                          "{\n"
14292                                                                          "    vec4 result = gs_fs;\n"
14293                                                                          "\n"
14294                                                                          "VARIABLE_USE"
14295                                                                          "\n"
14296                                                                          "    fs_out += result;\n"
14297                                                                          "}\n"
14298                                                                          "\n";
14299         static const GLchar* gs = "#version 430 core\n"
14300                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14301                                                           "\n"
14302                                                           "layout(points)                           in;\n"
14303                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
14304                                                           "\n"
14305                                                           "in  vec4 tes_gs[];\n"
14306                                                           "out vec4 gs_fs;\n"
14307                                                           "\n"
14308                                                           "void main()\n"
14309                                                           "{\n"
14310                                                           "    gs_fs = tes_gs[0];\n"
14311                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14312                                                           "    EmitVertex();\n"
14313                                                           "    gs_fs = tes_gs[0];\n"
14314                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14315                                                           "    EmitVertex();\n"
14316                                                           "    gs_fs = tes_gs[0];\n"
14317                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
14318                                                           "    EmitVertex();\n"
14319                                                           "    gs_fs = tes_gs[0];\n"
14320                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
14321                                                           "    EmitVertex();\n"
14322                                                           "}\n"
14323                                                           "\n";
14324         static const GLchar* gs_tested = "#version 430 core\n"
14325                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14326                                                                          "\n"
14327                                                                          "layout(points)                           in;\n"
14328                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
14329                                                                          "\n"
14330                                                                          "VAR_DEFINITION"
14331                                                                          "\n"
14332                                                                          "in  vec4 tes_gs[];\n"
14333                                                                          "out vec4 gs_fs;\n"
14334                                                                          "\n"
14335                                                                          "void main()\n"
14336                                                                          "{\n"
14337                                                                          "    vec4 result = tes_gs[0];\n"
14338                                                                          "\n"
14339                                                                          "VARIABLE_USE"
14340                                                                          "\n"
14341                                                                          "    gs_fs = result;\n"
14342                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
14343                                                                          "    EmitVertex();\n"
14344                                                                          "    gs_fs = result;\n"
14345                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
14346                                                                          "    EmitVertex();\n"
14347                                                                          "    gs_fs = result;\n"
14348                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
14349                                                                          "    EmitVertex();\n"
14350                                                                          "    gs_fs = result;\n"
14351                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
14352                                                                          "    EmitVertex();\n"
14353                                                                          "}\n"
14354                                                                          "\n";
14355         static const GLchar* tcs = "#version 430 core\n"
14356                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14357                                                            "\n"
14358                                                            "layout(vertices = 1) out;\n"
14359                                                            "\n"
14360                                                            "in  vec4 vs_tcs[];\n"
14361                                                            "out vec4 tcs_tes[];\n"
14362                                                            "\n"
14363                                                            "void main()\n"
14364                                                            "{\n"
14365                                                            "\n"
14366                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
14367                                                            "\n"
14368                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
14369                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
14370                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
14371                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
14372                                                            "    gl_TessLevelInner[0] = 1.0;\n"
14373                                                            "    gl_TessLevelInner[1] = 1.0;\n"
14374                                                            "}\n"
14375                                                            "\n";
14376         static const GLchar* tcs_tested = "#version 430 core\n"
14377                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14378                                                                           "\n"
14379                                                                           "layout(vertices = 1) out;\n"
14380                                                                           "\n"
14381                                                                           "VAR_DEFINITION"
14382                                                                           "\n"
14383                                                                           "in  vec4 vs_tcs[];\n"
14384                                                                           "out vec4 tcs_tes[];\n"
14385                                                                           "\n"
14386                                                                           "void main()\n"
14387                                                                           "{\n"
14388                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
14389                                                                           "\n"
14390                                                                           "VARIABLE_USE"
14391                                                                           "\n"
14392                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
14393                                                                           "\n"
14394                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
14395                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
14396                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
14397                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
14398                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
14399                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
14400                                                                           "}\n"
14401                                                                           "\n";
14402         static const GLchar* tes = "#version 430 core\n"
14403                                                            "#extension GL_ARB_enhanced_layouts : require\n"
14404                                                            "\n"
14405                                                            "layout(isolines, point_mode) in;\n"
14406                                                            "\n"
14407                                                            "in  vec4 tcs_tes[];\n"
14408                                                            "out vec4 tes_gs;\n"
14409                                                            "\n"
14410                                                            "void main()\n"
14411                                                            "{\n"
14412                                                            "    tes_gs = tcs_tes[0];\n"
14413                                                            "}\n"
14414                                                            "\n";
14415         static const GLchar* tes_tested = "#version 430 core\n"
14416                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14417                                                                           "\n"
14418                                                                           "layout(isolines, point_mode) in;\n"
14419                                                                           "\n"
14420                                                                           "VAR_DEFINITION"
14421                                                                           "\n"
14422                                                                           "in  vec4 tcs_tes[];\n"
14423                                                                           "out vec4 tes_gs;\n"
14424                                                                           "\n"
14425                                                                           "void main()\n"
14426                                                                           "{\n"
14427                                                                           "    vec4 result = tcs_tes[0];\n"
14428                                                                           "\n"
14429                                                                           "VARIABLE_USE"
14430                                                                           "\n"
14431                                                                           "    tes_gs += result;\n"
14432                                                                           "}\n"
14433                                                                           "\n";
14434         static const GLchar* vs = "#version 430 core\n"
14435                                                           "#extension GL_ARB_enhanced_layouts : require\n"
14436                                                           "\n"
14437                                                           "in  vec4 in_vs;\n"
14438                                                           "out vec4 vs_tcs;\n"
14439                                                           "\n"
14440                                                           "void main()\n"
14441                                                           "{\n"
14442                                                           "    vs_tcs = in_vs;\n"
14443                                                           "}\n"
14444                                                           "\n";
14445         static const GLchar* vs_tested = "#version 430 core\n"
14446                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
14447                                                                          "\n"
14448                                                                          "VAR_DEFINITION"
14449                                                                          "\n"
14450                                                                          "in  vec4 in_vs;\n"
14451                                                                          "out vec4 vs_tcs;\n"
14452                                                                          "\n"
14453                                                                          "void main()\n"
14454                                                                          "{\n"
14455                                                                          "    vec4 result = in_vs;\n"
14456                                                                          "\n"
14457                                                                          "VARIABLE_USE"
14458                                                                          "\n"
14459                                                                          "    vs_tcs += result;\n"
14460                                                                          "}\n"
14461                                                                          "\n";
14462
14463         std::string source;
14464         testCase&   test_case = m_test_cases[test_case_index];
14465
14466         if (test_case.m_stage == stage)
14467         {
14468                 const GLchar*                    array = "";
14469                 GLchar                                   buffer[16];
14470                 const GLchar*                    direction = "in ";
14471                 const GLchar*                    flat     = "";
14472                 const GLchar*                    index   = "";
14473                 GLuint                                   last     = getLastInputLocation(stage, test_case.m_type, 0);
14474                 size_t                                   position  = 0;
14475                 size_t                                   temp;
14476                 const GLchar*                    type_name = test_case.m_type.GetGLSLTypeName();
14477                 Utils::Variable::STORAGE storage   = Utils::Variable::VARYING_INPUT;
14478                 const GLchar*                    var_use   = input_use;
14479
14480                 if (false == test_case.m_is_input)
14481                 {
14482                         direction = "out";
14483                         last      = getLastOutputLocation(stage, test_case.m_type, 0);
14484                         storage   = Utils::Variable::VARYING_OUTPUT;
14485                         var_use   = output_use;
14486                 }
14487
14488                 if (true == isFlatRequired(stage, test_case.m_type, storage))
14489                 {
14490                         flat = "flat";
14491                 }
14492
14493                 sprintf(buffer, "%d", last);
14494
14495                 switch (stage)
14496                 {
14497                 case Utils::Shader::FRAGMENT:
14498                         source = fs_tested;
14499                         break;
14500                 case Utils::Shader::GEOMETRY:
14501                         source = gs_tested;
14502                         array  = "[]";
14503                         index  = "[0]";
14504                         break;
14505                 case Utils::Shader::TESS_CTRL:
14506                         source = tcs_tested;
14507                         array  = "[]";
14508                         index  = "[gl_InvocationID]";
14509                         break;
14510                 case Utils::Shader::TESS_EVAL:
14511                         source = tes_tested;
14512                         array  = "[]";
14513                         index  = "[0]";
14514                         break;
14515                 case Utils::Shader::VERTEX:
14516                         source = vs_tested;
14517                         break;
14518                 default:
14519                         TCU_FAIL("Invalid enum");
14520                 }
14521
14522                 temp = position;
14523                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
14524                 position = temp;
14525                 Utils::replaceToken("LAST", position, buffer, source);
14526                 Utils::replaceToken("FLAT", position, flat, source);
14527                 Utils::replaceToken("DIRECTION", position, direction, source);
14528                 Utils::replaceToken("ARRAY", position, array, source);
14529                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
14530
14531                 Utils::replaceAllTokens("TYPE", type_name, source);
14532                 Utils::replaceAllTokens("INDEX", index, source);
14533         }
14534         else
14535         {
14536                 switch (stage)
14537                 {
14538                 case Utils::Shader::FRAGMENT:
14539                         source = fs;
14540                         break;
14541                 case Utils::Shader::GEOMETRY:
14542                         source = gs;
14543                         break;
14544                 case Utils::Shader::TESS_CTRL:
14545                         source = tcs;
14546                         break;
14547                 case Utils::Shader::TESS_EVAL:
14548                         source = tes;
14549                         break;
14550                 case Utils::Shader::VERTEX:
14551                         source = vs;
14552                         break;
14553                 default:
14554                         TCU_FAIL("Invalid enum");
14555                 }
14556         }
14557
14558         return source;
14559 }
14560
14561 /** Get description of test case
14562  *
14563  * @param test_case_index Index of test case
14564  *
14565  * @return Test case description
14566  **/
14567 std::string VaryingLocationLimitTest::getTestCaseName(GLuint test_case_index)
14568 {
14569         std::stringstream stream;
14570         testCase&                 test_case = m_test_cases[test_case_index];
14571
14572         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
14573                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
14574
14575         if (true == test_case.m_is_input)
14576         {
14577                 stream << "input";
14578         }
14579         else
14580         {
14581                 stream << "output";
14582         }
14583
14584         return stream.str();
14585 }
14586
14587 /** Get number of test cases
14588  *
14589  * @return Number of test cases
14590  **/
14591 GLuint VaryingLocationLimitTest::getTestCaseNumber()
14592 {
14593         return static_cast<GLuint>(m_test_cases.size());
14594 }
14595
14596 /** Selects if "compute" stage is relevant for test
14597  *
14598  * @param ignored
14599  *
14600  * @return false
14601  **/
14602 bool VaryingLocationLimitTest::isComputeRelevant(GLuint /* test_case_index */)
14603 {
14604         return false;
14605 }
14606
14607 /** Prepare all test cases
14608  *
14609  **/
14610 void VaryingLocationLimitTest::testInit()
14611 {
14612         const GLuint n_types = getTypesNumber();
14613
14614         for (GLuint i = 0; i < n_types; ++i)
14615         {
14616                 const Utils::Type& type = getType(i);
14617
14618                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
14619                 {
14620                         if (Utils::Shader::COMPUTE == stage)
14621                         {
14622                                 continue;
14623                         }
14624
14625                         testCase test_case_in  = { true, type, (Utils::Shader::STAGES)stage };
14626                         testCase test_case_out = { false, type, (Utils::Shader::STAGES)stage };
14627
14628                         m_test_cases.push_back(test_case_in);
14629
14630                         if (Utils::Shader::FRAGMENT != stage)
14631                         {
14632                                 m_test_cases.push_back(test_case_out);
14633                         }
14634                 }
14635         }
14636 }
14637
14638 /** Constructor
14639  *
14640  * @param context Test framework context
14641  **/
14642 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context)
14643         : VaryingLocationsTest(context, "varying_components",
14644                                                    "Test verifies that input and output components are respected")
14645 {
14646 }
14647
14648 /** Constructor
14649  *
14650  * @param context          Test framework context
14651  * @param test_name        Name of test
14652  * @param test_description Description of test
14653  **/
14654 VaryingComponentsTest::VaryingComponentsTest(deqp::Context& context, const glw::GLchar* test_name,
14655                                                                                          const glw::GLchar* test_description)
14656         : VaryingLocationsTest(context, test_name, test_description)
14657 {
14658 }
14659
14660 /** Get interface of program
14661  *
14662  * @param test_case_index     Test case
14663  * @param program_interface   Interface of program
14664  * @param varying_passthrough Collection of connections between in and out variables
14665  **/
14666 void VaryingComponentsTest::getProgramInterface(GLuint test_case_index, Utils::ProgramInterface& program_interface,
14667                                                                                                 Utils::VaryingPassthrough& varying_passthrough)
14668 {
14669         GLuint                             array_length = getArrayLength();
14670         const testCase&            test_case    = m_test_cases[test_case_index];
14671         const Utils::Type         vector_type  = Utils::Type::GetType(test_case.m_type, 1, 4);
14672         Utils::ShaderInterface si                       = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
14673
14674         /* Zero means no array, however we still need at least 1 slot of data */
14675         if (0 == array_length)
14676         {
14677                 array_length += 1;
14678         }
14679
14680         /* Generate data */
14681         const std::vector<GLubyte>& data          = vector_type.GenerateDataPacked();
14682         const size_t                            data_size = data.size();
14683
14684         /* Prepare data for variables */
14685         m_data.resize(array_length * data_size);
14686
14687         GLubyte*           dst = &m_data[0];
14688         const GLubyte* src = &data[0];
14689
14690         for (GLuint i = 0; i < array_length; ++i)
14691         {
14692                 memcpy(dst + data_size * i, src, data_size);
14693         }
14694
14695         /* Prepare interface for each stage */
14696         prepareShaderStage(Utils::Shader::FRAGMENT, vector_type, program_interface, test_case, varying_passthrough);
14697         prepareShaderStage(Utils::Shader::GEOMETRY, vector_type, program_interface, test_case, varying_passthrough);
14698         prepareShaderStage(Utils::Shader::TESS_CTRL, vector_type, program_interface, test_case, varying_passthrough);
14699         prepareShaderStage(Utils::Shader::TESS_EVAL, vector_type, program_interface, test_case, varying_passthrough);
14700         prepareShaderStage(Utils::Shader::VERTEX, vector_type, program_interface, test_case, varying_passthrough);
14701 }
14702
14703 /** Get type name
14704  *
14705  * @param test_case_index Index of test case
14706  *
14707  * @return Name of type test in test_case_index
14708  **/
14709 std::string VaryingComponentsTest::getTestCaseName(glw::GLuint test_case_index)
14710 {
14711         std::string name;
14712
14713         const testCase& test_case = m_test_cases[test_case_index];
14714
14715         name = "Type: ";
14716
14717         switch (test_case.m_type)
14718         {
14719         case Utils::Type::Double:
14720                 name.append(Utils::Type::_double.GetGLSLTypeName());
14721                 break;
14722         case Utils::Type::Float:
14723                 name.append(Utils::Type::_float.GetGLSLTypeName());
14724                 break;
14725         case Utils::Type::Int:
14726                 name.append(Utils::Type::_int.GetGLSLTypeName());
14727                 break;
14728         case Utils::Type::Uint:
14729                 name.append(Utils::Type::uint.GetGLSLTypeName());
14730                 break;
14731         }
14732
14733         name.append(", layout: ");
14734
14735         switch (test_case.m_layout)
14736         {
14737         case GVEC4:
14738                 name.append("GVEC4");
14739                 break;
14740         case SCALAR_GVEC3:
14741                 name.append("SCALAR_GVEC3");
14742                 break;
14743         case GVEC3_SCALAR:
14744                 name.append("GVEC3_SCALAR");
14745                 break;
14746         case GVEC2_GVEC2:
14747                 name.append("GVEC2_GVEC2");
14748                 break;
14749         case GVEC2_SCALAR_SCALAR:
14750                 name.append("GVEC2_SCALAR_SCALAR");
14751                 break;
14752         case SCALAR_GVEC2_SCALAR:
14753                 name.append("SCALAR_GVEC2_SCALAR");
14754                 break;
14755         case SCALAR_SCALAR_GVEC2:
14756                 name.append("SCALAR_SCALAR_GVEC2");
14757                 break;
14758         case SCALAR_SCALAR_SCALAR_SCALAR:
14759                 name.append("SCALAR_SCALAR_SCALAR_SCALAR");
14760                 break;
14761         }
14762
14763         return name;
14764 }
14765
14766 /** Returns number of types to test
14767  *
14768  * @return Number of types, 34
14769  **/
14770 glw::GLuint VaryingComponentsTest::getTestCaseNumber()
14771 {
14772         return static_cast<GLuint>(m_test_cases.size());
14773 }
14774
14775 /* Prepare test cases */
14776 void VaryingComponentsTest::testInit()
14777 {
14778         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Double));
14779         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Double));
14780         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Double));
14781         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Double));
14782         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Double));
14783         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Double));
14784         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Double));
14785         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Double));
14786
14787         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Float));
14788         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Float));
14789         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Float));
14790         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Float));
14791         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Float));
14792         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Float));
14793         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Float));
14794         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Float));
14795
14796         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Int));
14797         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Int));
14798         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Int));
14799         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Int));
14800         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Int));
14801         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Int));
14802         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Int));
14803         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Int));
14804
14805         m_test_cases.push_back(testCase(GVEC4, Utils::Type::Uint));
14806         m_test_cases.push_back(testCase(SCALAR_GVEC3, Utils::Type::Uint));
14807         m_test_cases.push_back(testCase(GVEC3_SCALAR, Utils::Type::Uint));
14808         m_test_cases.push_back(testCase(GVEC2_GVEC2, Utils::Type::Uint));
14809         m_test_cases.push_back(testCase(GVEC2_SCALAR_SCALAR, Utils::Type::Uint));
14810         m_test_cases.push_back(testCase(SCALAR_GVEC2_SCALAR, Utils::Type::Uint));
14811         m_test_cases.push_back(testCase(SCALAR_SCALAR_GVEC2, Utils::Type::Uint));
14812         m_test_cases.push_back(testCase(SCALAR_SCALAR_SCALAR_SCALAR, Utils::Type::Uint));
14813 }
14814
14815 /** Inform that test use components
14816  *
14817  * @param ignored
14818  *
14819  * @return true
14820  **/
14821 bool VaryingComponentsTest::useComponentQualifier(glw::GLuint /* test_case_index */)
14822 {
14823         return true;
14824 }
14825
14826 /** Get length of arrays that should be used during test
14827  *
14828  * @return 0u - no array at all
14829  **/
14830 GLuint VaryingComponentsTest::getArrayLength()
14831 {
14832         return 0;
14833 }
14834
14835 std::string VaryingComponentsTest::prepareGlobals(GLuint last_in_location, GLuint last_out_location)
14836 {
14837         std::string globals = VaryingLocationsTest::prepareGlobals(last_in_location, last_out_location);
14838
14839         globals.append("const uint comp_x = 0u;\n"
14840                                    "const uint comp_y = 1u;\n"
14841                                    "const uint comp_z = 2u;\n"
14842                                    "const uint comp_w = 3u;\n");
14843
14844         return globals;
14845 }
14846
14847 /**
14848  *
14849  **/
14850 std::string VaryingComponentsTest::prepareName(const glw::GLchar* name, glw::GLint location, glw::GLint component,
14851                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
14852 {
14853         GLchar            buffer[16];
14854         std::string   result   = "PREFIXNAME_lLOCATION_cCOMPONENT";
14855         size_t            position = 0;
14856         const GLchar* prefix   = Utils::ProgramInterface::GetStagePrefix(stage, storage);
14857
14858         Utils::replaceToken("PREFIX", position, prefix, result);
14859         Utils::replaceToken("NAME", position, name, result);
14860
14861         sprintf(buffer, "%d", location);
14862         Utils::replaceToken("LOCATION", position, buffer, result);
14863
14864         sprintf(buffer, "%d", component);
14865         Utils::replaceToken("COMPONENT", position, buffer, result);
14866
14867         return result;
14868 }
14869
14870 std::string VaryingComponentsTest::prepareQualifiers(const glw::GLchar* location, const glw::GLchar* component,
14871                                                                                                          const glw::GLchar* interpolation)
14872 {
14873         size_t          position   = 0;
14874         std::string qualifiers = "layout (location = LOCATION, component = COMPONENT) INTERPOLATION";
14875
14876         Utils::replaceToken("LOCATION", position, location, qualifiers);
14877         Utils::replaceToken("COMPONENT", position, component, qualifiers);
14878         Utils::replaceToken("INTERPOLATION", position, interpolation, qualifiers);
14879
14880         return qualifiers;
14881 }
14882
14883 /**
14884  *
14885  **/
14886 void VaryingComponentsTest::prepareShaderStage(Utils::Shader::STAGES stage, const Utils::Type& vector_type,
14887                                                                                            Utils::ProgramInterface& program_interface, const testCase& test_case,
14888                                                                                            Utils::VaryingPassthrough& varying_passthrough)
14889 {
14890         const GLuint                    array_length = getArrayLength();
14891         const Utils::Type&              basic_type = Utils::Type::GetType(vector_type.m_basic_type, 1 /* n_cols */, 1 /* n_rows */);
14892         descriptor                              desc_in[8];
14893         descriptor                              desc_out[8];
14894         const GLuint                    first_in_loc  = 0;
14895         const GLuint                    first_out_loc = 0;
14896         const GLchar*                   interpolation = "";
14897         const GLuint                    last_in_loc   = getLastInputLocation(stage, vector_type, array_length);
14898         GLuint                                  last_out_loc  = 0;
14899         GLuint                                  n_desc            = 0;
14900         Utils::ShaderInterface& si                        = program_interface.GetShaderInterface(stage);
14901
14902         /* Select interpolation */
14903         if ((Utils::Shader::FRAGMENT == stage) || (Utils::Shader::GEOMETRY == stage))
14904         {
14905                 interpolation = " flat";
14906         }
14907
14908         if (Utils::Shader::FRAGMENT != stage)
14909         {
14910                 last_out_loc = getLastOutputLocation(stage, vector_type, array_length);
14911         }
14912
14913         switch (test_case.m_layout)
14914         {
14915         case GVEC4:
14916                 n_desc = 2;
14917                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 4, "gvec4");
14918                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 4, "gvec4");
14919
14920                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 4, "gvec4");
14921                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 4, "gvec4");
14922                 break;
14923         case SCALAR_GVEC3:
14924                 n_desc = 4;
14925                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14926                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14927                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 3, "gvec3");
14928                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 3, "gvec3");
14929
14930                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14931                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14932                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 3, "gvec3");
14933                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 3, "gvec3");
14934                 break;
14935         case GVEC3_SCALAR:
14936                 n_desc = 4;
14937                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 3, "gvec3");
14938                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 3, "gvec3");
14939                 desc_in[2].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14940                 desc_in[3].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14941
14942                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 3, "gvec3");
14943                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 3, "gvec3");
14944                 desc_out[2].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14945                 desc_out[3].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14946                 break;
14947         case GVEC2_GVEC2:
14948                 n_desc = 4;
14949                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14950                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14951                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14952                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14953
14954                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14955                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14956                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
14957                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
14958                 break;
14959         case GVEC2_SCALAR_SCALAR:
14960                 n_desc = 6;
14961                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 2, "gvec2");
14962                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 2, "gvec2");
14963                 desc_in[2].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
14964                 desc_in[3].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
14965                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14966                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14967
14968                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 2, "gvec2");
14969                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 2, "gvec2");
14970                 desc_out[2].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
14971                 desc_out[3].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
14972                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14973                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14974                 break;
14975         case SCALAR_GVEC2_SCALAR:
14976                 n_desc = 6;
14977                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14978                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14979                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 2, "gvec2");
14980                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 2, "gvec2");
14981                 desc_in[4].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
14982                 desc_in[5].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
14983
14984                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
14985                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
14986                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 2, "gvec2");
14987                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 2, "gvec2");
14988                 desc_out[4].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
14989                 desc_out[5].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
14990                 break;
14991         case SCALAR_SCALAR_GVEC2:
14992                 n_desc = 6;
14993                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
14994                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
14995                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
14996                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
14997                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 2, "gvec2");
14998                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 2, "gvec2");
14999
15000                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15001                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15002                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15003                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15004                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 2, "gvec2");
15005                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 2, "gvec2");
15006                 break;
15007         case SCALAR_SCALAR_SCALAR_SCALAR:
15008                 n_desc = 8;
15009                 desc_in[0].assign(0, "comp_x", first_in_loc, "first_input_location", 1, "scalar");
15010                 desc_in[1].assign(0, "comp_x", last_in_loc, "last_input_location", 1, "scalar");
15011                 desc_in[2].assign(1, "comp_y", first_in_loc, "first_input_location", 1, "scalar");
15012                 desc_in[3].assign(1, "comp_y", last_in_loc, "last_input_location", 1, "scalar");
15013                 desc_in[4].assign(2, "comp_z", first_in_loc, "first_input_location", 1, "scalar");
15014                 desc_in[5].assign(2, "comp_z", last_in_loc, "last_input_location", 1, "scalar");
15015                 desc_in[6].assign(3, "comp_w", first_in_loc, "first_input_location", 1, "scalar");
15016                 desc_in[7].assign(3, "comp_w", last_in_loc, "last_input_location", 1, "scalar");
15017
15018                 desc_out[0].assign(0, "comp_x", first_out_loc, "first_output_location", 1, "scalar");
15019                 desc_out[1].assign(0, "comp_x", last_out_loc, "last_output_location", 1, "scalar");
15020                 desc_out[2].assign(1, "comp_y", first_out_loc, "first_output_location", 1, "scalar");
15021                 desc_out[3].assign(1, "comp_y", last_out_loc, "last_output_location", 1, "scalar");
15022                 desc_out[4].assign(2, "comp_z", first_out_loc, "first_output_location", 1, "scalar");
15023                 desc_out[5].assign(2, "comp_z", last_out_loc, "last_output_location", 1, "scalar");
15024                 desc_out[6].assign(3, "comp_w", first_out_loc, "first_output_location", 1, "scalar");
15025                 desc_out[7].assign(3, "comp_w", last_out_loc, "last_output_location", 1, "scalar");
15026                 break;
15027         }
15028
15029         for (GLuint i = 0; i < n_desc; ++i)
15030         {
15031                 const descriptor& in_desc = desc_in[i];
15032
15033                 Utils::Variable* in =
15034                         prepareVarying(basic_type, in_desc, interpolation, si, stage, Utils::Variable::VARYING_INPUT);
15035
15036                 if (Utils::Shader::FRAGMENT != stage)
15037                 {
15038                         const descriptor& out_desc = desc_out[i];
15039
15040                         Utils::Variable* out =
15041                                 prepareVarying(basic_type, out_desc, interpolation, si, stage, Utils::Variable::VARYING_OUTPUT);
15042
15043                         varying_passthrough.Add(stage, in, out);
15044                 }
15045         }
15046
15047         si.m_globals = prepareGlobals(last_in_loc, last_out_loc);
15048 }
15049
15050 /**
15051  *
15052  **/
15053 Utils::Variable* VaryingComponentsTest::prepareVarying(const Utils::Type& basic_type, const descriptor& desc,
15054                                                                                                            const GLchar* interpolation, Utils::ShaderInterface& si,
15055                                                                                                            Utils::Shader::STAGES stage, Utils::Variable::STORAGE storage)
15056 {
15057         const GLuint       array_length   = getArrayLength();
15058         const GLuint       component_size = basic_type.GetSize();
15059         const std::string& name                   = prepareName(desc.m_name, desc.m_location, desc.m_component, stage, storage);
15060         const GLuint       offset                 = desc.m_component * component_size;
15061         const std::string& qual                   = prepareQualifiers(desc.m_location_str, desc.m_component_str, interpolation);
15062         const GLuint       size                   = desc.m_n_rows * component_size;
15063         const Utils::Type& type                   = Utils::Type::GetType(basic_type.m_basic_type, 1 /* n_columns */, desc.m_n_rows);
15064         Utils::Variable*   var                    = 0;
15065
15066         if (Utils::Variable::VARYING_INPUT == storage)
15067         {
15068                 var = si.Input(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15069                                            desc.m_location /* expected_location */, type, /* built_in_type */
15070                                            GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15071                                            offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15072         }
15073         else
15074         {
15075                 var = si.Output(name.c_str(), qual.c_str() /* qualifiers */, desc.m_component /* expected_componenet */,
15076                                                 desc.m_location /* expected_location */, type, /* built_in_type */
15077                                                 GL_FALSE /* normalized */, array_length /* n_array_elements */, 0u /* stride */,
15078                                                 offset /* offset */, (GLvoid*)&m_data[offset] /* data */, size /* data_size */);
15079         }
15080
15081         return var;
15082 }
15083
15084 void VaryingComponentsTest::descriptor::assign(glw::GLint component, const glw::GLchar* component_str,
15085                                                                                            glw::GLint location, const glw::GLchar* location_str, glw::GLuint n_rows,
15086                                                                                            const glw::GLchar* name)
15087 {
15088         m_component             = component;
15089         m_component_str = component_str;
15090         m_location              = location;
15091         m_location_str  = location_str;
15092         m_n_rows                = n_rows;
15093         m_name                  = name;
15094 }
15095
15096 VaryingComponentsTest::testCase::testCase(COMPONENTS_LAYOUT layout, Utils::Type::TYPES type)
15097         : m_layout(layout), m_type(type)
15098 {
15099 }
15100
15101 /** Constructor
15102  *
15103  * @param context Test framework context
15104  **/
15105 VaryingArrayComponentsTest::VaryingArrayComponentsTest(deqp::Context& context)
15106         : VaryingComponentsTest(context, "varying_array_components",
15107                                                         "Test verifies that input and output components are respected for arrays")
15108 {
15109 }
15110
15111 /** Get length of arrays that should be used during test
15112  *
15113  * @return 4u
15114  **/
15115 GLuint VaryingArrayComponentsTest::getArrayLength()
15116 {
15117         return 4u;
15118 }
15119
15120 /** Constructor
15121  *
15122  * @param context Test framework context
15123  **/
15124 VaryingExceedingComponentsTest::VaryingExceedingComponentsTest(deqp::Context& context)
15125         : NegativeTestBase(context, "varying_exceeding_components",
15126                                            "Test verifies that compiler reports error when component qualifier exceed limits")
15127 {
15128 }
15129
15130 /** Source for given test case and stage
15131  *
15132  * @param test_case_index Index of test case
15133  * @param stage           Shader stage
15134  *
15135  * @return Shader source
15136  **/
15137 std::string VaryingExceedingComponentsTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15138 {
15139         static const GLchar* var_definition_arr =
15140                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15141         static const GLchar* var_definition_one =
15142                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15143         static const GLchar* input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
15144                                                                                  "    {\n"
15145                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15146                                                                                  "    }\n";
15147         static const GLchar* input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
15148                                                                                  "    {\n"
15149                                                                                  "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15150                                                                                  "    }\n";
15151         static const GLchar* output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
15152                                                                                   "    if (vec4(0) == result)\n"
15153                                                                                   "    {\n"
15154                                                                                   "        gokuINDEX[0] = TYPE(1);\n"
15155                                                                                   "    }\n";
15156         static const GLchar* output_use_one = "    gokuINDEX = TYPE(0);\n"
15157                                                                                   "    if (vec4(0) == result)\n"
15158                                                                                   "    {\n"
15159                                                                                   "        gokuINDEX = TYPE(1);\n"
15160                                                                                   "    }\n";
15161         static const GLchar* fs = "#version 430 core\n"
15162                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15163                                                           "\n"
15164                                                           "in  vec4 gs_fs;\n"
15165                                                           "out vec4 fs_out;\n"
15166                                                           "\n"
15167                                                           "void main()\n"
15168                                                           "{\n"
15169                                                           "    fs_out = gs_fs;\n"
15170                                                           "}\n"
15171                                                           "\n";
15172         static const GLchar* fs_tested = "#version 430 core\n"
15173                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15174                                                                          "\n"
15175                                                                          "VAR_DEFINITION"
15176                                                                          "\n"
15177                                                                          "in  vec4 gs_fs;\n"
15178                                                                          "out vec4 fs_out;\n"
15179                                                                          "\n"
15180                                                                          "void main()\n"
15181                                                                          "{\n"
15182                                                                          "    vec4 result = gs_fs;\n"
15183                                                                          "\n"
15184                                                                          "VARIABLE_USE"
15185                                                                          "\n"
15186                                                                          "    fs_out += result;\n"
15187                                                                          "}\n"
15188                                                                          "\n";
15189         static const GLchar* gs = "#version 430 core\n"
15190                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15191                                                           "\n"
15192                                                           "layout(points)                           in;\n"
15193                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15194                                                           "\n"
15195                                                           "in  vec4 tes_gs[];\n"
15196                                                           "out vec4 gs_fs;\n"
15197                                                           "\n"
15198                                                           "void main()\n"
15199                                                           "{\n"
15200                                                           "    gs_fs = tes_gs[0];\n"
15201                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15202                                                           "    EmitVertex();\n"
15203                                                           "    gs_fs = tes_gs[0];\n"
15204                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15205                                                           "    EmitVertex();\n"
15206                                                           "    gs_fs = tes_gs[0];\n"
15207                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15208                                                           "    EmitVertex();\n"
15209                                                           "    gs_fs = tes_gs[0];\n"
15210                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15211                                                           "    EmitVertex();\n"
15212                                                           "}\n"
15213                                                           "\n";
15214         static const GLchar* gs_tested = "#version 430 core\n"
15215                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15216                                                                          "\n"
15217                                                                          "layout(points)                           in;\n"
15218                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15219                                                                          "\n"
15220                                                                          "VAR_DEFINITION"
15221                                                                          "\n"
15222                                                                          "in  vec4 tes_gs[];\n"
15223                                                                          "out vec4 gs_fs;\n"
15224                                                                          "\n"
15225                                                                          "void main()\n"
15226                                                                          "{\n"
15227                                                                          "    vec4 result = tes_gs[0];\n"
15228                                                                          "\n"
15229                                                                          "VARIABLE_USE"
15230                                                                          "\n"
15231                                                                          "    gs_fs = result;\n"
15232                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15233                                                                          "    EmitVertex();\n"
15234                                                                          "    gs_fs = result;\n"
15235                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15236                                                                          "    EmitVertex();\n"
15237                                                                          "    gs_fs = result;\n"
15238                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15239                                                                          "    EmitVertex();\n"
15240                                                                          "    gs_fs = result;\n"
15241                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15242                                                                          "    EmitVertex();\n"
15243                                                                          "}\n"
15244                                                                          "\n";
15245         static const GLchar* tcs = "#version 430 core\n"
15246                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15247                                                            "\n"
15248                                                            "layout(vertices = 1) out;\n"
15249                                                            "\n"
15250                                                            "in  vec4 vs_tcs[];\n"
15251                                                            "out vec4 tcs_tes[];\n"
15252                                                            "\n"
15253                                                            "void main()\n"
15254                                                            "{\n"
15255                                                            "\n"
15256                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15257                                                            "\n"
15258                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15259                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15260                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15261                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15262                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15263                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15264                                                            "}\n"
15265                                                            "\n";
15266         static const GLchar* tcs_tested = "#version 430 core\n"
15267                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15268                                                                           "\n"
15269                                                                           "layout(vertices = 1) out;\n"
15270                                                                           "\n"
15271                                                                           "VAR_DEFINITION"
15272                                                                           "\n"
15273                                                                           "in  vec4 vs_tcs[];\n"
15274                                                                           "out vec4 tcs_tes[];\n"
15275                                                                           "\n"
15276                                                                           "void main()\n"
15277                                                                           "{\n"
15278                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15279                                                                           "\n"
15280                                                                           "VARIABLE_USE"
15281                                                                           "\n"
15282                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15283                                                                           "\n"
15284                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15285                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15286                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15287                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15288                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15289                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15290                                                                           "}\n"
15291                                                                           "\n";
15292         static const GLchar* tes = "#version 430 core\n"
15293                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15294                                                            "\n"
15295                                                            "layout(isolines, point_mode) in;\n"
15296                                                            "\n"
15297                                                            "in  vec4 tcs_tes[];\n"
15298                                                            "out vec4 tes_gs;\n"
15299                                                            "\n"
15300                                                            "void main()\n"
15301                                                            "{\n"
15302                                                            "    tes_gs = tcs_tes[0];\n"
15303                                                            "}\n"
15304                                                            "\n";
15305         static const GLchar* tes_tested = "#version 430 core\n"
15306                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15307                                                                           "\n"
15308                                                                           "layout(isolines, point_mode) in;\n"
15309                                                                           "\n"
15310                                                                           "VAR_DEFINITION"
15311                                                                           "\n"
15312                                                                           "in  vec4 tcs_tes[];\n"
15313                                                                           "out vec4 tes_gs;\n"
15314                                                                           "\n"
15315                                                                           "void main()\n"
15316                                                                           "{\n"
15317                                                                           "    vec4 result = tcs_tes[0];\n"
15318                                                                           "\n"
15319                                                                           "VARIABLE_USE"
15320                                                                           "\n"
15321                                                                           "    tes_gs += result;\n"
15322                                                                           "}\n"
15323                                                                           "\n";
15324         static const GLchar* vs = "#version 430 core\n"
15325                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15326                                                           "\n"
15327                                                           "in  vec4 in_vs;\n"
15328                                                           "out vec4 vs_tcs;\n"
15329                                                           "\n"
15330                                                           "void main()\n"
15331                                                           "{\n"
15332                                                           "    vs_tcs = in_vs;\n"
15333                                                           "}\n"
15334                                                           "\n";
15335         static const GLchar* vs_tested = "#version 430 core\n"
15336                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15337                                                                          "\n"
15338                                                                          "VAR_DEFINITION"
15339                                                                          "\n"
15340                                                                          "in  vec4 in_vs;\n"
15341                                                                          "out vec4 vs_tcs;\n"
15342                                                                          "\n"
15343                                                                          "void main()\n"
15344                                                                          "{\n"
15345                                                                          "    vec4 result = in_vs;\n"
15346                                                                          "\n"
15347                                                                          "VARIABLE_USE"
15348                                                                          "\n"
15349                                                                          "    vs_tcs += result;\n"
15350                                                                          "}\n"
15351                                                                          "\n";
15352
15353         std::string source;
15354         testCase&   test_case = m_test_cases[test_case_index];
15355
15356         if (test_case.m_stage == stage)
15357         {
15358                 const GLchar* array = "";
15359                 GLchar            buffer[16];
15360                 const GLchar* var_definition = 0;
15361                 const GLchar* direction          = "in ";
15362                 const GLchar* index                      = "";
15363                 size_t            position               = 0;
15364                 size_t            temp;
15365                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15366                 const GLchar* var_use   = 0;
15367
15368                 if (false == test_case.m_is_input)
15369                 {
15370                         direction = "out";
15371
15372                         if (false == test_case.m_is_array)
15373                         {
15374                                 var_definition = var_definition_one;
15375                                 var_use            = output_use_one;
15376                         }
15377                         else
15378                         {
15379                                 var_definition = var_definition_arr;
15380                                 var_use            = output_use_arr;
15381                         }
15382                 }
15383                 else
15384                 {
15385                         if (false == test_case.m_is_array)
15386                         {
15387                                 var_definition = var_definition_one;
15388                                 var_use            = input_use_one;
15389                         }
15390                         else
15391                         {
15392                                 var_definition = var_definition_arr;
15393                                 var_use            = input_use_arr;
15394                         }
15395                 }
15396
15397                 sprintf(buffer, "%d", test_case.m_component);
15398
15399                 switch (stage)
15400                 {
15401                 case Utils::Shader::FRAGMENT:
15402                         source = fs_tested;
15403                         break;
15404                 case Utils::Shader::GEOMETRY:
15405                         source = gs_tested;
15406                         array  = "[]";
15407                         index  = "[0]";
15408                         break;
15409                 case Utils::Shader::TESS_CTRL:
15410                         source = tcs_tested;
15411                         array  = "[]";
15412                         index  = "[gl_InvocationID]";
15413                         break;
15414                 case Utils::Shader::TESS_EVAL:
15415                         source = tes_tested;
15416                         array  = "[]";
15417                         index  = "[0]";
15418                         break;
15419                 case Utils::Shader::VERTEX:
15420                         source = vs_tested;
15421                         break;
15422                 default:
15423                         TCU_FAIL("Invalid enum");
15424                 }
15425
15426                 temp = position;
15427                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15428                 position = temp;
15429                 Utils::replaceToken("COMPONENT", position, buffer, source);
15430                 Utils::replaceToken("DIRECTION", position, direction, source);
15431                 Utils::replaceToken("ARRAY", position, array, source);
15432                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15433
15434                 Utils::replaceAllTokens("TYPE", type_name, source);
15435                 Utils::replaceAllTokens("INDEX", index, source);
15436         }
15437         else
15438         {
15439                 switch (stage)
15440                 {
15441                 case Utils::Shader::FRAGMENT:
15442                         source = fs;
15443                         break;
15444                 case Utils::Shader::GEOMETRY:
15445                         source = gs;
15446                         break;
15447                 case Utils::Shader::TESS_CTRL:
15448                         source = tcs;
15449                         break;
15450                 case Utils::Shader::TESS_EVAL:
15451                         source = tes;
15452                         break;
15453                 case Utils::Shader::VERTEX:
15454                         source = vs;
15455                         break;
15456                 default:
15457                         TCU_FAIL("Invalid enum");
15458                 }
15459         }
15460
15461         return source;
15462 }
15463
15464 /** Get description of test case
15465  *
15466  * @param test_case_index Index of test case
15467  *
15468  * @return Test case description
15469  **/
15470 std::string VaryingExceedingComponentsTest::getTestCaseName(GLuint test_case_index)
15471 {
15472         std::stringstream stream;
15473         testCase&                 test_case = m_test_cases[test_case_index];
15474
15475         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15476                    << " type: " << test_case.m_type.GetGLSLTypeName();
15477
15478         if (true == test_case.m_is_array)
15479         {
15480                 stream << "[1]";
15481         }
15482
15483         stream << ", direction: ";
15484
15485         if (true == test_case.m_is_input)
15486         {
15487                 stream << "input";
15488         }
15489         else
15490         {
15491                 stream << "output";
15492         }
15493
15494         stream << ", component: " << test_case.m_component;
15495
15496         return stream.str();
15497 }
15498
15499 /** Get number of test cases
15500  *
15501  * @return Number of test cases
15502  **/
15503 GLuint VaryingExceedingComponentsTest::getTestCaseNumber()
15504 {
15505         return static_cast<GLuint>(m_test_cases.size());
15506 }
15507
15508 /** Selects if "compute" stage is relevant for test
15509  *
15510  * @param ignored
15511  *
15512  * @return false
15513  **/
15514 bool VaryingExceedingComponentsTest::isComputeRelevant(GLuint /* test_case_index */)
15515 {
15516         return false;
15517 }
15518
15519 /** Prepare all test cases
15520  *
15521  **/
15522 void VaryingExceedingComponentsTest::testInit()
15523 {
15524         static const GLuint n_components_per_location = 4;
15525         const GLuint            n_types                                   = getTypesNumber();
15526
15527         for (GLuint i = 0; i < n_types; ++i)
15528         {
15529                 const Utils::Type& type                          = getType(i);
15530                 const GLuint       n_req_components  = type.m_n_rows;
15531                 const GLuint       valid_component   = n_components_per_location - n_req_components;
15532                 const GLuint       invalid_component = valid_component + 1;
15533
15534                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15535                 {
15536                         if (Utils::Shader::COMPUTE == stage)
15537                         {
15538                                 continue;
15539                         }
15540
15541                         /* Component cannot be used for matrices */
15542                         if (1 != type.m_n_columns)
15543                         {
15544                                 continue;
15545                         }
15546
15547                         testCase test_case_in_arr  = { invalid_component, true, true, (Utils::Shader::STAGES)stage, type };
15548                         testCase test_case_in_one  = { invalid_component, true, false, (Utils::Shader::STAGES)stage, type };
15549                         testCase test_case_out_arr = { invalid_component, false, true, (Utils::Shader::STAGES)stage, type };
15550                         testCase test_case_out_one = { invalid_component, false, false, (Utils::Shader::STAGES)stage, type };
15551
15552                         m_test_cases.push_back(test_case_in_arr);
15553                         m_test_cases.push_back(test_case_in_one);
15554
15555                         if (Utils::Shader::FRAGMENT != stage)
15556                         {
15557                                 m_test_cases.push_back(test_case_out_arr);
15558                                 m_test_cases.push_back(test_case_out_one);
15559                         }
15560                 }
15561         }
15562 }
15563
15564 /** Constructor
15565  *
15566  * @param context Test framework context
15567  **/
15568 VaryingComponentWithoutLocationTest::VaryingComponentWithoutLocationTest(deqp::Context& context)
15569         : NegativeTestBase(context, "varying_component_without_location",
15570                                            "Test verifies that compiler reports error when component qualifier is used without location")
15571 {
15572 }
15573
15574 /** Source for given test case and stage
15575  *
15576  * @param test_case_index Index of test case
15577  * @param stage           Shader stage
15578  *
15579  * @return Shader source
15580  **/
15581 std::string VaryingComponentWithoutLocationTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15582 {
15583         static const GLchar* var_definition = "layout (component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15584         static const GLchar* input_use          = "    if (TYPE(0) == gokuINDEX)\n"
15585                                                                          "    {\n"
15586                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
15587                                                                          "    }\n";
15588         static const GLchar* output_use = "    gokuINDEX = TYPE(0);\n"
15589                                                                           "    if (vec4(0) == result)\n"
15590                                                                           "    {\n"
15591                                                                           "        gokuINDEX = TYPE(1);\n"
15592                                                                           "    }\n";
15593         static const GLchar* fs = "#version 430 core\n"
15594                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15595                                                           "\n"
15596                                                           "in  vec4 gs_fs;\n"
15597                                                           "out vec4 fs_out;\n"
15598                                                           "\n"
15599                                                           "void main()\n"
15600                                                           "{\n"
15601                                                           "    fs_out = gs_fs;\n"
15602                                                           "}\n"
15603                                                           "\n";
15604         static const GLchar* fs_tested = "#version 430 core\n"
15605                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15606                                                                          "\n"
15607                                                                          "VAR_DEFINITION"
15608                                                                          "\n"
15609                                                                          "in  vec4 gs_fs;\n"
15610                                                                          "out vec4 fs_out;\n"
15611                                                                          "\n"
15612                                                                          "void main()\n"
15613                                                                          "{\n"
15614                                                                          "    vec4 result = gs_fs;\n"
15615                                                                          "\n"
15616                                                                          "VARIABLE_USE"
15617                                                                          "\n"
15618                                                                          "    fs_out += result;\n"
15619                                                                          "}\n"
15620                                                                          "\n";
15621         static const GLchar* gs = "#version 430 core\n"
15622                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15623                                                           "\n"
15624                                                           "layout(points)                           in;\n"
15625                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
15626                                                           "\n"
15627                                                           "in  vec4 tes_gs[];\n"
15628                                                           "out vec4 gs_fs;\n"
15629                                                           "\n"
15630                                                           "void main()\n"
15631                                                           "{\n"
15632                                                           "    gs_fs = tes_gs[0];\n"
15633                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15634                                                           "    EmitVertex();\n"
15635                                                           "    gs_fs = tes_gs[0];\n"
15636                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15637                                                           "    EmitVertex();\n"
15638                                                           "    gs_fs = tes_gs[0];\n"
15639                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
15640                                                           "    EmitVertex();\n"
15641                                                           "    gs_fs = tes_gs[0];\n"
15642                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
15643                                                           "    EmitVertex();\n"
15644                                                           "}\n"
15645                                                           "\n";
15646         static const GLchar* gs_tested = "#version 430 core\n"
15647                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15648                                                                          "\n"
15649                                                                          "layout(points)                           in;\n"
15650                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
15651                                                                          "\n"
15652                                                                          "VAR_DEFINITION"
15653                                                                          "\n"
15654                                                                          "in  vec4 tes_gs[];\n"
15655                                                                          "out vec4 gs_fs;\n"
15656                                                                          "\n"
15657                                                                          "void main()\n"
15658                                                                          "{\n"
15659                                                                          "    vec4 result = tes_gs[0];\n"
15660                                                                          "\n"
15661                                                                          "VARIABLE_USE"
15662                                                                          "\n"
15663                                                                          "    gs_fs = result;\n"
15664                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
15665                                                                          "    EmitVertex();\n"
15666                                                                          "    gs_fs = result;\n"
15667                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
15668                                                                          "    EmitVertex();\n"
15669                                                                          "    gs_fs = result;\n"
15670                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
15671                                                                          "    EmitVertex();\n"
15672                                                                          "    gs_fs = result;\n"
15673                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
15674                                                                          "    EmitVertex();\n"
15675                                                                          "}\n"
15676                                                                          "\n";
15677         static const GLchar* tcs = "#version 430 core\n"
15678                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15679                                                            "\n"
15680                                                            "layout(vertices = 1) out;\n"
15681                                                            "\n"
15682                                                            "in  vec4 vs_tcs[];\n"
15683                                                            "out vec4 tcs_tes[];\n"
15684                                                            "\n"
15685                                                            "void main()\n"
15686                                                            "{\n"
15687                                                            "\n"
15688                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
15689                                                            "\n"
15690                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
15691                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
15692                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
15693                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
15694                                                            "    gl_TessLevelInner[0] = 1.0;\n"
15695                                                            "    gl_TessLevelInner[1] = 1.0;\n"
15696                                                            "}\n"
15697                                                            "\n";
15698         static const GLchar* tcs_tested = "#version 430 core\n"
15699                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15700                                                                           "\n"
15701                                                                           "layout(vertices = 1) out;\n"
15702                                                                           "\n"
15703                                                                           "VAR_DEFINITION"
15704                                                                           "\n"
15705                                                                           "in  vec4 vs_tcs[];\n"
15706                                                                           "out vec4 tcs_tes[];\n"
15707                                                                           "\n"
15708                                                                           "void main()\n"
15709                                                                           "{\n"
15710                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
15711                                                                           "\n"
15712                                                                           "VARIABLE_USE"
15713                                                                           "\n"
15714                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
15715                                                                           "\n"
15716                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
15717                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
15718                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
15719                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
15720                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
15721                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
15722                                                                           "}\n"
15723                                                                           "\n";
15724         static const GLchar* tes = "#version 430 core\n"
15725                                                            "#extension GL_ARB_enhanced_layouts : require\n"
15726                                                            "\n"
15727                                                            "layout(isolines, point_mode) in;\n"
15728                                                            "\n"
15729                                                            "in  vec4 tcs_tes[];\n"
15730                                                            "out vec4 tes_gs;\n"
15731                                                            "\n"
15732                                                            "void main()\n"
15733                                                            "{\n"
15734                                                            "    tes_gs = tcs_tes[0];\n"
15735                                                            "}\n"
15736                                                            "\n";
15737         static const GLchar* tes_tested = "#version 430 core\n"
15738                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15739                                                                           "\n"
15740                                                                           "layout(isolines, point_mode) in;\n"
15741                                                                           "\n"
15742                                                                           "VAR_DEFINITION"
15743                                                                           "\n"
15744                                                                           "in  vec4 tcs_tes[];\n"
15745                                                                           "out vec4 tes_gs;\n"
15746                                                                           "\n"
15747                                                                           "void main()\n"
15748                                                                           "{\n"
15749                                                                           "    vec4 result = tcs_tes[0];\n"
15750                                                                           "\n"
15751                                                                           "VARIABLE_USE"
15752                                                                           "\n"
15753                                                                           "    tes_gs += result;\n"
15754                                                                           "}\n"
15755                                                                           "\n";
15756         static const GLchar* vs = "#version 430 core\n"
15757                                                           "#extension GL_ARB_enhanced_layouts : require\n"
15758                                                           "\n"
15759                                                           "in  vec4 in_vs;\n"
15760                                                           "out vec4 vs_tcs;\n"
15761                                                           "\n"
15762                                                           "void main()\n"
15763                                                           "{\n"
15764                                                           "    vs_tcs = in_vs;\n"
15765                                                           "}\n"
15766                                                           "\n";
15767         static const GLchar* vs_tested = "#version 430 core\n"
15768                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
15769                                                                          "\n"
15770                                                                          "VAR_DEFINITION"
15771                                                                          "\n"
15772                                                                          "in  vec4 in_vs;\n"
15773                                                                          "out vec4 vs_tcs;\n"
15774                                                                          "\n"
15775                                                                          "void main()\n"
15776                                                                          "{\n"
15777                                                                          "    vec4 result = in_vs;\n"
15778                                                                          "\n"
15779                                                                          "VARIABLE_USE"
15780                                                                          "\n"
15781                                                                          "    vs_tcs += result;\n"
15782                                                                          "}\n"
15783                                                                          "\n";
15784
15785         std::string source;
15786         testCase&   test_case = m_test_cases[test_case_index];
15787
15788         if (test_case.m_stage == stage)
15789         {
15790                 const GLchar* array = "";
15791                 GLchar            buffer[16];
15792                 const GLchar* direction = "in ";
15793                 const GLchar* index             = "";
15794                 size_t            position  = 0;
15795                 size_t            temp;
15796                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
15797                 const GLchar* var_use   = input_use;
15798
15799                 if (false == test_case.m_is_input)
15800                 {
15801                         direction = "out";
15802                         var_use   = output_use;
15803                 }
15804
15805                 sprintf(buffer, "%d", test_case.m_component);
15806
15807                 switch (stage)
15808                 {
15809                 case Utils::Shader::FRAGMENT:
15810                         source = fs_tested;
15811                         break;
15812                 case Utils::Shader::GEOMETRY:
15813                         source = gs_tested;
15814                         array  = "[]";
15815                         index  = "[0]";
15816                         break;
15817                 case Utils::Shader::TESS_CTRL:
15818                         source = tcs_tested;
15819                         array  = "[]";
15820                         index  = "[gl_InvocationID]";
15821                         break;
15822                 case Utils::Shader::TESS_EVAL:
15823                         source = tes_tested;
15824                         array  = "[]";
15825                         index  = "[0]";
15826                         break;
15827                 case Utils::Shader::VERTEX:
15828                         source = vs_tested;
15829                         break;
15830                 default:
15831                         TCU_FAIL("Invalid enum");
15832                 }
15833
15834                 temp = position;
15835                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
15836                 position = temp;
15837                 Utils::replaceToken("COMPONENT", position, buffer, source);
15838                 Utils::replaceToken("DIRECTION", position, direction, source);
15839                 Utils::replaceToken("ARRAY", position, array, source);
15840                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
15841
15842                 Utils::replaceAllTokens("TYPE", type_name, source);
15843                 Utils::replaceAllTokens("INDEX", index, source);
15844         }
15845         else
15846         {
15847                 switch (stage)
15848                 {
15849                 case Utils::Shader::FRAGMENT:
15850                         source = fs;
15851                         break;
15852                 case Utils::Shader::GEOMETRY:
15853                         source = gs;
15854                         break;
15855                 case Utils::Shader::TESS_CTRL:
15856                         source = tcs;
15857                         break;
15858                 case Utils::Shader::TESS_EVAL:
15859                         source = tes;
15860                         break;
15861                 case Utils::Shader::VERTEX:
15862                         source = vs;
15863                         break;
15864                 default:
15865                         TCU_FAIL("Invalid enum");
15866                 }
15867         }
15868
15869         return source;
15870 }
15871
15872 /** Get description of test case
15873  *
15874  * @param test_case_index Index of test case
15875  *
15876  * @return Test case description
15877  **/
15878 std::string VaryingComponentWithoutLocationTest::getTestCaseName(GLuint test_case_index)
15879 {
15880         std::stringstream stream;
15881         testCase&                 test_case = m_test_cases[test_case_index];
15882
15883         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
15884                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", direction: ";
15885
15886         if (true == test_case.m_is_input)
15887         {
15888                 stream << "input";
15889         }
15890         else
15891         {
15892                 stream << "output";
15893         }
15894
15895         stream << ", component: " << test_case.m_component;
15896
15897         return stream.str();
15898 }
15899
15900 /** Get number of test cases
15901  *
15902  * @return Number of test cases
15903  **/
15904 GLuint VaryingComponentWithoutLocationTest::getTestCaseNumber()
15905 {
15906         return static_cast<GLuint>(m_test_cases.size());
15907 }
15908
15909 /** Selects if "compute" stage is relevant for test
15910  *
15911  * @param ignored
15912  *
15913  * @return false
15914  **/
15915 bool VaryingComponentWithoutLocationTest::isComputeRelevant(GLuint /* test_case_index */)
15916 {
15917         return false;
15918 }
15919
15920 /** Prepare all test cases
15921  *
15922  **/
15923 void VaryingComponentWithoutLocationTest::testInit()
15924 {
15925         static const GLuint n_components_per_location = 4;
15926         const GLuint            n_types                                   = getTypesNumber();
15927
15928         for (GLuint i = 0; i < n_types; ++i)
15929         {
15930                 const Utils::Type& type                         = getType(i);
15931                 const GLuint       n_req_components = type.m_n_rows;
15932                 const GLuint       valid_component  = n_components_per_location - n_req_components;
15933
15934                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
15935                 {
15936                         if (Utils::Shader::COMPUTE == stage)
15937                         {
15938                                 continue;
15939                         }
15940
15941                         /* Component cannot be used for matrices */
15942                         if (1 != type.m_n_columns)
15943                         {
15944                                 continue;
15945                         }
15946
15947                         testCase test_case_in  = { valid_component, true, (Utils::Shader::STAGES)stage, type };
15948                         testCase test_case_out = { valid_component, false, (Utils::Shader::STAGES)stage, type };
15949
15950                         m_test_cases.push_back(test_case_in);
15951
15952                         if (Utils::Shader::FRAGMENT != stage)
15953                         {
15954                                 m_test_cases.push_back(test_case_out);
15955                         }
15956                 }
15957         }
15958 }
15959
15960 /** Constructor
15961  *
15962  * @param context Test framework context
15963  **/
15964 VaryingComponentOfInvalidTypeTest::VaryingComponentOfInvalidTypeTest(deqp::Context& context)
15965         : NegativeTestBase(context, "varying_component_of_invalid_type",
15966                                            "Test verifies that compiler reports error when component qualifier is used for invalid type")
15967 {
15968 }
15969
15970 /** Source for given test case and stage
15971  *
15972  * @param test_case_index Index of test case
15973  * @param stage           Shader stage
15974  *
15975  * @return Shader source
15976  **/
15977 std::string VaryingComponentOfInvalidTypeTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
15978 {
15979         static const GLchar* block_definition_arr = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15980                                                                                                 "    TYPE member;\n"
15981                                                                                                 "} gokuARRAY[1];\n";
15982         static const GLchar* block_definition_one = "layout (location = 1, component = COMPONENT) flat DIRECTION Goku {\n"
15983                                                                                                 "    TYPE member;\n"
15984                                                                                                 "} gokuARRAY;\n";
15985         static const GLchar* matrix_definition_arr =
15986                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY[1];\n";
15987         static const GLchar* matrix_definition_one =
15988                 "layout (location = 1, component = COMPONENT) flat DIRECTION TYPE gokuARRAY;\n";
15989         static const GLchar* struct_definition_arr =
15990                 "struct Goku {\n"
15991                 "    TYPE member;\n"
15992                 "};\n"
15993                 "\n"
15994                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY[1];\n";
15995         static const GLchar* struct_definition_one =
15996                 "struct Goku {\n"
15997                 "    TYPE member;\n"
15998                 "};\n"
15999                 "\n"
16000                 "layout (location = 1, component = COMPONENT) flat DIRECTION Goku gokuARRAY;\n";
16001         static const GLchar* matrix_input_use_arr = "    if (TYPE(0) == gokuINDEX[0])\n"
16002                                                                                                 "    {\n"
16003                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16004                                                                                                 "    }\n";
16005         static const GLchar* matrix_input_use_one = "    if (TYPE(0) == gokuINDEX)\n"
16006                                                                                                 "    {\n"
16007                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16008                                                                                                 "    }\n";
16009         static const GLchar* matrix_output_use_arr = "    gokuINDEX[0] = TYPE(0);\n"
16010                                                                                                  "    if (vec4(0) == result)\n"
16011                                                                                                  "    {\n"
16012                                                                                                  "        gokuINDEX[0] = TYPE(1);\n"
16013                                                                                                  "    }\n";
16014         static const GLchar* matrix_output_use_one = "    gokuINDEX = TYPE(0);\n"
16015                                                                                                  "    if (vec4(0) == result)\n"
16016                                                                                                  "    {\n"
16017                                                                                                  "        gokuINDEX = TYPE(1);\n"
16018                                                                                                  "    }\n";
16019         static const GLchar* member_input_use_arr = "    if (TYPE(0) == gokuINDEX[0].member)\n"
16020                                                                                                 "    {\n"
16021                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16022                                                                                                 "    }\n";
16023         static const GLchar* member_input_use_one = "    if (TYPE(0) == gokuINDEX.member)\n"
16024                                                                                                 "    {\n"
16025                                                                                                 "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16026                                                                                                 "    }\n";
16027         static const GLchar* member_output_use_arr = "    gokuINDEX[0].member = TYPE(0);\n"
16028                                                                                                  "    if (vec4(0) == result)\n"
16029                                                                                                  "    {\n"
16030                                                                                                  "        gokuINDEX[0].member = TYPE(1);\n"
16031                                                                                                  "    }\n";
16032         static const GLchar* member_output_use_one = "    gokuINDEX.member = TYPE(0);\n"
16033                                                                                                  "    if (vec4(0) == result)\n"
16034                                                                                                  "    {\n"
16035                                                                                                  "        gokuINDEX.member = TYPE(1);\n"
16036                                                                                                  "    }\n";
16037         static const GLchar* fs = "#version 430 core\n"
16038                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16039                                                           "\n"
16040                                                           "in  vec4 gs_fs;\n"
16041                                                           "out vec4 fs_out;\n"
16042                                                           "\n"
16043                                                           "void main()\n"
16044                                                           "{\n"
16045                                                           "    fs_out = gs_fs;\n"
16046                                                           "}\n"
16047                                                           "\n";
16048         static const GLchar* fs_tested = "#version 430 core\n"
16049                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16050                                                                          "\n"
16051                                                                          "VAR_DEFINITION"
16052                                                                          "\n"
16053                                                                          "in  vec4 gs_fs;\n"
16054                                                                          "out vec4 fs_out;\n"
16055                                                                          "\n"
16056                                                                          "void main()\n"
16057                                                                          "{\n"
16058                                                                          "    vec4 result = gs_fs;\n"
16059                                                                          "\n"
16060                                                                          "VARIABLE_USE"
16061                                                                          "\n"
16062                                                                          "    fs_out += result;\n"
16063                                                                          "}\n"
16064                                                                          "\n";
16065         static const GLchar* gs = "#version 430 core\n"
16066                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16067                                                           "\n"
16068                                                           "layout(points)                           in;\n"
16069                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16070                                                           "\n"
16071                                                           "in  vec4 tes_gs[];\n"
16072                                                           "out vec4 gs_fs;\n"
16073                                                           "\n"
16074                                                           "void main()\n"
16075                                                           "{\n"
16076                                                           "    gs_fs = tes_gs[0];\n"
16077                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16078                                                           "    EmitVertex();\n"
16079                                                           "    gs_fs = tes_gs[0];\n"
16080                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16081                                                           "    EmitVertex();\n"
16082                                                           "    gs_fs = tes_gs[0];\n"
16083                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16084                                                           "    EmitVertex();\n"
16085                                                           "    gs_fs = tes_gs[0];\n"
16086                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16087                                                           "    EmitVertex();\n"
16088                                                           "}\n"
16089                                                           "\n";
16090         static const GLchar* gs_tested = "#version 430 core\n"
16091                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16092                                                                          "\n"
16093                                                                          "layout(points)                           in;\n"
16094                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16095                                                                          "\n"
16096                                                                          "VAR_DEFINITION"
16097                                                                          "\n"
16098                                                                          "in  vec4 tes_gs[];\n"
16099                                                                          "out vec4 gs_fs;\n"
16100                                                                          "\n"
16101                                                                          "void main()\n"
16102                                                                          "{\n"
16103                                                                          "    vec4 result = tes_gs[0];\n"
16104                                                                          "\n"
16105                                                                          "VARIABLE_USE"
16106                                                                          "\n"
16107                                                                          "    gs_fs = result;\n"
16108                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16109                                                                          "    EmitVertex();\n"
16110                                                                          "    gs_fs = result;\n"
16111                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16112                                                                          "    EmitVertex();\n"
16113                                                                          "    gs_fs = result;\n"
16114                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16115                                                                          "    EmitVertex();\n"
16116                                                                          "    gs_fs = result;\n"
16117                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16118                                                                          "    EmitVertex();\n"
16119                                                                          "}\n"
16120                                                                          "\n";
16121         static const GLchar* tcs = "#version 430 core\n"
16122                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16123                                                            "\n"
16124                                                            "layout(vertices = 1) out;\n"
16125                                                            "\n"
16126                                                            "in  vec4 vs_tcs[];\n"
16127                                                            "out vec4 tcs_tes[];\n"
16128                                                            "\n"
16129                                                            "void main()\n"
16130                                                            "{\n"
16131                                                            "\n"
16132                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16133                                                            "\n"
16134                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16135                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16136                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16137                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16138                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16139                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16140                                                            "}\n"
16141                                                            "\n";
16142         static const GLchar* tcs_tested = "#version 430 core\n"
16143                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16144                                                                           "\n"
16145                                                                           "layout(vertices = 1) out;\n"
16146                                                                           "\n"
16147                                                                           "VAR_DEFINITION"
16148                                                                           "\n"
16149                                                                           "in  vec4 vs_tcs[];\n"
16150                                                                           "out vec4 tcs_tes[];\n"
16151                                                                           "\n"
16152                                                                           "void main()\n"
16153                                                                           "{\n"
16154                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16155                                                                           "\n"
16156                                                                           "VARIABLE_USE"
16157                                                                           "\n"
16158                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16159                                                                           "\n"
16160                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16161                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16162                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16163                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16164                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16165                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16166                                                                           "}\n"
16167                                                                           "\n";
16168         static const GLchar* tes = "#version 430 core\n"
16169                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16170                                                            "\n"
16171                                                            "layout(isolines, point_mode) in;\n"
16172                                                            "\n"
16173                                                            "in  vec4 tcs_tes[];\n"
16174                                                            "out vec4 tes_gs;\n"
16175                                                            "\n"
16176                                                            "void main()\n"
16177                                                            "{\n"
16178                                                            "    tes_gs = tcs_tes[0];\n"
16179                                                            "}\n"
16180                                                            "\n";
16181         static const GLchar* tes_tested = "#version 430 core\n"
16182                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16183                                                                           "\n"
16184                                                                           "layout(isolines, point_mode) in;\n"
16185                                                                           "\n"
16186                                                                           "VAR_DEFINITION"
16187                                                                           "\n"
16188                                                                           "in  vec4 tcs_tes[];\n"
16189                                                                           "out vec4 tes_gs;\n"
16190                                                                           "\n"
16191                                                                           "void main()\n"
16192                                                                           "{\n"
16193                                                                           "    vec4 result = tcs_tes[0];\n"
16194                                                                           "\n"
16195                                                                           "VARIABLE_USE"
16196                                                                           "\n"
16197                                                                           "    tes_gs += result;\n"
16198                                                                           "}\n"
16199                                                                           "\n";
16200         static const GLchar* vs = "#version 430 core\n"
16201                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16202                                                           "\n"
16203                                                           "in  vec4 in_vs;\n"
16204                                                           "out vec4 vs_tcs;\n"
16205                                                           "\n"
16206                                                           "void main()\n"
16207                                                           "{\n"
16208                                                           "    vs_tcs = in_vs;\n"
16209                                                           "}\n"
16210                                                           "\n";
16211         static const GLchar* vs_tested = "#version 430 core\n"
16212                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16213                                                                          "\n"
16214                                                                          "VAR_DEFINITION"
16215                                                                          "\n"
16216                                                                          "in  vec4 in_vs;\n"
16217                                                                          "out vec4 vs_tcs;\n"
16218                                                                          "\n"
16219                                                                          "void main()\n"
16220                                                                          "{\n"
16221                                                                          "    vec4 result = in_vs;\n"
16222                                                                          "\n"
16223                                                                          "VARIABLE_USE"
16224                                                                          "\n"
16225                                                                          "    vs_tcs += result;\n"
16226                                                                          "}\n"
16227                                                                          "\n";
16228
16229         std::string source;
16230         testCase&   test_case = m_test_cases[test_case_index];
16231
16232         if (test_case.m_stage == stage)
16233         {
16234                 const GLchar* array = "";
16235                 GLchar            buffer[16];
16236                 const GLchar* var_definition = 0;
16237                 const GLchar* direction          = "in ";
16238                 const GLchar* index                      = "";
16239                 size_t            position               = 0;
16240                 size_t            temp;
16241                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16242                 const GLchar* var_use   = 0;
16243
16244                 if (false == test_case.m_is_input)
16245                 {
16246                         direction = "out";
16247
16248                         if (false == test_case.m_is_array)
16249                         {
16250                                 switch (test_case.m_case)
16251                                 {
16252                                 case BLOCK:
16253                                         var_definition = block_definition_one;
16254                                         var_use            = member_output_use_one;
16255                                         break;
16256                                 case MATRIX:
16257                                         var_definition = matrix_definition_one;
16258                                         var_use            = matrix_output_use_one;
16259                                         break;
16260                                 case STRUCT:
16261                                         var_definition = struct_definition_one;
16262                                         var_use            = member_output_use_one;
16263                                         break;
16264                                 default:
16265                                         TCU_FAIL("Invalid enum");
16266                                 }
16267                         }
16268                         else
16269                         {
16270                                 switch (test_case.m_case)
16271                                 {
16272                                 case BLOCK:
16273                                         var_definition = block_definition_arr;
16274                                         var_use            = member_output_use_arr;
16275                                         break;
16276                                 case MATRIX:
16277                                         var_definition = matrix_definition_arr;
16278                                         var_use            = matrix_output_use_arr;
16279                                         break;
16280                                 case STRUCT:
16281                                         var_definition = struct_definition_arr;
16282                                         var_use            = member_output_use_arr;
16283                                         break;
16284                                 default:
16285                                         TCU_FAIL("Invalid enum");
16286                                 }
16287                         }
16288                 }
16289                 else
16290                 {
16291                         if (false == test_case.m_is_array)
16292                         {
16293                                 switch (test_case.m_case)
16294                                 {
16295                                 case BLOCK:
16296                                         var_definition = block_definition_one;
16297                                         var_use            = member_input_use_one;
16298                                         break;
16299                                 case MATRIX:
16300                                         var_definition = matrix_definition_one;
16301                                         var_use            = matrix_input_use_one;
16302                                         break;
16303                                 case STRUCT:
16304                                         var_definition = struct_definition_one;
16305                                         var_use            = member_input_use_one;
16306                                         break;
16307                                 default:
16308                                         TCU_FAIL("Invalid enum");
16309                                 }
16310                         }
16311                         else
16312                         {
16313                                 switch (test_case.m_case)
16314                                 {
16315                                 case BLOCK:
16316                                         var_definition = block_definition_arr;
16317                                         var_use            = member_input_use_arr;
16318                                         break;
16319                                 case MATRIX:
16320                                         var_definition = matrix_definition_arr;
16321                                         var_use            = matrix_input_use_arr;
16322                                         break;
16323                                 case STRUCT:
16324                                         var_definition = struct_definition_arr;
16325                                         var_use            = member_input_use_arr;
16326                                         break;
16327                                 default:
16328                                         TCU_FAIL("Invalid enum");
16329                                 }
16330                         }
16331                 }
16332
16333                 sprintf(buffer, "%d", test_case.m_component);
16334
16335                 switch (stage)
16336                 {
16337                 case Utils::Shader::FRAGMENT:
16338                         source = fs_tested;
16339                         break;
16340                 case Utils::Shader::GEOMETRY:
16341                         source = gs_tested;
16342                         array  = "[]";
16343                         index  = "[0]";
16344                         break;
16345                 case Utils::Shader::TESS_CTRL:
16346                         source = tcs_tested;
16347                         array  = "[]";
16348                         index  = "[gl_InvocationID]";
16349                         break;
16350                 case Utils::Shader::TESS_EVAL:
16351                         source = tes_tested;
16352                         array  = "[]";
16353                         index  = "[0]";
16354                         break;
16355                 case Utils::Shader::VERTEX:
16356                         source = vs_tested;
16357                         break;
16358                 default:
16359                         TCU_FAIL("Invalid enum");
16360                 }
16361
16362                 temp = position;
16363                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16364                 position = temp;
16365                 Utils::replaceToken("COMPONENT", position, buffer, source);
16366                 Utils::replaceToken("DIRECTION", position, direction, source);
16367                 Utils::replaceToken("ARRAY", position, array, source);
16368                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16369
16370                 Utils::replaceAllTokens("TYPE", type_name, source);
16371                 Utils::replaceAllTokens("INDEX", index, source);
16372         }
16373         else
16374         {
16375                 switch (stage)
16376                 {
16377                 case Utils::Shader::FRAGMENT:
16378                         source = fs;
16379                         break;
16380                 case Utils::Shader::GEOMETRY:
16381                         source = gs;
16382                         break;
16383                 case Utils::Shader::TESS_CTRL:
16384                         source = tcs;
16385                         break;
16386                 case Utils::Shader::TESS_EVAL:
16387                         source = tes;
16388                         break;
16389                 case Utils::Shader::VERTEX:
16390                         source = vs;
16391                         break;
16392                 default:
16393                         TCU_FAIL("Invalid enum");
16394                 }
16395         }
16396
16397         return source;
16398 }
16399
16400 /** Get description of test case
16401  *
16402  * @param test_case_index Index of test case
16403  *
16404  * @return Test case description
16405  **/
16406 std::string VaryingComponentOfInvalidTypeTest::getTestCaseName(GLuint test_case_index)
16407 {
16408         std::stringstream stream;
16409         testCase&                 test_case = m_test_cases[test_case_index];
16410
16411         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16412                    << " type: " << test_case.m_type.GetGLSLTypeName();
16413
16414         if (true == test_case.m_is_array)
16415         {
16416                 stream << "[1]";
16417         }
16418
16419         stream << ", direction: ";
16420
16421         if (true == test_case.m_is_input)
16422         {
16423                 stream << "input";
16424         }
16425         else
16426         {
16427                 stream << "output";
16428         }
16429
16430         stream << ", component: " << test_case.m_component;
16431
16432         return stream.str();
16433 }
16434
16435 /** Get number of test cases
16436  *
16437  * @return Number of test cases
16438  **/
16439 GLuint VaryingComponentOfInvalidTypeTest::getTestCaseNumber()
16440 {
16441         return static_cast<GLuint>(m_test_cases.size());
16442 }
16443
16444 /** Selects if "compute" stage is relevant for test
16445  *
16446  * @param ignored
16447  *
16448  * @return false
16449  **/
16450 bool VaryingComponentOfInvalidTypeTest::isComputeRelevant(GLuint /* test_case_index */)
16451 {
16452         return false;
16453 }
16454
16455 /** Prepare all test cases
16456  *
16457  **/
16458 void VaryingComponentOfInvalidTypeTest::testInit()
16459 {
16460         static const GLuint n_components_per_location = 4;
16461         const GLuint            n_types                                   = getTypesNumber();
16462
16463         for (GLuint i = 0; i < n_types; ++i)
16464         {
16465                 const Utils::Type& type                         = getType(i);
16466                 const GLuint       n_req_components = type.m_n_rows;
16467                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16468
16469                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16470                 {
16471                         if (Utils::Shader::COMPUTE == stage)
16472                         {
16473                                 continue;
16474                         }
16475
16476                         /* Use different CASE for matrices */
16477                         if (1 != type.m_n_columns)
16478                         {
16479                                 testCase test_case_in_arr = { MATRIX, valid_component, true, true, (Utils::Shader::STAGES)stage, type };
16480                                 testCase test_case_in_one = {
16481                                         MATRIX, valid_component, false, true, (Utils::Shader::STAGES)stage, type
16482                                 };
16483                                 testCase test_case_out_arr = {
16484                                         MATRIX, valid_component, true, false, (Utils::Shader::STAGES)stage, type
16485                                 };
16486                                 testCase test_case_out_one = {
16487                                         MATRIX, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16488                                 };
16489
16490                                 m_test_cases.push_back(test_case_in_arr);
16491                                 m_test_cases.push_back(test_case_in_one);
16492
16493                                 if (Utils::Shader::FRAGMENT != stage)
16494                                 {
16495                                         m_test_cases.push_back(test_case_out_arr);
16496                                         m_test_cases.push_back(test_case_out_one);
16497                                 }
16498                         }
16499                         else
16500                         {
16501                                 for (GLuint c = BLOCK; c < MAX_CASES; ++c)
16502                                 {
16503                                         testCase test_case_in_arr = { (CASES)c, valid_component, true, true, (Utils::Shader::STAGES)stage,
16504                                                                                                   type };
16505                                         testCase test_case_in_one = { (CASES)c, valid_component, false, true, (Utils::Shader::STAGES)stage,
16506                                                                                                   type };
16507                                         testCase test_case_out_arr = { (CASES)c, valid_component, true, false, (Utils::Shader::STAGES)stage,
16508                                                                                                    type };
16509                                         testCase test_case_out_one = {
16510                                                 (CASES)c, valid_component, false, false, (Utils::Shader::STAGES)stage, type
16511                                         };
16512
16513                                         if (Utils::Shader::VERTEX != stage)
16514                                         {
16515                                                 m_test_cases.push_back(test_case_in_arr);
16516                                                 m_test_cases.push_back(test_case_in_one);
16517                                         }
16518
16519                                         if (Utils::Shader::FRAGMENT != stage)
16520                                         {
16521                                                 m_test_cases.push_back(test_case_out_arr);
16522                                                 m_test_cases.push_back(test_case_out_one);
16523                                         }
16524                                 }
16525                         }
16526                 }
16527         }
16528 }
16529
16530 /** Constructor
16531  *
16532  * @param context Test framework context
16533  **/
16534 InputComponentAliasingTest::InputComponentAliasingTest(deqp::Context& context)
16535         : NegativeTestBase(context, "input_component_aliasing",
16536                                            "Test verifies that compiler reports component aliasing as error")
16537 {
16538 }
16539
16540 /** Source for given test case and stage
16541  *
16542  * @param test_case_index Index of test case
16543  * @param stage           Shader stage
16544  *
16545  * @return Shader source
16546  **/
16547 std::string InputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16548 {
16549         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) FLAT in TYPE gohanARRAY;\n"
16550                                                                                   "layout (location = 1, component = COMPONENT) FLAT in TYPE gotenARRAY;\n";
16551         static const GLchar* test_one = "    if (TYPE(0) == gohanINDEX)\n"
16552                                                                         "    {\n"
16553                                                                         "        result += vec4(1, 0.5, 0.25, 0.125);\n"
16554                                                                         "    }\n";
16555         static const GLchar* test_both = "    if (TYPE(0) == gohanINDEX)\n"
16556                                                                          "    {\n"
16557                                                                          "        result = vec4(goten.xxxx);\n"
16558                                                                          "    }\n";
16559         static const GLchar* fs = "#version 430 core\n"
16560                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16561                                                           "\n"
16562                                                           "in  vec4 gs_fs;\n"
16563                                                           "out vec4 fs_out;\n"
16564                                                           "\n"
16565                                                           "void main()\n"
16566                                                           "{\n"
16567                                                           "    fs_out = gs_fs;\n"
16568                                                           "}\n"
16569                                                           "\n";
16570         static const GLchar* fs_tested = "#version 430 core\n"
16571                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16572                                                                          "\n"
16573                                                                          "VAR_DEFINITION"
16574                                                                          "\n"
16575                                                                          "in  vec4 gs_fs;\n"
16576                                                                          "out vec4 fs_out;\n"
16577                                                                          "\n"
16578                                                                          "void main()\n"
16579                                                                          "{\n"
16580                                                                          "    vec4 result = gs_fs;\n"
16581                                                                          "\n"
16582                                                                          "VARIABLE_USE"
16583                                                                          "\n"
16584                                                                          "    fs_out += result;\n"
16585                                                                          "}\n"
16586                                                                          "\n";
16587         static const GLchar* gs = "#version 430 core\n"
16588                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16589                                                           "\n"
16590                                                           "layout(points)                           in;\n"
16591                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
16592                                                           "\n"
16593                                                           "in  vec4 tes_gs[];\n"
16594                                                           "out vec4 gs_fs;\n"
16595                                                           "\n"
16596                                                           "void main()\n"
16597                                                           "{\n"
16598                                                           "    gs_fs = tes_gs[0];\n"
16599                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16600                                                           "    EmitVertex();\n"
16601                                                           "    gs_fs = tes_gs[0];\n"
16602                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16603                                                           "    EmitVertex();\n"
16604                                                           "    gs_fs = tes_gs[0];\n"
16605                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
16606                                                           "    EmitVertex();\n"
16607                                                           "    gs_fs = tes_gs[0];\n"
16608                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
16609                                                           "    EmitVertex();\n"
16610                                                           "}\n"
16611                                                           "\n";
16612         static const GLchar* gs_tested = "#version 430 core\n"
16613                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16614                                                                          "\n"
16615                                                                          "layout(points)                           in;\n"
16616                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
16617                                                                          "\n"
16618                                                                          "VAR_DEFINITION"
16619                                                                          "\n"
16620                                                                          "in  vec4 tes_gs[];\n"
16621                                                                          "out vec4 gs_fs;\n"
16622                                                                          "\n"
16623                                                                          "void main()\n"
16624                                                                          "{\n"
16625                                                                          "    vec4 result = tes_gs[0];\n"
16626                                                                          "\n"
16627                                                                          "VARIABLE_USE"
16628                                                                          "\n"
16629                                                                          "    gs_fs = result;\n"
16630                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
16631                                                                          "    EmitVertex();\n"
16632                                                                          "    gs_fs = result;\n"
16633                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
16634                                                                          "    EmitVertex();\n"
16635                                                                          "    gs_fs = result;\n"
16636                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
16637                                                                          "    EmitVertex();\n"
16638                                                                          "    gs_fs = result;\n"
16639                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
16640                                                                          "    EmitVertex();\n"
16641                                                                          "}\n"
16642                                                                          "\n";
16643         static const GLchar* tcs = "#version 430 core\n"
16644                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16645                                                            "\n"
16646                                                            "layout(vertices = 1) out;\n"
16647                                                            "\n"
16648                                                            "in  vec4 vs_tcs[];\n"
16649                                                            "out vec4 tcs_tes[];\n"
16650                                                            "\n"
16651                                                            "void main()\n"
16652                                                            "{\n"
16653                                                            "\n"
16654                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
16655                                                            "\n"
16656                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
16657                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
16658                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
16659                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
16660                                                            "    gl_TessLevelInner[0] = 1.0;\n"
16661                                                            "    gl_TessLevelInner[1] = 1.0;\n"
16662                                                            "}\n"
16663                                                            "\n";
16664         static const GLchar* tcs_tested = "#version 430 core\n"
16665                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16666                                                                           "\n"
16667                                                                           "layout(vertices = 1) out;\n"
16668                                                                           "\n"
16669                                                                           "VAR_DEFINITION"
16670                                                                           "\n"
16671                                                                           "in  vec4 vs_tcs[];\n"
16672                                                                           "out vec4 tcs_tes[];\n"
16673                                                                           "\n"
16674                                                                           "void main()\n"
16675                                                                           "{\n"
16676                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
16677                                                                           "\n"
16678                                                                           "VARIABLE_USE"
16679                                                                           "\n"
16680                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
16681                                                                           "\n"
16682                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
16683                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
16684                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
16685                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
16686                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
16687                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
16688                                                                           "}\n"
16689                                                                           "\n";
16690         static const GLchar* tes = "#version 430 core\n"
16691                                                            "#extension GL_ARB_enhanced_layouts : require\n"
16692                                                            "\n"
16693                                                            "layout(isolines, point_mode) in;\n"
16694                                                            "\n"
16695                                                            "in  vec4 tcs_tes[];\n"
16696                                                            "out vec4 tes_gs;\n"
16697                                                            "\n"
16698                                                            "void main()\n"
16699                                                            "{\n"
16700                                                            "    tes_gs = tcs_tes[0];\n"
16701                                                            "}\n"
16702                                                            "\n";
16703         static const GLchar* tes_tested = "#version 430 core\n"
16704                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16705                                                                           "\n"
16706                                                                           "layout(isolines, point_mode) in;\n"
16707                                                                           "\n"
16708                                                                           "VAR_DEFINITION"
16709                                                                           "\n"
16710                                                                           "in  vec4 tcs_tes[];\n"
16711                                                                           "out vec4 tes_gs;\n"
16712                                                                           "\n"
16713                                                                           "void main()\n"
16714                                                                           "{\n"
16715                                                                           "    vec4 result = tcs_tes[0];\n"
16716                                                                           "\n"
16717                                                                           "VARIABLE_USE"
16718                                                                           "\n"
16719                                                                           "    tes_gs += result;\n"
16720                                                                           "}\n"
16721                                                                           "\n";
16722         static const GLchar* vs = "#version 430 core\n"
16723                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16724                                                           "\n"
16725                                                           "in  vec4 in_vs;\n"
16726                                                           "out vec4 vs_tcs;\n"
16727                                                           "\n"
16728                                                           "void main()\n"
16729                                                           "{\n"
16730                                                           "    vs_tcs = in_vs;\n"
16731                                                           "}\n"
16732                                                           "\n";
16733         static const GLchar* vs_tested = "#version 430 core\n"
16734                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16735                                                                          "\n"
16736                                                                          "VAR_DEFINITION"
16737                                                                          "\n"
16738                                                                          "in  vec4 in_vs;\n"
16739                                                                          "out vec4 vs_tcs;\n"
16740                                                                          "\n"
16741                                                                          "void main()\n"
16742                                                                          "{\n"
16743                                                                          "    vec4 result = in_vs;\n"
16744                                                                          "\n"
16745                                                                          "VARIABLE_USE"
16746                                                                          "\n"
16747                                                                          "    vs_tcs += result;\n"
16748                                                                          "}\n"
16749                                                                          "\n";
16750
16751         std::string source;
16752         testCase&   test_case = m_test_cases[test_case_index];
16753
16754         if (test_case.m_stage == stage)
16755         {
16756                 const GLchar* array = "";
16757                 GLchar            buffer_gohan[16];
16758                 GLchar            buffer_goten[16];
16759                 const GLchar* flat                = "";
16760                 const GLchar* index               = "";
16761                 const bool      is_flat_req = isFlatRequired(stage, test_case.m_type, Utils::Variable::VARYING_INPUT);
16762                 size_t            position      = 0;
16763                 size_t            temp;
16764                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
16765                 const GLchar* var_use   = test_one;
16766
16767                 if (true == test_case.m_use_both)
16768                 {
16769                         var_use = test_both;
16770                 }
16771
16772                 if (true == is_flat_req)
16773                 {
16774                         flat = "flat";
16775                 }
16776
16777                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
16778                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
16779
16780                 switch (stage)
16781                 {
16782                 case Utils::Shader::FRAGMENT:
16783                         source = fs_tested;
16784                         break;
16785                 case Utils::Shader::GEOMETRY:
16786                         source = gs_tested;
16787                         array  = "[]";
16788                         index  = "[0]";
16789                         break;
16790                 case Utils::Shader::TESS_CTRL:
16791                         source = tcs_tested;
16792                         array  = "[]";
16793                         index  = "[gl_InvocationID]";
16794                         break;
16795                 case Utils::Shader::TESS_EVAL:
16796                         source = tes_tested;
16797                         array  = "[]";
16798                         index  = "[0]";
16799                         break;
16800                 case Utils::Shader::VERTEX:
16801                         source = vs_tested;
16802                         break;
16803                 default:
16804                         TCU_FAIL("Invalid enum");
16805                 }
16806
16807                 temp = position;
16808                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
16809                 position = temp;
16810                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
16811                 Utils::replaceToken("ARRAY", position, array, source);
16812                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
16813                 Utils::replaceToken("ARRAY", position, array, source);
16814                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
16815
16816                 Utils::replaceAllTokens("FLAT", flat, source);
16817                 Utils::replaceAllTokens("TYPE", type_name, source);
16818                 Utils::replaceAllTokens("INDEX", index, source);
16819         }
16820         else
16821         {
16822                 switch (stage)
16823                 {
16824                 case Utils::Shader::FRAGMENT:
16825                         source = fs;
16826                         break;
16827                 case Utils::Shader::GEOMETRY:
16828                         source = gs;
16829                         break;
16830                 case Utils::Shader::TESS_CTRL:
16831                         source = tcs;
16832                         break;
16833                 case Utils::Shader::TESS_EVAL:
16834                         source = tes;
16835                         break;
16836                 case Utils::Shader::VERTEX:
16837                         source = vs;
16838                         break;
16839                 default:
16840                         TCU_FAIL("Invalid enum");
16841                 }
16842         }
16843
16844         return source;
16845 }
16846
16847 /** Get description of test case
16848  *
16849  * @param test_case_index Index of test case
16850  *
16851  * @return Test case description
16852  **/
16853 std::string InputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
16854 {
16855         std::stringstream stream;
16856         testCase&                 test_case = m_test_cases[test_case_index];
16857
16858         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
16859                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
16860                    << " & " << test_case.m_component_goten;
16861
16862         return stream.str();
16863 }
16864
16865 /** Get number of test cases
16866  *
16867  * @return Number of test cases
16868  **/
16869 GLuint InputComponentAliasingTest::getTestCaseNumber()
16870 {
16871         return static_cast<GLuint>(m_test_cases.size());
16872 }
16873
16874 /** Selects if "compute" stage is relevant for test
16875  *
16876  * @param ignored
16877  *
16878  * @return false
16879  **/
16880 bool InputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
16881 {
16882         return false;
16883 }
16884
16885 /** Selects if compilation failure is expected result
16886  *
16887  * @param test_case_index Index of test case
16888  *
16889  * @return false for VS that use only single variable, true otherwise
16890  **/
16891 bool InputComponentAliasingTest::isFailureExpected(GLuint test_case_index)
16892 {
16893         testCase& test_case = m_test_cases[test_case_index];
16894
16895         return !((Utils::Shader::VERTEX == test_case.m_stage) && (false == test_case.m_use_both));
16896 }
16897
16898 /** Prepare all test cases
16899  *
16900  **/
16901 void InputComponentAliasingTest::testInit()
16902 {
16903         static const GLuint n_components_per_location = 4;
16904         const GLuint            n_types                                   = getTypesNumber();
16905
16906         for (GLuint i = 0; i < n_types; ++i)
16907         {
16908                 const Utils::Type& type                         = getType(i);
16909                 const GLuint       n_req_components = type.m_n_rows;
16910                 const GLuint       valid_component  = n_components_per_location - n_req_components;
16911
16912                 /* Skip matrices */
16913                 if (1 != type.m_n_columns)
16914                 {
16915                         continue;
16916                 }
16917
16918                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
16919                 {
16920                         if (Utils::Shader::COMPUTE == stage)
16921                         {
16922                                 continue;
16923                         }
16924
16925                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
16926                         {
16927                                 const GLint first_aliasing = gohan - n_req_components + 1;
16928                                 const GLint last_aliasing  = gohan + n_req_components - 1;
16929
16930                                 const GLuint goten_start = std::max(0, first_aliasing);
16931                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
16932
16933                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
16934                                 {
16935                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type, false };
16936
16937                                         m_test_cases.push_back(test_case);
16938
16939                                         if (Utils::Shader::VERTEX == test_case.m_stage)
16940                                         {
16941                                                 test_case.m_use_both = true;
16942
16943                                                 m_test_cases.push_back(test_case);
16944                                         }
16945                                 }
16946                         }
16947                 }
16948         }
16949 }
16950
16951 /** Constructor
16952  *
16953  * @param context Test framework context
16954  **/
16955 OutputComponentAliasingTest::OutputComponentAliasingTest(deqp::Context& context)
16956         : NegativeTestBase(context, "output_component_aliasing",
16957                                            "Test verifies that compiler reports component aliasing as error")
16958 {
16959 }
16960
16961 /** Source for given test case and stage
16962  *
16963  * @param test_case_index Index of test case
16964  * @param stage           Shader stage
16965  *
16966  * @return Shader source
16967  **/
16968 std::string OutputComponentAliasingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
16969 {
16970         static const GLchar* var_definition = "layout (location = 1, component = COMPONENT) flat out TYPE gohanARRAY;\n"
16971                                                                                   "layout (location = 1, component = COMPONENT) flat out TYPE gotenARRAY;\n";
16972         static const GLchar* l_test = "    gohanINDEX = TYPE(1);\n"
16973                                                                   "    gotenINDEX = TYPE(0);\n";
16974         static const GLchar* fs = "#version 430 core\n"
16975                                                           "#extension GL_ARB_enhanced_layouts : require\n"
16976                                                           "\n"
16977                                                           "in  vec4 gs_fs;\n"
16978                                                           "out vec4 fs_out;\n"
16979                                                           "\n"
16980                                                           "void main()\n"
16981                                                           "{\n"
16982                                                           "    fs_out = gs_fs;\n"
16983                                                           "}\n"
16984                                                           "\n";
16985         static const GLchar* fs_tested = "#version 430 core\n"
16986                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
16987                                                                          "\n"
16988                                                                          "VAR_DEFINITION"
16989                                                                          "\n"
16990                                                                          "in  vec4 gs_fs;\n"
16991                                                                          "out vec4 fs_out;\n"
16992                                                                          "\n"
16993                                                                          "void main()\n"
16994                                                                          "{\n"
16995                                                                          "    vec4 result = gs_fs;\n"
16996                                                                          "\n"
16997                                                                          "VARIABLE_USE"
16998                                                                          "\n"
16999                                                                          "    fs_out += result;\n"
17000                                                                          "}\n"
17001                                                                          "\n";
17002         static const GLchar* gs = "#version 430 core\n"
17003                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17004                                                           "\n"
17005                                                           "layout(points)                           in;\n"
17006                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17007                                                           "\n"
17008                                                           "in  vec4 tes_gs[];\n"
17009                                                           "out vec4 gs_fs;\n"
17010                                                           "\n"
17011                                                           "void main()\n"
17012                                                           "{\n"
17013                                                           "    gs_fs = tes_gs[0];\n"
17014                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17015                                                           "    EmitVertex();\n"
17016                                                           "    gs_fs = tes_gs[0];\n"
17017                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17018                                                           "    EmitVertex();\n"
17019                                                           "    gs_fs = tes_gs[0];\n"
17020                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17021                                                           "    EmitVertex();\n"
17022                                                           "    gs_fs = tes_gs[0];\n"
17023                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17024                                                           "    EmitVertex();\n"
17025                                                           "}\n"
17026                                                           "\n";
17027         static const GLchar* gs_tested = "#version 430 core\n"
17028                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17029                                                                          "\n"
17030                                                                          "layout(points)                           in;\n"
17031                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17032                                                                          "\n"
17033                                                                          "VAR_DEFINITION"
17034                                                                          "\n"
17035                                                                          "in  vec4 tes_gs[];\n"
17036                                                                          "out vec4 gs_fs;\n"
17037                                                                          "\n"
17038                                                                          "void main()\n"
17039                                                                          "{\n"
17040                                                                          "    vec4 result = tes_gs[0];\n"
17041                                                                          "\n"
17042                                                                          "VARIABLE_USE"
17043                                                                          "\n"
17044                                                                          "    gs_fs = result;\n"
17045                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17046                                                                          "    EmitVertex();\n"
17047                                                                          "    gs_fs = result;\n"
17048                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17049                                                                          "    EmitVertex();\n"
17050                                                                          "    gs_fs = result;\n"
17051                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17052                                                                          "    EmitVertex();\n"
17053                                                                          "    gs_fs = result;\n"
17054                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17055                                                                          "    EmitVertex();\n"
17056                                                                          "}\n"
17057                                                                          "\n";
17058         static const GLchar* tcs = "#version 430 core\n"
17059                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17060                                                            "\n"
17061                                                            "layout(vertices = 1) out;\n"
17062                                                            "\n"
17063                                                            "in  vec4 vs_tcs[];\n"
17064                                                            "out vec4 tcs_tes[];\n"
17065                                                            "\n"
17066                                                            "void main()\n"
17067                                                            "{\n"
17068                                                            "\n"
17069                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17070                                                            "\n"
17071                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17072                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17073                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17074                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17075                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17076                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17077                                                            "}\n"
17078                                                            "\n";
17079         static const GLchar* tcs_tested = "#version 430 core\n"
17080                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17081                                                                           "\n"
17082                                                                           "layout(vertices = 1) out;\n"
17083                                                                           "\n"
17084                                                                           "VAR_DEFINITION"
17085                                                                           "\n"
17086                                                                           "in  vec4 vs_tcs[];\n"
17087                                                                           "out vec4 tcs_tes[];\n"
17088                                                                           "\n"
17089                                                                           "void main()\n"
17090                                                                           "{\n"
17091                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17092                                                                           "\n"
17093                                                                           "VARIABLE_USE"
17094                                                                           "\n"
17095                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17096                                                                           "\n"
17097                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17098                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17099                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17100                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17101                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17102                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17103                                                                           "}\n"
17104                                                                           "\n";
17105         static const GLchar* tes = "#version 430 core\n"
17106                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17107                                                            "\n"
17108                                                            "layout(isolines, point_mode) in;\n"
17109                                                            "\n"
17110                                                            "in  vec4 tcs_tes[];\n"
17111                                                            "out vec4 tes_gs;\n"
17112                                                            "\n"
17113                                                            "void main()\n"
17114                                                            "{\n"
17115                                                            "    tes_gs = tcs_tes[0];\n"
17116                                                            "}\n"
17117                                                            "\n";
17118         static const GLchar* tes_tested = "#version 430 core\n"
17119                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17120                                                                           "\n"
17121                                                                           "layout(isolines, point_mode) in;\n"
17122                                                                           "\n"
17123                                                                           "VAR_DEFINITION"
17124                                                                           "\n"
17125                                                                           "in  vec4 tcs_tes[];\n"
17126                                                                           "out vec4 tes_gs;\n"
17127                                                                           "\n"
17128                                                                           "void main()\n"
17129                                                                           "{\n"
17130                                                                           "    vec4 result = tcs_tes[0];\n"
17131                                                                           "\n"
17132                                                                           "VARIABLE_USE"
17133                                                                           "\n"
17134                                                                           "    tes_gs += result;\n"
17135                                                                           "}\n"
17136                                                                           "\n";
17137         static const GLchar* vs = "#version 430 core\n"
17138                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17139                                                           "\n"
17140                                                           "in  vec4 in_vs;\n"
17141                                                           "out vec4 vs_tcs;\n"
17142                                                           "\n"
17143                                                           "void main()\n"
17144                                                           "{\n"
17145                                                           "    vs_tcs = in_vs;\n"
17146                                                           "}\n"
17147                                                           "\n";
17148         static const GLchar* vs_tested = "#version 430 core\n"
17149                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17150                                                                          "\n"
17151                                                                          "VAR_DEFINITION"
17152                                                                          "\n"
17153                                                                          "in  vec4 in_vs;\n"
17154                                                                          "out vec4 vs_tcs;\n"
17155                                                                          "\n"
17156                                                                          "void main()\n"
17157                                                                          "{\n"
17158                                                                          "    vec4 result = in_vs;\n"
17159                                                                          "\n"
17160                                                                          "VARIABLE_USE"
17161                                                                          "\n"
17162                                                                          "    vs_tcs += result;\n"
17163                                                                          "}\n"
17164                                                                          "\n";
17165
17166         std::string source;
17167         testCase&   test_case = m_test_cases[test_case_index];
17168
17169         if (test_case.m_stage == stage)
17170         {
17171                 const GLchar* array = "";
17172                 GLchar            buffer_gohan[16];
17173                 GLchar            buffer_goten[16];
17174                 const GLchar* index     = "";
17175                 size_t            position = 0;
17176                 size_t            temp;
17177                 const GLchar* type_name = test_case.m_type.GetGLSLTypeName();
17178
17179                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17180                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17181
17182                 switch (stage)
17183                 {
17184                 case Utils::Shader::FRAGMENT:
17185                         source = fs_tested;
17186                         break;
17187                 case Utils::Shader::GEOMETRY:
17188                         source = gs_tested;
17189                         array  = "[]";
17190                         index  = "[0]";
17191                         break;
17192                 case Utils::Shader::TESS_CTRL:
17193                         source = tcs_tested;
17194                         array  = "[]";
17195                         index  = "[gl_InvocationID]";
17196                         break;
17197                 case Utils::Shader::TESS_EVAL:
17198                         source = tes_tested;
17199                         array  = "[]";
17200                         index  = "[0]";
17201                         break;
17202                 case Utils::Shader::VERTEX:
17203                         source = vs_tested;
17204                         break;
17205                 default:
17206                         TCU_FAIL("Invalid enum");
17207                 }
17208
17209                 temp = position;
17210                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17211                 position = temp;
17212                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17213                 Utils::replaceToken("ARRAY", position, array, source);
17214                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17215                 Utils::replaceToken("ARRAY", position, array, source);
17216                 Utils::replaceToken("VARIABLE_USE", position, l_test, source);
17217
17218                 Utils::replaceAllTokens("TYPE", type_name, source);
17219                 Utils::replaceAllTokens("INDEX", index, source);
17220         }
17221         else
17222         {
17223                 switch (stage)
17224                 {
17225                 case Utils::Shader::FRAGMENT:
17226                         source = fs;
17227                         break;
17228                 case Utils::Shader::GEOMETRY:
17229                         source = gs;
17230                         break;
17231                 case Utils::Shader::TESS_CTRL:
17232                         source = tcs;
17233                         break;
17234                 case Utils::Shader::TESS_EVAL:
17235                         source = tes;
17236                         break;
17237                 case Utils::Shader::VERTEX:
17238                         source = vs;
17239                         break;
17240                 default:
17241                         TCU_FAIL("Invalid enum");
17242                 }
17243         }
17244
17245         return source;
17246 }
17247
17248 /** Get description of test case
17249  *
17250  * @param test_case_index Index of test case
17251  *
17252  * @return Test case description
17253  **/
17254 std::string OutputComponentAliasingTest::getTestCaseName(GLuint test_case_index)
17255 {
17256         std::stringstream stream;
17257         testCase&                 test_case = m_test_cases[test_case_index];
17258
17259         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
17260                    << " type: " << test_case.m_type.GetGLSLTypeName() << ", components: " << test_case.m_component_gohan
17261                    << " & " << test_case.m_component_goten;
17262
17263         return stream.str();
17264 }
17265
17266 /** Get number of test cases
17267  *
17268  * @return Number of test cases
17269  **/
17270 GLuint OutputComponentAliasingTest::getTestCaseNumber()
17271 {
17272         return static_cast<GLuint>(m_test_cases.size());
17273 }
17274
17275 /** Selects if "compute" stage is relevant for test
17276  *
17277  * @param ignored
17278  *
17279  * @return false
17280  **/
17281 bool OutputComponentAliasingTest::isComputeRelevant(GLuint /* test_case_index */)
17282 {
17283         return false;
17284 }
17285
17286 /** Prepare all test cases
17287  *
17288  **/
17289 void OutputComponentAliasingTest::testInit()
17290 {
17291         static const GLuint n_components_per_location = 4;
17292         const GLuint            n_types                                   = getTypesNumber();
17293
17294         for (GLuint i = 0; i < n_types; ++i)
17295         {
17296                 const Utils::Type& type                         = getType(i);
17297                 const GLuint       n_req_components = type.m_n_rows;
17298                 const GLuint       valid_component  = n_components_per_location - n_req_components;
17299
17300                 /* Skip matrices */
17301                 if (1 != type.m_n_columns)
17302                 {
17303                         continue;
17304                 }
17305
17306                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17307                 {
17308                         if (Utils::Shader::COMPUTE == stage)
17309                         {
17310                                 continue;
17311                         }
17312
17313                         if ((Utils::Shader::FRAGMENT == stage) && (Utils::Type::Double == type.m_basic_type))
17314                         {
17315                                 continue;
17316                         }
17317
17318                         for (GLuint gohan = 0; gohan <= valid_component; ++gohan)
17319                         {
17320                                 const GLint first_aliasing = gohan - n_req_components + 1;
17321                                 const GLint last_aliasing  = gohan + n_req_components - 1;
17322
17323                                 const GLuint goten_start = std::max(0, first_aliasing);
17324                                 const GLuint goten_stop  = std::min((GLint)valid_component, last_aliasing);
17325
17326                                 for (GLuint goten = goten_start; goten <= goten_stop; ++goten)
17327                                 {
17328                                         testCase test_case = { gohan, goten, (Utils::Shader::STAGES)stage, type };
17329
17330                                         m_test_cases.push_back(test_case);
17331                                 }
17332                         }
17333                 }
17334         }
17335 }
17336
17337 /** Constructor
17338  *
17339  * @param context Test framework context
17340  **/
17341 VaryingLocationAliasingWithMixedTypesTest::VaryingLocationAliasingWithMixedTypesTest(deqp::Context& context)
17342         : NegativeTestBase(context, "varying_location_aliasing_with_mixed_types",
17343                                            "Test verifies that compiler reports error when float/int types are mixed at one location")
17344 {
17345 }
17346
17347 /** Source for given test case and stage
17348  *
17349  * @param test_case_index Index of test case
17350  * @param stage           Shader stage
17351  *
17352  * @return Shader source
17353  **/
17354 std::string VaryingLocationAliasingWithMixedTypesTest::getShaderSource(GLuint                            test_case_index,
17355                                                                                                                                            Utils::Shader::STAGES stage)
17356 {
17357         static const GLchar* var_definition =
17358                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gohanARRAY;\n"
17359                 "layout (location = 1, component = COMPONENT) FLAT DIRECTION TYPE gotenARRAY;\n";
17360         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17361                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17362                                                                          "    {\n"
17363                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17364                                                                          "    }\n";
17365         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17366                                                                           "    gotenINDEX = TYPE(1);\n"
17367                                                                           "    if (vec4(0) == result)\n"
17368                                                                           "    {\n"
17369                                                                           "        gohanINDEX = TYPE(1);\n"
17370                                                                           "        gotenINDEX = TYPE(0);\n"
17371                                                                           "    }\n";
17372         static const GLchar* fs = "#version 430 core\n"
17373                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17374                                                           "\n"
17375                                                           "in  vec4 gs_fs;\n"
17376                                                           "out vec4 fs_out;\n"
17377                                                           "\n"
17378                                                           "void main()\n"
17379                                                           "{\n"
17380                                                           "    fs_out = gs_fs;\n"
17381                                                           "}\n"
17382                                                           "\n";
17383         static const GLchar* fs_tested = "#version 430 core\n"
17384                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17385                                                                          "\n"
17386                                                                          "VAR_DEFINITION"
17387                                                                          "\n"
17388                                                                          "in  vec4 gs_fs;\n"
17389                                                                          "out vec4 fs_out;\n"
17390                                                                          "\n"
17391                                                                          "void main()\n"
17392                                                                          "{\n"
17393                                                                          "    vec4 result = gs_fs;\n"
17394                                                                          "\n"
17395                                                                          "VARIABLE_USE"
17396                                                                          "\n"
17397                                                                          "    fs_out += result;\n"
17398                                                                          "}\n"
17399                                                                          "\n";
17400         static const GLchar* gs = "#version 430 core\n"
17401                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17402                                                           "\n"
17403                                                           "layout(points)                           in;\n"
17404                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17405                                                           "\n"
17406                                                           "in  vec4 tes_gs[];\n"
17407                                                           "out vec4 gs_fs;\n"
17408                                                           "\n"
17409                                                           "void main()\n"
17410                                                           "{\n"
17411                                                           "    gs_fs = tes_gs[0];\n"
17412                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17413                                                           "    EmitVertex();\n"
17414                                                           "    gs_fs = tes_gs[0];\n"
17415                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17416                                                           "    EmitVertex();\n"
17417                                                           "    gs_fs = tes_gs[0];\n"
17418                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17419                                                           "    EmitVertex();\n"
17420                                                           "    gs_fs = tes_gs[0];\n"
17421                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17422                                                           "    EmitVertex();\n"
17423                                                           "}\n"
17424                                                           "\n";
17425         static const GLchar* gs_tested = "#version 430 core\n"
17426                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17427                                                                          "\n"
17428                                                                          "layout(points)                           in;\n"
17429                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17430                                                                          "\n"
17431                                                                          "VAR_DEFINITION"
17432                                                                          "\n"
17433                                                                          "in  vec4 tes_gs[];\n"
17434                                                                          "out vec4 gs_fs;\n"
17435                                                                          "\n"
17436                                                                          "void main()\n"
17437                                                                          "{\n"
17438                                                                          "    vec4 result = tes_gs[0];\n"
17439                                                                          "\n"
17440                                                                          "VARIABLE_USE"
17441                                                                          "\n"
17442                                                                          "    gs_fs = result;\n"
17443                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17444                                                                          "    EmitVertex();\n"
17445                                                                          "    gs_fs = result;\n"
17446                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17447                                                                          "    EmitVertex();\n"
17448                                                                          "    gs_fs = result;\n"
17449                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17450                                                                          "    EmitVertex();\n"
17451                                                                          "    gs_fs = result;\n"
17452                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17453                                                                          "    EmitVertex();\n"
17454                                                                          "}\n"
17455                                                                          "\n";
17456         static const GLchar* tcs = "#version 430 core\n"
17457                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17458                                                            "\n"
17459                                                            "layout(vertices = 1) out;\n"
17460                                                            "\n"
17461                                                            "in  vec4 vs_tcs[];\n"
17462                                                            "out vec4 tcs_tes[];\n"
17463                                                            "\n"
17464                                                            "void main()\n"
17465                                                            "{\n"
17466                                                            "\n"
17467                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17468                                                            "\n"
17469                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17470                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17471                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17472                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17473                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17474                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17475                                                            "}\n"
17476                                                            "\n";
17477         static const GLchar* tcs_tested = "#version 430 core\n"
17478                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17479                                                                           "\n"
17480                                                                           "layout(vertices = 1) out;\n"
17481                                                                           "\n"
17482                                                                           "VAR_DEFINITION"
17483                                                                           "\n"
17484                                                                           "in  vec4 vs_tcs[];\n"
17485                                                                           "out vec4 tcs_tes[];\n"
17486                                                                           "\n"
17487                                                                           "void main()\n"
17488                                                                           "{\n"
17489                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
17490                                                                           "\n"
17491                                                                           "VARIABLE_USE"
17492                                                                           "\n"
17493                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
17494                                                                           "\n"
17495                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
17496                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
17497                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
17498                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
17499                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
17500                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
17501                                                                           "}\n"
17502                                                                           "\n";
17503         static const GLchar* tes = "#version 430 core\n"
17504                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17505                                                            "\n"
17506                                                            "layout(isolines, point_mode) in;\n"
17507                                                            "\n"
17508                                                            "in  vec4 tcs_tes[];\n"
17509                                                            "out vec4 tes_gs;\n"
17510                                                            "\n"
17511                                                            "void main()\n"
17512                                                            "{\n"
17513                                                            "    tes_gs = tcs_tes[0];\n"
17514                                                            "}\n"
17515                                                            "\n";
17516         static const GLchar* tes_tested = "#version 430 core\n"
17517                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17518                                                                           "\n"
17519                                                                           "layout(isolines, point_mode) in;\n"
17520                                                                           "\n"
17521                                                                           "VAR_DEFINITION"
17522                                                                           "\n"
17523                                                                           "in  vec4 tcs_tes[];\n"
17524                                                                           "out vec4 tes_gs;\n"
17525                                                                           "\n"
17526                                                                           "void main()\n"
17527                                                                           "{\n"
17528                                                                           "    vec4 result = tcs_tes[0];\n"
17529                                                                           "\n"
17530                                                                           "VARIABLE_USE"
17531                                                                           "\n"
17532                                                                           "    tes_gs += result;\n"
17533                                                                           "}\n"
17534                                                                           "\n";
17535         static const GLchar* vs = "#version 430 core\n"
17536                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17537                                                           "\n"
17538                                                           "in  vec4 in_vs;\n"
17539                                                           "out vec4 vs_tcs;\n"
17540                                                           "\n"
17541                                                           "void main()\n"
17542                                                           "{\n"
17543                                                           "    vs_tcs = in_vs;\n"
17544                                                           "}\n"
17545                                                           "\n";
17546         static const GLchar* vs_tested = "#version 430 core\n"
17547                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17548                                                                          "\n"
17549                                                                          "VAR_DEFINITION"
17550                                                                          "\n"
17551                                                                          "in  vec4 in_vs;\n"
17552                                                                          "out vec4 vs_tcs;\n"
17553                                                                          "\n"
17554                                                                          "void main()\n"
17555                                                                          "{\n"
17556                                                                          "    vec4 result = in_vs;\n"
17557                                                                          "\n"
17558                                                                          "VARIABLE_USE"
17559                                                                          "\n"
17560                                                                          "    vs_tcs += result;\n"
17561                                                                          "}\n"
17562                                                                          "\n";
17563
17564         std::string source;
17565         testCase&   test_case = m_test_cases[test_case_index];
17566
17567         if (test_case.m_stage == stage)
17568         {
17569                 const GLchar*                    array = "";
17570                 GLchar                                   buffer_gohan[16];
17571                 GLchar                                   buffer_goten[16];
17572                 const GLchar*                    direction  = "in ";
17573                 const GLchar*                    flat_gohan = "";
17574                 const GLchar*                    flat_goten = "";
17575                 const GLchar*                    index          = "";
17576                 size_t                                   position   = 0;
17577                 size_t                                   temp;
17578                 const GLchar*                    type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
17579                 const GLchar*                    type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
17580                 Utils::Variable::STORAGE storage                 = Utils::Variable::VARYING_INPUT;
17581                 const GLchar*                    var_use                 = input_use;
17582
17583                 if (false == test_case.m_is_input)
17584                 {
17585                         direction = "out";
17586                         storage   = Utils::Variable::VARYING_OUTPUT;
17587                         var_use   = output_use;
17588                 }
17589
17590                 if (true == isFlatRequired(stage, test_case.m_type_gohan, storage))
17591                 {
17592                         flat_gohan = "flat";
17593                 }
17594
17595                 if (true == isFlatRequired(stage, test_case.m_type_goten, storage))
17596                 {
17597                         flat_goten = "flat";
17598                 }
17599
17600                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
17601                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
17602
17603                 switch (stage)
17604                 {
17605                 case Utils::Shader::FRAGMENT:
17606                         source = fs_tested;
17607                         break;
17608                 case Utils::Shader::GEOMETRY:
17609                         source = gs_tested;
17610                         array  = "[]";
17611                         index  = "[0]";
17612                         break;
17613                 case Utils::Shader::TESS_CTRL:
17614                         source = tcs_tested;
17615                         array  = "[]";
17616                         index  = "[gl_InvocationID]";
17617                         break;
17618                 case Utils::Shader::TESS_EVAL:
17619                         source = tes_tested;
17620                         array  = "[]";
17621                         index  = "[0]";
17622                         break;
17623                 case Utils::Shader::VERTEX:
17624                         source = vs_tested;
17625                         break;
17626                 default:
17627                         TCU_FAIL("Invalid enum");
17628                 }
17629
17630                 temp = position;
17631                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
17632                 position = temp;
17633                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
17634                 Utils::replaceToken("FLAT", position, flat_gohan, source);
17635                 Utils::replaceToken("DIRECTION", position, direction, source);
17636                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
17637                 Utils::replaceToken("ARRAY", position, array, source);
17638                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
17639                 Utils::replaceToken("FLAT", position, flat_goten, source);
17640                 Utils::replaceToken("DIRECTION", position, direction, source);
17641                 Utils::replaceToken("TYPE", position, type_goten_name, source);
17642                 Utils::replaceToken("ARRAY", position, array, source);
17643
17644                 temp = position;
17645                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
17646                 position = temp;
17647                 if (true == test_case.m_is_input)
17648                 {
17649                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17650                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17651                 }
17652                 else
17653                 {
17654                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17655                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17656                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
17657                         Utils::replaceToken("TYPE", position, type_goten_name, source);
17658                 }
17659
17660                 Utils::replaceAllTokens("INDEX", index, source);
17661         }
17662         else
17663         {
17664                 switch (stage)
17665                 {
17666                 case Utils::Shader::FRAGMENT:
17667                         source = fs;
17668                         break;
17669                 case Utils::Shader::GEOMETRY:
17670                         source = gs;
17671                         break;
17672                 case Utils::Shader::TESS_CTRL:
17673                         source = tcs;
17674                         break;
17675                 case Utils::Shader::TESS_EVAL:
17676                         source = tes;
17677                         break;
17678                 case Utils::Shader::VERTEX:
17679                         source = vs;
17680                         break;
17681                 default:
17682                         TCU_FAIL("Invalid enum");
17683                 }
17684         }
17685
17686         return source;
17687 }
17688
17689 /** Get description of test case
17690  *
17691  * @param test_case_index Index of test case
17692  *
17693  * @return Test case description
17694  **/
17695 std::string VaryingLocationAliasingWithMixedTypesTest::getTestCaseName(GLuint test_case_index)
17696 {
17697         std::stringstream stream;
17698         testCase&                 test_case = m_test_cases[test_case_index];
17699
17700         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
17701                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
17702                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
17703
17704         if (true == test_case.m_is_input)
17705         {
17706                 stream << "input";
17707         }
17708         else
17709         {
17710                 stream << "output";
17711         }
17712
17713         return stream.str();
17714 }
17715
17716 /** Get number of test cases
17717  *
17718  * @return Number of test cases
17719  **/
17720 GLuint VaryingLocationAliasingWithMixedTypesTest::getTestCaseNumber()
17721 {
17722         return static_cast<GLuint>(m_test_cases.size());
17723 }
17724
17725 /** Selects if "compute" stage is relevant for test
17726  *
17727  * @param ignored
17728  *
17729  * @return false
17730  **/
17731 bool VaryingLocationAliasingWithMixedTypesTest::isComputeRelevant(GLuint /* test_case_index */)
17732 {
17733         return false;
17734 }
17735
17736 /** Prepare all test cases
17737  *
17738  **/
17739 void VaryingLocationAliasingWithMixedTypesTest::testInit()
17740 {
17741         static const GLuint n_components_per_location = 4;
17742         const GLuint            n_types                                   = getTypesNumber();
17743
17744         for (GLuint i = 0; i < n_types; ++i)
17745         {
17746                 const Utils::Type& type_gohan              = getType(i);
17747                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
17748
17749                 /* Skip matrices */
17750                 if (1 != type_gohan.m_n_columns)
17751                 {
17752                         continue;
17753                 }
17754
17755                 for (GLuint j = 0; j < n_types; ++j)
17756                 {
17757                         const Utils::Type& type_goten              = getType(j);
17758                         const bool                 is_float_type_goten = isFloatType(type_goten);
17759
17760                         /* Skip matrices */
17761                         if (1 != type_goten.m_n_columns)
17762                         {
17763                                 continue;
17764                         }
17765
17766                         /* Skip valid combinations */
17767                         if (is_float_type_gohan == is_float_type_goten)
17768                         {
17769                                 continue;
17770                         }
17771
17772                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
17773                         const GLuint n_req_components_goten = type_goten.m_n_rows;
17774                         const GLuint valid_component_gohan  = n_components_per_location - n_req_components_gohan;
17775                         const GLuint valid_component_goten  = n_components_per_location - n_req_components_goten;
17776
17777                         /* Skip pairs that cannot fit into one location */
17778                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
17779                         {
17780                                 continue;
17781                         }
17782
17783                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
17784                         {
17785                                 /* Skip compute shader */
17786                                 if (Utils::Shader::COMPUTE == stage)
17787                                 {
17788                                         continue;
17789                                 }
17790
17791                                 for (GLuint gohan = 0; gohan <= valid_component_gohan; ++gohan)
17792                                 {
17793                                         const GLint first_aliasing = gohan - n_req_components_goten + 1;
17794                                         const GLint last_aliasing  = gohan + n_req_components_gohan - 1;
17795
17796                                         const GLuint goten_lower_limit = std::max(0, first_aliasing);
17797                                         const GLuint goten_upper_limit = last_aliasing + 1;
17798
17799                                         /* Compoennets before gohan */
17800                                         for (GLuint goten = 0; goten < goten_lower_limit; ++goten)
17801                                         {
17802                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17803                                                                                                   type_gohan, type_goten };
17804                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17805                                                                                                    type_gohan, type_goten };
17806
17807                                                 m_test_cases.push_back(test_case_in);
17808
17809                                                 /* Skip double outputs in fragment shader */
17810                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17811                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17812                                                 {
17813                                                         m_test_cases.push_back(test_case_out);
17814                                                 }
17815                                         }
17816
17817                                         /* Components after gohan */
17818                                         for (GLuint goten = goten_upper_limit; goten <= valid_component_goten; ++goten)
17819                                         {
17820                                                 testCase test_case_in = { gohan,          goten,         true, (Utils::Shader::STAGES)stage,
17821                                                                                                   type_gohan, type_goten };
17822                                                 testCase test_case_out = { gohan,         goten,         false, (Utils::Shader::STAGES)stage,
17823                                                                                                    type_gohan, type_goten };
17824
17825                                                 m_test_cases.push_back(test_case_in);
17826
17827                                                 /* Skip double outputs in fragment shader */
17828                                                 if ((Utils::Shader::FRAGMENT != stage) || ((Utils::Type::Double != type_gohan.m_basic_type) &&
17829                                                                                                                                    (Utils::Type::Double != type_goten.m_basic_type)))
17830                                                 {
17831                                                         m_test_cases.push_back(test_case_out);
17832                                                 }
17833                                         }
17834                                 }
17835                         }
17836                 }
17837         }
17838 }
17839
17840 /** Check if given type is float
17841  *
17842  * @param type Type in question
17843  *
17844  * @return true if tpye is float, false otherwise
17845  **/
17846 bool VaryingLocationAliasingWithMixedTypesTest::isFloatType(const Utils::Type& type)
17847 {
17848         bool is_float = false;
17849
17850         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
17851         {
17852                 is_float = true;
17853         }
17854
17855         return is_float;
17856 }
17857
17858 /** Constructor
17859  *
17860  * @param context Test framework context
17861  **/
17862 VaryingLocationAliasingWithMixedInterpolationTest::VaryingLocationAliasingWithMixedInterpolationTest(
17863         deqp::Context& context)
17864         : NegativeTestBase(
17865                   context, "varying_location_aliasing_with_mixed_interpolation",
17866                   "Test verifies that compiler reports error when interpolation qualifiers are mixed at one location")
17867 {
17868 }
17869
17870 /** Source for given test case and stage
17871  *
17872  * @param test_case_index Index of test case
17873  * @param stage           Shader stage
17874  *
17875  * @return Shader source
17876  **/
17877 std::string VaryingLocationAliasingWithMixedInterpolationTest::getShaderSource(GLuint                            test_case_index,
17878                                                                                                                                                            Utils::Shader::STAGES stage)
17879 {
17880         static const GLchar* var_definition =
17881                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
17882                 "layout (location = 1, component = COMPONENT) INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
17883         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX) &&\n"
17884                                                                          "        (TYPE(1) == gotenINDEX) )\n"
17885                                                                          "    {\n"
17886                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
17887                                                                          "    }\n";
17888         static const GLchar* output_use = "    gohanINDEX = TYPE(0);\n"
17889                                                                           "    gotenINDEX = TYPE(1);\n"
17890                                                                           "    if (vec4(0) == result)\n"
17891                                                                           "    {\n"
17892                                                                           "        gohanINDEX = TYPE(1);\n"
17893                                                                           "        gotenINDEX = TYPE(0);\n"
17894                                                                           "    }\n";
17895         static const GLchar* fs = "#version 430 core\n"
17896                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17897                                                           "\n"
17898                                                           "in  vec4 gs_fs;\n"
17899                                                           "out vec4 fs_out;\n"
17900                                                           "\n"
17901                                                           "void main()\n"
17902                                                           "{\n"
17903                                                           "    fs_out = gs_fs;\n"
17904                                                           "}\n"
17905                                                           "\n";
17906         static const GLchar* fs_tested = "#version 430 core\n"
17907                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17908                                                                          "\n"
17909                                                                          "VAR_DEFINITION"
17910                                                                          "\n"
17911                                                                          "in  vec4 gs_fs;\n"
17912                                                                          "out vec4 fs_out;\n"
17913                                                                          "\n"
17914                                                                          "void main()\n"
17915                                                                          "{\n"
17916                                                                          "    vec4 result = gs_fs;\n"
17917                                                                          "\n"
17918                                                                          "VARIABLE_USE"
17919                                                                          "\n"
17920                                                                          "    fs_out = result;\n"
17921                                                                          "}\n"
17922                                                                          "\n";
17923         static const GLchar* gs = "#version 430 core\n"
17924                                                           "#extension GL_ARB_enhanced_layouts : require\n"
17925                                                           "\n"
17926                                                           "layout(points)                           in;\n"
17927                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
17928                                                           "\n"
17929                                                           "in  vec4 tes_gs[];\n"
17930                                                           "out vec4 gs_fs;\n"
17931                                                           "\n"
17932                                                           "void main()\n"
17933                                                           "{\n"
17934                                                           "    gs_fs = tes_gs[0];\n"
17935                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17936                                                           "    EmitVertex();\n"
17937                                                           "    gs_fs = tes_gs[0];\n"
17938                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17939                                                           "    EmitVertex();\n"
17940                                                           "    gs_fs = tes_gs[0];\n"
17941                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
17942                                                           "    EmitVertex();\n"
17943                                                           "    gs_fs = tes_gs[0];\n"
17944                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
17945                                                           "    EmitVertex();\n"
17946                                                           "}\n"
17947                                                           "\n";
17948         static const GLchar* gs_tested = "#version 430 core\n"
17949                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
17950                                                                          "\n"
17951                                                                          "layout(points)                           in;\n"
17952                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
17953                                                                          "\n"
17954                                                                          "VAR_DEFINITION"
17955                                                                          "\n"
17956                                                                          "in  vec4 tes_gs[];\n"
17957                                                                          "out vec4 gs_fs;\n"
17958                                                                          "\n"
17959                                                                          "void main()\n"
17960                                                                          "{\n"
17961                                                                          "    vec4 result = tes_gs[0];\n"
17962                                                                          "\n"
17963                                                                          "VARIABLE_USE"
17964                                                                          "\n"
17965                                                                          "    gs_fs = result;\n"
17966                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
17967                                                                          "    EmitVertex();\n"
17968                                                                          "    gs_fs = result;\n"
17969                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
17970                                                                          "    EmitVertex();\n"
17971                                                                          "    gs_fs = result;\n"
17972                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
17973                                                                          "    EmitVertex();\n"
17974                                                                          "    gs_fs = result;\n"
17975                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
17976                                                                          "    EmitVertex();\n"
17977                                                                          "}\n"
17978                                                                          "\n";
17979         static const GLchar* tcs = "#version 430 core\n"
17980                                                            "#extension GL_ARB_enhanced_layouts : require\n"
17981                                                            "\n"
17982                                                            "layout(vertices = 1) out;\n"
17983                                                            "\n"
17984                                                            "in  vec4 vs_tcs[];\n"
17985                                                            "out vec4 tcs_tes[];\n"
17986                                                            "\n"
17987                                                            "void main()\n"
17988                                                            "{\n"
17989                                                            "\n"
17990                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
17991                                                            "\n"
17992                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
17993                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
17994                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
17995                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
17996                                                            "    gl_TessLevelInner[0] = 1.0;\n"
17997                                                            "    gl_TessLevelInner[1] = 1.0;\n"
17998                                                            "}\n"
17999                                                            "\n";
18000         static const GLchar* tcs_tested = "#version 430 core\n"
18001                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18002                                                                           "\n"
18003                                                                           "layout(vertices = 1) out;\n"
18004                                                                           "\n"
18005                                                                           "VAR_DEFINITION"
18006                                                                           "\n"
18007                                                                           "in  vec4 vs_tcs[];\n"
18008                                                                           "out vec4 tcs_tes[];\n"
18009                                                                           "\n"
18010                                                                           "void main()\n"
18011                                                                           "{\n"
18012                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18013                                                                           "\n"
18014                                                                           "VARIABLE_USE"
18015                                                                           "\n"
18016                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18017                                                                           "\n"
18018                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18019                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18020                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18021                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18022                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18023                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18024                                                                           "}\n"
18025                                                                           "\n";
18026         static const GLchar* tes = "#version 430 core\n"
18027                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18028                                                            "\n"
18029                                                            "layout(isolines, point_mode) in;\n"
18030                                                            "\n"
18031                                                            "in  vec4 tcs_tes[];\n"
18032                                                            "out vec4 tes_gs;\n"
18033                                                            "\n"
18034                                                            "void main()\n"
18035                                                            "{\n"
18036                                                            "    tes_gs = tcs_tes[0];\n"
18037                                                            "}\n"
18038                                                            "\n";
18039         static const GLchar* tes_tested = "#version 430 core\n"
18040                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18041                                                                           "\n"
18042                                                                           "layout(isolines, point_mode) in;\n"
18043                                                                           "\n"
18044                                                                           "VAR_DEFINITION"
18045                                                                           "\n"
18046                                                                           "in  vec4 tcs_tes[];\n"
18047                                                                           "out vec4 tes_gs;\n"
18048                                                                           "\n"
18049                                                                           "void main()\n"
18050                                                                           "{\n"
18051                                                                           "    vec4 result = tcs_tes[0];\n"
18052                                                                           "\n"
18053                                                                           "VARIABLE_USE"
18054                                                                           "\n"
18055                                                                           "    tes_gs += result;\n"
18056                                                                           "}\n"
18057                                                                           "\n";
18058         static const GLchar* vs = "#version 430 core\n"
18059                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18060                                                           "\n"
18061                                                           "in  vec4 in_vs;\n"
18062                                                           "out vec4 vs_tcs;\n"
18063                                                           "\n"
18064                                                           "void main()\n"
18065                                                           "{\n"
18066                                                           "    vs_tcs = in_vs;\n"
18067                                                           "}\n"
18068                                                           "\n";
18069         static const GLchar* vs_tested = "#version 430 core\n"
18070                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18071                                                                          "\n"
18072                                                                          "VAR_DEFINITION"
18073                                                                          "\n"
18074                                                                          "in  vec4 in_vs;\n"
18075                                                                          "out vec4 vs_tcs;\n"
18076                                                                          "\n"
18077                                                                          "void main()\n"
18078                                                                          "{\n"
18079                                                                          "    vec4 result = in_vs;\n"
18080                                                                          "\n"
18081                                                                          "VARIABLE_USE"
18082                                                                          "\n"
18083                                                                          "    vs_tcs += result;\n"
18084                                                                          "}\n"
18085                                                                          "\n";
18086
18087         std::string source;
18088         testCase&   test_case = m_test_cases[test_case_index];
18089
18090         if (test_case.m_stage == stage)
18091         {
18092                 const GLchar* array = "";
18093                 GLchar            buffer_gohan[16];
18094                 GLchar            buffer_goten[16];
18095                 const GLchar* direction = "in ";
18096                 const GLchar* index             = "";
18097                 const GLchar* int_gohan = getInterpolationQualifier(test_case.m_interpolation_gohan);
18098                 const GLchar* int_goten = getInterpolationQualifier(test_case.m_interpolation_goten);
18099                 size_t            position  = 0;
18100                 size_t            temp;
18101                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18102                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18103                 const GLchar* var_use             = input_use;
18104
18105                 if (false == test_case.m_is_input)
18106                 {
18107                         direction = "out";
18108
18109                         var_use = output_use;
18110                 }
18111
18112                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18113                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18114
18115                 switch (stage)
18116                 {
18117                 case Utils::Shader::FRAGMENT:
18118                         source = fs_tested;
18119                         break;
18120                 case Utils::Shader::GEOMETRY:
18121                         source = gs_tested;
18122                         array  = "[]";
18123                         index  = "[0]";
18124                         break;
18125                 case Utils::Shader::TESS_CTRL:
18126                         source = tcs_tested;
18127                         array  = "[]";
18128                         index  = "[gl_InvocationID]";
18129                         break;
18130                 case Utils::Shader::TESS_EVAL:
18131                         source = tes_tested;
18132                         array  = "[]";
18133                         index  = "[0]";
18134                         break;
18135                 case Utils::Shader::VERTEX:
18136                         source = vs_tested;
18137                         break;
18138                 default:
18139                         TCU_FAIL("Invalid enum");
18140                 }
18141
18142                 temp = position;
18143                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18144                 position = temp;
18145                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18146                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18147                 Utils::replaceToken("DIRECTION", position, direction, source);
18148                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18149                 Utils::replaceToken("ARRAY", position, array, source);
18150                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18151                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18152                 Utils::replaceToken("DIRECTION", position, direction, source);
18153                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18154                 Utils::replaceToken("ARRAY", position, array, source);
18155
18156                 temp = position;
18157                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18158                 position = temp;
18159                 if (true == test_case.m_is_input)
18160                 {
18161                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18162                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18163                 }
18164                 else
18165                 {
18166                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18167                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18168                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18169                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18170                 }
18171
18172                 Utils::replaceAllTokens("INDEX", index, source);
18173         }
18174         else
18175         {
18176                 switch (stage)
18177                 {
18178                 case Utils::Shader::FRAGMENT:
18179                         source = fs;
18180                         break;
18181                 case Utils::Shader::GEOMETRY:
18182                         source = gs;
18183                         break;
18184                 case Utils::Shader::TESS_CTRL:
18185                         source = tcs;
18186                         break;
18187                 case Utils::Shader::TESS_EVAL:
18188                         source = tes;
18189                         break;
18190                 case Utils::Shader::VERTEX:
18191                         source = vs;
18192                         break;
18193                 default:
18194                         TCU_FAIL("Invalid enum");
18195                 }
18196         }
18197
18198         return source;
18199 }
18200
18201 /** Get description of test case
18202  *
18203  * @param test_case_index Index of test case
18204  *
18205  * @return Test case description
18206  **/
18207 std::string VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseName(GLuint test_case_index)
18208 {
18209         std::stringstream stream;
18210         testCase&                 test_case = m_test_cases[test_case_index];
18211
18212         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18213                    << getInterpolationQualifier(test_case.m_interpolation_gohan) << " "
18214                    << test_case.m_type_gohan.GetGLSLTypeName() << " at " << test_case.m_component_gohan << ", "
18215                    << getInterpolationQualifier(test_case.m_interpolation_goten) << " "
18216                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18217
18218         if (true == test_case.m_is_input)
18219         {
18220                 stream << "input";
18221         }
18222         else
18223         {
18224                 stream << "output";
18225         }
18226
18227         return stream.str();
18228 }
18229
18230 /** Get number of test cases
18231  *
18232  * @return Number of test cases
18233  **/
18234 GLuint VaryingLocationAliasingWithMixedInterpolationTest::getTestCaseNumber()
18235 {
18236         return static_cast<GLuint>(m_test_cases.size());
18237 }
18238
18239 /** Selects if "compute" stage is relevant for test
18240  *
18241  * @param ignored
18242  *
18243  * @return false
18244  **/
18245 bool VaryingLocationAliasingWithMixedInterpolationTest::isComputeRelevant(GLuint /* test_case_index */)
18246 {
18247         return false;
18248 }
18249
18250 /** Prepare all test cases
18251  *
18252  **/
18253 void VaryingLocationAliasingWithMixedInterpolationTest::testInit()
18254 {
18255         static const GLuint n_components_per_location = 4;
18256         const GLuint            n_types                                   = getTypesNumber();
18257
18258         for (GLuint i = 0; i < n_types; ++i)
18259         {
18260                 const Utils::Type& type_gohan              = getType(i);
18261                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18262
18263                 /* Skip matrices */
18264                 if (1 != type_gohan.m_n_columns)
18265                 {
18266                         continue;
18267                 }
18268
18269                 for (GLuint j = 0; j < n_types; ++j)
18270                 {
18271                         const Utils::Type& type_goten              = getType(j);
18272                         const bool                 is_float_type_goten = isFloatType(type_goten);
18273
18274                         /* Skip matrices */
18275                         if (1 != type_goten.m_n_columns)
18276                         {
18277                                 continue;
18278                         }
18279
18280                         /* Skip invalid combinations */
18281                         if (is_float_type_gohan != is_float_type_goten)
18282                         {
18283                                 continue;
18284                         }
18285
18286                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18287                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18288
18289                         /* Skip pairs that cannot fit into one location */
18290                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18291                         {
18292                                 continue;
18293                         }
18294
18295                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
18296                         {
18297                                 /* Skip compute shader */
18298                                 if (Utils::Shader::COMPUTE == stage)
18299                                 {
18300                                         continue;
18301                                 }
18302
18303                                 const GLuint gohan = 0;
18304                                 const GLuint goten = gohan + n_req_components_gohan;
18305
18306                                 for (GLuint int_gohan = 0; int_gohan < INTERPOLATION_MAX; ++int_gohan)
18307                                 {
18308                                         for (GLuint int_goten = 0; int_goten < INTERPOLATION_MAX; ++int_goten)
18309                                         {
18310                                                 const bool is_gohan_double = (Utils::Type::Double == type_gohan.m_basic_type) ? true : false;
18311                                                 const bool is_goten_double = (Utils::Type::Double == type_goten.m_basic_type) ? true : false;
18312                                                 const bool is_gohan_flat   = (FLAT == int_gohan) ? true : false;
18313                                                 const bool is_goten_flat   = (FLAT == int_goten) ? true : false;
18314                                                 const bool is_gohan_accepted_as_fs_in =
18315                                                         (is_gohan_double && is_gohan_flat) || (!is_gohan_double);
18316                                                 const bool is_goten_accepted_as_fs_in =
18317                                                         (is_goten_double && is_goten_flat) || (!is_goten_double);
18318                                                 const bool is_comb_accepted_as_fs_in = is_gohan_accepted_as_fs_in && is_goten_accepted_as_fs_in;
18319
18320                                                 /* Skip when both are the same */
18321                                                 if (int_gohan == int_goten)
18322                                                 {
18323                                                         continue;
18324                                                 }
18325
18326                                                 testCase test_case_in = { gohan,
18327                                                                                                   goten,
18328                                                                                                   (INTERPOLATIONS)int_gohan,
18329                                                                                                   (INTERPOLATIONS)int_goten,
18330                                                                                                   true,
18331                                                                                                   (Utils::Shader::STAGES)stage,
18332                                                                                                   type_gohan,
18333                                                                                                   type_goten };
18334
18335                                                 testCase test_case_out = { gohan,
18336                                                                                                    goten,
18337                                                                                                    (INTERPOLATIONS)int_gohan,
18338                                                                                                    (INTERPOLATIONS)int_goten,
18339                                                                                                    false,
18340                                                                                                    (Utils::Shader::STAGES)stage,
18341                                                                                                    type_gohan,
18342                                                                                                    type_goten };
18343
18344                                                 /* Skip inputs in:
18345                                                  * vertex shader,
18346                                                  * fragment shader when not flat double is used
18347                                                  */
18348                                                 if ((Utils::Shader::VERTEX != stage) &&
18349                                                         ((Utils::Shader::FRAGMENT != stage) || (true == is_comb_accepted_as_fs_in)))
18350                                                 {
18351                                                         m_test_cases.push_back(test_case_in);
18352                                                 }
18353
18354                                                 /* Skip outputs in fragment shader */
18355                                                 if (Utils::Shader::FRAGMENT != stage)
18356                                                 {
18357                                                         m_test_cases.push_back(test_case_out);
18358                                                 }
18359                                         }
18360                                 }
18361                         }
18362                 }
18363         }
18364 }
18365
18366 /** Get interpolation qualifier
18367  *
18368  * @param interpolation Enumeration
18369  *
18370  * @return GLSL qualifier
18371  **/
18372 const GLchar* VaryingLocationAliasingWithMixedInterpolationTest::getInterpolationQualifier(INTERPOLATIONS interpolation)
18373 {
18374         const GLchar* result = 0;
18375
18376         switch (interpolation)
18377         {
18378         case SMOOTH:
18379                 result = "smooth";
18380                 break;
18381         case FLAT:
18382                 result = "flat";
18383                 break;
18384         case NO_PERSPECTIVE:
18385                 result = "noperspective";
18386                 break;
18387         default:
18388                 TCU_FAIL("Invalid enum");
18389         }
18390
18391         return result;
18392 }
18393
18394 /** Check if given type is float
18395  *
18396  * @param type Type in question
18397  *
18398  * @return true if tpye is float, false otherwise
18399  **/
18400 bool VaryingLocationAliasingWithMixedInterpolationTest::isFloatType(const Utils::Type& type)
18401 {
18402         bool is_float = false;
18403
18404         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18405         {
18406                 is_float = true;
18407         }
18408
18409         return is_float;
18410 }
18411
18412 /** Constructor
18413  *
18414  * @param context Test framework context
18415  **/
18416 VaryingLocationAliasingWithMixedAuxiliaryStorageTest::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(
18417         deqp::Context& context)
18418         : NegativeTestBase(
18419                   context, "varying_location_aliasing_with_mixed_auxiliary_storage",
18420                   "Test verifies that compiler reports error when auxiliary storage qualifiers are mixed at one location")
18421 {
18422 }
18423
18424 /** Source for given test case and stage
18425  *
18426  * @param test_case_index Index of test case
18427  * @param stage           Shader stage
18428  *
18429  * @return Shader source
18430  **/
18431 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getShaderSource(GLuint                                test_case_index,
18432                                                                                                                                                                   Utils::Shader::STAGES stage)
18433 {
18434         static const GLchar* var_definition =
18435                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gohanARRAY;\n"
18436                 "layout (location = 1, component = COMPONENT) AUX INTERPOLATION DIRECTION TYPE gotenARRAY;\n";
18437         static const GLchar* input_use = "    if ((TYPE(0) == gohanINDEX_GOHAN) &&\n"
18438                                                                          "        (TYPE(1) == gotenINDEX_GOTEN) )\n"
18439                                                                          "    {\n"
18440                                                                          "        result += vec4(1, 0.5, 0.25, 0.125);\n"
18441                                                                          "    }\n";
18442         static const GLchar* output_use = "    gohanINDEX_GOHAN = TYPE(0);\n"
18443                                                                           "    gotenINDEX_GOTEN = TYPE(1);\n"
18444                                                                           "    if (vec4(0) == result)\n"
18445                                                                           "    {\n"
18446                                                                           "        gohanINDEX_GOHAN = TYPE(1);\n"
18447                                                                           "        gotenINDEX_GOTEN = TYPE(0);\n"
18448                                                                           "    }\n";
18449         static const GLchar* fs = "#version 430 core\n"
18450                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18451                                                           "\n"
18452                                                           "in  vec4 gs_fs;\n"
18453                                                           "out vec4 fs_out;\n"
18454                                                           "\n"
18455                                                           "void main()\n"
18456                                                           "{\n"
18457                                                           "    fs_out = gs_fs;\n"
18458                                                           "}\n"
18459                                                           "\n";
18460         static const GLchar* fs_tested = "#version 430 core\n"
18461                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18462                                                                          "\n"
18463                                                                          "VAR_DEFINITION"
18464                                                                          "\n"
18465                                                                          "in  vec4 gs_fs;\n"
18466                                                                          "out vec4 fs_out;\n"
18467                                                                          "\n"
18468                                                                          "void main()\n"
18469                                                                          "{\n"
18470                                                                          "    vec4 result = gs_fs;\n"
18471                                                                          "\n"
18472                                                                          "VARIABLE_USE"
18473                                                                          "\n"
18474                                                                          "    fs_out = result;\n"
18475                                                                          "}\n"
18476                                                                          "\n";
18477         static const GLchar* gs = "#version 430 core\n"
18478                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18479                                                           "\n"
18480                                                           "layout(points)                           in;\n"
18481                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
18482                                                           "\n"
18483                                                           "in  vec4 tes_gs[];\n"
18484                                                           "out vec4 gs_fs;\n"
18485                                                           "\n"
18486                                                           "void main()\n"
18487                                                           "{\n"
18488                                                           "    gs_fs = tes_gs[0];\n"
18489                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18490                                                           "    EmitVertex();\n"
18491                                                           "    gs_fs = tes_gs[0];\n"
18492                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18493                                                           "    EmitVertex();\n"
18494                                                           "    gs_fs = tes_gs[0];\n"
18495                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
18496                                                           "    EmitVertex();\n"
18497                                                           "    gs_fs = tes_gs[0];\n"
18498                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
18499                                                           "    EmitVertex();\n"
18500                                                           "}\n"
18501                                                           "\n";
18502         static const GLchar* gs_tested = "#version 430 core\n"
18503                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18504                                                                          "\n"
18505                                                                          "layout(points)                           in;\n"
18506                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
18507                                                                          "\n"
18508                                                                          "VAR_DEFINITION"
18509                                                                          "\n"
18510                                                                          "in  vec4 tes_gs[];\n"
18511                                                                          "out vec4 gs_fs;\n"
18512                                                                          "\n"
18513                                                                          "void main()\n"
18514                                                                          "{\n"
18515                                                                          "    vec4 result = tes_gs[0];\n"
18516                                                                          "\n"
18517                                                                          "VARIABLE_USE"
18518                                                                          "\n"
18519                                                                          "    gs_fs = result;\n"
18520                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
18521                                                                          "    EmitVertex();\n"
18522                                                                          "    gs_fs = result;\n"
18523                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
18524                                                                          "    EmitVertex();\n"
18525                                                                          "    gs_fs = result;\n"
18526                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
18527                                                                          "    EmitVertex();\n"
18528                                                                          "    gs_fs = result;\n"
18529                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
18530                                                                          "    EmitVertex();\n"
18531                                                                          "}\n"
18532                                                                          "\n";
18533         static const GLchar* tcs = "#version 430 core\n"
18534                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18535                                                            "\n"
18536                                                            "layout(vertices = 1) out;\n"
18537                                                            "\n"
18538                                                            "in  vec4 vs_tcs[];\n"
18539                                                            "out vec4 tcs_tes[];\n"
18540                                                            "\n"
18541                                                            "void main()\n"
18542                                                            "{\n"
18543                                                            "\n"
18544                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
18545                                                            "\n"
18546                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
18547                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
18548                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
18549                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
18550                                                            "    gl_TessLevelInner[0] = 1.0;\n"
18551                                                            "    gl_TessLevelInner[1] = 1.0;\n"
18552                                                            "}\n"
18553                                                            "\n";
18554         static const GLchar* tcs_tested = "#version 430 core\n"
18555                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18556                                                                           "\n"
18557                                                                           "layout(vertices = 1) out;\n"
18558                                                                           "\n"
18559                                                                           "VAR_DEFINITION"
18560                                                                           "\n"
18561                                                                           "in  vec4 vs_tcs[];\n"
18562                                                                           "out vec4 tcs_tes[];\n"
18563                                                                           "\n"
18564                                                                           "void main()\n"
18565                                                                           "{\n"
18566                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
18567                                                                           "\n"
18568                                                                           "VARIABLE_USE"
18569                                                                           "\n"
18570                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
18571                                                                           "\n"
18572                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
18573                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
18574                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
18575                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
18576                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
18577                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
18578                                                                           "}\n"
18579                                                                           "\n";
18580         static const GLchar* tes = "#version 430 core\n"
18581                                                            "#extension GL_ARB_enhanced_layouts : require\n"
18582                                                            "\n"
18583                                                            "layout(isolines, point_mode) in;\n"
18584                                                            "\n"
18585                                                            "in  vec4 tcs_tes[];\n"
18586                                                            "out vec4 tes_gs;\n"
18587                                                            "\n"
18588                                                            "void main()\n"
18589                                                            "{\n"
18590                                                            "    tes_gs = tcs_tes[0];\n"
18591                                                            "}\n"
18592                                                            "\n";
18593         static const GLchar* tes_tested = "#version 430 core\n"
18594                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18595                                                                           "\n"
18596                                                                           "layout(isolines, point_mode) in;\n"
18597                                                                           "\n"
18598                                                                           "VAR_DEFINITION"
18599                                                                           "\n"
18600                                                                           "in  vec4 tcs_tes[];\n"
18601                                                                           "out vec4 tes_gs;\n"
18602                                                                           "\n"
18603                                                                           "void main()\n"
18604                                                                           "{\n"
18605                                                                           "    vec4 result = tcs_tes[0];\n"
18606                                                                           "\n"
18607                                                                           "VARIABLE_USE"
18608                                                                           "\n"
18609                                                                           "    tes_gs += result;\n"
18610                                                                           "}\n"
18611                                                                           "\n";
18612         static const GLchar* vs = "#version 430 core\n"
18613                                                           "#extension GL_ARB_enhanced_layouts : require\n"
18614                                                           "\n"
18615                                                           "in  vec4 in_vs;\n"
18616                                                           "out vec4 vs_tcs;\n"
18617                                                           "\n"
18618                                                           "void main()\n"
18619                                                           "{\n"
18620                                                           "    vs_tcs = in_vs;\n"
18621                                                           "}\n"
18622                                                           "\n";
18623         static const GLchar* vs_tested = "#version 430 core\n"
18624                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
18625                                                                          "\n"
18626                                                                          "VAR_DEFINITION"
18627                                                                          "\n"
18628                                                                          "in  vec4 in_vs;\n"
18629                                                                          "out vec4 vs_tcs;\n"
18630                                                                          "\n"
18631                                                                          "void main()\n"
18632                                                                          "{\n"
18633                                                                          "    vec4 result = in_vs;\n"
18634                                                                          "\n"
18635                                                                          "VARIABLE_USE"
18636                                                                          "\n"
18637                                                                          "    vs_tcs += result;\n"
18638                                                                          "}\n"
18639                                                                          "\n";
18640
18641         std::string source;
18642         testCase&   test_case = m_test_cases[test_case_index];
18643
18644         if (test_case.m_stage == stage)
18645         {
18646                 const GLchar* array_gohan = "";
18647                 const GLchar* array_goten = "";
18648                 const GLchar* aux_gohan   = getAuxiliaryQualifier(test_case.m_aux_gohan);
18649                 const GLchar* aux_goten   = getAuxiliaryQualifier(test_case.m_aux_goten);
18650                 GLchar            buffer_gohan[16];
18651                 GLchar            buffer_goten[16];
18652                 const GLchar* direction   = "in ";
18653                 const GLchar* index_gohan = "";
18654                 const GLchar* index_goten = "";
18655                 const GLchar* int_gohan   = test_case.m_int_gohan;
18656                 const GLchar* int_goten   = test_case.m_int_goten;
18657                 size_t            position      = 0;
18658                 size_t            temp;
18659                 const GLchar* type_gohan_name = test_case.m_type_gohan.GetGLSLTypeName();
18660                 const GLchar* type_goten_name = test_case.m_type_goten.GetGLSLTypeName();
18661                 const GLchar* var_use             = input_use;
18662
18663                 if (false == test_case.m_is_input)
18664                 {
18665                         direction = "out";
18666
18667                         var_use = output_use;
18668                 }
18669
18670                 sprintf(buffer_gohan, "%d", test_case.m_component_gohan);
18671                 sprintf(buffer_goten, "%d", test_case.m_component_goten);
18672
18673                 switch (stage)
18674                 {
18675                 case Utils::Shader::FRAGMENT:
18676                         source = fs_tested;
18677                         break;
18678                 case Utils::Shader::GEOMETRY:
18679                         source          = gs_tested;
18680                         array_gohan = "[]";
18681                         index_gohan = "[0]";
18682                         array_goten = "[]";
18683                         index_goten = "[0]";
18684                         break;
18685                 case Utils::Shader::TESS_CTRL:
18686                         source = tcs_tested;
18687                         if (PATCH != test_case.m_aux_gohan)
18688                         {
18689                                 array_gohan = "[]";
18690                                 index_gohan = "[gl_InvocationID]";
18691                         }
18692                         if (PATCH != test_case.m_aux_goten)
18693                         {
18694                                 array_goten = "[]";
18695                                 index_goten = "[gl_InvocationID]";
18696                         }
18697                         break;
18698                 case Utils::Shader::TESS_EVAL:
18699                         source          = tes_tested;
18700                         array_gohan = "[]";
18701                         index_gohan = "[0]";
18702                         array_goten = "[]";
18703                         index_goten = "[0]";
18704                         break;
18705                 case Utils::Shader::VERTEX:
18706                         source = vs_tested;
18707                         break;
18708                 default:
18709                         TCU_FAIL("Invalid enum");
18710                 }
18711
18712                 temp = position;
18713                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
18714                 position = temp;
18715                 Utils::replaceToken("COMPONENT", position, buffer_gohan, source);
18716                 Utils::replaceToken("AUX", position, aux_gohan, source);
18717                 Utils::replaceToken("INTERPOLATION", position, int_gohan, source);
18718                 Utils::replaceToken("DIRECTION", position, direction, source);
18719                 Utils::replaceToken("TYPE", position, type_gohan_name, source);
18720                 Utils::replaceToken("ARRAY", position, array_gohan, source);
18721                 Utils::replaceToken("COMPONENT", position, buffer_goten, source);
18722                 Utils::replaceToken("AUX", position, aux_goten, source);
18723                 Utils::replaceToken("INTERPOLATION", position, int_goten, source);
18724                 Utils::replaceToken("DIRECTION", position, direction, source);
18725                 Utils::replaceToken("TYPE", position, type_goten_name, source);
18726                 Utils::replaceToken("ARRAY", position, array_goten, source);
18727
18728                 temp = position;
18729                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
18730                 position = temp;
18731                 if (true == test_case.m_is_input)
18732                 {
18733                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18734                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18735                 }
18736                 else
18737                 {
18738                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18739                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18740                         Utils::replaceToken("TYPE", position, type_gohan_name, source);
18741                         Utils::replaceToken("TYPE", position, type_goten_name, source);
18742                 }
18743
18744                 Utils::replaceAllTokens("INDEX_GOHAN", index_gohan, source);
18745                 Utils::replaceAllTokens("INDEX_GOTEN", index_goten, source);
18746         }
18747         else
18748         {
18749                 switch (stage)
18750                 {
18751                 case Utils::Shader::FRAGMENT:
18752                         source = fs;
18753                         break;
18754                 case Utils::Shader::GEOMETRY:
18755                         source = gs;
18756                         break;
18757                 case Utils::Shader::TESS_CTRL:
18758                         source = tcs;
18759                         break;
18760                 case Utils::Shader::TESS_EVAL:
18761                         source = tes;
18762                         break;
18763                 case Utils::Shader::VERTEX:
18764                         source = vs;
18765                         break;
18766                 default:
18767                         TCU_FAIL("Invalid enum");
18768                 }
18769         }
18770
18771         return source;
18772 }
18773
18774 /** Get description of test case
18775  *
18776  * @param test_case_index Index of test case
18777  *
18778  * @return Test case description
18779  **/
18780 std::string VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseName(GLuint test_case_index)
18781 {
18782         std::stringstream stream;
18783         testCase&                 test_case = m_test_cases[test_case_index];
18784
18785         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", "
18786                    << getAuxiliaryQualifier(test_case.m_aux_gohan) << " " << test_case.m_type_gohan.GetGLSLTypeName() << " at "
18787                    << test_case.m_component_gohan << ", " << getAuxiliaryQualifier(test_case.m_aux_goten) << " "
18788                    << test_case.m_type_goten.GetGLSLTypeName() << " at " << test_case.m_component_goten << ". Direction: ";
18789
18790         if (true == test_case.m_is_input)
18791         {
18792                 stream << "input";
18793         }
18794         else
18795         {
18796                 stream << "output";
18797         }
18798
18799         return stream.str();
18800 }
18801
18802 /** Get number of test cases
18803  *
18804  * @return Number of test cases
18805  **/
18806 GLuint VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getTestCaseNumber()
18807 {
18808         return static_cast<GLuint>(m_test_cases.size());
18809 }
18810
18811 /** Selects if "compute" stage is relevant for test
18812  *
18813  * @param ignored
18814  *
18815  * @return false
18816  **/
18817 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isComputeRelevant(GLuint /* test_case_index */)
18818 {
18819         return false;
18820 }
18821
18822 /** Prepare all test cases
18823  *
18824  **/
18825 void VaryingLocationAliasingWithMixedAuxiliaryStorageTest::testInit()
18826 {
18827         static const GLuint n_components_per_location = 4;
18828         const GLuint            n_types                                   = getTypesNumber();
18829
18830         for (GLuint i = 0; i < n_types; ++i)
18831         {
18832                 const Utils::Type& type_gohan              = getType(i);
18833                 const bool                 is_float_type_gohan = isFloatType(type_gohan);
18834
18835                 /* Skip matrices */
18836                 if (1 != type_gohan.m_n_columns)
18837                 {
18838                         continue;
18839                 }
18840
18841                 for (GLuint j = 0; j < n_types; ++j)
18842                 {
18843                         const Utils::Type& type_goten              = getType(j);
18844                         const bool                 is_flat_req_gohan   = (Utils::Type::Float == type_gohan.m_basic_type) ? false : true;
18845                         const bool                 is_flat_req_goten   = (Utils::Type::Float == type_goten.m_basic_type) ? false : true;
18846                         const bool                 is_float_type_goten = isFloatType(type_goten);
18847
18848                         /* Skip matrices */
18849                         if (1 != type_goten.m_n_columns)
18850                         {
18851                                 continue;
18852                         }
18853
18854                         /* Skip invalid combinations */
18855                         if (is_float_type_gohan != is_float_type_goten)
18856                         {
18857                                 continue;
18858                         }
18859
18860                         const GLuint n_req_components_gohan = type_gohan.m_n_rows;
18861                         const GLuint n_req_components_goten = type_goten.m_n_rows;
18862
18863                         /* Skip pairs that cannot fit into one location */
18864                         if (n_components_per_location < (n_req_components_gohan + n_req_components_goten))
18865                         {
18866                                 continue;
18867                         }
18868
18869                         const GLuint gohan = 0;
18870                         const GLuint goten = gohan + n_req_components_gohan;
18871
18872                         const GLchar* fs_int_gohan = is_flat_req_gohan ? "flat" : "";
18873                         const GLchar* fs_int_goten = is_flat_req_goten ? "flat" : "";
18874
18875                         testCase test_case_tcs_np = { gohan,      goten,         NONE, PATCH, "", "", false, Utils::Shader::TESS_CTRL,
18876                                                                                   type_gohan, type_goten };
18877
18878                         testCase test_case_tcs_pn = { gohan,      goten,         PATCH, NONE, "", "", false, Utils::Shader::TESS_CTRL,
18879                                                                                   type_gohan, type_goten };
18880
18881                         testCase test_case_tes_np = { gohan,      goten,         NONE, PATCH, "", "", true, Utils::Shader::TESS_EVAL,
18882                                                                                   type_gohan, type_goten };
18883
18884                         testCase test_case_tes_pn = { gohan,      goten,         PATCH, NONE, "", "", true, Utils::Shader::TESS_EVAL,
18885                                                                                   type_gohan, type_goten };
18886
18887                         testCase test_case_fs_nc = { gohan,                goten,                NONE, CENTROID,
18888                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18889                                                                                  type_gohan,   type_goten };
18890
18891                         testCase test_case_fs_cn = { gohan,                goten,                CENTROID, NONE,
18892                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18893                                                                                  type_gohan,   type_goten };
18894
18895                         testCase test_case_fs_ns = { gohan,                goten,                NONE, SAMPLE,
18896                                                                                  fs_int_gohan, fs_int_goten, true, Utils::Shader::FRAGMENT,
18897                                                                                  type_gohan,   type_goten };
18898
18899                         testCase test_case_fs_sn = { gohan,                goten,                SAMPLE, NONE,
18900                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18901                                                                                  type_gohan,   type_goten };
18902
18903                         testCase test_case_fs_cs = { gohan,                goten,                CENTROID, SAMPLE,
18904                                                                                  fs_int_gohan, fs_int_goten, true,       Utils::Shader::FRAGMENT,
18905                                                                                  type_gohan,   type_goten };
18906
18907                         testCase test_case_fs_sc = { gohan,                goten,                SAMPLE, CENTROID,
18908                                                                                  fs_int_gohan, fs_int_goten, true,   Utils::Shader::FRAGMENT,
18909                                                                                  type_gohan,   type_goten };
18910
18911                         m_test_cases.push_back(test_case_tcs_np);
18912                         m_test_cases.push_back(test_case_tcs_pn);
18913                         m_test_cases.push_back(test_case_tes_np);
18914                         m_test_cases.push_back(test_case_tes_pn);
18915                         m_test_cases.push_back(test_case_fs_nc);
18916                         m_test_cases.push_back(test_case_fs_cn);
18917                         m_test_cases.push_back(test_case_fs_ns);
18918                         m_test_cases.push_back(test_case_fs_sn);
18919                         m_test_cases.push_back(test_case_fs_cs);
18920                         m_test_cases.push_back(test_case_fs_sc);
18921                 }
18922         }
18923 }
18924
18925 /** Get auxiliary storage qualifier
18926  *
18927  * @param aux Enumeration
18928  *
18929  * @return GLSL qualifier
18930  **/
18931 const GLchar* VaryingLocationAliasingWithMixedAuxiliaryStorageTest::getAuxiliaryQualifier(AUXILIARIES aux)
18932 {
18933         const GLchar* result = 0;
18934
18935         switch (aux)
18936         {
18937         case NONE:
18938                 result = "";
18939                 break;
18940         case PATCH:
18941                 result = "patch";
18942                 break;
18943         case CENTROID:
18944                 result = "centroid";
18945                 break;
18946         case SAMPLE:
18947                 result = "sample";
18948                 break;
18949         default:
18950                 TCU_FAIL("Invalid enum");
18951         }
18952
18953         return result;
18954 }
18955
18956 /** Check if given type is float
18957  *
18958  * @param type Type in question
18959  *
18960  * @return true if tpye is float, false otherwise
18961  **/
18962 bool VaryingLocationAliasingWithMixedAuxiliaryStorageTest::isFloatType(const Utils::Type& type)
18963 {
18964         bool is_float = false;
18965
18966         if ((Utils::Type::Double == type.m_basic_type) || (Utils::Type::Float == type.m_basic_type))
18967         {
18968                 is_float = true;
18969         }
18970
18971         return is_float;
18972 }
18973
18974 /* Constants used by VertexAttribLocationAPITest */
18975 const GLuint VertexAttribLocationAPITest::m_goten_location = 6;
18976
18977 /** Constructor
18978  *
18979  * @param context Test framework context
18980  **/
18981 VertexAttribLocationAPITest::VertexAttribLocationAPITest(deqp::Context& context)
18982         : TextureTestBase(context, "vertex_attrib_location_api",
18983                                           "Test verifies that attribute locations API works as expected")
18984 {
18985 }
18986
18987 /** Does BindAttribLocation for "goten" and relink program
18988  *
18989  * @param program           Program object
18990  * @param program_interface Interface of program
18991  **/
18992 void VertexAttribLocationAPITest::prepareAttribLocation(Utils::Program&                  program,
18993                                                                                                                 Utils::ProgramInterface& program_interface)
18994 {
18995         const Functions& gl = m_context.getRenderContext().getFunctions();
18996
18997         gl.bindAttribLocation(program.m_id, m_goten_location, "goten");
18998         GLU_EXPECT_NO_ERROR(gl.getError(), "BindAttribLocation");
18999
19000         program.Link(gl, program.m_id);
19001
19002         /* We still need to get locations for gohan and chichi */
19003         TextureTestBase::prepareAttribLocation(program, program_interface);
19004 }
19005
19006 /** Get interface of program
19007  *
19008  * @param ignored
19009  * @param program_interface   Interface of program
19010  * @param ignored
19011  **/
19012 void VertexAttribLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19013                                                                                                           Utils::ProgramInterface& program_interface,
19014                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19015 {
19016         Utils::ShaderInterface& si                = program_interface.GetShaderInterface(Utils::Shader::VERTEX);
19017         const Utils::Type&              type      = Utils::Type::vec4;
19018         const GLuint                    type_size = type.GetSize();
19019
19020         /* Offsets */
19021         const GLuint chichi_offset = 0;
19022         const GLuint goten_offset  = chichi_offset + type_size;
19023         const GLuint gohan_offset  = goten_offset + type_size;
19024         const GLuint goku_offset   = gohan_offset + type_size;
19025
19026         /* Locations */
19027         const GLuint goku_location  = 2;
19028         const GLuint goten_location = m_goten_location;
19029
19030         /* Generate data */
19031         m_goku_data   = type.GenerateDataPacked();
19032         m_gohan_data  = type.GenerateDataPacked();
19033         m_goten_data  = type.GenerateDataPacked();
19034         m_chichi_data = type.GenerateDataPacked();
19035
19036         /* Globals */
19037         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19038
19039         /* Attributes */
19040         si.Input("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19041                          goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19042                          0u /* n_array_elements */, 0u /* stride */, goku_offset /* offset */, (GLvoid*)&m_goku_data[0] /* data */,
19043                          m_goku_data.size() /* data_size */);
19044
19045         si.Input("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19046                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19047                          0u /* n_array_elements */, 0u /* stride */, gohan_offset /* offset */,
19048                          (GLvoid*)&m_gohan_data[0] /* data */, m_gohan_data.size() /* data_size */);
19049
19050         si.Input("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19051                          goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19052                          0u /* n_array_elements */, 0u /* stride */, goten_offset /* offset */,
19053                          (GLvoid*)&m_goten_data[0] /* data */, m_goten_data.size() /* data_size */);
19054
19055         si.Input("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19056                          Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19057                          0u /* n_array_elements */, 0u /* stride */, chichi_offset /* offset */,
19058                          (GLvoid*)&m_chichi_data[0] /* data */, m_chichi_data.size() /* data_size */);
19059 }
19060
19061 /** Selects if "compute" stage is relevant for test
19062  *
19063  * @param ignored
19064  *
19065  * @return false
19066  **/
19067 bool VertexAttribLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19068 {
19069         return false;
19070 }
19071
19072 /* Constants used by FragmentDataLocationAPITest */
19073 const GLuint FragmentDataLocationAPITest::m_goten_location = 6;
19074
19075 /** Constructor
19076  *
19077  * @param context Test framework context
19078  **/
19079 FragmentDataLocationAPITest::FragmentDataLocationAPITest(deqp::Context& context)
19080         : TextureTestBase(context, "fragment_data_location_api",
19081                                           "Test verifies that fragment data locations API works as expected")
19082         , m_goku(context)
19083         , m_gohan(context)
19084         , m_goten(context)
19085         , m_chichi(context)
19086 {
19087 }
19088
19089 /** Verifies contents of drawn images
19090  *
19091  * @param ignored
19092  * @param ignored
19093  *
19094  * @return true if images are filled with expected values, false otherwise
19095  **/
19096 bool FragmentDataLocationAPITest::checkResults(glw::GLuint /* test_case_index */, Utils::Texture& /* color_0 */)
19097 {
19098         static const GLuint size                        = m_width * m_height;
19099         static const GLuint expected_goku   = 0xff000000;
19100         static const GLuint expected_gohan  = 0xff0000ff;
19101         static const GLuint expected_goten  = 0xff00ff00;
19102         static const GLuint expected_chichi = 0xffff0000;
19103
19104         std::vector<GLuint> data;
19105         data.resize(size);
19106
19107         m_goku.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19108
19109         for (GLuint i = 0; i < size; ++i)
19110         {
19111                 const GLuint color = data[i];
19112
19113                 if (expected_goku != color)
19114                 {
19115                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19116                                                                                                 << tcu::TestLog::EndMessage;
19117                         return false;
19118                 }
19119         }
19120
19121         m_gohan.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19122
19123         for (GLuint i = 0; i < size; ++i)
19124         {
19125                 const GLuint color = data[i];
19126
19127                 if (expected_gohan != color)
19128                 {
19129                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19130                                                                                                 << tcu::TestLog::EndMessage;
19131                         return false;
19132                 }
19133         }
19134
19135         m_goten.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19136
19137         for (GLuint i = 0; i < size; ++i)
19138         {
19139                 const GLuint color = data[i];
19140
19141                 if (expected_goten != color)
19142                 {
19143                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19144                                                                                                 << tcu::TestLog::EndMessage;
19145                         return false;
19146                 }
19147         }
19148
19149         m_chichi.Get(GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
19150
19151         for (GLuint i = 0; i < size; ++i)
19152         {
19153                 const GLuint color = data[i];
19154
19155                 if (expected_chichi != color)
19156                 {
19157                         m_context.getTestContext().getLog() << tcu::TestLog::Message << "RGBA8[" << i << "]:" << color
19158                                                                                                 << tcu::TestLog::EndMessage;
19159                         return false;
19160                 }
19161         }
19162
19163         return true;
19164 }
19165
19166 /** Prepare code snippet that will set out variables
19167  *
19168  * @param ignored
19169  * @param ignored
19170  * @param stage               Shader stage
19171  *
19172  * @return Code that pass in variables to next stage
19173  **/
19174 std::string FragmentDataLocationAPITest::getPassSnippet(GLuint /* test_case_index */,
19175                                                                                                                 Utils::VaryingPassthrough& /* varying_passthrough */,
19176                                                                                                                 Utils::Shader::STAGES stage)
19177 {
19178         std::string result;
19179
19180         /* Skip for compute shader */
19181         if (Utils::Shader::FRAGMENT != stage)
19182         {
19183                 result = "";
19184         }
19185         else
19186         {
19187                 result = "chichi = vec4(0, 0, 1, 1);\n"
19188                                  "    goku   = vec4(0, 0, 0, 1);\n"
19189                                  "    goten  = vec4(0, 1, 0, 1);\n"
19190                                  "    gohan  = vec4(1, 0, 0, 1);\n";
19191         }
19192
19193         return result;
19194 }
19195
19196 /** Get interface of program
19197  *
19198  * @param ignored
19199  * @param program_interface Interface of program
19200  * @param ignored
19201  **/
19202 void FragmentDataLocationAPITest::getProgramInterface(GLuint /* test_case_index */,
19203                                                                                                           Utils::ProgramInterface& program_interface,
19204                                                                                                           Utils::VaryingPassthrough& /* varying_passthrough */)
19205 {
19206         Utils::ShaderInterface& si   = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19207         const Utils::Type&              type = Utils::Type::vec4;
19208
19209         /* Locations */
19210         m_goku_location = 2;
19211
19212         /* Globals */
19213         si.m_globals = "const uint GOKU_LOCATION = 2;\n";
19214
19215         /* Attributes */
19216         si.Output("goku" /* name */, "layout (location = GOKU_LOCATION)" /* qualifiers */, 0 /* expected_componenet */,
19217                           m_goku_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19218                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19219
19220         si.Output("gohan" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19221                           Utils::Variable::m_automatic_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19222                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19223
19224         si.Output("goten" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19225                           m_goten_location /* expected_location */, type /* type */, GL_FALSE /* normalized */,
19226                           0u /* n_array_elements */, 0u /* stride */, 0u /* offset */, (GLvoid*)0 /* data */, 0u /* data_size */);
19227
19228         si.Output("chichi" /* name */, "" /* qualifiers */, 0 /* expected_componenet */,
19229                           Utils::Variable::m_automatic_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
19233 /** Selects if "compute" stage is relevant for test
19234  *
19235  * @param ignored
19236  *
19237  * @return false
19238  **/
19239 bool FragmentDataLocationAPITest::isComputeRelevant(GLuint /* test_case_index */)
19240 {
19241         return false;
19242 }
19243
19244 /** Get locations for all outputs with automatic_location
19245  *
19246  * @param program           Program object
19247  * @param program_interface Interface of program
19248  **/
19249 void FragmentDataLocationAPITest::prepareFragmentDataLoc(Utils::Program&                  program,
19250                                                                                                                  Utils::ProgramInterface& program_interface)
19251 {
19252         /* Bind location of goten */
19253         const Functions& gl = m_context.getRenderContext().getFunctions();
19254
19255         gl.bindFragDataLocation(program.m_id, m_goten_location, "goten");
19256         GLU_EXPECT_NO_ERROR(gl.getError(), "BindFragDataLocation");
19257
19258         program.Link(gl, program.m_id);
19259
19260         /* Prepare locations for gohan and chichi */
19261         TextureTestBase::prepareFragmentDataLoc(program, program_interface);
19262
19263         /* Get all locations */
19264         Utils::ShaderInterface& si = program_interface.GetShaderInterface(Utils::Shader::FRAGMENT);
19265
19266         Utils::Variable::PtrVector& outputs = si.m_outputs;
19267
19268         for (Utils::Variable::PtrVector::iterator it = outputs.begin(); outputs.end() != it; ++it)
19269         {
19270                 const Utils::Variable::Descriptor& desc = (*it)->m_descriptor;
19271
19272                 if (0 == desc.m_name.compare("gohan"))
19273                 {
19274                         m_gohan_location = desc.m_expected_location;
19275                 }
19276                 else if (0 == desc.m_name.compare("chichi"))
19277                 {
19278                         m_chichi_location = desc.m_expected_location;
19279                 }
19280
19281                 /* Locations of goku and goten are fixed */
19282         }
19283 }
19284
19285 /** Prepare framebuffer with single texture as color attachment
19286  *
19287  * @param framebuffer     Framebuffer
19288  * @param color_0_texture Texture that will used as color attachment
19289  **/
19290 void FragmentDataLocationAPITest::prepareFramebuffer(Utils::Framebuffer& framebuffer, Utils::Texture& color_0_texture)
19291 {
19292         /* Let parent prepare its stuff */
19293         TextureTestBase::prepareFramebuffer(framebuffer, color_0_texture);
19294
19295         /* Prepare data */
19296         std::vector<GLuint> texture_data;
19297         texture_data.resize(m_width * m_height);
19298
19299         for (GLuint i = 0; i < texture_data.size(); ++i)
19300         {
19301                 texture_data[i] = 0x20406080;
19302         }
19303
19304         /* Prepare textures */
19305         m_goku.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19306
19307         m_gohan.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19308
19309         m_goten.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19310
19311         m_chichi.Init(Utils::Texture::TEX_2D, m_width, m_height, 0, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, &texture_data[0]);
19312
19313         /* Attach textures to framebuffer */
19314         framebuffer.Bind();
19315         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goku_location, m_goku.m_id, m_width, m_height);
19316         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_gohan_location, m_gohan.m_id, m_width, m_height);
19317         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_goten_location, m_goten.m_id, m_width, m_height);
19318         framebuffer.AttachTexture(GL_COLOR_ATTACHMENT0 + m_chichi_location, m_chichi.m_id, m_width, m_height);
19319
19320         /* Set up drawbuffers */
19321         const Functions& gl = m_context.getRenderContext().getFunctions();
19322         //  1. There are only 4 outputs in fragment shader, so only need to do buffer mapping for 4 attachments,
19323         //  2. another issue is each output variable has a location, it is the fragment color index, so the index of
19324         //  GL_COLOR_ATTACHMENT in glDrawBuffers() should keep the same with the location, to make test correct,
19325         //  we needt to change the above code of glDrawBuffers() as :
19326         GLint  buffers_size = 4;
19327         GLenum buffers[]        = { GLenum(GL_COLOR_ATTACHMENT0 + m_chichi_location),
19328                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goku_location),
19329                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_goten_location),
19330                                                  GLenum(GL_COLOR_ATTACHMENT0 + m_gohan_location) };
19331         gl.drawBuffers(buffers_size, buffers);
19332         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawBuffers");
19333 }
19334
19335 /** Constructor
19336  *
19337  * @param context Test framework context
19338  **/
19339 XFBInputTest::XFBInputTest(deqp::Context& context)
19340         : NegativeTestBase(context, "xfb_input",
19341                                            "Test verifies that compiler reports error when xfb qualifiers are used with input")
19342 {
19343 }
19344
19345 /** Source for given test case and stage
19346  *
19347  * @param test_case_index Index of test case
19348  * @param stage           Shader stage
19349  *
19350  * @return Shader source
19351  **/
19352 std::string XFBInputTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
19353 {
19354         static const GLchar* buffer_var_definition = "layout (xfb_buffer = 2) in vec4 gohanARRAY;\n";
19355         static const GLchar* offset_var_definition = "layout (xfb_offset = 16) in vec4 gohanARRAY;\n";
19356         static const GLchar* stride_var_definition = "layout (xfb_stride = 32) in vec4 gohanARRAY;\n";
19357         static const GLchar* input_use                     = "    result += gohanINDEX;\n";
19358         static const GLchar* fs                                    = "#version 430 core\n"
19359                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19360                                                           "\n"
19361                                                           "in  vec4 gs_fs;\n"
19362                                                           "out vec4 fs_out;\n"
19363                                                           "\n"
19364                                                           "void main()\n"
19365                                                           "{\n"
19366                                                           "    fs_out = gs_fs;\n"
19367                                                           "}\n"
19368                                                           "\n";
19369         static const GLchar* fs_tested = "#version 430 core\n"
19370                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19371                                                                          "\n"
19372                                                                          "VAR_DEFINITION"
19373                                                                          "\n"
19374                                                                          "in  vec4 gs_fs;\n"
19375                                                                          "out vec4 fs_out;\n"
19376                                                                          "\n"
19377                                                                          "void main()\n"
19378                                                                          "{\n"
19379                                                                          "    vec4 result = gs_fs;\n"
19380                                                                          "\n"
19381                                                                          "VARIABLE_USE"
19382                                                                          "\n"
19383                                                                          "    fs_out = result;\n"
19384                                                                          "}\n"
19385                                                                          "\n";
19386         static const GLchar* gs = "#version 430 core\n"
19387                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19388                                                           "\n"
19389                                                           "layout(points)                           in;\n"
19390                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
19391                                                           "\n"
19392                                                           "in  vec4 tes_gs[];\n"
19393                                                           "out vec4 gs_fs;\n"
19394                                                           "\n"
19395                                                           "void main()\n"
19396                                                           "{\n"
19397                                                           "    gs_fs = tes_gs[0];\n"
19398                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19399                                                           "    EmitVertex();\n"
19400                                                           "    gs_fs = tes_gs[0];\n"
19401                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19402                                                           "    EmitVertex();\n"
19403                                                           "    gs_fs = tes_gs[0];\n"
19404                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
19405                                                           "    EmitVertex();\n"
19406                                                           "    gs_fs = tes_gs[0];\n"
19407                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
19408                                                           "    EmitVertex();\n"
19409                                                           "}\n"
19410                                                           "\n";
19411         static const GLchar* gs_tested = "#version 430 core\n"
19412                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19413                                                                          "\n"
19414                                                                          "layout(points)                           in;\n"
19415                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
19416                                                                          "\n"
19417                                                                          "VAR_DEFINITION"
19418                                                                          "\n"
19419                                                                          "in  vec4 tes_gs[];\n"
19420                                                                          "out vec4 gs_fs;\n"
19421                                                                          "\n"
19422                                                                          "void main()\n"
19423                                                                          "{\n"
19424                                                                          "    vec4 result = tes_gs[0];\n"
19425                                                                          "\n"
19426                                                                          "VARIABLE_USE"
19427                                                                          "\n"
19428                                                                          "    gs_fs = result;\n"
19429                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
19430                                                                          "    EmitVertex();\n"
19431                                                                          "    gs_fs = result;\n"
19432                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
19433                                                                          "    EmitVertex();\n"
19434                                                                          "    gs_fs = result;\n"
19435                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
19436                                                                          "    EmitVertex();\n"
19437                                                                          "    gs_fs = result;\n"
19438                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
19439                                                                          "    EmitVertex();\n"
19440                                                                          "}\n"
19441                                                                          "\n";
19442         static const GLchar* tcs = "#version 430 core\n"
19443                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19444                                                            "\n"
19445                                                            "layout(vertices = 1) out;\n"
19446                                                            "\n"
19447                                                            "in  vec4 vs_tcs[];\n"
19448                                                            "out vec4 tcs_tes[];\n"
19449                                                            "\n"
19450                                                            "void main()\n"
19451                                                            "{\n"
19452                                                            "\n"
19453                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
19454                                                            "\n"
19455                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
19456                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
19457                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
19458                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
19459                                                            "    gl_TessLevelInner[0] = 1.0;\n"
19460                                                            "    gl_TessLevelInner[1] = 1.0;\n"
19461                                                            "}\n"
19462                                                            "\n";
19463         static const GLchar* tcs_tested = "#version 430 core\n"
19464                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19465                                                                           "\n"
19466                                                                           "layout(vertices = 1) out;\n"
19467                                                                           "\n"
19468                                                                           "VAR_DEFINITION"
19469                                                                           "\n"
19470                                                                           "in  vec4 vs_tcs[];\n"
19471                                                                           "out vec4 tcs_tes[];\n"
19472                                                                           "\n"
19473                                                                           "void main()\n"
19474                                                                           "{\n"
19475                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
19476                                                                           "\n"
19477                                                                           "VARIABLE_USE"
19478                                                                           "\n"
19479                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
19480                                                                           "\n"
19481                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
19482                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
19483                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
19484                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
19485                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
19486                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
19487                                                                           "}\n"
19488                                                                           "\n";
19489         static const GLchar* tes = "#version 430 core\n"
19490                                                            "#extension GL_ARB_enhanced_layouts : require\n"
19491                                                            "\n"
19492                                                            "layout(isolines, point_mode) in;\n"
19493                                                            "\n"
19494                                                            "in  vec4 tcs_tes[];\n"
19495                                                            "out vec4 tes_gs;\n"
19496                                                            "\n"
19497                                                            "void main()\n"
19498                                                            "{\n"
19499                                                            "    tes_gs = tcs_tes[0];\n"
19500                                                            "}\n"
19501                                                            "\n";
19502         static const GLchar* tes_tested = "#version 430 core\n"
19503                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19504                                                                           "\n"
19505                                                                           "layout(isolines, point_mode) in;\n"
19506                                                                           "\n"
19507                                                                           "VAR_DEFINITION"
19508                                                                           "\n"
19509                                                                           "in  vec4 tcs_tes[];\n"
19510                                                                           "out vec4 tes_gs;\n"
19511                                                                           "\n"
19512                                                                           "void main()\n"
19513                                                                           "{\n"
19514                                                                           "    vec4 result = tcs_tes[0];\n"
19515                                                                           "\n"
19516                                                                           "VARIABLE_USE"
19517                                                                           "\n"
19518                                                                           "    tes_gs += result;\n"
19519                                                                           "}\n"
19520                                                                           "\n";
19521         static const GLchar* vs = "#version 430 core\n"
19522                                                           "#extension GL_ARB_enhanced_layouts : require\n"
19523                                                           "\n"
19524                                                           "in  vec4 in_vs;\n"
19525                                                           "out vec4 vs_tcs;\n"
19526                                                           "\n"
19527                                                           "void main()\n"
19528                                                           "{\n"
19529                                                           "    vs_tcs = in_vs;\n"
19530                                                           "}\n"
19531                                                           "\n";
19532         static const GLchar* vs_tested = "#version 430 core\n"
19533                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
19534                                                                          "\n"
19535                                                                          "VAR_DEFINITION"
19536                                                                          "\n"
19537                                                                          "in  vec4 in_vs;\n"
19538                                                                          "out vec4 vs_tcs;\n"
19539                                                                          "\n"
19540                                                                          "void main()\n"
19541                                                                          "{\n"
19542                                                                          "    vec4 result = in_vs;\n"
19543                                                                          "\n"
19544                                                                          "VARIABLE_USE"
19545                                                                          "\n"
19546                                                                          "    vs_tcs += result;\n"
19547                                                                          "}\n"
19548                                                                          "\n";
19549
19550         std::string source;
19551         testCase&   test_case = m_test_cases[test_case_index];
19552
19553         if (test_case.m_stage == stage)
19554         {
19555                 const GLchar* array     = "";
19556                 const GLchar* index     = "";
19557                 size_t            position = 0;
19558                 size_t            temp;
19559                 const GLchar* var_definition = 0;
19560                 const GLchar* var_use            = input_use;
19561
19562                 switch (test_case.m_qualifier)
19563                 {
19564                 case BUFFER:
19565                         var_definition = buffer_var_definition;
19566                         break;
19567                 case OFFSET:
19568                         var_definition = offset_var_definition;
19569                         break;
19570                 case STRIDE:
19571                         var_definition = stride_var_definition;
19572                         break;
19573                 default:
19574                         TCU_FAIL("Invalid enum");
19575                 }
19576
19577                 switch (stage)
19578                 {
19579                 case Utils::Shader::FRAGMENT:
19580                         source = fs_tested;
19581                         break;
19582                 case Utils::Shader::GEOMETRY:
19583                         source = gs_tested;
19584                         array  = "[]";
19585                         index  = "[0]";
19586                         break;
19587                 case Utils::Shader::TESS_CTRL:
19588                         source = tcs_tested;
19589                         array  = "[]";
19590                         index  = "[gl_InvocationID]";
19591                         break;
19592                 case Utils::Shader::TESS_EVAL:
19593                         source = tes_tested;
19594                         array  = "[]";
19595                         index  = "[0]";
19596                         break;
19597                 case Utils::Shader::VERTEX:
19598                         source = vs_tested;
19599                         break;
19600                 default:
19601                         TCU_FAIL("Invalid enum");
19602                 }
19603
19604                 temp = position;
19605                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
19606                 position = temp;
19607                 Utils::replaceToken("ARRAY", position, array, source);
19608                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
19609
19610                 Utils::replaceAllTokens("INDEX", index, source);
19611         }
19612         else
19613         {
19614                 switch (stage)
19615                 {
19616                 case Utils::Shader::FRAGMENT:
19617                         source = fs;
19618                         break;
19619                 case Utils::Shader::GEOMETRY:
19620                         source = gs;
19621                         break;
19622                 case Utils::Shader::TESS_CTRL:
19623                         source = tcs;
19624                         break;
19625                 case Utils::Shader::TESS_EVAL:
19626                         source = tes;
19627                         break;
19628                 case Utils::Shader::VERTEX:
19629                         source = vs;
19630                         break;
19631                 default:
19632                         TCU_FAIL("Invalid enum");
19633                 }
19634         }
19635
19636         return source;
19637 }
19638
19639 /** Get description of test case
19640  *
19641  * @param test_case_index Index of test case
19642  *
19643  * @return Test case description
19644  **/
19645 std::string XFBInputTest::getTestCaseName(GLuint test_case_index)
19646 {
19647         std::stringstream stream;
19648         testCase&                 test_case = m_test_cases[test_case_index];
19649
19650         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", qualifier: ";
19651
19652         switch (test_case.m_qualifier)
19653         {
19654         case BUFFER:
19655                 stream << "xfb_buffer";
19656                 break;
19657         case OFFSET:
19658                 stream << "xfb_offset";
19659                 break;
19660         case STRIDE:
19661                 stream << "xfb_stride";
19662                 break;
19663         default:
19664                 TCU_FAIL("Invalid enum");
19665         }
19666
19667         return stream.str();
19668 }
19669
19670 /** Get number of test cases
19671  *
19672  * @return Number of test cases
19673  **/
19674 GLuint XFBInputTest::getTestCaseNumber()
19675 {
19676         return static_cast<GLuint>(m_test_cases.size());
19677 }
19678
19679 /** Selects if "compute" stage is relevant for test
19680  *
19681  * @param ignored
19682  *
19683  * @return false
19684  **/
19685 bool XFBInputTest::isComputeRelevant(GLuint /* test_case_index */)
19686 {
19687         return false;
19688 }
19689
19690 /** Prepare all test cases
19691  *
19692  **/
19693 void XFBInputTest::testInit()
19694 {
19695         for (GLuint qualifier = 0; qualifier < QUALIFIERS_MAX; ++qualifier)
19696         {
19697                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
19698                 {
19699                         if (Utils::Shader::COMPUTE == stage)
19700                         {
19701                                 continue;
19702                         }
19703
19704                         testCase test_case = { (QUALIFIERS)qualifier, (Utils::Shader::STAGES)stage };
19705
19706                         m_test_cases.push_back(test_case);
19707                 }
19708         }
19709 }
19710
19711 /* Constants used by XFBAllStagesTest */
19712 const GLuint XFBAllStagesTest::m_gs_index = 3;
19713
19714 /** Constructor
19715  *
19716  * @param context Test context
19717  **/
19718 XFBAllStagesTest::XFBAllStagesTest(deqp::Context& context)
19719         : BufferTestBase(context, "xfb_all_stages",
19720                                          "Test verifies that only last stage in vertex processing can output to transform feedback")
19721 {
19722         /* Nothing to be done here */
19723 }
19724
19725 /** Get descriptors of buffers necessary for test
19726  *
19727  * @param ignored
19728  * @param out_descriptors Descriptors of buffers used by test
19729  **/
19730 void XFBAllStagesTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
19731                                                                                         bufferDescriptor::Vector& out_descriptors)
19732 {
19733         static const GLuint n_stages = 4;
19734         const Utils::Type&  vec4         = Utils::Type::vec4;
19735
19736         /* Data */
19737         tcu::Vec4 sum;
19738
19739         /* Test uses single uniform and xfb per stage + uniform for fragment shader */
19740         out_descriptors.resize(n_stages * 2 + 1);
19741
19742         /* */
19743         for (GLuint i = 0; i < n_stages; ++i)
19744         {
19745                 /* Get references */
19746                 bufferDescriptor& uniform = out_descriptors[i + 0];
19747                 bufferDescriptor& xfb    = out_descriptors[i + n_stages];
19748
19749                 /* Index */
19750                 uniform.m_index = i;
19751                 xfb.m_index             = i;
19752
19753                 /* Target */
19754                 uniform.m_target = Utils::Buffer::Uniform;
19755                 xfb.m_target     = Utils::Buffer::Transform_feedback;
19756
19757                 /* Data */
19758                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19759
19760                 sum += var;
19761
19762                 uniform.m_initial_data.resize(vec4.GetSize());
19763                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19764
19765                 xfb.m_initial_data = vec4.GenerateDataPacked();
19766
19767                 if (m_gs_index != i)
19768                 {
19769                         xfb.m_expected_data = xfb.m_initial_data;
19770                 }
19771                 else
19772                 {
19773                         xfb.m_expected_data.resize(vec4.GetSize());
19774                         memcpy(&xfb.m_expected_data[0], sum.getPtr(), vec4.GetSize());
19775                 }
19776         }
19777
19778         /* FS */
19779         {
19780                 /* Get reference */
19781                 bufferDescriptor& uniform = out_descriptors[n_stages * 2];
19782
19783                 /* Index */
19784                 uniform.m_index = n_stages;
19785
19786                 /* Target */
19787                 uniform.m_target = Utils::Buffer::Uniform;
19788
19789                 /* Data */
19790                 const tcu::Vec4 var(Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat(), Utils::GetRandFloat());
19791
19792                 uniform.m_initial_data.resize(vec4.GetSize());
19793                 memcpy(&uniform.m_initial_data[0], var.getPtr(), vec4.GetSize());
19794         }
19795 }
19796
19797 /** Get body of main function for given shader stage
19798  *
19799  * @param ignored
19800  * @param stage            Shader stage
19801  * @param out_assignments  Set to empty
19802  * @param out_calculations Set to empty
19803  **/
19804 void XFBAllStagesTest::getShaderBody(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19805                                                                          std::string& out_assignments, std::string& out_calculations)
19806 {
19807         out_calculations = "";
19808
19809         static const GLchar* vs  = "    vs_tcs  = uni_vs;\n";
19810         static const GLchar* tcs = "    tcs_tes[gl_InvocationID] = uni_tcs + vs_tcs[gl_InvocationID];\n";
19811         static const GLchar* tes = "    tes_gs  = uni_tes + tcs_tes[0];\n";
19812         static const GLchar* gs  = "    gs_fs   = uni_gs  + tes_gs[0];\n";
19813         static const GLchar* fs  = "    fs_out  = uni_fs  + gs_fs;\n";
19814
19815         const GLchar* assignments = 0;
19816         switch (stage)
19817         {
19818         case Utils::Shader::FRAGMENT:
19819                 assignments = fs;
19820                 break;
19821         case Utils::Shader::GEOMETRY:
19822                 assignments = gs;
19823                 break;
19824         case Utils::Shader::TESS_CTRL:
19825                 assignments = tcs;
19826                 break;
19827         case Utils::Shader::TESS_EVAL:
19828                 assignments = tes;
19829                 break;
19830         case Utils::Shader::VERTEX:
19831                 assignments = vs;
19832                 break;
19833         default:
19834                 TCU_FAIL("Invalid enum");
19835         }
19836
19837         out_assignments = assignments;
19838 }
19839
19840 /** Get interface of shader
19841  *
19842  * @param ignored
19843  * @param stage         Shader stage
19844  * @param out_interface Set to ""
19845  **/
19846 void XFBAllStagesTest::getShaderInterface(glw::GLuint /* test_case_index */, Utils::Shader::STAGES stage,
19847                                                                                   std::string& out_interface)
19848 {
19849         static const GLchar* vs = "layout(xfb_buffer = 0, xfb_offset = 0) out     vec4 vs_tcs;\n"
19850                                                           "layout(binding    = 0)                 uniform vs_block {\n"
19851                                                           "    vec4 uni_vs;\n"
19852                                                           "};\n";
19853         static const GLchar* tcs = "                                       in      vec4 vs_tcs[];\n"
19854                                                            "layout(xfb_buffer = 1, xfb_offset = 0) out     vec4 tcs_tes[1];\n"
19855                                                            "layout(binding    = 1)                 uniform tcs_block {\n"
19856                                                            "    vec4 uni_tcs;\n"
19857                                                            "};\n";
19858         static const GLchar* tes = "                                       in      vec4 tcs_tes[];\n"
19859                                                            "layout(xfb_buffer = 2, xfb_offset = 0) out     vec4 tes_gs;\n"
19860                                                            "layout(binding    = 2)                 uniform tes_block {\n"
19861                                                            "    vec4 uni_tes;\n"
19862                                                            "};\n";
19863         static const GLchar* gs = "                                       in      vec4 tes_gs[];\n"
19864                                                           "layout(xfb_buffer = 3, xfb_offset = 0) out     vec4 gs_fs;\n"
19865                                                           "layout(binding    = 3)                 uniform gs_block {\n"
19866                                                           "    vec4 uni_gs;\n"
19867                                                           "};\n";
19868         static const GLchar* fs = "                       in      vec4 gs_fs;\n"
19869                                                           "                       out     vec4 fs_out;\n"
19870                                                           "layout(binding    = 4) uniform fs_block {\n"
19871                                                           "    vec4 uni_fs;\n"
19872                                                           "};\n";
19873
19874         const GLchar* interface = 0;
19875         switch (stage)
19876         {
19877         case Utils::Shader::FRAGMENT:
19878                 interface = fs;
19879                 break;
19880         case Utils::Shader::GEOMETRY:
19881                 interface = gs;
19882                 break;
19883         case Utils::Shader::TESS_CTRL:
19884                 interface = tcs;
19885                 break;
19886         case Utils::Shader::TESS_EVAL:
19887                 interface = tes;
19888                 break;
19889         case Utils::Shader::VERTEX:
19890                 interface = vs;
19891                 break;
19892         default:
19893                 TCU_FAIL("Invalid enum");
19894         }
19895
19896         out_interface = interface;
19897 }
19898
19899 /* Constants used by XFBStrideOfEmptyListTest */
19900 const GLuint XFBStrideOfEmptyListTest::m_stride = 64;
19901
19902 /** Constructor
19903  *
19904  * @param context Test context
19905  **/
19906 XFBStrideOfEmptyListTest::XFBStrideOfEmptyListTest(deqp::Context& context)
19907         : BufferTestBase(context, "xfb_stride_of_empty_list",
19908                                          "Test verifies that xfb_stride qualifier is respected when no xfb_offset is specified")
19909 {
19910         /* Nothing to be done here */
19911 }
19912
19913 /** Execute drawArrays for single vertex
19914  *
19915  * @param test_case_index Index of test case
19916  *
19917  * @return true if proper error is reported
19918  **/
19919 bool XFBStrideOfEmptyListTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
19920 {
19921         const Functions& gl             = m_context.getRenderContext().getFunctions();
19922         bool                     result = true;
19923
19924         /* Draw */
19925         gl.disable(GL_RASTERIZER_DISCARD);
19926         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
19927
19928         gl.beginTransformFeedback(GL_POINTS);
19929         GLenum error = gl.getError();
19930         switch (test_case_index)
19931         {
19932         case VALID:
19933                 if (GL_NO_ERROR != error)
19934                 {
19935                         gl.endTransformFeedback();
19936                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
19937                 }
19938
19939                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
19940                 error = gl.getError();
19941
19942                 gl.endTransformFeedback();
19943                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
19944                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
19945
19946                 break;
19947
19948         case FIRST_MISSING:
19949                 if (GL_NO_ERROR == error)
19950                 {
19951                         gl.endTransformFeedback();
19952                 }
19953
19954                 if (GL_INVALID_OPERATION != error)
19955                 {
19956                         m_context.getTestContext().getLog()
19957                                 << tcu::TestLog::Message << "XFB at index 0, that is written by GS, is missing. It was expected that "
19958                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19959                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19960
19961                         result = false;
19962                 }
19963
19964                 break;
19965
19966         case SECOND_MISSING:
19967                 if (GL_NO_ERROR == error)
19968                 {
19969                         gl.endTransformFeedback();
19970                 }
19971
19972                 if (GL_INVALID_OPERATION != error)
19973                 {
19974                         m_context.getTestContext().getLog()
19975                                 << tcu::TestLog::Message << "XFB at index 1, that is declared as empty, is missing. It was expected "
19976                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
19977                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
19978
19979                         result = false;
19980                 }
19981
19982                 break;
19983         }
19984
19985         /* Done */
19986         return result;
19987 }
19988
19989 /** Get descriptors of buffers necessary for test
19990  *
19991  * @param test_case_index Index of test case
19992  * @param out_descriptors Descriptors of buffers used by test
19993  **/
19994 void XFBStrideOfEmptyListTest::getBufferDescriptors(glw::GLuint                           test_case_index,
19995                                                                                                         bufferDescriptor::Vector& out_descriptors)
19996 {
19997         switch (test_case_index)
19998         {
19999         case VALID:
20000         {
20001                 /* Test needs single uniform and two xfbs */
20002                 out_descriptors.resize(3);
20003
20004                 /* Get references */
20005                 bufferDescriptor& uniform = out_descriptors[0];
20006                 bufferDescriptor& xfb_0   = out_descriptors[1];
20007                 bufferDescriptor& xfb_1   = out_descriptors[2];
20008
20009                 /* Index */
20010                 uniform.m_index = 0;
20011                 xfb_0.m_index   = 0;
20012                 xfb_1.m_index   = 1;
20013
20014                 /* Target */
20015                 uniform.m_target = Utils::Buffer::Uniform;
20016                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20017                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20018
20019                 /* Data */
20020                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20021
20022                 xfb_0.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20023                 xfb_0.m_expected_data = uniform.m_initial_data;
20024
20025                 /* Data, contents are the same as no modification is expected */
20026                 xfb_1.m_initial_data.resize(m_stride);
20027                 xfb_1.m_expected_data.resize(m_stride);
20028
20029                 for (GLuint i = 0; i < m_stride; ++i)
20030                 {
20031                         xfb_1.m_initial_data[0]  = (glw::GLubyte)i;
20032                         xfb_1.m_expected_data[0] = (glw::GLubyte)i;
20033                 }
20034         }
20035
20036         break;
20037
20038         case FIRST_MISSING:
20039         {
20040                 /* Test needs single uniform and two xfbs */
20041                 out_descriptors.resize(2);
20042
20043                 /* Get references */
20044                 bufferDescriptor& uniform = out_descriptors[0];
20045                 bufferDescriptor& xfb_1   = out_descriptors[1];
20046
20047                 /* Index */
20048                 uniform.m_index = 0;
20049                 xfb_1.m_index   = 1;
20050
20051                 /* Target */
20052                 uniform.m_target = Utils::Buffer::Uniform;
20053                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20054
20055                 /* Data */
20056                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20057
20058                 /* Draw call will not be executed, contents does not matter */
20059                 xfb_1.m_initial_data.resize(m_stride);
20060         }
20061
20062         break;
20063
20064         case SECOND_MISSING:
20065         {
20066                 /* Test needs single uniform and two xfbs */
20067                 out_descriptors.resize(2);
20068
20069                 /* Get references */
20070                 bufferDescriptor& uniform = out_descriptors[0];
20071                 bufferDescriptor& xfb_0   = out_descriptors[1];
20072
20073                 /* Index */
20074                 uniform.m_index = 0;
20075                 xfb_0.m_index   = 0;
20076
20077                 /* Target */
20078                 uniform.m_target = Utils::Buffer::Uniform;
20079                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20080
20081                 /* Data */
20082                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20083
20084                 /* Draw call will not be executed, contents does not matter */
20085                 xfb_0.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20086         }
20087
20088         break;
20089         }
20090 }
20091
20092 /** Get body of main function for given shader stage
20093  *
20094  * @param ignored
20095  * @param stage            Shader stage
20096  * @param out_assignments  Set to empty
20097  * @param out_calculations Set to empty
20098  **/
20099 void XFBStrideOfEmptyListTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20100                                                                                          std::string& out_assignments, std::string& out_calculations)
20101 {
20102         out_calculations = "";
20103
20104         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20105         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20106
20107         const GLchar* assignments = "";
20108         switch (stage)
20109         {
20110         case Utils::Shader::FRAGMENT:
20111                 assignments = fs;
20112                 break;
20113         case Utils::Shader::GEOMETRY:
20114                 assignments = gs;
20115                 break;
20116         default:
20117                 break;
20118         }
20119
20120         out_assignments = assignments;
20121 }
20122
20123 /** Get interface of shader
20124  *
20125  * @param ignored
20126  * @param stage            Shader stage
20127  * @param out_interface    Set to ""
20128  **/
20129 void XFBStrideOfEmptyListTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20130                                                                                                   std::string& out_interface)
20131 {
20132         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0)  out     vec4 gs_fs;\n"
20133                                                           "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
20134                                                           "\n"
20135                                                           "layout (binding    = 0)                  uniform gs_block {\n"
20136                                                           "    vec4 uni_gs;\n"
20137                                                           "};\n";
20138         static const GLchar* fs = "in  vec4 gs_fs;\n"
20139                                                           "out vec4 fs_out;\n";
20140
20141         switch (stage)
20142         {
20143         case Utils::Shader::FRAGMENT:
20144                 out_interface = fs;
20145                 break;
20146         case Utils::Shader::GEOMETRY:
20147                 out_interface = gs;
20148                 break;
20149         default:
20150                 out_interface = "";
20151                 return;
20152         }
20153 }
20154
20155 /** Returns buffer details in human readable form.
20156  *
20157  * @param test_case_index Index of test case
20158  *
20159  * @return Case description
20160  **/
20161 std::string XFBStrideOfEmptyListTest::getTestCaseName(GLuint test_case_index)
20162 {
20163         std::string result;
20164
20165         switch (test_case_index)
20166         {
20167         case VALID:
20168                 result = "Valid case";
20169                 break;
20170         case FIRST_MISSING:
20171                 result = "Missing xfb at index 0";
20172                 break;
20173         case SECOND_MISSING:
20174                 result = "Missing xfb at index 1";
20175                 break;
20176         default:
20177                 TCU_FAIL("Invalid enum");
20178         }
20179
20180         return result;
20181 }
20182
20183 /** Get number of test cases
20184  *
20185  * @return 3
20186  **/
20187 GLuint XFBStrideOfEmptyListTest::getTestCaseNumber()
20188 {
20189         return 3;
20190 }
20191
20192 /* Constants used by XFBStrideOfEmptyListTest */
20193 const GLuint XFBStrideOfEmptyListAndAPITest::m_stride = 64;
20194
20195 /** Constructor
20196  *
20197  * @param context Test context
20198  **/
20199 XFBStrideOfEmptyListAndAPITest::XFBStrideOfEmptyListAndAPITest(deqp::Context& context)
20200         : BufferTestBase(context, "xfb_stride_of_empty_list_and_api",
20201                                          "Test verifies that xfb_stride qualifier is not overriden by API")
20202 {
20203         /* Nothing to be done here */
20204 }
20205
20206 /** Execute drawArrays for single vertex
20207  *
20208  * @param test_case_index Index of test case
20209  *
20210  * @return true if proper error is reported
20211  **/
20212 bool XFBStrideOfEmptyListAndAPITest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
20213 {
20214         const Functions& gl             = m_context.getRenderContext().getFunctions();
20215         bool                     result = true;
20216
20217         /* Draw */
20218         gl.disable(GL_RASTERIZER_DISCARD);
20219         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
20220
20221         gl.beginTransformFeedback(GL_POINTS);
20222         GLenum error = gl.getError();
20223         switch (test_case_index)
20224         {
20225         case VALID:
20226                 if (GL_NO_ERROR != error)
20227                 {
20228                         gl.endTransformFeedback();
20229                         GLU_EXPECT_NO_ERROR(error, "BeginTransformFeedback");
20230                 }
20231
20232                 gl.drawArrays(GL_PATCHES, 0 /* first */, 1 /* count */);
20233                 error = gl.getError();
20234
20235                 gl.endTransformFeedback();
20236                 GLU_EXPECT_NO_ERROR(error, "DrawArrays");
20237                 GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
20238
20239                 break;
20240
20241         case FIRST_MISSING:
20242                 if (GL_NO_ERROR == error)
20243                 {
20244                         gl.endTransformFeedback();
20245                 }
20246
20247                 if (GL_INVALID_OPERATION != error)
20248                 {
20249                         m_context.getTestContext().getLog()
20250                                 << tcu::TestLog::Message << "XFB at index 0, that is declared as empty, is missing. It was expected "
20251                                                                                         "that INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20252                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20253
20254                         result = false;
20255                 }
20256
20257                 break;
20258
20259         case SECOND_MISSING:
20260                 if (GL_NO_ERROR == error)
20261                 {
20262                         gl.endTransformFeedback();
20263                 }
20264
20265                 if (GL_INVALID_OPERATION != error)
20266                 {
20267                         m_context.getTestContext().getLog()
20268                                 << tcu::TestLog::Message << "XFB at index 1, that is written by GS, is missing. It was expected that "
20269                                                                                         "INVALID_OPERATION will generated by BeginTransformFeedback. Got: "
20270                                 << glu::getErrorStr(error) << tcu::TestLog::EndMessage;
20271
20272                         result = false;
20273                 }
20274
20275                 break;
20276         }
20277
20278         /* Done */
20279         return result;
20280 }
20281
20282 /** Get descriptors of buffers necessary for test
20283  *
20284  * @param test_case_index Index of test case
20285  * @param out_descriptors Descriptors of buffers used by test
20286  **/
20287 void XFBStrideOfEmptyListAndAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
20288                                                                                                                   bufferDescriptor::Vector& out_descriptors)
20289 {
20290         switch (test_case_index)
20291         {
20292         case VALID:
20293         {
20294                 /* Test needs single uniform and two xfbs */
20295                 out_descriptors.resize(3);
20296
20297                 /* Get references */
20298                 bufferDescriptor& uniform = out_descriptors[0];
20299                 bufferDescriptor& xfb_0   = out_descriptors[1];
20300                 bufferDescriptor& xfb_1   = out_descriptors[2];
20301
20302                 /* Index */
20303                 uniform.m_index = 0;
20304                 xfb_0.m_index   = 0;
20305                 xfb_1.m_index   = 1;
20306
20307                 /* Target */
20308                 uniform.m_target = Utils::Buffer::Uniform;
20309                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20310                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20311
20312                 /* Data */
20313                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20314
20315                 /* Data, contents are the same as no modification is expected */
20316                 xfb_0.m_initial_data.resize(m_stride);
20317                 xfb_0.m_expected_data.resize(m_stride);
20318
20319                 for (GLuint i = 0; i < m_stride; ++i)
20320                 {
20321                         xfb_0.m_initial_data[0]  = (glw::GLubyte)i;
20322                         xfb_0.m_expected_data[0] = (glw::GLubyte)i;
20323                 }
20324
20325                 xfb_1.m_initial_data  = Utils::Type::vec4.GenerateDataPacked();
20326                 xfb_1.m_expected_data = uniform.m_initial_data;
20327         }
20328
20329         break;
20330
20331         case FIRST_MISSING:
20332         {
20333                 /* Test needs single uniform and two xfbs */
20334                 out_descriptors.resize(2);
20335
20336                 /* Get references */
20337                 bufferDescriptor& uniform = out_descriptors[0];
20338                 bufferDescriptor& xfb_1   = out_descriptors[1];
20339
20340                 /* Index */
20341                 uniform.m_index = 0;
20342                 xfb_1.m_index   = 1;
20343
20344                 /* Target */
20345                 uniform.m_target = Utils::Buffer::Uniform;
20346                 xfb_1.m_target   = Utils::Buffer::Transform_feedback;
20347
20348                 /* Data */
20349                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20350
20351                 /* Draw call will not be executed, contents does not matter */
20352                 xfb_1.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20353         }
20354
20355         break;
20356
20357         case SECOND_MISSING:
20358         {
20359                 /* Test needs single uniform and two xfbs */
20360                 out_descriptors.resize(2);
20361
20362                 /* Get references */
20363                 bufferDescriptor& uniform = out_descriptors[0];
20364                 bufferDescriptor& xfb_0   = out_descriptors[1];
20365
20366                 /* Index */
20367                 uniform.m_index = 0;
20368                 xfb_0.m_index   = 0;
20369
20370                 /* Target */
20371                 uniform.m_target = Utils::Buffer::Uniform;
20372                 xfb_0.m_target   = Utils::Buffer::Transform_feedback;
20373
20374                 /* Data */
20375                 uniform.m_initial_data = Utils::Type::vec4.GenerateDataPacked();
20376
20377                 /* Draw call will not be executed, contents does not matter */
20378                 xfb_0.m_initial_data.resize(m_stride);
20379         }
20380
20381         break;
20382         }
20383 }
20384
20385 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
20386  *
20387  * @param ignored
20388  * @param captured_varyings Vector of varying names to be captured
20389  **/
20390 void XFBStrideOfEmptyListAndAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
20391                                                                                                                  Utils::Program::NameVector& captured_varyings)
20392 {
20393         captured_varyings.push_back("gs_fs");
20394 }
20395
20396 /** Get body of main function for given shader stage
20397  *
20398  * @param ignored
20399  * @param stage            Shader stage
20400  * @param out_assignments  Set to empty
20401  * @param out_calculations Set to empty
20402  **/
20403 void XFBStrideOfEmptyListAndAPITest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20404                                                                                                    std::string& out_assignments, std::string& out_calculations)
20405 {
20406         out_calculations = "";
20407
20408         static const GLchar* gs = "    gs_fs  = uni_gs;\n";
20409         static const GLchar* fs = "    fs_out = vec4(gs_fs);\n";
20410
20411         const GLchar* assignments = "";
20412         switch (stage)
20413         {
20414         case Utils::Shader::FRAGMENT:
20415                 assignments = fs;
20416                 break;
20417         case Utils::Shader::GEOMETRY:
20418                 assignments = gs;
20419                 break;
20420         default:
20421                 break;
20422         }
20423
20424         out_assignments = assignments;
20425 }
20426
20427 /** Get interface of shader
20428  *
20429  * @param ignored
20430  * @param stage            Shader stage
20431  * @param out_interface    Set to ""
20432  **/
20433 void XFBStrideOfEmptyListAndAPITest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
20434                                                                                                                 std::string& out_interface)
20435 {
20436         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_stride = 64) out;\n"
20437                                                           "layout (xfb_buffer = 1, xfb_offset = 0)  out vec4 gs_fs;\n"
20438                                                           "\n"
20439                                                           "layout(binding    = 0) uniform gs_block {\n"
20440                                                           "    vec4 uni_gs;\n"
20441                                                           "};\n";
20442         static const GLchar* fs = "in  vec4 gs_fs;\n"
20443                                                           "out vec4 fs_out;\n";
20444
20445         switch (stage)
20446         {
20447         case Utils::Shader::FRAGMENT:
20448                 out_interface = fs;
20449                 break;
20450         case Utils::Shader::GEOMETRY:
20451                 out_interface = gs;
20452                 break;
20453         default:
20454                 out_interface = "";
20455                 return;
20456         }
20457 }
20458
20459 /** Returns buffer details in human readable form.
20460  *
20461  * @param test_case_index Index of test case
20462  *
20463  * @return Case description
20464  **/
20465 std::string XFBStrideOfEmptyListAndAPITest::getTestCaseName(GLuint test_case_index)
20466 {
20467         std::string result;
20468
20469         switch (test_case_index)
20470         {
20471         case VALID:
20472                 result = "Valid case";
20473                 break;
20474         case FIRST_MISSING:
20475                 result = "Missing xfb at index 0";
20476                 break;
20477         case SECOND_MISSING:
20478                 result = "Missing xfb at index 1";
20479                 break;
20480         default:
20481                 TCU_FAIL("Invalid enum");
20482         }
20483
20484         return result;
20485 }
20486
20487 /** Get number of test cases
20488  *
20489  * @return 2
20490  **/
20491 GLuint XFBStrideOfEmptyListAndAPITest::getTestCaseNumber()
20492 {
20493         return 3;
20494 }
20495
20496 /** Constructor
20497  *
20498  * @param context Test framework context
20499  **/
20500 XFBTooSmallStrideTest::XFBTooSmallStrideTest(deqp::Context& context)
20501         : NegativeTestBase(context, "xfb_too_small_stride",
20502                                            "Test verifies that compiler reports error when xfb_stride sets not enough space")
20503 {
20504 }
20505
20506 /** Source for given test case and stage
20507  *
20508  * @param test_case_index Index of test case
20509  * @param stage           Shader stage
20510  *
20511  * @return Shader source
20512  **/
20513 std::string XFBTooSmallStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20514 {
20515         static const GLchar* array_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20516                                                                                                 "\n"
20517                                                                                                 "layout (xfb_offset = 16) out vec4 gohanARRAY[4];\n";
20518         static const GLchar* block_var_definition = "layout (xfb_buffer = 0, xfb_stride = 32) out;\n"
20519                                                                                                 "\n"
20520                                                                                                 "layout (xfb_offset = 0) out Goku {\n"
20521                                                                                                 "    vec4 gohan;\n"
20522                                                                                                 "    vec4 goten;\n"
20523                                                                                                 "    vec4 chichi;\n"
20524                                                                                                 "} gokuARRAY;\n";
20525         static const GLchar* offset_var_definition = "layout (xfb_buffer = 0, xfb_stride = 40) out;\n"
20526                                                                                                  "\n"
20527                                                                                                  "layout (xfb_offset = 32) out vec4 gohanARRAY;\n";
20528         // 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;"
20529         // To make the shader failed to compile, change xfb_stride to a value that is smaller than 32
20530         static const GLchar* stride_var_definition = "layout (xfb_buffer = 0, xfb_stride = 28) out;\n"
20531                                                                                                  "\n"
20532                                                                                                  "layout (xfb_offset = 16, xfb_stride = 28) out vec4 gohanARRAY;\n";
20533         static const GLchar* array_use = "    gohanINDEX[0] = result / 2;\n"
20534                                                                          "    gohanINDEX[1] = result / 4;\n"
20535                                                                          "    gohanINDEX[2] = result / 6;\n"
20536                                                                          "    gohanINDEX[3] = result / 8;\n";
20537         static const GLchar* block_use = "    gokuINDEX.gohan  = result / 2;\n"
20538                                                                          "    gokuINDEX.goten  = result / 4;\n"
20539                                                                          "    gokuINDEX.chichi = result / 6;\n";
20540         static const GLchar* output_use = "gohanINDEX = result / 4;\n";
20541         static const GLchar* fs                 = "#version 430 core\n"
20542                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20543                                                           "\n"
20544                                                           "in  vec4 gs_fs;\n"
20545                                                           "out vec4 fs_out;\n"
20546                                                           "\n"
20547                                                           "void main()\n"
20548                                                           "{\n"
20549                                                           "    fs_out = gs_fs;\n"
20550                                                           "}\n"
20551                                                           "\n";
20552         static const GLchar* gs_tested = "#version 430 core\n"
20553                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20554                                                                          "\n"
20555                                                                          "layout(points)                           in;\n"
20556                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20557                                                                          "\n"
20558                                                                          "VAR_DEFINITION"
20559                                                                          "\n"
20560                                                                          "in  vec4 tes_gs[];\n"
20561                                                                          "out vec4 gs_fs;\n"
20562                                                                          "\n"
20563                                                                          "void main()\n"
20564                                                                          "{\n"
20565                                                                          "    vec4 result = tes_gs[0];\n"
20566                                                                          "\n"
20567                                                                          "VARIABLE_USE"
20568                                                                          "\n"
20569                                                                          "    gs_fs = result;\n"
20570                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20571                                                                          "    EmitVertex();\n"
20572                                                                          "    gs_fs = result;\n"
20573                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20574                                                                          "    EmitVertex();\n"
20575                                                                          "    gs_fs = result;\n"
20576                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20577                                                                          "    EmitVertex();\n"
20578                                                                          "    gs_fs = result;\n"
20579                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20580                                                                          "    EmitVertex();\n"
20581                                                                          "}\n"
20582                                                                          "\n";
20583         static const GLchar* tcs = "#version 430 core\n"
20584                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20585                                                            "\n"
20586                                                            "layout(vertices = 1) out;\n"
20587                                                            "\n"
20588                                                            "in  vec4 vs_tcs[];\n"
20589                                                            "out vec4 tcs_tes[];\n"
20590                                                            "\n"
20591                                                            "void main()\n"
20592                                                            "{\n"
20593                                                            "\n"
20594                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
20595                                                            "\n"
20596                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20597                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20598                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20599                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20600                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20601                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20602                                                            "}\n"
20603                                                            "\n";
20604         static const GLchar* tcs_tested = "#version 430 core\n"
20605                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20606                                                                           "\n"
20607                                                                           "layout(vertices = 1) out;\n"
20608                                                                           "\n"
20609                                                                           "VAR_DEFINITION"
20610                                                                           "\n"
20611                                                                           "in  vec4 vs_tcs[];\n"
20612                                                                           "out vec4 tcs_tes[];\n"
20613                                                                           "\n"
20614                                                                           "void main()\n"
20615                                                                           "{\n"
20616                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
20617                                                                           "\n"
20618                                                                           "VARIABLE_USE"
20619                                                                           "\n"
20620                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
20621                                                                           "\n"
20622                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
20623                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
20624                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
20625                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
20626                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
20627                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
20628                                                                           "}\n"
20629                                                                           "\n";
20630         static const GLchar* tes_tested = "#version 430 core\n"
20631                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20632                                                                           "\n"
20633                                                                           "layout(isolines, point_mode) in;\n"
20634                                                                           "\n"
20635                                                                           "VAR_DEFINITION"
20636                                                                           "\n"
20637                                                                           "in  vec4 tcs_tes[];\n"
20638                                                                           "out vec4 tes_gs;\n"
20639                                                                           "\n"
20640                                                                           "void main()\n"
20641                                                                           "{\n"
20642                                                                           "    vec4 result = tcs_tes[0];\n"
20643                                                                           "\n"
20644                                                                           "VARIABLE_USE"
20645                                                                           "\n"
20646                                                                           "    tes_gs += result;\n"
20647                                                                           "}\n"
20648                                                                           "\n";
20649         static const GLchar* vs = "#version 430 core\n"
20650                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20651                                                           "\n"
20652                                                           "in  vec4 in_vs;\n"
20653                                                           "out vec4 vs_tcs;\n"
20654                                                           "\n"
20655                                                           "void main()\n"
20656                                                           "{\n"
20657                                                           "    vs_tcs = in_vs;\n"
20658                                                           "}\n"
20659                                                           "\n";
20660         static const GLchar* vs_tested = "#version 430 core\n"
20661                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20662                                                                          "\n"
20663                                                                          "VAR_DEFINITION"
20664                                                                          "\n"
20665                                                                          "in  vec4 in_vs;\n"
20666                                                                          "out vec4 vs_tcs;\n"
20667                                                                          "\n"
20668                                                                          "void main()\n"
20669                                                                          "{\n"
20670                                                                          "    vec4 result = in_vs;\n"
20671                                                                          "\n"
20672                                                                          "VARIABLE_USE"
20673                                                                          "\n"
20674                                                                          "    vs_tcs += result;\n"
20675                                                                          "}\n"
20676                                                                          "\n";
20677
20678         std::string source;
20679         testCase&   test_case = m_test_cases[test_case_index];
20680
20681         if (test_case.m_stage == stage)
20682         {
20683                 const GLchar* array     = "";
20684                 const GLchar* index     = "";
20685                 size_t            position = 0;
20686                 size_t            temp;
20687                 const GLchar* var_definition = 0;
20688                 const GLchar* var_use            = 0;
20689
20690                 switch (test_case.m_case)
20691                 {
20692                 case OFFSET:
20693                         var_definition = offset_var_definition;
20694                         var_use            = output_use;
20695                         break;
20696                 case STRIDE:
20697                         var_definition = stride_var_definition;
20698                         var_use            = output_use;
20699                         break;
20700                 case BLOCK:
20701                         var_definition = block_var_definition;
20702                         var_use            = block_use;
20703                         break;
20704                 case ARRAY:
20705                         var_definition = array_var_definition;
20706                         var_use            = array_use;
20707                         break;
20708                 default:
20709                         TCU_FAIL("Invalid enum");
20710                 }
20711
20712                 switch (stage)
20713                 {
20714                 case Utils::Shader::GEOMETRY:
20715                         source = gs_tested;
20716                         array  = "[]";
20717                         index  = "[0]";
20718                         break;
20719                 case Utils::Shader::TESS_CTRL:
20720                         source = tcs_tested;
20721                         array  = "[]";
20722                         index  = "[gl_InvocationID]";
20723                         break;
20724                 case Utils::Shader::TESS_EVAL:
20725                         source = tes_tested;
20726                         array  = "[]";
20727                         index  = "[0]";
20728                         break;
20729                 case Utils::Shader::VERTEX:
20730                         source = vs_tested;
20731                         break;
20732                 default:
20733                         TCU_FAIL("Invalid enum");
20734                 }
20735
20736                 temp = position;
20737                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
20738                 position = temp;
20739                 Utils::replaceToken("ARRAY", position, array, source);
20740                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
20741
20742                 Utils::replaceAllTokens("INDEX", index, source);
20743         }
20744         else
20745         {
20746                 switch (test_case.m_stage)
20747                 {
20748                 case Utils::Shader::GEOMETRY:
20749                         switch (stage)
20750                         {
20751                         case Utils::Shader::FRAGMENT:
20752                                 source = fs;
20753                                 break;
20754                         case Utils::Shader::VERTEX:
20755                                 source = vs;
20756                                 break;
20757                         default:
20758                                 source = "";
20759                         }
20760                         break;
20761                 case Utils::Shader::TESS_CTRL:
20762                         switch (stage)
20763                         {
20764                         case Utils::Shader::FRAGMENT:
20765                                 source = fs;
20766                                 break;
20767                         case Utils::Shader::VERTEX:
20768                                 source = vs;
20769                                 break;
20770                         default:
20771                                 source = "";
20772                         }
20773                         break;
20774                 case Utils::Shader::TESS_EVAL:
20775                         switch (stage)
20776                         {
20777                         case Utils::Shader::FRAGMENT:
20778                                 source = fs;
20779                                 break;
20780                         case Utils::Shader::TESS_CTRL:
20781                                 source = tcs;
20782                                 break;
20783                         case Utils::Shader::VERTEX:
20784                                 source = vs;
20785                                 break;
20786                         default:
20787                                 source = "";
20788                         }
20789                         break;
20790                 case Utils::Shader::VERTEX:
20791                         switch (stage)
20792                         {
20793                         case Utils::Shader::FRAGMENT:
20794                                 source = fs;
20795                                 break;
20796                         default:
20797                                 source = "";
20798                         }
20799                         break;
20800                 default:
20801                         TCU_FAIL("Invalid enum");
20802                         break;
20803                 }
20804         }
20805
20806         return source;
20807 }
20808
20809 /** Get description of test case
20810  *
20811  * @param test_case_index Index of test case
20812  *
20813  * @return Test case description
20814  **/
20815 std::string XFBTooSmallStrideTest::getTestCaseName(GLuint test_case_index)
20816 {
20817         std::stringstream stream;
20818         testCase&                 test_case = m_test_cases[test_case_index];
20819
20820         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
20821
20822         switch (test_case.m_case)
20823         {
20824         case OFFSET:
20825                 stream << "buffer stride: 40, vec4 offset: 32";
20826                 break;
20827         case STRIDE:
20828                 stream << "buffer stride: 32, vec4 off 16 stride: 32";
20829                 break;
20830         case BLOCK:
20831                 stream << "buffer stride: 32, block 3xvec4 offset 0";
20832                 break;
20833         case ARRAY:
20834                 stream << "buffer stride: 32, vec4[4] offset 16";
20835                 break;
20836         default:
20837                 TCU_FAIL("Invalid enum");
20838         }
20839
20840         return stream.str();
20841 }
20842
20843 /** Get number of test cases
20844  *
20845  * @return Number of test cases
20846  **/
20847 GLuint XFBTooSmallStrideTest::getTestCaseNumber()
20848 {
20849         return static_cast<GLuint>(m_test_cases.size());
20850 }
20851
20852 /** Selects if "compute" stage is relevant for test
20853  *
20854  * @param ignored
20855  *
20856  * @return false
20857  **/
20858 bool XFBTooSmallStrideTest::isComputeRelevant(GLuint /* test_case_index */)
20859 {
20860         return false;
20861 }
20862
20863 /** Prepare all test cases
20864  *
20865  **/
20866 void XFBTooSmallStrideTest::testInit()
20867 {
20868         for (GLuint c = 0; c < CASE_MAX; ++c)
20869         {
20870                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
20871                 {
20872                         /*
20873                          It is invalid to define transform feedback output in TCS, according to spec:
20874                          The data captured in transform feedback mode depends on the active programs on each of the shader stages.
20875                          If a program is active for the geometry shader stage, transform feedback captures the vertices of each
20876                          primitive emitted by the geometry shader. Otherwise, if a program is active for the tessellation evaluation
20877                          shader stage, transform feedback captures each primitive produced by the tessellation primitive generator,
20878                          whose vertices are processed by the tessellation evaluation shader. Otherwise, transform feedback captures
20879                          each primitive processed by the vertex shader.
20880                          */
20881                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
20882                                 (Utils::Shader::FRAGMENT == stage))
20883                         {
20884                                 continue;
20885                         }
20886
20887                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
20888
20889                         m_test_cases.push_back(test_case);
20890                 }
20891         }
20892 }
20893
20894 /** Constructor
20895  *
20896  * @param context Test framework context
20897  **/
20898 XFBVariableStrideTest::XFBVariableStrideTest(deqp::Context& context)
20899         : NegativeTestBase(context, "xfb_variable_stride", "Test verifies that stride qualifier is respected")
20900 {
20901 }
20902
20903 /** Source for given test case and stage
20904  *
20905  * @param test_case_index Index of test case
20906  * @param stage           Shader stage
20907  *
20908  * @return Shader source
20909  **/
20910 std::string XFBVariableStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
20911 {
20912         static const GLchar* invalid_var_definition =
20913                 "const uint type_size = SIZE;\n"
20914                 "\n"
20915                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n"
20916                 "layout (xfb_offset = type_size)                     out TYPE vegetaARRAY;\n";
20917         static const GLchar* valid_var_definition =
20918                 "const uint type_size = SIZE;\n"
20919                 "\n"
20920                 "layout (xfb_offset = 0, xfb_stride = 2 * type_size) out TYPE gokuARRAY;\n";
20921         static const GLchar* invalid_use = "    gokuINDEX   = TYPE(1);\n"
20922                                                                            "    vegetaINDEX = TYPE(0);\n"
20923                                                                            "    if (vec4(0) == result)\n"
20924                                                                            "    {\n"
20925                                                                            "        gokuINDEX   = TYPE(0);\n"
20926                                                                            "        vegetaINDEX = TYPE(1);\n"
20927                                                                            "    }\n";
20928         static const GLchar* valid_use = "    gokuINDEX   = TYPE(1);\n"
20929                                                                          "    if (vec4(0) == result)\n"
20930                                                                          "    {\n"
20931                                                                          "        gokuINDEX   = TYPE(0);\n"
20932                                                                          "    }\n";
20933         static const GLchar* fs = "#version 430 core\n"
20934                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20935                                                           "\n"
20936                                                           "in  vec4 any_fs;\n"
20937                                                           "out vec4 fs_out;\n"
20938                                                           "\n"
20939                                                           "void main()\n"
20940                                                           "{\n"
20941                                                           "    fs_out = any_fs;\n"
20942                                                           "}\n"
20943                                                           "\n";
20944         static const GLchar* gs_tested = "#version 430 core\n"
20945                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
20946                                                                          "\n"
20947                                                                          "layout(points)                           in;\n"
20948                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
20949                                                                          "\n"
20950                                                                          "VAR_DEFINITION"
20951                                                                          "\n"
20952                                                                          "in  vec4 vs_any[];\n"
20953                                                                          "out vec4 any_fs;\n"
20954                                                                          "\n"
20955                                                                          "void main()\n"
20956                                                                          "{\n"
20957                                                                          "    vec4 result = vs_any[0];\n"
20958                                                                          "\n"
20959                                                                          "VARIABLE_USE"
20960                                                                          "\n"
20961                                                                          "    any_fs = result;\n"
20962                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
20963                                                                          "    EmitVertex();\n"
20964                                                                          "    any_fs = result;\n"
20965                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
20966                                                                          "    EmitVertex();\n"
20967                                                                          "    any_fs = result;\n"
20968                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
20969                                                                          "    EmitVertex();\n"
20970                                                                          "    any_fs = result;\n"
20971                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
20972                                                                          "    EmitVertex();\n"
20973                                                                          "}\n"
20974                                                                          "\n";
20975         static const GLchar* tcs = "#version 430 core\n"
20976                                                            "#extension GL_ARB_enhanced_layouts : require\n"
20977                                                            "\n"
20978                                                            "layout(vertices = 1) out;\n"
20979                                                            "\n"
20980                                                            "in  vec4 vs_any[];\n"
20981                                                            "out vec4 tcs_tes[];\n"
20982                                                            "\n"
20983                                                            "void main()\n"
20984                                                            "{\n"
20985                                                            "\n"
20986                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
20987                                                            "\n"
20988                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
20989                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
20990                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
20991                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
20992                                                            "    gl_TessLevelInner[0] = 1.0;\n"
20993                                                            "    gl_TessLevelInner[1] = 1.0;\n"
20994                                                            "}\n"
20995                                                            "\n";
20996         static const GLchar* tcs_tested = "#version 430 core\n"
20997                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
20998                                                                           "\n"
20999                                                                           "layout(vertices = 1) out;\n"
21000                                                                           "\n"
21001                                                                           "VAR_DEFINITION"
21002                                                                           "\n"
21003                                                                           "in  vec4 vs_any[];\n"
21004                                                                           "out vec4 any_fs[];\n"
21005                                                                           "\n"
21006                                                                           "void main()\n"
21007                                                                           "{\n"
21008                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21009                                                                           "\n"
21010                                                                           "VARIABLE_USE"
21011                                                                           "\n"
21012                                                                           "    any_fs[gl_InvocationID] = result;\n"
21013                                                                           "\n"
21014                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21015                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21016                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21017                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21018                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21019                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21020                                                                           "}\n"
21021                                                                           "\n";
21022         static const GLchar* tes_tested = "#version 430 core\n"
21023                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21024                                                                           "\n"
21025                                                                           "layout(isolines, point_mode) in;\n"
21026                                                                           "\n"
21027                                                                           "VAR_DEFINITION"
21028                                                                           "\n"
21029                                                                           "in  vec4 tcs_tes[];\n"
21030                                                                           "out vec4 any_fs;\n"
21031                                                                           "\n"
21032                                                                           "void main()\n"
21033                                                                           "{\n"
21034                                                                           "    vec4 result = tcs_tes[0];\n"
21035                                                                           "\n"
21036                                                                           "VARIABLE_USE"
21037                                                                           "\n"
21038                                                                           "    any_fs = result;\n"
21039                                                                           "}\n"
21040                                                                           "\n";
21041         static const GLchar* vs = "#version 430 core\n"
21042                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21043                                                           "\n"
21044                                                           "in  vec4 in_vs;\n"
21045                                                           "out vec4 vs_any;\n"
21046                                                           "\n"
21047                                                           "void main()\n"
21048                                                           "{\n"
21049                                                           "    vs_any = in_vs;\n"
21050                                                           "}\n"
21051                                                           "\n";
21052         static const GLchar* vs_tested = "#version 430 core\n"
21053                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21054                                                                          "\n"
21055                                                                          "VAR_DEFINITION"
21056                                                                          "\n"
21057                                                                          "in  vec4 in_vs;\n"
21058                                                                          "out vec4 any_fs;\n"
21059                                                                          "\n"
21060                                                                          "void main()\n"
21061                                                                          "{\n"
21062                                                                          "    vec4 result = in_vs;\n"
21063                                                                          "\n"
21064                                                                          "VARIABLE_USE"
21065                                                                          "\n"
21066                                                                          "    any_fs = result;\n"
21067                                                                          "}\n"
21068                                                                          "\n";
21069
21070         std::string source;
21071         testCase&   test_case = m_test_cases[test_case_index];
21072
21073         if (test_case.m_stage == stage)
21074         {
21075                 const GLchar* array = "";
21076                 GLchar            buffer[16];
21077                 const GLchar* index     = "";
21078                 size_t            position = 0;
21079                 size_t            temp;
21080                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
21081                 const GLchar* var_definition = 0;
21082                 const GLchar* var_use            = 0;
21083
21084                 sprintf(buffer, "%d", test_case.m_type.GetSize());
21085
21086                 switch (test_case.m_case)
21087                 {
21088                 case VALID:
21089                         var_definition = valid_var_definition;
21090                         var_use            = valid_use;
21091                         break;
21092                 case INVALID:
21093                         var_definition = invalid_var_definition;
21094                         var_use            = invalid_use;
21095                         break;
21096                 default:
21097                         TCU_FAIL("Invalid enum");
21098                 }
21099
21100                 switch (stage)
21101                 {
21102                 case Utils::Shader::GEOMETRY:
21103                         source = gs_tested;
21104                         array  = "[1]";
21105                         index  = "[0]";
21106                         break;
21107                 case Utils::Shader::TESS_CTRL:
21108                         source = tcs_tested;
21109                         array  = "[1]";
21110                         index  = "[gl_InvocationID]";
21111                         break;
21112                 case Utils::Shader::TESS_EVAL:
21113                         source = tes_tested;
21114                         array  = "[1]";
21115                         index  = "[0]";
21116                         break;
21117                 case Utils::Shader::VERTEX:
21118                         source = vs_tested;
21119                         break;
21120                 default:
21121                         TCU_FAIL("Invalid enum");
21122                 }
21123
21124                 temp = position;
21125                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21126                 position = temp;
21127                 Utils::replaceToken("SIZE", position, buffer, source);
21128                 Utils::replaceToken("ARRAY", position, array, source);
21129                 if (INVALID == test_case.m_case)
21130                 {
21131                         Utils::replaceToken("ARRAY", position, array, source);
21132                 }
21133                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21134
21135                 Utils::replaceAllTokens("TYPE", type_name, source);
21136                 Utils::replaceAllTokens("INDEX", index, source);
21137         }
21138         else
21139         {
21140                 switch (test_case.m_stage)
21141                 {
21142                 case Utils::Shader::GEOMETRY:
21143                         switch (stage)
21144                         {
21145                         case Utils::Shader::FRAGMENT:
21146                                 source = fs;
21147                                 break;
21148                         case Utils::Shader::VERTEX:
21149                                 source = vs;
21150                                 break;
21151                         default:
21152                                 source = "";
21153                         }
21154                         break;
21155                 case Utils::Shader::TESS_CTRL:
21156                         switch (stage)
21157                         {
21158                         case Utils::Shader::FRAGMENT:
21159                                 source = fs;
21160                                 break;
21161                         case Utils::Shader::VERTEX:
21162                                 source = vs;
21163                                 break;
21164                         default:
21165                                 source = "";
21166                         }
21167                         break;
21168                 case Utils::Shader::TESS_EVAL:
21169                         switch (stage)
21170                         {
21171                         case Utils::Shader::FRAGMENT:
21172                                 source = fs;
21173                                 break;
21174                         case Utils::Shader::TESS_CTRL:
21175                                 source = tcs;
21176                                 break;
21177                         case Utils::Shader::VERTEX:
21178                                 source = vs;
21179                                 break;
21180                         default:
21181                                 source = "";
21182                         }
21183                         break;
21184                 case Utils::Shader::VERTEX:
21185                         switch (stage)
21186                         {
21187                         case Utils::Shader::FRAGMENT:
21188                                 source = fs;
21189                                 break;
21190                         default:
21191                                 source = "";
21192                         }
21193                         break;
21194                 default:
21195                         TCU_FAIL("Invalid enum");
21196                         break;
21197                 }
21198         }
21199
21200         return source;
21201 }
21202
21203 /** Get description of test case
21204  *
21205  * @param test_case_index Index of test case
21206  *
21207  * @return Test case description
21208  **/
21209 std::string XFBVariableStrideTest::getTestCaseName(GLuint test_case_index)
21210 {
21211         std::stringstream stream;
21212         testCase&                 test_case = m_test_cases[test_case_index];
21213
21214         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
21215                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
21216
21217         switch (test_case.m_case)
21218         {
21219         case VALID:
21220                 stream << "valid";
21221                 break;
21222         case INVALID:
21223                 stream << "invalid";
21224                 break;
21225         default:
21226                 TCU_FAIL("Invalid enum");
21227         }
21228
21229         return stream.str();
21230 }
21231
21232 /** Get number of test cases
21233  *
21234  * @return Number of test cases
21235  **/
21236 GLuint XFBVariableStrideTest::getTestCaseNumber()
21237 {
21238         return static_cast<GLuint>(m_test_cases.size());
21239 }
21240
21241 /** Selects if "compute" stage is relevant for test
21242  *
21243  * @param ignored
21244  *
21245  * @return false
21246  **/
21247 bool XFBVariableStrideTest::isComputeRelevant(GLuint /* test_case_index */)
21248 {
21249         return false;
21250 }
21251
21252 /** Selects if compilation failure is expected result
21253  *
21254  * @param test_case_index Index of test case
21255  *
21256  * @return true
21257  **/
21258 bool XFBVariableStrideTest::isFailureExpected(GLuint test_case_index)
21259 {
21260         testCase& test_case = m_test_cases[test_case_index];
21261
21262         return (INVALID == test_case.m_case);
21263 }
21264
21265 /** Prepare all test cases
21266  *
21267  **/
21268 void XFBVariableStrideTest::testInit()
21269 {
21270         const GLuint n_types = getTypesNumber();
21271
21272         for (GLuint i = 0; i < n_types; ++i)
21273         {
21274                 const Utils::Type& type = getType(i);
21275
21276                 /*
21277                  Some of the cases are declared as following are considered as invalid,
21278                  but accoring to spec, the following declaration is valid: shaders in the
21279                  transform feedback capturing mode have an initial global default of layout(xfb_buffer=0) out,
21280                  so for the first variable's declaration, the xfb_stride = 16 is applied on buffer 0,  for the
21281                  second variable, its buffer is also inherited from global buffer 0, and its offset does not overflows
21282                  the stride.
21283
21284                  The xfb_stride is the memory width of given buffer, not for variable even though xfb_stride
21285                  is declared on the variable. It seems that the writter of this case misunderstand the concept of
21286                  xfb_stride, because spec describes that xfb_stride can be declared multiple times for the same buffer,
21287                  it is a compile or link-time error to have different values specified for the stride for the same buffer.
21288
21289                  int type_size = 8;
21290                  layout (xfb_offset = 0, xfb_stride = 2 * type_size) out double goku;
21291                  layout (xfb_offset = type_size)                     out double vegeta;
21292                  */
21293                 // all the shaders are valid, so remove the following loop(it contains CASE_MAX is enum of valid and invalid)
21294                 // for (GLuint c = 0; c < CASE_MAX; ++c)
21295                 {
21296                         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21297                         {
21298                                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21299                                         (Utils::Shader::FRAGMENT == stage))
21300                                 {
21301                                         continue;
21302                                 }
21303
21304                                 testCase test_case = { (CASES)VALID, (Utils::Shader::STAGES)stage, type };
21305
21306                                 m_test_cases.push_back(test_case);
21307                         }
21308                 }
21309         }
21310 }
21311
21312 /** Constructor
21313  *
21314  * @param context Test framework context
21315  **/
21316 XFBBlockStrideTest::XFBBlockStrideTest(deqp::Context& context)
21317         : TestBase(context, "xfb_block_stride", "Test verifies that stride qualifier is respected for blocks")
21318 {
21319 }
21320
21321 /** Source for given test case and stage
21322  *
21323  * @param test_case_index Index of test case
21324  * @param stage           Shader stage
21325  *
21326  * @return Shader source
21327  **/
21328 std::string XFBBlockStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21329 {
21330         static const GLchar* var_definition = "layout (xfb_offset = 0, xfb_stride = 128) out Goku {\n"
21331                                                                                   "    vec4 gohan;\n"
21332                                                                                   "    vec4 goten;\n"
21333                                                                                   "    vec4 chichi;\n"
21334                                                                                   "} gokuARRAY;\n";
21335         static const GLchar* var_use = "    gokuINDEX.gohan  = vec4(1, 0, 0, 0);\n"
21336                                                                    "    gokuINDEX.goten  = vec4(0, 0, 1, 0);\n"
21337                                                                    "    gokuINDEX.chichi = vec4(0, 1, 0, 0);\n"
21338                                                                    "    if (vec4(0) == result)\n"
21339                                                                    "    {\n"
21340                                                                    "        gokuINDEX.gohan  = vec4(0, 1, 1, 1);\n"
21341                                                                    "        gokuINDEX.goten  = vec4(1, 1, 0, 1);\n"
21342                                                                    "        gokuINDEX.chichi = vec4(1, 0, 1, 1);\n"
21343                                                                    "    }\n";
21344         static const GLchar* gs_tested =
21345                 "#version 430 core\n"
21346                 "#extension GL_ARB_enhanced_layouts : require\n"
21347                 "\n"
21348                 "layout(points)                           in;\n"
21349                 "layout(triangle_strip, max_vertices = 4) out;\n"
21350                 "\n"
21351                 "VAR_DEFINITION"
21352                 "\n"
21353                 "out gl_PerVertex \n"
21354                 "{ \n"
21355                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
21356                 "}; \n"
21357                 "in  vec4 tes_gs[];\n"
21358                 "out vec4 gs_fs;\n"
21359                 "\n"
21360                 "void main()\n"
21361                 "{\n"
21362                 "    vec4 result = tes_gs[0];\n"
21363                 "\n"
21364                 "VARIABLE_USE"
21365                 "\n"
21366                 "    gs_fs = result;\n"
21367                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21368                 "    EmitVertex();\n"
21369                 "    gs_fs = result;\n"
21370                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21371                 "    EmitVertex();\n"
21372                 "    gs_fs = result;\n"
21373                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
21374                 "    EmitVertex();\n"
21375                 "    gs_fs = result;\n"
21376                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
21377                 "    EmitVertex();\n"
21378                 "}\n"
21379                 "\n";
21380         static const GLchar* tcs = "#version 430 core\n"
21381                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21382                                                            "\n"
21383                                                            "layout(vertices = 1) out;\n"
21384                                                            "\n"
21385                                                            "in  vec4 vs_tcs[];\n"
21386                                                            "out vec4 tcs_tes[];\n"
21387                                                            "\n"
21388                                                            "void main()\n"
21389                                                            "{\n"
21390                                                            "\n"
21391                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
21392                                                            "\n"
21393                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21394                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21395                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21396                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21397                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21398                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21399                                                            "}\n"
21400                                                            "\n";
21401 #if 0
21402         static const GLchar* tcs_tested =
21403                 "#version 430 core\n"
21404                 "#extension GL_ARB_enhanced_layouts : require\n"
21405                 "\n"
21406                 "layout(vertices = 1) out;\n"
21407                 "\n"
21408                 "VAR_DEFINITION"
21409                 "\n"
21410                 "in  vec4 vs_tcs[];\n"
21411                 "out vec4 tcs_tes[];\n"
21412                 "\n"
21413                 "void main()\n"
21414                 "{\n"
21415                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
21416                 "\n"
21417                 "VARIABLE_USE"
21418                 "\n"
21419                 "    tcs_tes[gl_InvocationID] = result;\n"
21420                 "\n"
21421                 "    gl_TessLevelOuter[0] = 1.0;\n"
21422                 "    gl_TessLevelOuter[1] = 1.0;\n"
21423                 "    gl_TessLevelOuter[2] = 1.0;\n"
21424                 "    gl_TessLevelOuter[3] = 1.0;\n"
21425                 "    gl_TessLevelInner[0] = 1.0;\n"
21426                 "    gl_TessLevelInner[1] = 1.0;\n"
21427                 "}\n"
21428                 "\n";
21429 #endif
21430         static const GLchar* tes_tested = "#version 430 core\n"
21431                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21432                                                                           "\n"
21433                                                                           "layout(isolines, point_mode) in;\n"
21434                                                                           "\n"
21435                                                                           "VAR_DEFINITION"
21436                                                                           "\n"
21437                                                                           "in  vec4 tcs_tes[];\n"
21438                                                                           "out vec4 tes_gs;\n"
21439                                                                           "\n"
21440                                                                           "void main()\n"
21441                                                                           "{\n"
21442                                                                           "    vec4 result = tcs_tes[0];\n"
21443                                                                           "\n"
21444                                                                           "VARIABLE_USE"
21445                                                                           "\n"
21446                                                                           "    tes_gs += result;\n"
21447                                                                           "}\n"
21448                                                                           "\n";
21449         static const GLchar* vs = "#version 430 core\n"
21450                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21451                                                           "\n"
21452                                                           "in  vec4 in_vs;\n"
21453                                                           "out vec4 vs_tcs;\n"
21454                                                           "\n"
21455                                                           "void main()\n"
21456                                                           "{\n"
21457                                                           "    vs_tcs = in_vs;\n"
21458                                                           "}\n"
21459                                                           "\n";
21460         static const GLchar* vs_tested = "#version 430 core\n"
21461                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21462                                                                          "\n"
21463                                                                          "VAR_DEFINITION"
21464                                                                          "\n"
21465                                                                          "in  vec4 in_vs;\n"
21466                                                                          "out vec4 vs_tcs;\n"
21467                                                                          "\n"
21468                                                                          "void main()\n"
21469                                                                          "{\n"
21470                                                                          "    vec4 result = in_vs;\n"
21471                                                                          "\n"
21472                                                                          "VARIABLE_USE"
21473                                                                          "\n"
21474                                                                          "    vs_tcs += result;\n"
21475                                                                          "}\n"
21476                                                                          "\n";
21477
21478         std::string                       source;
21479         Utils::Shader::STAGES test_case = m_test_cases[test_case_index];
21480
21481         if (test_case == stage)
21482         {
21483                 const GLchar* array     = "";
21484                 const GLchar* index     = "";
21485                 size_t            position = 0;
21486                 size_t            temp;
21487                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
21488                 // change array = "[]" to "[1]"
21489                 switch (stage)
21490                 {
21491                 case Utils::Shader::GEOMETRY:
21492                         source = gs_tested;
21493                         array  = "[1]";
21494                         index  = "[0]";
21495                         break;
21496 /*
21497                          It is invalid to define transform feedback output in HS
21498                          */
21499 #if 0
21500                         case Utils::Shader::TESS_CTRL:
21501                         source = tcs_tested;
21502                         array = "[]";
21503                         index = "[gl_InvocationID]";
21504                         break;
21505 #endif
21506                 case Utils::Shader::TESS_EVAL:
21507                         source = tes_tested;
21508                         array  = "[1]";
21509                         index  = "[0]";
21510                         break;
21511                 case Utils::Shader::VERTEX:
21512                         source = vs_tested;
21513                         break;
21514                 default:
21515                         TCU_FAIL("Invalid enum");
21516                 }
21517
21518                 temp = position;
21519                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
21520                 position = temp;
21521                 Utils::replaceToken("ARRAY", position, array, source);
21522                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
21523
21524                 Utils::replaceAllTokens("INDEX", index, source);
21525         }
21526         else
21527         {
21528                 switch (test_case)
21529                 {
21530                 case Utils::Shader::GEOMETRY:
21531                         switch (stage)
21532                         {
21533                         case Utils::Shader::VERTEX:
21534                                 source = vs;
21535                                 break;
21536                         default:
21537                                 source = "";
21538                         }
21539                         break;
21540                 case Utils::Shader::TESS_CTRL:
21541                         switch (stage)
21542                         {
21543                         case Utils::Shader::VERTEX:
21544                                 source = vs;
21545                                 break;
21546                         default:
21547                                 source = "";
21548                         }
21549                         break;
21550                 case Utils::Shader::TESS_EVAL:
21551                         switch (stage)
21552                         {
21553                         case Utils::Shader::TESS_CTRL:
21554                                 source = tcs;
21555                                 break;
21556                         case Utils::Shader::VERTEX:
21557                                 source = vs;
21558                                 break;
21559                         default:
21560                                 source = "";
21561                         }
21562                         break;
21563                 case Utils::Shader::VERTEX:
21564                         source = "";
21565                         break;
21566                 default:
21567                         TCU_FAIL("Invalid enum");
21568                         break;
21569                 }
21570         }
21571
21572         return source;
21573 }
21574
21575 /** Get description of test case
21576  *
21577  * @param test_case_index Index of test case
21578  *
21579  * @return Test case description
21580  **/
21581 std::string XFBBlockStrideTest::getTestCaseName(GLuint test_case_index)
21582 {
21583         std::stringstream stream;
21584
21585         stream << "Stage: " << Utils::Shader::GetStageName(m_test_cases[test_case_index]);
21586
21587         return stream.str();
21588 }
21589
21590 /** Get number of test cases
21591  *
21592  * @return Number of test cases
21593  **/
21594 GLuint XFBBlockStrideTest::getTestCaseNumber()
21595 {
21596         return static_cast<GLuint>(m_test_cases.size());
21597 }
21598
21599 /** Inspects program for xfb stride
21600  *
21601  * @param program Program to query
21602  *
21603  * @return true if query results match expected values, false otherwise
21604  **/
21605 bool XFBBlockStrideTest::inspectProgram(Utils::Program& program)
21606 {
21607         GLint stride = 0;
21608
21609         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
21610                                                 1 /* buf_size */, &stride);
21611
21612         return (128 == stride);
21613 }
21614
21615 /** Runs test case
21616  *
21617  * @param test_case_index Id of test case
21618  *
21619  * @return true if test case pass, false otherwise
21620  **/
21621 bool XFBBlockStrideTest::testCase(GLuint test_case_index)
21622 {
21623         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
21624         Utils::Program   program(m_context);
21625         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
21626         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
21627         bool                       test_case_result = true;
21628         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
21629
21630         program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
21631
21632         test_case_result = inspectProgram(program);
21633
21634         return test_case_result;
21635 }
21636
21637 /** Prepare all test cases
21638  *
21639  **/
21640 void XFBBlockStrideTest::testInit()
21641 {
21642         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
21643         {
21644                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
21645                         (Utils::Shader::FRAGMENT == stage))
21646                 {
21647                         continue;
21648                 }
21649
21650                 m_test_cases.push_back((Utils::Shader::STAGES)stage);
21651         }
21652 }
21653
21654 /** Constructor
21655  *
21656  * @param context Test context
21657  **/
21658 XFBBlockMemberStrideTest::XFBBlockMemberStrideTest(deqp::Context& context)
21659         : BufferTestBase(context, "xfb_block_member_stride",
21660                                          "Test verifies that xfb_stride qualifier is respected for block member")
21661 {
21662         /* Nothing to be done here */
21663 }
21664
21665 /** Get descriptors of buffers necessary for test
21666  *
21667  * @param ignored
21668  * @param out_descriptors Descriptors of buffers used by test
21669  **/
21670 void XFBBlockMemberStrideTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
21671                                                                                                         bufferDescriptor::Vector& out_descriptors)
21672 {
21673         const Utils::Type& vec4 = Utils::Type::vec4;
21674
21675         /* Test needs single uniform and xfb */
21676         out_descriptors.resize(2);
21677
21678         /* Get references */
21679         bufferDescriptor& uniform = out_descriptors[0];
21680         bufferDescriptor& xfb    = out_descriptors[1];
21681
21682         /* Index */
21683         uniform.m_index = 0;
21684         xfb.m_index             = 0;
21685
21686         /* Target */
21687         uniform.m_target = Utils::Buffer::Uniform;
21688         xfb.m_target     = Utils::Buffer::Transform_feedback;
21689
21690         /* Data */
21691         static const GLuint                     vec4_size   = 16;
21692         const std::vector<GLubyte>& gohan_data  = vec4.GenerateDataPacked();
21693         const std::vector<GLubyte>& goten_data  = vec4.GenerateDataPacked();
21694         const std::vector<GLubyte>& chichi_data = vec4.GenerateDataPacked();
21695
21696         /* Uniform data */
21697         uniform.m_initial_data.resize(3 * vec4_size);
21698         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], vec4_size);
21699         memcpy(&uniform.m_initial_data[0] + vec4_size, &goten_data[0], vec4_size);
21700         memcpy(&uniform.m_initial_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21701
21702         /* XFB data */
21703         xfb.m_initial_data.resize(4 * vec4_size);
21704         xfb.m_expected_data.resize(4 * vec4_size);
21705
21706         for (GLuint i = 0; i < 4 * vec4_size; ++i)
21707         {
21708                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
21709                 xfb.m_expected_data[i] = (glw::GLubyte)i;
21710         }
21711
21712         // the xfb_offset of "chichi" should be 32
21713         memcpy(&xfb.m_expected_data[0] + 0, &gohan_data[0], vec4_size);
21714         memcpy(&xfb.m_expected_data[0] + vec4_size, &goten_data[0], vec4_size);
21715         memcpy(&xfb.m_expected_data[0] + 2 * vec4_size, &chichi_data[0], vec4_size);
21716 }
21717
21718 /** Get body of main function for given shader stage
21719  *
21720  * @param ignored
21721  * @param stage            Shader stage
21722  * @param out_assignments  Set to empty
21723  * @param out_calculations Set to empty
21724  **/
21725 void XFBBlockMemberStrideTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21726                                                                                          std::string& out_assignments, std::string& out_calculations)
21727 {
21728         out_calculations = "";
21729
21730         static const GLchar* gs = "    gohan  = uni_gohan;\n"
21731                                                           "    goten  = uni_goten;\n"
21732                                                           "    chichi = uni_chichi;\n";
21733         static const GLchar* fs = "    fs_out = gohan + goten + chichi;\n";
21734
21735         const GLchar* assignments = "";
21736         switch (stage)
21737         {
21738         case Utils::Shader::FRAGMENT:
21739                 assignments = fs;
21740                 break;
21741         case Utils::Shader::GEOMETRY:
21742                 assignments = gs;
21743                 break;
21744         default:
21745                 break;
21746         }
21747
21748         out_assignments = assignments;
21749 }
21750
21751 /** Get interface of shader
21752  *
21753  * @param ignored
21754  * @param stage            Shader stage
21755  * @param out_interface    Set to ""
21756  **/
21757 void XFBBlockMemberStrideTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
21758                                                                                                   std::string& out_interface)
21759 {
21760         static const GLchar* gs = "layout (xfb_buffer = 0, xfb_offset = 0) out Goku {\n"
21761                                                           "                             vec4 gohan;\n"
21762                                                           "    layout (xfb_stride = 32) vec4 goten;\n"
21763                                                           "                             vec4 chichi;\n"
21764                                                           "};\n"
21765                                                           "layout(binding = 0) uniform gs_block {\n"
21766                                                           "    vec4 uni_gohan;\n"
21767                                                           "    vec4 uni_goten;\n"
21768                                                           "    vec4 uni_chichi;\n"
21769                                                           "};\n";
21770         static const GLchar* fs = "in Goku {\n"
21771                                                           "    vec4 gohan;\n"
21772                                                           "    vec4 goten;\n"
21773                                                           "    vec4 chichi;\n"
21774                                                           "};\n"
21775                                                           "out vec4 fs_out;\n";
21776
21777         switch (stage)
21778         {
21779         case Utils::Shader::FRAGMENT:
21780                 out_interface = fs;
21781                 break;
21782         case Utils::Shader::GEOMETRY:
21783                 out_interface = gs;
21784                 break;
21785         default:
21786                 out_interface = "";
21787                 return;
21788         }
21789 }
21790
21791 /** Inspects program to check if all resources are as expected
21792  *
21793  * @param ignored
21794  * @param program    Program instance
21795  * @param out_stream Error message
21796  *
21797  * @return true if everything is ok, false otherwise
21798  **/
21799 bool XFBBlockMemberStrideTest::inspectProgram(GLuint /* test_case_index*/, Utils::Program& program,
21800                                                                                           std::stringstream& out_stream)
21801 {
21802         const GLuint gohan_id  = program.GetResourceIndex("gohan", GL_TRANSFORM_FEEDBACK_VARYING);
21803         const GLuint goten_id  = program.GetResourceIndex("goten", GL_TRANSFORM_FEEDBACK_VARYING);
21804         const GLuint chichi_id = program.GetResourceIndex("chichi", GL_TRANSFORM_FEEDBACK_VARYING);
21805
21806         GLint gohan_offset  = 0;
21807         GLint goten_offset  = 0;
21808         GLint chichi_offset = 0;
21809
21810         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, gohan_id, GL_OFFSET, 1, &gohan_offset);
21811         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, goten_id, GL_OFFSET, 1, &goten_offset);
21812         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, chichi_id, GL_OFFSET, 1, &chichi_offset);
21813
21814         // the xfb_offset of "chichi" should be 32
21815         if ((0 != gohan_offset) || (16 != goten_offset) || (32 != chichi_offset))
21816         {
21817                 out_stream << "Got wrong offset: [" << gohan_offset << ", " << goten_offset << ", " << chichi_offset
21818                                    << "] expected: [0, 16, 48]";
21819                 return false;
21820         }
21821
21822         return true;
21823 }
21824
21825 /** Constructor
21826  *
21827  * @param context Test framework context
21828  **/
21829 XFBDuplicatedStrideTest::XFBDuplicatedStrideTest(deqp::Context& context)
21830         : NegativeTestBase(context, "xfb_duplicated_stride",
21831                                            "Test verifies that compiler reports error when conflicting stride qualifiers are used")
21832 {
21833 }
21834
21835 /** Source for given test case and stage
21836  *
21837  * @param test_case_index Index of test case
21838  * @param stage           Shader stage
21839  *
21840  * @return Shader source
21841  **/
21842 std::string XFBDuplicatedStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
21843 {
21844         static const GLchar* invalid_var_definition = "const uint valid_stride = 64;\n"
21845                                                                                                   "const uint conflicting_stride = 128;\n"
21846                                                                                                   "\n"
21847                                                                                                   "layout (xfb_buffer = 0, xfb_stride = valid_stride)       out;\n"
21848                                                                                                   "layout (xfb_buffer = 0, xfb_stride = conflicting_stride) out;\n";
21849         static const GLchar* valid_var_definition = "const uint valid_stride = 64;\n"
21850                                                                                                 "\n"
21851                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n"
21852                                                                                                 "layout (xfb_buffer = 0, xfb_stride = valid_stride) out;\n";
21853         static const GLchar* fs = "#version 430 core\n"
21854                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21855                                                           "\n"
21856                                                           "in  vec4 any_fs;\n"
21857                                                           "out vec4 fs_out;\n"
21858                                                           "\n"
21859                                                           "void main()\n"
21860                                                           "{\n"
21861                                                           "    fs_out = any_fs;\n"
21862                                                           "}\n"
21863                                                           "\n";
21864         static const GLchar* gs_tested = "#version 430 core\n"
21865                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21866                                                                          "\n"
21867                                                                          "layout(points)                           in;\n"
21868                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
21869                                                                          "\n"
21870                                                                          "VAR_DEFINITION"
21871                                                                          "\n"
21872                                                                          "in  vec4 vs_any[];\n"
21873                                                                          "out vec4 any_fs;\n"
21874                                                                          "\n"
21875                                                                          "void main()\n"
21876                                                                          "{\n"
21877                                                                          "    vec4 result = vs_any[0];\n"
21878                                                                          "\n"
21879                                                                          "VARIABLE_USE"
21880                                                                          "\n"
21881                                                                          "    any_fs = result;\n"
21882                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
21883                                                                          "    EmitVertex();\n"
21884                                                                          "    any_fs = result;\n"
21885                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
21886                                                                          "    EmitVertex();\n"
21887                                                                          "    any_fs = result;\n"
21888                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
21889                                                                          "    EmitVertex();\n"
21890                                                                          "    any_fs = result;\n"
21891                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
21892                                                                          "    EmitVertex();\n"
21893                                                                          "}\n"
21894                                                                          "\n";
21895         static const GLchar* tcs = "#version 430 core\n"
21896                                                            "#extension GL_ARB_enhanced_layouts : require\n"
21897                                                            "\n"
21898                                                            "layout(vertices = 1) out;\n"
21899                                                            "\n"
21900                                                            "in  vec4 vs_any[];\n"
21901                                                            "out vec4 tcs_tes[];\n"
21902                                                            "\n"
21903                                                            "void main()\n"
21904                                                            "{\n"
21905                                                            "\n"
21906                                                            "    tcs_tes[gl_InvocationID] = vs_any[gl_InvocationID];\n"
21907                                                            "\n"
21908                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
21909                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
21910                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
21911                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
21912                                                            "    gl_TessLevelInner[0] = 1.0;\n"
21913                                                            "    gl_TessLevelInner[1] = 1.0;\n"
21914                                                            "}\n"
21915                                                            "\n";
21916         static const GLchar* tcs_tested = "#version 430 core\n"
21917                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21918                                                                           "\n"
21919                                                                           "layout(vertices = 1) out;\n"
21920                                                                           "\n"
21921                                                                           "VAR_DEFINITION"
21922                                                                           "\n"
21923                                                                           "in  vec4 vs_any[];\n"
21924                                                                           "out vec4 any_fs[];\n"
21925                                                                           "\n"
21926                                                                           "void main()\n"
21927                                                                           "{\n"
21928                                                                           "    vec4 result = vs_any[gl_InvocationID];\n"
21929                                                                           "\n"
21930                                                                           "VARIABLE_USE"
21931                                                                           "\n"
21932                                                                           "    any_fs[gl_InvocationID] = result;\n"
21933                                                                           "\n"
21934                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
21935                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
21936                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
21937                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
21938                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
21939                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
21940                                                                           "}\n"
21941                                                                           "\n";
21942         static const GLchar* tes_tested = "#version 430 core\n"
21943                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21944                                                                           "\n"
21945                                                                           "layout(isolines, point_mode) in;\n"
21946                                                                           "\n"
21947                                                                           "VAR_DEFINITION"
21948                                                                           "\n"
21949                                                                           "in  vec4 tcs_tes[];\n"
21950                                                                           "out vec4 any_fs;\n"
21951                                                                           "\n"
21952                                                                           "void main()\n"
21953                                                                           "{\n"
21954                                                                           "    vec4 result = tcs_tes[0];\n"
21955                                                                           "\n"
21956                                                                           "VARIABLE_USE"
21957                                                                           "\n"
21958                                                                           "    any_fs = result;\n"
21959                                                                           "}\n"
21960                                                                           "\n";
21961         static const GLchar* vs = "#version 430 core\n"
21962                                                           "#extension GL_ARB_enhanced_layouts : require\n"
21963                                                           "\n"
21964                                                           "in  vec4 in_vs;\n"
21965                                                           "out vec4 vs_any;\n"
21966                                                           "\n"
21967                                                           "void main()\n"
21968                                                           "{\n"
21969                                                           "    vs_any = in_vs;\n"
21970                                                           "}\n"
21971                                                           "\n";
21972         static const GLchar* vs_tested = "#version 430 core\n"
21973                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
21974                                                                          "\n"
21975                                                                          "VAR_DEFINITION"
21976                                                                          "\n"
21977                                                                          "in  vec4 in_vs;\n"
21978                                                                          "out vec4 any_fs;\n"
21979                                                                          "\n"
21980                                                                          "void main()\n"
21981                                                                          "{\n"
21982                                                                          "    vec4 result = in_vs;\n"
21983                                                                          "\n"
21984                                                                          "VARIABLE_USE"
21985                                                                          "\n"
21986                                                                          "    any_fs += result;\n"
21987                                                                          "}\n"
21988                                                                          "\n";
21989
21990         std::string source;
21991         testCase&   test_case = m_test_cases[test_case_index];
21992
21993         if (test_case.m_stage == stage)
21994         {
21995                 size_t            position               = 0;
21996                 const GLchar* var_definition = 0;
21997                 const GLchar* var_use            = "";
21998
21999                 switch (test_case.m_case)
22000                 {
22001                 case VALID:
22002                         var_definition = valid_var_definition;
22003                         break;
22004                 case INVALID:
22005                         var_definition = invalid_var_definition;
22006                         break;
22007                 default:
22008                         TCU_FAIL("Invalid enum");
22009                 }
22010
22011                 switch (stage)
22012                 {
22013                 case Utils::Shader::GEOMETRY:
22014                         source = gs_tested;
22015                         break;
22016                 case Utils::Shader::TESS_CTRL:
22017                         source = tcs_tested;
22018                         break;
22019                 case Utils::Shader::TESS_EVAL:
22020                         source = tes_tested;
22021                         break;
22022                 case Utils::Shader::VERTEX:
22023                         source = vs_tested;
22024                         break;
22025                 default:
22026                         TCU_FAIL("Invalid enum");
22027                 }
22028
22029                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22030                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22031         }
22032         else
22033         {
22034                 switch (test_case.m_stage)
22035                 {
22036                 case Utils::Shader::GEOMETRY:
22037                         switch (stage)
22038                         {
22039                         case Utils::Shader::FRAGMENT:
22040                                 source = fs;
22041                                 break;
22042                         case Utils::Shader::VERTEX:
22043                                 source = vs;
22044                                 break;
22045                         default:
22046                                 source = "";
22047                         }
22048                         break;
22049                 case Utils::Shader::TESS_CTRL:
22050                         switch (stage)
22051                         {
22052                         case Utils::Shader::FRAGMENT:
22053                                 source = fs;
22054                                 break;
22055                         case Utils::Shader::VERTEX:
22056                                 source = vs;
22057                                 break;
22058                         default:
22059                                 source = "";
22060                         }
22061                         break;
22062                 case Utils::Shader::TESS_EVAL:
22063                         switch (stage)
22064                         {
22065                         case Utils::Shader::FRAGMENT:
22066                                 source = fs;
22067                                 break;
22068                         case Utils::Shader::TESS_CTRL:
22069                                 source = tcs;
22070                                 break;
22071                         case Utils::Shader::VERTEX:
22072                                 source = vs;
22073                                 break;
22074                         default:
22075                                 source = "";
22076                         }
22077                         break;
22078                 case Utils::Shader::VERTEX:
22079                         switch (stage)
22080                         {
22081                         case Utils::Shader::FRAGMENT:
22082                                 source = fs;
22083                                 break;
22084                         default:
22085                                 source = "";
22086                         }
22087                         break;
22088                 default:
22089                         TCU_FAIL("Invalid enum");
22090                         break;
22091                 }
22092         }
22093
22094         return source;
22095 }
22096
22097 /** Get description of test case
22098  *
22099  * @param test_case_index Index of test case
22100  *
22101  * @return Test case description
22102  **/
22103 std::string XFBDuplicatedStrideTest::getTestCaseName(GLuint test_case_index)
22104 {
22105         std::stringstream stream;
22106         testCase&                 test_case = m_test_cases[test_case_index];
22107
22108         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
22109
22110         switch (test_case.m_case)
22111         {
22112         case VALID:
22113                 stream << "valid";
22114                 break;
22115         case INVALID:
22116                 stream << "invalid";
22117                 break;
22118         default:
22119                 TCU_FAIL("Invalid enum");
22120         }
22121
22122         return stream.str();
22123 }
22124
22125 /** Get number of test cases
22126  *
22127  * @return Number of test cases
22128  **/
22129 GLuint XFBDuplicatedStrideTest::getTestCaseNumber()
22130 {
22131         return static_cast<GLuint>(m_test_cases.size());
22132 }
22133
22134 /** Selects if "compute" stage is relevant for test
22135  *
22136  * @param ignored
22137  *
22138  * @return false
22139  **/
22140 bool XFBDuplicatedStrideTest::isComputeRelevant(GLuint /* test_case_index */)
22141 {
22142         return false;
22143 }
22144
22145 /** Selects if compilation failure is expected result
22146  *
22147  * @param test_case_index Index of test case
22148  *
22149  * @return true
22150  **/
22151 bool XFBDuplicatedStrideTest::isFailureExpected(GLuint test_case_index)
22152 {
22153         testCase& test_case = m_test_cases[test_case_index];
22154
22155         return (INVALID == test_case.m_case);
22156 }
22157
22158 /** Prepare all test cases
22159  *
22160  **/
22161 void XFBDuplicatedStrideTest::testInit()
22162 {
22163         for (GLuint c = 0; c < CASE_MAX; ++c)
22164         {
22165                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22166                 {
22167                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22168                                 (Utils::Shader::FRAGMENT == stage))
22169                         {
22170                                 continue;
22171                         }
22172
22173                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
22174
22175                         m_test_cases.push_back(test_case);
22176                 }
22177         }
22178 }
22179
22180 /** Constructor
22181  *
22182  * @param context Test framework context
22183  **/
22184 XFBGetProgramResourceAPITest::XFBGetProgramResourceAPITest(deqp::Context& context)
22185         : TestBase(context, "xfb_get_program_resource_api",
22186                            "Test verifies that get program resource reports correct results for XFB")
22187 {
22188 }
22189
22190 /** Source for given test case and stage
22191  *
22192  * @param test_case_index Index of test case
22193  * @param stage           Shader stage
22194  *
22195  * @return Shader source
22196  **/
22197 std::string XFBGetProgramResourceAPITest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
22198 {
22199         static const GLchar* api_var_definition = "out TYPE b0_v1ARRAY;\n"
22200                                                                                           "out TYPE b1_v1ARRAY;\n"
22201                                                                                           "out TYPE b0_v3ARRAY;\n"
22202                                                                                           "out TYPE b0_v0ARRAY;\n";
22203         static const GLchar* xfb_var_definition =
22204                 "const uint type_size = SIZE;\n"
22205                 "\n"
22206                 "layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;\n"
22207                 "\n"
22208                 "layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out TYPE b0_v1ARRAY;\n"
22209                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out TYPE b1_v1ARRAY;\n"
22210                 "layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out TYPE b0_v3ARRAY;\n"
22211                 "layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out TYPE b0_v0ARRAY;\n";
22212         static const GLchar* var_use = "    b0_v1INDEX = TYPE(0);\n"
22213                                                                    "    b1_v1INDEX = TYPE(1);\n"
22214                                                                    "    b0_v3INDEX = TYPE(0);\n"
22215                                                                    "    b0_v0INDEX = TYPE(1);\n"
22216                                                                    "    if (vec4(0) == result)\n"
22217                                                                    "    {\n"
22218                                                                    "        b0_v1INDEX = TYPE(1);\n"
22219                                                                    "        b1_v1INDEX = TYPE(0);\n"
22220                                                                    "        b0_v3INDEX = TYPE(1);\n"
22221                                                                    "        b0_v0INDEX = TYPE(0);\n"
22222                                                                    "    }\n";
22223         static const GLchar* gs_tested =
22224                 "#version 430 core\n"
22225                 "#extension GL_ARB_enhanced_layouts : require\n"
22226                 "\n"
22227                 "layout(points)                           in;\n"
22228                 "layout(triangle_strip, max_vertices = 4) out;\n"
22229                 "\n"
22230                 "VAR_DEFINITION"
22231                 "\n"
22232                 "out gl_PerVertex \n"
22233                 "{ \n"
22234                 "   vec4  gl_Position; \n" // gl_Position must be redeclared in separable program mode
22235                 "}; \n"
22236                 "in  vec4 tes_gs[];\n"
22237                 "out vec4 gs_fs;\n"
22238                 "\n"
22239                 "void main()\n"
22240                 "{\n"
22241                 "    vec4 result = tes_gs[0];\n"
22242                 "\n"
22243                 "VARIABLE_USE"
22244                 "\n"
22245                 "    gs_fs = result;\n"
22246                 "    gl_Position  = vec4(-1, -1, 0, 1);\n"
22247                 "    EmitVertex();\n"
22248                 "    gs_fs = result;\n"
22249                 "    gl_Position  = vec4(-1, 1, 0, 1);\n"
22250                 "    EmitVertex();\n"
22251                 "    gs_fs = result;\n"
22252                 "    gl_Position  = vec4(1, -1, 0, 1);\n"
22253                 "    EmitVertex();\n"
22254                 "    gs_fs = result;\n"
22255                 "    gl_Position  = vec4(1, 1, 0, 1);\n"
22256                 "    EmitVertex();\n"
22257                 "}\n"
22258                 "\n";
22259 #if 0
22260         static const GLchar* tcs_tested =
22261                 "#version 430 core\n"
22262                 "#extension GL_ARB_enhanced_layouts : require\n"
22263                 "\n"
22264                 "layout(vertices = 1) out;\n"
22265                 "\n"
22266                 "VAR_DEFINITION"
22267                 "\n"
22268                 "in  vec4 vs_tcs[];\n"
22269                 "out vec4 tcs_tes[];\n"
22270                 "\n"
22271                 "void main()\n"
22272                 "{\n"
22273                 "    vec4 result = vs_tcs[gl_InvocationID];\n"
22274                 "\n"
22275                 "VARIABLE_USE"
22276                 "\n"
22277                 "    tcs_tes[gl_InvocationID] = result;\n"
22278                 "\n"
22279                 "    gl_TessLevelOuter[0] = 1.0;\n"
22280                 "    gl_TessLevelOuter[1] = 1.0;\n"
22281                 "    gl_TessLevelOuter[2] = 1.0;\n"
22282                 "    gl_TessLevelOuter[3] = 1.0;\n"
22283                 "    gl_TessLevelInner[0] = 1.0;\n"
22284                 "    gl_TessLevelInner[1] = 1.0;\n"
22285                 "}\n"
22286                 "\n";
22287 #endif
22288         static const GLchar* tes_tested = "#version 430 core\n"
22289                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
22290                                                                           "\n"
22291                                                                           "layout(isolines, point_mode) in;\n"
22292                                                                           "\n"
22293                                                                           "VAR_DEFINITION"
22294                                                                           "\n"
22295                                                                           "in  vec4 tcs_tes[];\n"
22296                                                                           "out vec4 tes_gs;\n"
22297                                                                           "\n"
22298                                                                           "void main()\n"
22299                                                                           "{\n"
22300                                                                           "    vec4 result = tcs_tes[0];\n"
22301                                                                           "\n"
22302                                                                           "VARIABLE_USE"
22303                                                                           "\n"
22304                                                                           "    tes_gs = result;\n"
22305                                                                           "}\n"
22306                                                                           "\n";
22307         static const GLchar* vs_tested = "#version 430 core\n"
22308                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
22309                                                                          "\n"
22310                                                                          "VAR_DEFINITION"
22311                                                                          "\n"
22312                                                                          "in  vec4 in_vs;\n"
22313                                                                          "out vec4 vs_tcs;\n"
22314                                                                          "\n"
22315                                                                          "void main()\n"
22316                                                                          "{\n"
22317                                                                          "    vec4 result = in_vs;\n"
22318                                                                          "\n"
22319                                                                          "VARIABLE_USE"
22320                                                                          "\n"
22321                                                                          "    vs_tcs = result;\n"
22322                                                                          "}\n"
22323                                                                          "\n";
22324
22325         std::string              source;
22326         const test_Case& test_case = m_test_cases[test_case_index];
22327
22328         if (test_case.m_stage == stage)
22329         {
22330                 const GLchar* array = "";
22331                 GLchar            buffer[16];
22332                 const GLchar* index     = "";
22333                 size_t            position = 0;
22334                 size_t            temp;
22335                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
22336                 const GLchar* var_definition = 0;
22337
22338                 sprintf(buffer, "%d", test_case.m_type.GetSize());
22339
22340                 if (XFB == test_case.m_case)
22341                 {
22342                         var_definition = xfb_var_definition;
22343                 }
22344                 else
22345                 {
22346                         var_definition = api_var_definition;
22347                 }
22348
22349                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
22350                 // change array = "[]" to "[1]"
22351                 switch (stage)
22352                 {
22353                 case Utils::Shader::GEOMETRY:
22354                         source = gs_tested;
22355                         array  = "[1]";
22356                         index  = "[0]";
22357                         break;
22358 // It is invalid to output transform feedback varyings in tessellation control shader
22359 #if 0
22360                 case Utils::Shader::TESS_CTRL:
22361                         source = tcs_tested;
22362                         array = "[]";
22363                         index = "[gl_InvocationID]";
22364                         break;
22365 #endif
22366                 case Utils::Shader::TESS_EVAL:
22367                         source = tes_tested;
22368                         array  = "[1]";
22369                         index  = "[0]";
22370                         break;
22371                 case Utils::Shader::VERTEX:
22372                         source = vs_tested;
22373                         break;
22374                 default:
22375                         TCU_FAIL("Invalid enum");
22376                 }
22377
22378                 temp = position;
22379                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
22380                 if (XFB == test_case.m_case)
22381                 {
22382                         position = temp;
22383                         Utils::replaceToken("SIZE", position, buffer, source);
22384                 }
22385                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
22386
22387                 Utils::replaceAllTokens("ARRAY", array, source);
22388                 Utils::replaceAllTokens("INDEX", index, source);
22389                 Utils::replaceAllTokens("TYPE", type_name, source);
22390         }
22391         else
22392         {
22393                 source = "";
22394         }
22395
22396         return source;
22397 }
22398
22399 /** Get description of test case
22400  *
22401  * @param test_case_index Index of test case
22402  *
22403  * @return Test case description
22404  **/
22405 std::string XFBGetProgramResourceAPITest::getTestCaseName(GLuint test_case_index)
22406 {
22407         std::stringstream stream;
22408         const test_Case&  test_case = m_test_cases[test_case_index];
22409
22410         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
22411                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", case: ";
22412
22413         switch (test_case.m_case)
22414         {
22415         case INTERLEAVED:
22416                 stream << "interleaved";
22417                 break;
22418         case SEPARATED:
22419                 stream << "separated";
22420                 break;
22421         case XFB:
22422                 stream << "xfb";
22423                 break;
22424         default:
22425                 TCU_FAIL("Invalid enum");
22426         }
22427
22428         return stream.str();
22429 }
22430
22431 /** Get number of test cases
22432  *
22433  * @return Number of test cases
22434  **/
22435 GLuint XFBGetProgramResourceAPITest::getTestCaseNumber()
22436 {
22437         return static_cast<GLuint>(m_test_cases.size());
22438 }
22439
22440 /** Inspects program for offset, buffer index, buffer stride and type
22441  *
22442  * @param test_case_index Index of test case
22443  * @param program         Program to query
22444  *
22445  * @return true if query results match expected values, false otherwise
22446  **/
22447 bool XFBGetProgramResourceAPITest::inspectProgram(glw::GLuint test_case_index, Utils::Program& program)
22448 {
22449         GLint                    b0_stride      = 0;
22450         GLint                    b1_stride      = 0;
22451         GLint                    b0_v0_buf      = 0;
22452         GLint                    b0_v0_offset = 0;
22453         GLint                    b0_v0_type   = 0;
22454         GLint                    b0_v1_buf      = 0;
22455         GLint                    b0_v1_offset = 0;
22456         GLint                    b0_v1_type   = 0;
22457         GLint                    b0_v3_buf      = 0;
22458         GLint                    b0_v3_offset = 0;
22459         GLint                    b0_v3_type   = 0;
22460         GLint                    b1_v1_buf      = 0;
22461         GLint                    b1_v1_offset = 0;
22462         GLint                    b1_v1_type   = 0;
22463         const test_Case& test_case      = m_test_cases[test_case_index];
22464         const GLenum     type_enum      = test_case.m_type.GetTypeGLenum();
22465         const GLint              type_size      = test_case.m_type.GetSize();
22466
22467         GLuint b0_v0_index = program.GetResourceIndex("b0_v0", GL_TRANSFORM_FEEDBACK_VARYING);
22468         GLuint b0_v1_index = program.GetResourceIndex("b0_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22469         GLuint b0_v3_index = program.GetResourceIndex("b0_v3", GL_TRANSFORM_FEEDBACK_VARYING);
22470         GLuint b1_v1_index = program.GetResourceIndex("b1_v1", GL_TRANSFORM_FEEDBACK_VARYING);
22471
22472         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_OFFSET, 1 /* buf_size */, &b0_v0_offset);
22473         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_OFFSET, 1 /* buf_size */, &b0_v1_offset);
22474         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_OFFSET, 1 /* buf_size */, &b0_v3_offset);
22475         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_OFFSET, 1 /* buf_size */, &b1_v1_offset);
22476
22477         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TYPE, 1 /* buf_size */, &b0_v0_type);
22478         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TYPE, 1 /* buf_size */, &b0_v1_type);
22479         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TYPE, 1 /* buf_size */, &b0_v3_type);
22480         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TYPE, 1 /* buf_size */, &b1_v1_type);
22481
22482         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v0_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22483                                                 1 /* buf_size */, &b0_v0_buf);
22484         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22485                                                 1 /* buf_size */, &b0_v1_buf);
22486         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b0_v3_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22487                                                 1 /* buf_size */, &b0_v3_buf);
22488         program.GetResource(GL_TRANSFORM_FEEDBACK_VARYING, b1_v1_index, GL_TRANSFORM_FEEDBACK_BUFFER_INDEX,
22489                                                 1 /* buf_size */, &b1_v1_buf);
22490
22491         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b0_v0_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22492                                                 &b0_stride);
22493         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, b1_v1_buf, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE, 1 /* buf_size */,
22494                                                 &b1_stride);
22495
22496         if (SEPARATED != test_case.m_case)
22497         {
22498                 return (((GLint)(4 * type_size) == b0_stride) && ((GLint)(4 * type_size) == b1_stride) &&
22499                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0 * type_size) == b0_v0_offset) &&
22500                                 ((GLint)(type_enum) == b0_v0_type) && ((GLint)(0) == b0_v1_buf) &&
22501                                 ((GLint)(1 * type_size) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22502                                 ((GLint)(0) == b0_v3_buf) && ((GLint)(3 * type_size) == b0_v3_offset) &&
22503                                 ((GLint)(type_enum) == b0_v3_type) && ((GLint)(1) == b1_v1_buf) &&
22504                                 ((GLint)(1 * type_size) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22505         }
22506         else
22507         {
22508                 return (((GLint)(1 * type_size) == b0_stride) && ((GLint)(1 * type_size) == b1_stride) &&
22509                                 ((GLint)(0) == b0_v0_buf) && ((GLint)(0) == b0_v0_offset) && ((GLint)(type_enum) == b0_v0_type) &&
22510                                 ((GLint)(1) == b0_v1_buf) && ((GLint)(0) == b0_v1_offset) && ((GLint)(type_enum) == b0_v1_type) &&
22511                                 ((GLint)(2) == b0_v3_buf) && ((GLint)(0) == b0_v3_offset) && ((GLint)(type_enum) == b0_v3_type) &&
22512                                 ((GLint)(3) == b1_v1_buf) && ((GLint)(0) == b1_v1_offset) && ((GLint)(type_enum) == b1_v1_type));
22513         }
22514 }
22515
22516 /** Insert gl_SkipComponents
22517  *
22518  * @param num_components How many gl_SkipComponents1 need to be inserted
22519  * @param varyings The transform feedback varyings string vector
22520  *
22521  **/
22522 void XFBGetProgramResourceAPITest::insertSkipComponents(int num_components, Utils::Program::NameVector& varyings)
22523 {
22524         int num_component_4 = num_components / 4;
22525         int num_component_1 = num_components % 4;
22526         for (int i = 0; i < num_component_4; i++)
22527         {
22528                 varyings.push_back("gl_SkipComponents4");
22529         }
22530         switch (num_component_1)
22531         {
22532         case 1:
22533                 varyings.push_back("gl_SkipComponents1");
22534                 break;
22535         case 2:
22536                 varyings.push_back("gl_SkipComponents2");
22537                 break;
22538         case 3:
22539                 varyings.push_back("gl_SkipComponents3");
22540                 break;
22541         default:
22542                 break;
22543         }
22544 }
22545
22546 /** Runs test case
22547  *
22548  * @param test_case_index Id of test case
22549  *
22550  * @return true if test case pass, false otherwise
22551  **/
22552 bool XFBGetProgramResourceAPITest::testCase(GLuint test_case_index)
22553 {
22554         const std::string& gs_source = getShaderSource(test_case_index, Utils::Shader::GEOMETRY);
22555         Utils::Program   program(m_context);
22556         const std::string& tcs_source           = getShaderSource(test_case_index, Utils::Shader::TESS_CTRL);
22557         const std::string& tes_source           = getShaderSource(test_case_index, Utils::Shader::TESS_EVAL);
22558         const test_Case&   test_case            = m_test_cases[test_case_index];
22559         bool                       test_case_result = true;
22560         const std::string& vs_source            = getShaderSource(test_case_index, Utils::Shader::VERTEX);
22561
22562         // According to spec: gl_SkipComponents1 ~ gl_SkipComponents4 is treated as specifying a one- to four-component floating point output variables with undefined values.
22563         // 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.
22564
22565         if (INTERLEAVED == test_case.m_case)
22566         {
22567                 /*
22568                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22569                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22570                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22571                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22572
22573                  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,
22574                  we need to calculate how many "gl_SkipComponents" need to be inserted.
22575                  */
22576                 Utils::Program::NameVector captured_varyings;
22577                 captured_varyings.push_back("b0_v0");
22578                 captured_varyings.push_back("b0_v1");
22579                 // Compute how many gl_SkipComponents to be inserted
22580                 int numComponents = test_case.m_type.GetSize() / 4;
22581                 insertSkipComponents(numComponents, captured_varyings);
22582                 captured_varyings.push_back("b0_v3");
22583                 captured_varyings.push_back("gl_NextBuffer");
22584                 insertSkipComponents(numComponents, captured_varyings);
22585                 captured_varyings.push_back("b1_v1");
22586                 insertSkipComponents(numComponents * 2, captured_varyings);
22587
22588                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, true,
22589                                          true /* separable */);
22590         }
22591         else if (SEPARATED == test_case.m_case)
22592         {
22593                 Utils::Program::NameVector captured_varyings;
22594
22595                 captured_varyings.push_back("b0_v0");
22596                 captured_varyings.push_back("b0_v1");
22597                 captured_varyings.push_back("b0_v3");
22598                 captured_varyings.push_back("b1_v1");
22599
22600                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, captured_varyings, false,
22601                                          true /* separable */);
22602         }
22603         else
22604         {
22605
22606                 program.Init("" /* cs */, "", gs_source, tcs_source, tes_source, vs_source, true /* separable */);
22607         }
22608
22609         test_case_result = inspectProgram(test_case_index, program);
22610
22611         return test_case_result;
22612 }
22613
22614 /** Prepare all test cases
22615  *
22616  **/
22617 void XFBGetProgramResourceAPITest::testInit()
22618 {
22619         const Functions& gl              = m_context.getRenderContext().getFunctions();
22620         const GLuint     n_types = getTypesNumber();
22621         GLint                    max_xfb_int;
22622         GLint                    max_xfb_sep;
22623
22624         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_xfb_int);
22625         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22626
22627         gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, &max_xfb_sep);
22628         GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
22629
22630         GLint max_varyings;
22631         gl.getIntegerv(GL_MAX_VARYING_COMPONENTS, &max_varyings);
22632
22633         for (GLuint i = 0; i < n_types; ++i)
22634         {
22635                 // 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,
22636                 // 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
22637                 // shader valid, we can either skip the dmat4, dmat4x3 or query the implementation-dependent value MAX_VARYING_COMPONENTS before generating the shader
22638                 // to guarantee the number of varying not exceeded.
22639                 /*
22640                  layout (xfb_buffer = 1, xfb_stride = 4 * type_size) out;
22641                  layout (xfb_buffer = 0, xfb_offset = 1 * type_size) out type b0_v1;
22642                  layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out type b1_v1;
22643                  layout (xfb_buffer = 0, xfb_offset = 3 * type_size) out type b0_v3;
22644                  layout (xfb_buffer = 0, xfb_offset = 0 * type_size) out type b0_v0;
22645                  in  vec4 in_vs;
22646                  out vec4 vs_tcs;
22647                  */
22648                 if (i == 7 || i == 9)
22649                         continue;
22650                 const Utils::Type& type = getType(i);
22651                 if (4 * type.GetNumComponents() + 4 > (GLuint)max_varyings)
22652                 {
22653                         continue;
22654                 }
22655                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
22656                 {
22657                         /*
22658                          It is invalid to define transform feedback output in HS
22659                          */
22660                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
22661                                 (Utils::Shader::FRAGMENT == stage))
22662                         {
22663                                 continue;
22664                         }
22665
22666                         test_Case test_case_int = { INTERLEAVED, (Utils::Shader::STAGES)stage, type };
22667                         test_Case test_case_sep = { SEPARATED, (Utils::Shader::STAGES)stage, type };
22668                         test_Case test_case_xfb = { XFB, (Utils::Shader::STAGES)stage, type };
22669
22670                         if ((int)type.GetSize() <= max_xfb_int)
22671                         {
22672                                 m_test_cases.push_back(test_case_xfb);
22673                                 m_test_cases.push_back(test_case_int);
22674                         }
22675
22676                         if ((int)type.GetSize() <= max_xfb_sep)
22677                         {
22678                                 m_test_cases.push_back(test_case_sep);
22679                         }
22680                 }
22681         }
22682 }
22683
22684 /** Constructor
22685  *
22686  * @param context Test context
22687  **/
22688 XFBOverrideQualifiersWithAPITest::XFBOverrideQualifiersWithAPITest(deqp::Context& context)
22689         : BufferTestBase(context, "xfb_override_qualifiers_with_api",
22690                                          "Test verifies that xfb_offset qualifier is not overriden with API")
22691 {
22692         /* Nothing to be done here */
22693 }
22694
22695 /** Get descriptors of buffers necessary for test
22696  *
22697  * @param test_case_index Index of test case
22698  * @param out_descriptors Descriptors of buffers used by test
22699  **/
22700 void XFBOverrideQualifiersWithAPITest::getBufferDescriptors(glw::GLuint                           test_case_index,
22701                                                                                                                         bufferDescriptor::Vector& out_descriptors)
22702 {
22703         const Utils::Type& type = getType(test_case_index);
22704
22705         /* Test needs single uniform and xfb */
22706         out_descriptors.resize(2);
22707
22708         /* Get references */
22709         bufferDescriptor& uniform = out_descriptors[0];
22710         bufferDescriptor& xfb    = out_descriptors[1];
22711
22712         /* Index */
22713         uniform.m_index = 0;
22714         xfb.m_index             = 0;
22715
22716         /* Target */
22717         uniform.m_target = Utils::Buffer::Uniform;
22718         xfb.m_target     = Utils::Buffer::Transform_feedback;
22719
22720         /* Data */
22721         const GLuint                            gen_start   = Utils::s_rand;
22722         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22723         const std::vector<GLubyte>& trunks_data = type.GenerateData();
22724         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22725         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22726
22727         Utils::s_rand                                                           = gen_start;
22728         const std::vector<GLubyte>& vegeta_data_pck = type.GenerateDataPacked();
22729         /*
22730          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)
22731          how can make them equal ? is it as designed?  Add the following statement,  which can make sure goku_data_pck equals to goku_data
22732          */
22733         const std::vector<GLubyte>& goku_data_pck = type.GenerateDataPacked();
22734
22735         const GLuint type_size   = static_cast<GLuint>(vegeta_data.size());
22736         const GLuint type_size_pck = static_cast<GLuint>(vegeta_data_pck.size());
22737
22738         /* Uniform data */
22739         uniform.m_initial_data.resize(4 * type_size);
22740         memcpy(&uniform.m_initial_data[0] + 0, &vegeta_data[0], type_size);
22741         memcpy(&uniform.m_initial_data[0] + type_size, &trunks_data[0], type_size);
22742         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goku_data[0], type_size);
22743         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &gohan_data[0], type_size);
22744
22745         /* XFB data */
22746         xfb.m_initial_data.resize(4 * type_size_pck);
22747         xfb.m_expected_data.resize(4 * type_size_pck);
22748
22749         for (GLuint i = 0; i < 4 * type_size_pck; ++i)
22750         {
22751                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
22752                 xfb.m_expected_data[i] = (glw::GLubyte)i;
22753         }
22754
22755         memcpy(&xfb.m_expected_data[0] + 0, &goku_data_pck[0], type_size_pck);
22756         memcpy(&xfb.m_expected_data[0] + 2 * type_size_pck, &vegeta_data_pck[0], type_size_pck);
22757 }
22758
22759 /** Get list of names of varyings that will be registered with TransformFeedbackVaryings
22760  *
22761  * @param ignored
22762  * @param captured_varyings List of names
22763  **/
22764 void XFBOverrideQualifiersWithAPITest::getCapturedVaryings(glw::GLuint /* test_case_index */,
22765                                                                                                                    Utils::Program::NameVector& captured_varyings)
22766 {
22767         captured_varyings.resize(2);
22768
22769         captured_varyings[0] = "trunks";
22770         captured_varyings[1] = "gohan";
22771 }
22772
22773 /** Get body of main function for given shader stage
22774  *
22775  * @param test_case_index  Index of test case
22776  * @param stage            Shader stage
22777  * @param out_assignments  Set to empty
22778  * @param out_calculations Set to empty
22779  **/
22780 void XFBOverrideQualifiersWithAPITest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
22781                                                                                                          std::string& out_assignments, std::string& out_calculations)
22782 {
22783         out_calculations = "";
22784
22785         static const GLchar* gs = "    vegeta = uni_vegeta;\n"
22786                                                           "    trunks = uni_trunks;\n"
22787                                                           "    goku   = uni_goku;\n"
22788                                                           "    gohan  = uni_gohan;\n";
22789         static const GLchar* fs = "    fs_out = vec4(0);\n"
22790                                                           "    if (TYPE(1) == gohan + goku + trunks + vegeta)\n"
22791                                                           "    {\n"
22792                                                           "        fs_out = vec4(1);\n"
22793                                                           "    }\n";
22794
22795         const GLchar* assignments = "";
22796         switch (stage)
22797         {
22798         case Utils::Shader::FRAGMENT:
22799                 assignments = fs;
22800                 break;
22801         case Utils::Shader::GEOMETRY:
22802                 assignments = gs;
22803                 break;
22804         default:
22805                 break;
22806         }
22807
22808         out_assignments = assignments;
22809
22810         if (Utils::Shader::FRAGMENT == stage)
22811         {
22812                 const Utils::Type& type = getType(test_case_index);
22813
22814                 Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_assignments);
22815         }
22816 }
22817
22818 /** Get interface of shader
22819  *
22820  * @param test_case_index  Index of test case
22821  * @param stage            Shader stage
22822  * @param out_interface    Set to ""
22823  **/
22824 void XFBOverrideQualifiersWithAPITest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
22825                                                                                                                   std::string& out_interface)
22826 {
22827         static const GLchar* gs = "const uint sizeof_type = SIZE;\n"
22828                                                           "\n"
22829                                                           "layout (xfb_offset = 2 * sizeof_type) flat out TYPE vegeta;\n"
22830                                                           "                                      flat out TYPE trunks;\n"
22831                                                           "layout (xfb_offset = 0)               flat out TYPE goku;\n"
22832                                                           "                                      flat out TYPE gohan;\n"
22833                                                           "\n"
22834                                                           /*
22835                  There is no packing qualifier for uniform block gs_block, according to spec, it should be "shared" by default,
22836                  the definition equals to "layout(binding=0, shared)", if the block is declared as shared, each block member will
22837                  not be packed, and each block member's layout in memory is implementation dependent, so we can't use the API
22838                  glBufferData() to update the UBO directly, we need to query each block member's offset first, then upload the
22839                  data to the corresponding offset, otherwise we can't get the correct data from UBO; to make the test passed,
22840                  we need to add the qualifier std140,  and change the declaration as layout(binding=0, std140), which can make
22841                  sure all the block members are packed and the application can upload the data by glBufferData() directly.
22842                  */
22843                                                           "layout(binding = 0, std140) uniform gs_block {\n"
22844                                                           "    TYPE uni_vegeta;\n"
22845                                                           "    TYPE uni_trunks;\n"
22846                                                           "    TYPE uni_goku;\n"
22847                                                           "    TYPE uni_gohan;\n"
22848                                                           "};\n";
22849         static const GLchar* fs = "flat in TYPE vegeta;\n"
22850                                                           "flat in TYPE trunks;\n"
22851                                                           "flat in TYPE goku;\n"
22852                                                           "flat in TYPE gohan;\n"
22853                                                           "\n"
22854                                                           "out vec4 fs_out;\n";
22855
22856         const Utils::Type& type = getType(test_case_index);
22857
22858         switch (stage)
22859         {
22860         case Utils::Shader::FRAGMENT:
22861                 out_interface = fs;
22862                 break;
22863         case Utils::Shader::GEOMETRY:
22864                 out_interface = gs;
22865                 break;
22866         default:
22867                 out_interface = "";
22868                 return;
22869         }
22870
22871         if (Utils::Shader::GEOMETRY == stage)
22872         {
22873                 GLchar           buffer[16];
22874                 size_t           position  = 0;
22875                 const GLuint type_size = type.GetSize();
22876
22877                 sprintf(buffer, "%d", type_size);
22878
22879                 Utils::replaceToken("SIZE", position, buffer, out_interface);
22880         }
22881
22882         Utils::replaceAllTokens("TYPE", type.GetGLSLTypeName(), out_interface);
22883 }
22884
22885 /** Get type name
22886  *
22887  * @param test_case_index Index of test case
22888  *
22889  * @return Name of type test in test_case_index
22890  **/
22891 std::string XFBOverrideQualifiersWithAPITest::getTestCaseName(glw::GLuint test_case_index)
22892 {
22893         return getTypeName(test_case_index);
22894 }
22895
22896 /** Returns number of types to test
22897  *
22898  * @return Number of types, 34
22899  **/
22900 glw::GLuint XFBOverrideQualifiersWithAPITest::getTestCaseNumber()
22901 {
22902         return getTypesNumber();
22903 }
22904
22905 /** Inspects program to check if all resources are as expected
22906  *
22907  * @param test_case_index Index of test case
22908  * @param program         Program instance
22909  * @param out_stream      Error message
22910  *
22911  * @return true if everything is ok, false otherwise
22912  **/
22913 bool XFBOverrideQualifiersWithAPITest::inspectProgram(GLuint test_case_index, Utils::Program& program,
22914                                                                                                           std::stringstream& out_stream)
22915 {
22916         GLint                      stride       = 0;
22917         const Utils::Type& type          = getType(test_case_index);
22918         const GLuint       type_size = type.GetSize();
22919
22920         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
22921                                                 1 /* buf_size */, &stride);
22922
22923         if ((GLint)(3 * type_size) != stride)
22924         {
22925                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
22926
22927                 return false;
22928         }
22929
22930         return true;
22931 }
22932
22933 /** Constructor
22934  *
22935  * @param context Test context
22936  **/
22937 XFBVertexStreamsTest::XFBVertexStreamsTest(deqp::Context& context)
22938         : BufferTestBase(context, "xfb_vertex_streams",
22939                                          "Test verifies that xfb qualifier works with multiple output streams")
22940 {
22941         /* Nothing to be done here */
22942 }
22943
22944 /** Get descriptors of buffers necessary for test
22945  *
22946  * @param ignored
22947  * @param out_descriptors Descriptors of buffers used by test
22948  **/
22949 void XFBVertexStreamsTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
22950                                                                                                 bufferDescriptor::Vector& out_descriptors)
22951 {
22952         const Utils::Type& type = Utils::Type::vec4;
22953
22954         /* Test needs single uniform and three xfbs */
22955         out_descriptors.resize(4);
22956
22957         /* Get references */
22958         bufferDescriptor& uniform = out_descriptors[0];
22959         bufferDescriptor& xfb_1   = out_descriptors[1];
22960         bufferDescriptor& xfb_2   = out_descriptors[2];
22961         bufferDescriptor& xfb_3   = out_descriptors[3];
22962
22963         /* Index */
22964         uniform.m_index = 0;
22965         xfb_1.m_index   = 1;
22966         xfb_2.m_index   = 2;
22967         xfb_3.m_index   = 3;
22968
22969         /* Target */
22970         uniform.m_target = Utils::Buffer::Uniform;
22971         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
22972         xfb_2.m_target   = Utils::Buffer::Transform_feedback;
22973         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
22974
22975         /* Data */
22976         const std::vector<GLubyte>& goku_data   = type.GenerateData();
22977         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
22978         const std::vector<GLubyte>& goten_data  = type.GenerateData();
22979         const std::vector<GLubyte>& picolo_data = type.GenerateData();
22980         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
22981         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
22982
22983         const GLuint type_size = static_cast<GLuint>(vegeta_data.size());
22984
22985         /* Uniform data */
22986         uniform.m_initial_data.resize(6 * type_size);
22987         memcpy(&uniform.m_initial_data[0] + 0, &goku_data[0], type_size);
22988         memcpy(&uniform.m_initial_data[0] + type_size, &gohan_data[0], type_size);
22989         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
22990         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &picolo_data[0], type_size);
22991         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
22992         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &bulma_data[0], type_size);
22993
22994         /* XFB data */
22995         static const GLuint xfb_stride = 64;
22996         xfb_1.m_initial_data.resize(xfb_stride);
22997         xfb_1.m_expected_data.resize(xfb_stride);
22998         xfb_2.m_initial_data.resize(xfb_stride);
22999         xfb_2.m_expected_data.resize(xfb_stride);
23000         xfb_3.m_initial_data.resize(xfb_stride);
23001         xfb_3.m_expected_data.resize(xfb_stride);
23002
23003         for (GLuint i = 0; i < xfb_stride; ++i)
23004         {
23005                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
23006                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
23007                 xfb_2.m_initial_data[i]  = (glw::GLubyte)i;
23008                 xfb_2.m_expected_data[i] = (glw::GLubyte)i;
23009                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
23010                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
23011         }
23012
23013         memcpy(&xfb_1.m_expected_data[0] + 48, &goku_data[0], type_size);
23014         memcpy(&xfb_1.m_expected_data[0] + 32, &gohan_data[0], type_size);
23015         memcpy(&xfb_1.m_expected_data[0] + 16, &goten_data[0], type_size);
23016         memcpy(&xfb_3.m_expected_data[0] + 48, &picolo_data[0], type_size);
23017         memcpy(&xfb_3.m_expected_data[0] + 32, &vegeta_data[0], type_size);
23018         memcpy(&xfb_2.m_expected_data[0] + 32, &bulma_data[0], type_size);
23019 }
23020
23021 /** Get body of main function for given shader stage
23022  *
23023  * @param ignored
23024  * @param stage            Shader stage
23025  * @param out_assignments  Set to empty
23026  * @param out_calculations Set to empty
23027  **/
23028 void XFBVertexStreamsTest::getShaderBody(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23029                                                                                  std::string& out_assignments, std::string& out_calculations)
23030 {
23031         out_calculations = "";
23032
23033         // the shader declares the output variables with different "stream" qualifier, to make the data can export to
23034         // each stream, we must call the function EmitStreamVertex() and EndStreamPrimitive() to make each vertex emitted
23035         // by the GS is assigned to specific stream.
23036         static const GLchar* gs = "    goku   = uni_goku;\n"
23037                                                           "    gohan  = uni_gohan;\n"
23038                                                           "    goten  = uni_goten;\n"
23039                                                           "    EmitStreamVertex(0);\n"
23040                                                           "    EndStreamPrimitive(0);\n"
23041                                                           "    picolo = uni_picolo;\n"
23042                                                           "    vegeta = uni_vegeta;\n"
23043                                                           "    EmitStreamVertex(1);\n"
23044                                                           "    EndStreamPrimitive(1);\n"
23045                                                           "    bulma  = uni_bulma;\n"
23046                                                           "    EmitStreamVertex(2);\n"
23047                                                           "    EndStreamPrimitive(2);\n";
23048
23049         static const GLchar* fs = "    fs_out = gohan + goku + goten + picolo + vegeta + bulma;\n";
23050
23051         const GLchar* assignments = "";
23052         switch (stage)
23053         {
23054         case Utils::Shader::FRAGMENT:
23055                 assignments = fs;
23056                 break;
23057         case Utils::Shader::GEOMETRY:
23058                 assignments = gs;
23059                 break;
23060         default:
23061                 break;
23062         }
23063
23064         out_assignments = assignments;
23065 }
23066
23067 /** Get interface of shader
23068  *
23069  * @param ignored
23070  * @param stage            Shader stage
23071  * @param out_interface    Set to ""
23072  **/
23073 void XFBVertexStreamsTest::getShaderInterface(GLuint /* test_case_index */, Utils::Shader::STAGES stage,
23074                                                                                           std::string& out_interface)
23075 {
23076         static const GLchar* gs = "layout (xfb_buffer = 1, xfb_stride = 64) out;\n"
23077                                                           "layout (xfb_buffer = 2, xfb_stride = 64) out;\n"
23078                                                           "layout (xfb_buffer = 3, xfb_stride = 64) out;\n"
23079                                                           "\n"
23080                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23081                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23082                                                           "layout (stream = 0, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n"
23083                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 48) out vec4 picolo;\n"
23084                                                           "layout (stream = 1, xfb_buffer = 3, xfb_offset = 32) out vec4 vegeta;\n"
23085                                                           "layout (stream = 2, xfb_buffer = 2, xfb_offset = 32) out vec4 bulma;\n"
23086                                                           "\n"
23087                                                           "layout(binding = 0) uniform gs_block {\n"
23088                                                           "    vec4 uni_goku;\n"
23089                                                           "    vec4 uni_gohan;\n"
23090                                                           "    vec4 uni_goten;\n"
23091                                                           "    vec4 uni_picolo;\n"
23092                                                           "    vec4 uni_vegeta;\n"
23093                                                           "    vec4 uni_bulma;\n"
23094                                                           "};\n";
23095         /*
23096          Fixed incorrect usage of in/out qualifier, the following variable should be input symbols for fragment shader
23097          */
23098         static const GLchar* fs = "in vec4 goku;\n"
23099                                                           "in vec4 gohan;\n"
23100                                                           "in vec4 goten;\n"
23101                                                           "in vec4 picolo;\n"
23102                                                           "in vec4 vegeta;\n"
23103                                                           "in vec4 bulma;\n"
23104                                                           "\n"
23105                                                           "out vec4 fs_out;\n";
23106
23107         switch (stage)
23108         {
23109         case Utils::Shader::FRAGMENT:
23110                 out_interface = fs;
23111                 break;
23112         case Utils::Shader::GEOMETRY:
23113                 out_interface = gs;
23114                 break;
23115         default:
23116                 out_interface = "";
23117                 return;
23118         }
23119 }
23120
23121 /** Constructor
23122  *
23123  * @param context Test framework context
23124  **/
23125 XFBMultipleVertexStreamsTest::XFBMultipleVertexStreamsTest(deqp::Context& context)
23126         : NegativeTestBase(
23127                   context, "xfb_multiple_vertex_streams",
23128                   "Test verifies that compiler reports error when multiple streams are captured with same xfb_buffer")
23129 {
23130 }
23131
23132 /** Source for given test case and stage
23133  *
23134  * @param ignored
23135  * @param stage           Shader stage
23136  *
23137  * @return Shader source
23138  **/
23139 std::string XFBMultipleVertexStreamsTest::getShaderSource(GLuint /* test_case_index */, Utils::Shader::STAGES stage)
23140 {
23141         static const GLchar* var_definition = "const uint valid_stride = 64;\n"
23142                                                                                   "\n"
23143                                                                                   "layout (xfb_buffer = 1, xfb_stride = valid_stride) out;\n"
23144                                                                                   "layout (xfb_buffer = 3, xfb_stride = valid_stride) out;\n"
23145                                                                                   "\n"
23146                                                                                   "\n"
23147                                                                                   "layout (stream = 0, xfb_buffer = 1, xfb_offset = 48) out vec4 goku;\n"
23148                                                                                   "layout (stream = 1, xfb_buffer = 1, xfb_offset = 32) out vec4 gohan;\n"
23149                                                                                   "layout (stream = 2, xfb_buffer = 1, xfb_offset = 16) out vec4 goten;\n";
23150         static const GLchar* var_use = "    goku  = result / 2;\n"
23151                                                                    "    gohan = result / 4;\n"
23152                                                                    "    goten = result / 6;\n";
23153         static const GLchar* fs = "#version 430 core\n"
23154                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23155                                                           "\n"
23156                                                           "in  vec4 gs_fs;\n"
23157                                                           "in  vec4 goku;\n"
23158                                                           "out vec4 fs_out;\n"
23159                                                           "\n"
23160                                                           "void main()\n"
23161                                                           "{\n"
23162                                                           "    fs_out = gs_fs + goku;\n"
23163                                                           "}\n"
23164                                                           "\n";
23165         static const GLchar* gs = "#version 430 core\n"
23166                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23167                                                           "\n"
23168                                                           "layout(points)                           in;\n"
23169                                                           "layout(triangle_strip, max_vertices = 4) out;\n"
23170                                                           "\n"
23171                                                           "VAR_DEFINITION"
23172                                                           "\n"
23173                                                           "in  vec4 tes_gs[];\n"
23174                                                           "out vec4 gs_fs;\n"
23175                                                           "\n"
23176                                                           "void main()\n"
23177                                                           "{\n"
23178                                                           "    vec4 result = tes_gs[0];\n"
23179                                                           "\n"
23180                                                           "VARIABLE_USE"
23181                                                           "\n"
23182                                                           "    gs_fs = result;\n"
23183                                                           "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23184                                                           "    EmitVertex();\n"
23185                                                           "    gs_fs = result;\n"
23186                                                           "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23187                                                           "    EmitVertex();\n"
23188                                                           "    gs_fs = result;\n"
23189                                                           "    gl_Position  = vec4(1, -1, 0, 1);\n"
23190                                                           "    EmitVertex();\n"
23191                                                           "    gs_fs = result;\n"
23192                                                           "    gl_Position  = vec4(1, 1, 0, 1);\n"
23193                                                           "    EmitVertex();\n"
23194                                                           "}\n"
23195                                                           "\n";
23196         static const GLchar* vs = "#version 430 core\n"
23197                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23198                                                           "\n"
23199                                                           "in  vec4 in_vs;\n"
23200                                                           "out vec4 vs_tcs;\n"
23201                                                           "\n"
23202                                                           "void main()\n"
23203                                                           "{\n"
23204                                                           "    vs_tcs = in_vs;\n"
23205                                                           "}\n"
23206                                                           "\n";
23207
23208         std::string source;
23209
23210         if (Utils::Shader::GEOMETRY == stage)
23211         {
23212                 size_t position = 0;
23213
23214                 source = gs;
23215
23216                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23217                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23218         }
23219         else
23220         {
23221                 switch (stage)
23222                 {
23223                 case Utils::Shader::FRAGMENT:
23224                         source = fs;
23225                         break;
23226                 case Utils::Shader::VERTEX:
23227                         source = vs;
23228                         break;
23229                 default:
23230                         source = "";
23231                 }
23232         }
23233
23234         return source;
23235 }
23236
23237 /** Selects if "compute" stage is relevant for test
23238  *
23239  * @param ignored
23240  *
23241  * @return false
23242  **/
23243 bool XFBMultipleVertexStreamsTest::isComputeRelevant(GLuint /* test_case_index */)
23244 {
23245         return false;
23246 }
23247
23248 /** Constructor
23249  *
23250  * @param context Test framework context
23251  **/
23252 XFBExceedBufferLimitTest::XFBExceedBufferLimitTest(deqp::Context& context)
23253         : NegativeTestBase(context, "xfb_exceed_buffer_limit",
23254                                            "Test verifies that compiler reports error when xfb_buffer qualifier exceeds limit")
23255 {
23256 }
23257
23258 /** Source for given test case and stage
23259  *
23260  * @param test_case_index Index of test case
23261  * @param stage           Shader stage
23262  *
23263  * @return Shader source
23264  **/
23265 std::string XFBExceedBufferLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23266 {
23267         static const GLchar* block_var_definition = "const uint buffer_index = BUFFER;\n"
23268                                                                                                 "\n"
23269                                                                                                 "layout (xfb_buffer = buffer_index, xfb_offset = 0) out Goku {\n"
23270                                                                                                 "    vec4 member;\n"
23271                                                                                                 "} gokuARRAY;\n";
23272         static const GLchar* global_var_definition = "const uint buffer_index = BUFFER;\n"
23273                                                                                                  "\n"
23274                                                                                                  "layout (xfb_buffer = buffer_index) out;\n";
23275         static const GLchar* vector_var_definition = "const uint buffer_index = BUFFER;\n"
23276                                                                                                  "\n"
23277                                                                                                  "layout (xfb_buffer = buffer_index) out vec4 gokuARRAY;\n";
23278         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23279         static const GLchar* global_use = "";
23280         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23281         static const GLchar* fs                 = "#version 430 core\n"
23282                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23283                                                           "\n"
23284                                                           "in  vec4 gs_fs;\n"
23285                                                           "out vec4 fs_out;\n"
23286                                                           "\n"
23287                                                           "void main()\n"
23288                                                           "{\n"
23289                                                           "    fs_out = gs_fs;\n"
23290                                                           "}\n"
23291                                                           "\n";
23292         static const GLchar* gs_tested = "#version 430 core\n"
23293                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23294                                                                          "\n"
23295                                                                          "layout(points)                           in;\n"
23296                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23297                                                                          "\n"
23298                                                                          "VAR_DEFINITION"
23299                                                                          "\n"
23300                                                                          "in  vec4 tes_gs[];\n"
23301                                                                          "out vec4 gs_fs;\n"
23302                                                                          "\n"
23303                                                                          "void main()\n"
23304                                                                          "{\n"
23305                                                                          "    vec4 result = tes_gs[0];\n"
23306                                                                          "\n"
23307                                                                          "VARIABLE_USE"
23308                                                                          "\n"
23309                                                                          "    gs_fs = result;\n"
23310                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23311                                                                          "    EmitVertex();\n"
23312                                                                          "    gs_fs = result;\n"
23313                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23314                                                                          "    EmitVertex();\n"
23315                                                                          "    gs_fs = result;\n"
23316                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23317                                                                          "    EmitVertex();\n"
23318                                                                          "    gs_fs = result;\n"
23319                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23320                                                                          "    EmitVertex();\n"
23321                                                                          "}\n"
23322                                                                          "\n";
23323         static const GLchar* tcs = "#version 430 core\n"
23324                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23325                                                            "\n"
23326                                                            "layout(vertices = 1) out;\n"
23327                                                            "\n"
23328                                                            "in  vec4 vs_tcs[];\n"
23329                                                            "out vec4 tcs_tes[];\n"
23330                                                            "\n"
23331                                                            "void main()\n"
23332                                                            "{\n"
23333                                                            "\n"
23334                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23335                                                            "\n"
23336                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23337                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23338                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23339                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23340                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23341                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23342                                                            "}\n"
23343                                                            "\n";
23344         static const GLchar* tcs_tested = "#version 430 core\n"
23345                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23346                                                                           "\n"
23347                                                                           "layout(vertices = 1) out;\n"
23348                                                                           "\n"
23349                                                                           "VAR_DEFINITION"
23350                                                                           "\n"
23351                                                                           "in  vec4 vs_tcs[];\n"
23352                                                                           "out vec4 tcs_tes[];\n"
23353                                                                           "\n"
23354                                                                           "void main()\n"
23355                                                                           "{\n"
23356                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23357                                                                           "\n"
23358                                                                           "VARIABLE_USE"
23359                                                                           "\n"
23360                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23361                                                                           "\n"
23362                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23363                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23364                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23365                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23366                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23367                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23368                                                                           "}\n"
23369                                                                           "\n";
23370         static const GLchar* tes_tested = "#version 430 core\n"
23371                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23372                                                                           "\n"
23373                                                                           "layout(isolines, point_mode) in;\n"
23374                                                                           "\n"
23375                                                                           "VAR_DEFINITION"
23376                                                                           "\n"
23377                                                                           "in  vec4 tcs_tes[];\n"
23378                                                                           "out vec4 tes_gs;\n"
23379                                                                           "\n"
23380                                                                           "void main()\n"
23381                                                                           "{\n"
23382                                                                           "    vec4 result = tcs_tes[0];\n"
23383                                                                           "\n"
23384                                                                           "VARIABLE_USE"
23385                                                                           "\n"
23386                                                                           "    tes_gs += result;\n"
23387                                                                           "}\n"
23388                                                                           "\n";
23389         static const GLchar* vs = "#version 430 core\n"
23390                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23391                                                           "\n"
23392                                                           "in  vec4 in_vs;\n"
23393                                                           "out vec4 vs_tcs;\n"
23394                                                           "\n"
23395                                                           "void main()\n"
23396                                                           "{\n"
23397                                                           "    vs_tcs = in_vs;\n"
23398                                                           "}\n"
23399                                                           "\n";
23400         static const GLchar* vs_tested = "#version 430 core\n"
23401                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23402                                                                          "\n"
23403                                                                          "VAR_DEFINITION"
23404                                                                          "\n"
23405                                                                          "in  vec4 in_vs;\n"
23406                                                                          "out vec4 vs_tcs;\n"
23407                                                                          "\n"
23408                                                                          "void main()\n"
23409                                                                          "{\n"
23410                                                                          "    vec4 result = in_vs;\n"
23411                                                                          "\n"
23412                                                                          "VARIABLE_USE"
23413                                                                          "\n"
23414                                                                          "    vs_tcs = result;\n"
23415                                                                          "}\n"
23416                                                                          "\n";
23417
23418         std::string source;
23419         testCase&   test_case = m_test_cases[test_case_index];
23420
23421         if (test_case.m_stage == stage)
23422         {
23423                 const GLchar*   array = "";
23424                 GLchar                   buffer[16];
23425                 const Functions& gl                = m_context.getRenderContext().getFunctions();
23426                 const GLchar*   index    = "";
23427                 GLint                    max_n_xfb = 0;
23428                 size_t                   position  = 0;
23429                 size_t                   temp;
23430                 const GLchar*   var_definition = 0;
23431                 const GLchar*   var_use         = 0;
23432
23433                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, &max_n_xfb);
23434                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23435
23436                 sprintf(buffer, "%d", max_n_xfb);
23437
23438                 switch (test_case.m_case)
23439                 {
23440                 case BLOCK:
23441                         var_definition = block_var_definition;
23442                         var_use            = block_use;
23443                         break;
23444                 case GLOBAL:
23445                         var_definition = global_var_definition;
23446                         var_use            = global_use;
23447                         break;
23448                 case VECTOR:
23449                         var_definition = vector_var_definition;
23450                         var_use            = vector_use;
23451                         break;
23452                 default:
23453                         TCU_FAIL("Invalid enum");
23454                 }
23455
23456                 switch (stage)
23457                 {
23458                 case Utils::Shader::GEOMETRY:
23459                         source = gs_tested;
23460                         array  = "[]";
23461                         index  = "[0]";
23462                         break;
23463                 case Utils::Shader::TESS_CTRL:
23464                         source = tcs_tested;
23465                         array  = "[]";
23466                         index  = "[gl_InvocationID]";
23467                         break;
23468                 case Utils::Shader::TESS_EVAL:
23469                         source = tes_tested;
23470                         array  = "[]";
23471                         index  = "[0]";
23472                         break;
23473                 case Utils::Shader::VERTEX:
23474                         source = vs_tested;
23475                         break;
23476                 default:
23477                         TCU_FAIL("Invalid enum");
23478                 }
23479
23480                 temp = position;
23481                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23482                 position = temp;
23483                 Utils::replaceToken("BUFFER", position, buffer, source);
23484                 if (GLOBAL != test_case.m_case)
23485                 {
23486                         Utils::replaceToken("ARRAY", position, array, source);
23487                 }
23488                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23489
23490                 Utils::replaceAllTokens("INDEX", index, source);
23491         }
23492         else
23493         {
23494                 switch (test_case.m_stage)
23495                 {
23496                 case Utils::Shader::GEOMETRY:
23497                         switch (stage)
23498                         {
23499                         case Utils::Shader::FRAGMENT:
23500                                 source = fs;
23501                                 break;
23502                         case Utils::Shader::VERTEX:
23503                                 source = vs;
23504                                 break;
23505                         default:
23506                                 source = "";
23507                         }
23508                         break;
23509                 case Utils::Shader::TESS_CTRL:
23510                         switch (stage)
23511                         {
23512                         case Utils::Shader::FRAGMENT:
23513                                 source = fs;
23514                                 break;
23515                         case Utils::Shader::VERTEX:
23516                                 source = vs;
23517                                 break;
23518                         default:
23519                                 source = "";
23520                         }
23521                         break;
23522                 case Utils::Shader::TESS_EVAL:
23523                         switch (stage)
23524                         {
23525                         case Utils::Shader::FRAGMENT:
23526                                 source = fs;
23527                                 break;
23528                         case Utils::Shader::TESS_CTRL:
23529                                 source = tcs;
23530                                 break;
23531                         case Utils::Shader::VERTEX:
23532                                 source = vs;
23533                                 break;
23534                         default:
23535                                 source = "";
23536                         }
23537                         break;
23538                 case Utils::Shader::VERTEX:
23539                         switch (stage)
23540                         {
23541                         case Utils::Shader::FRAGMENT:
23542                                 source = fs;
23543                                 break;
23544                         default:
23545                                 source = "";
23546                         }
23547                         break;
23548                 default:
23549                         TCU_FAIL("Invalid enum");
23550                         break;
23551                 }
23552         }
23553
23554         return source;
23555 }
23556
23557 /** Get description of test case
23558  *
23559  * @param test_case_index Index of test case
23560  *
23561  * @return Test case description
23562  **/
23563 std::string XFBExceedBufferLimitTest::getTestCaseName(GLuint test_case_index)
23564 {
23565         std::stringstream stream;
23566         testCase&                 test_case = m_test_cases[test_case_index];
23567
23568         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23569
23570         switch (test_case.m_case)
23571         {
23572         case BLOCK:
23573                 stream << "BLOCK";
23574                 break;
23575         case GLOBAL:
23576                 stream << "GLOBAL";
23577                 break;
23578         case VECTOR:
23579                 stream << "VECTOR";
23580                 break;
23581         default:
23582                 TCU_FAIL("Invalid enum");
23583         }
23584
23585         return stream.str();
23586 }
23587
23588 /** Get number of test cases
23589  *
23590  * @return Number of test cases
23591  **/
23592 GLuint XFBExceedBufferLimitTest::getTestCaseNumber()
23593 {
23594         return static_cast<GLuint>(m_test_cases.size());
23595 }
23596
23597 /** Selects if "compute" stage is relevant for test
23598  *
23599  * @param ignored
23600  *
23601  * @return false
23602  **/
23603 bool XFBExceedBufferLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23604 {
23605         return false;
23606 }
23607
23608 /** Prepare all test cases
23609  *
23610  **/
23611 void XFBExceedBufferLimitTest::testInit()
23612 {
23613         for (GLuint c = 0; c < CASE_MAX; ++c)
23614         {
23615                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
23616                 {
23617                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
23618                                 (Utils::Shader::FRAGMENT == stage))
23619                         {
23620                                 continue;
23621                         }
23622
23623                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
23624
23625                         m_test_cases.push_back(test_case);
23626                 }
23627         }
23628 }
23629
23630 /** Constructor
23631  *
23632  * @param context Test framework context
23633  **/
23634 XFBExceedOffsetLimitTest::XFBExceedOffsetLimitTest(deqp::Context& context)
23635         : NegativeTestBase(context, "xfb_exceed_offset_limit",
23636                                            "Test verifies that compiler reports error when xfb_offset qualifier exceeds limit")
23637 {
23638 }
23639
23640 /** Source for given test case and stage
23641  *
23642  * @param test_case_index Index of test case
23643  * @param stage           Shader stage
23644  *
23645  * @return Shader source
23646  **/
23647 std::string XFBExceedOffsetLimitTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
23648 {
23649         static const GLchar* block_var_definition = "const uint max_size = SIZE;\n"
23650                                                                                                 "\n"
23651                                                                                                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out Goku {\n"
23652                                                                                                 "    vec4 member;\n"
23653                                                                                                 "} gokuARRAY;\n";
23654         static const GLchar* global_var_definition = "const uint max_size = SIZE;\n"
23655                                                                                                  "\n"
23656                                                                                                  "layout (xfb_buffer = 0, xfb_stride = max_size + 16) out;\n";
23657         static const GLchar* vector_var_definition =
23658                 "const uint max_size = SIZE;\n"
23659                 "\n"
23660                 "layout (xfb_buffer = 0, xfb_offset = max_size + 16) out vec4 gokuARRAY;\n";
23661         static const GLchar* block_use  = "    gokuINDEX.member = result / 2;\n";
23662         static const GLchar* global_use = "";
23663         static const GLchar* vector_use = "    gokuINDEX = result / 2;\n";
23664         static const GLchar* fs                 = "#version 430 core\n"
23665                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23666                                                           "\n"
23667                                                           "in  vec4 gs_fs;\n"
23668                                                           "out vec4 fs_out;\n"
23669                                                           "\n"
23670                                                           "void main()\n"
23671                                                           "{\n"
23672                                                           "    fs_out = gs_fs;\n"
23673                                                           "}\n"
23674                                                           "\n";
23675         static const GLchar* gs_tested = "#version 430 core\n"
23676                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23677                                                                          "\n"
23678                                                                          "layout(points)                           in;\n"
23679                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
23680                                                                          "\n"
23681                                                                          "VAR_DEFINITION"
23682                                                                          "\n"
23683                                                                          "in  vec4 tes_gs[];\n"
23684                                                                          "out vec4 gs_fs;\n"
23685                                                                          "\n"
23686                                                                          "void main()\n"
23687                                                                          "{\n"
23688                                                                          "    vec4 result = tes_gs[0];\n"
23689                                                                          "\n"
23690                                                                          "VARIABLE_USE"
23691                                                                          "\n"
23692                                                                          "    gs_fs = result;\n"
23693                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
23694                                                                          "    EmitVertex();\n"
23695                                                                          "    gs_fs = result;\n"
23696                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
23697                                                                          "    EmitVertex();\n"
23698                                                                          "    gs_fs = result;\n"
23699                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
23700                                                                          "    EmitVertex();\n"
23701                                                                          "    gs_fs = result;\n"
23702                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
23703                                                                          "    EmitVertex();\n"
23704                                                                          "}\n"
23705                                                                          "\n";
23706         static const GLchar* tcs = "#version 430 core\n"
23707                                                            "#extension GL_ARB_enhanced_layouts : require\n"
23708                                                            "\n"
23709                                                            "layout(vertices = 1) out;\n"
23710                                                            "\n"
23711                                                            "in  vec4 vs_tcs[];\n"
23712                                                            "out vec4 tcs_tes[];\n"
23713                                                            "\n"
23714                                                            "void main()\n"
23715                                                            "{\n"
23716                                                            "\n"
23717                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
23718                                                            "\n"
23719                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
23720                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
23721                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
23722                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
23723                                                            "    gl_TessLevelInner[0] = 1.0;\n"
23724                                                            "    gl_TessLevelInner[1] = 1.0;\n"
23725                                                            "}\n"
23726                                                            "\n";
23727         static const GLchar* tcs_tested = "#version 430 core\n"
23728                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23729                                                                           "\n"
23730                                                                           "layout(vertices = 1) out;\n"
23731                                                                           "\n"
23732                                                                           "VAR_DEFINITION"
23733                                                                           "\n"
23734                                                                           "in  vec4 vs_tcs[];\n"
23735                                                                           "out vec4 tcs_tes[];\n"
23736                                                                           "\n"
23737                                                                           "void main()\n"
23738                                                                           "{\n"
23739                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
23740                                                                           "\n"
23741                                                                           "VARIABLE_USE"
23742                                                                           "\n"
23743                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
23744                                                                           "\n"
23745                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
23746                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
23747                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
23748                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
23749                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
23750                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
23751                                                                           "}\n"
23752                                                                           "\n";
23753         static const GLchar* tes_tested = "#version 430 core\n"
23754                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23755                                                                           "\n"
23756                                                                           "layout(isolines, point_mode) in;\n"
23757                                                                           "\n"
23758                                                                           "VAR_DEFINITION"
23759                                                                           "\n"
23760                                                                           "in  vec4 tcs_tes[];\n"
23761                                                                           "out vec4 tes_gs;\n"
23762                                                                           "\n"
23763                                                                           "void main()\n"
23764                                                                           "{\n"
23765                                                                           "    vec4 result = tcs_tes[0];\n"
23766                                                                           "\n"
23767                                                                           "VARIABLE_USE"
23768                                                                           "\n"
23769                                                                           "    tes_gs += result;\n"
23770                                                                           "}\n"
23771                                                                           "\n";
23772         static const GLchar* vs = "#version 430 core\n"
23773                                                           "#extension GL_ARB_enhanced_layouts : require\n"
23774                                                           "\n"
23775                                                           "in  vec4 in_vs;\n"
23776                                                           "out vec4 vs_tcs;\n"
23777                                                           "\n"
23778                                                           "void main()\n"
23779                                                           "{\n"
23780                                                           "    vs_tcs = in_vs;\n"
23781                                                           "}\n"
23782                                                           "\n";
23783         static const GLchar* vs_tested = "#version 430 core\n"
23784                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
23785                                                                          "\n"
23786                                                                          "VAR_DEFINITION"
23787                                                                          "\n"
23788                                                                          "in  vec4 in_vs;\n"
23789                                                                          "out vec4 vs_tcs;\n"
23790                                                                          "\n"
23791                                                                          "void main()\n"
23792                                                                          "{\n"
23793                                                                          "    vec4 result = in_vs;\n"
23794                                                                          "\n"
23795                                                                          "VARIABLE_USE"
23796                                                                          "\n"
23797                                                                          "    vs_tcs = result;\n"
23798                                                                          "}\n"
23799                                                                          "\n";
23800
23801         std::string source;
23802         testCase&   test_case = m_test_cases[test_case_index];
23803
23804         if (test_case.m_stage == stage)
23805         {
23806                 const GLchar*   array = "";
23807                 GLchar                   buffer[16];
23808                 const Functions& gl                              = m_context.getRenderContext().getFunctions();
23809                 const GLchar*   index                    = "";
23810                 GLint                    max_n_xfb_comp  = 0;
23811                 GLint                    max_n_xfb_bytes = 0;
23812                 size_t                   position                = 0;
23813                 size_t                   temp;
23814                 const GLchar*   var_definition = 0;
23815                 const GLchar*   var_use         = 0;
23816
23817                 gl.getIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, &max_n_xfb_comp);
23818                 GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
23819
23820                 max_n_xfb_bytes = max_n_xfb_comp * 4;
23821
23822                 sprintf(buffer, "%d", max_n_xfb_bytes);
23823
23824                 switch (test_case.m_case)
23825                 {
23826                 case BLOCK:
23827                         var_definition = block_var_definition;
23828                         var_use            = block_use;
23829                         break;
23830                 case GLOBAL:
23831                         var_definition = global_var_definition;
23832                         var_use            = global_use;
23833                         break;
23834                 case VECTOR:
23835                         var_definition = vector_var_definition;
23836                         var_use            = vector_use;
23837                         break;
23838                 default:
23839                         TCU_FAIL("Invalid enum");
23840                 }
23841                 // It is a compile time error to apply xfb_offset to the declaration of an unsized array(GLSL4.5 spec: Page73)
23842                 // change array = "[]" to "[1]"
23843                 switch (stage)
23844                 {
23845                 case Utils::Shader::GEOMETRY:
23846                         source = gs_tested;
23847                         array  = "[1]";
23848                         index  = "[0]";
23849                         break;
23850                 case Utils::Shader::TESS_CTRL:
23851                         source = tcs_tested;
23852                         array  = "[1]";
23853                         index  = "[gl_InvocationID]";
23854                         break;
23855                 case Utils::Shader::TESS_EVAL:
23856                         source = tes_tested;
23857                         array  = "[1]";
23858                         index  = "[0]";
23859                         break;
23860                 case Utils::Shader::VERTEX:
23861                         source = vs_tested;
23862                         break;
23863                 default:
23864                         TCU_FAIL("Invalid enum");
23865                 }
23866
23867                 temp = position;
23868                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
23869                 position = temp;
23870                 Utils::replaceToken("SIZE", position, buffer, source);
23871                 if (GLOBAL != test_case.m_case)
23872                 {
23873                         Utils::replaceToken("ARRAY", position, array, source);
23874                 }
23875                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
23876
23877                 Utils::replaceAllTokens("INDEX", index, source);
23878         }
23879         else
23880         {
23881                 switch (test_case.m_stage)
23882                 {
23883                 case Utils::Shader::GEOMETRY:
23884                         switch (stage)
23885                         {
23886                         case Utils::Shader::FRAGMENT:
23887                                 source = fs;
23888                                 break;
23889                         case Utils::Shader::VERTEX:
23890                                 source = vs;
23891                                 break;
23892                         default:
23893                                 source = "";
23894                         }
23895                         break;
23896                 case Utils::Shader::TESS_CTRL:
23897                         switch (stage)
23898                         {
23899                         case Utils::Shader::FRAGMENT:
23900                                 source = fs;
23901                                 break;
23902                         case Utils::Shader::VERTEX:
23903                                 source = vs;
23904                                 break;
23905                         default:
23906                                 source = "";
23907                         }
23908                         break;
23909                 case Utils::Shader::TESS_EVAL:
23910                         switch (stage)
23911                         {
23912                         case Utils::Shader::FRAGMENT:
23913                                 source = fs;
23914                                 break;
23915                         case Utils::Shader::TESS_CTRL:
23916                                 source = tcs;
23917                                 break;
23918                         case Utils::Shader::VERTEX:
23919                                 source = vs;
23920                                 break;
23921                         default:
23922                                 source = "";
23923                         }
23924                         break;
23925                 case Utils::Shader::VERTEX:
23926                         switch (stage)
23927                         {
23928                         case Utils::Shader::FRAGMENT:
23929                                 source = fs;
23930                                 break;
23931                         default:
23932                                 source = "";
23933                         }
23934                         break;
23935                 default:
23936                         TCU_FAIL("Invalid enum");
23937                         break;
23938                 }
23939         }
23940
23941         return source;
23942 }
23943
23944 /** Get description of test case
23945  *
23946  * @param test_case_index Index of test case
23947  *
23948  * @return Test case description
23949  **/
23950 std::string XFBExceedOffsetLimitTest::getTestCaseName(GLuint test_case_index)
23951 {
23952         std::stringstream stream;
23953         testCase&                 test_case = m_test_cases[test_case_index];
23954
23955         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage) << ", case: ";
23956
23957         switch (test_case.m_case)
23958         {
23959         case BLOCK:
23960                 stream << "BLOCK";
23961                 break;
23962         case GLOBAL:
23963                 stream << "GLOBAL";
23964                 break;
23965         case VECTOR:
23966                 stream << "VECTOR";
23967                 break;
23968         default:
23969                 TCU_FAIL("Invalid enum");
23970         }
23971
23972         return stream.str();
23973 }
23974
23975 /** Get number of test cases
23976  *
23977  * @return Number of test cases
23978  **/
23979 GLuint XFBExceedOffsetLimitTest::getTestCaseNumber()
23980 {
23981         return static_cast<GLuint>(m_test_cases.size());
23982 }
23983
23984 /** Selects if "compute" stage is relevant for test
23985  *
23986  * @param ignored
23987  *
23988  * @return false
23989  **/
23990 bool XFBExceedOffsetLimitTest::isComputeRelevant(GLuint /* test_case_index */)
23991 {
23992         return false;
23993 }
23994
23995 /** Prepare all test cases
23996  *
23997  **/
23998 void XFBExceedOffsetLimitTest::testInit()
23999 {
24000         for (GLuint c = 0; c < CASE_MAX; ++c)
24001         {
24002                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24003                 {
24004                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
24005                                 (Utils::Shader::FRAGMENT == stage))
24006                         {
24007                                 continue;
24008                         }
24009
24010                         testCase test_case = { (CASES)c, (Utils::Shader::STAGES)stage };
24011
24012                         m_test_cases.push_back(test_case);
24013                 }
24014         }
24015 }
24016
24017 /** Constructor
24018  *
24019  * @param context Test context
24020  **/
24021 XFBGlobalBufferTest::XFBGlobalBufferTest(deqp::Context& context)
24022         : BufferTestBase(context, "xfb_global_buffer", "Test verifies that global xfb_buffer qualifier is respected")
24023 {
24024         /* Nothing to be done here */
24025 }
24026
24027 /** Get descriptors of buffers necessary for test
24028  *
24029  * @param test_case_index Index of test case
24030  * @param out_descriptors Descriptors of buffers used by test
24031  **/
24032 void XFBGlobalBufferTest::getBufferDescriptors(glw::GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24033 {
24034         // the function "getType(test_case_index)" can't return correct data type, so change code as following:
24035         const Utils::Type& type = m_test_cases[test_case_index].m_type;
24036
24037         /* Test needs single uniform and two xfbs */
24038         out_descriptors.resize(3);
24039
24040         /* Get references */
24041         bufferDescriptor& uniform = out_descriptors[0];
24042         bufferDescriptor& xfb_1   = out_descriptors[1];
24043         bufferDescriptor& xfb_3   = out_descriptors[2];
24044
24045         /* Index */
24046         uniform.m_index = 0;
24047         xfb_1.m_index   = 1;
24048         xfb_3.m_index   = 3;
24049
24050         /* Target */
24051         uniform.m_target = Utils::Buffer::Uniform;
24052         xfb_1.m_target   = Utils::Buffer::Transform_feedback;
24053         xfb_3.m_target   = Utils::Buffer::Transform_feedback;
24054
24055         /* Data */
24056         const GLuint                            gen_start   = Utils::s_rand;
24057         const std::vector<GLubyte>& chichi_data = type.GenerateData();
24058         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
24059         const std::vector<GLubyte>& trunks_data = type.GenerateData();
24060         const std::vector<GLubyte>& bra_data    = type.GenerateData();
24061         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
24062         const std::vector<GLubyte>& goten_data  = type.GenerateData();
24063
24064         Utils::s_rand                                                           = gen_start;
24065         const std::vector<GLubyte>& chichi_data_pck = type.GenerateDataPacked();
24066         const std::vector<GLubyte>& bulma_data_pck  = type.GenerateDataPacked();
24067         const std::vector<GLubyte>& trunks_data_pck = type.GenerateDataPacked();
24068         const std::vector<GLubyte>& bra_data_pck        = type.GenerateDataPacked();
24069         const std::vector<GLubyte>& gohan_data_pck  = type.GenerateDataPacked();
24070         const std::vector<GLubyte>& goten_data_pck  = type.GenerateDataPacked();
24071
24072         const GLuint type_size   = static_cast<GLuint>(chichi_data.size());
24073         const GLuint type_size_pck = static_cast<GLuint>(chichi_data_pck.size());
24074
24075         /* Uniform data */
24076         uniform.m_initial_data.resize(6 * type_size);
24077         memcpy(&uniform.m_initial_data[0] + 0, &chichi_data[0], type_size);
24078         memcpy(&uniform.m_initial_data[0] + type_size, &bulma_data[0], type_size);
24079         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &trunks_data[0], type_size);
24080         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &bra_data[0], type_size);
24081         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &gohan_data[0], type_size);
24082         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &goten_data[0], type_size);
24083
24084         /* XFB data */
24085         xfb_1.m_initial_data.resize(3 * type_size_pck);
24086         xfb_1.m_expected_data.resize(3 * type_size_pck);
24087         xfb_3.m_initial_data.resize(3 * type_size_pck);
24088         xfb_3.m_expected_data.resize(3 * type_size_pck);
24089
24090         for (GLuint i = 0; i < 3 * type_size_pck; ++i)
24091         {
24092                 xfb_1.m_initial_data[i]  = (glw::GLubyte)i;
24093                 xfb_1.m_expected_data[i] = (glw::GLubyte)i;
24094                 xfb_3.m_initial_data[i]  = (glw::GLubyte)i;
24095                 xfb_3.m_expected_data[i] = (glw::GLubyte)i;
24096         }
24097
24098         memcpy(&xfb_3.m_expected_data[0] + 2 * type_size_pck, &chichi_data_pck[0], type_size_pck);
24099         memcpy(&xfb_1.m_expected_data[0] + 0 * type_size_pck, &bulma_data_pck[0], type_size_pck);
24100         memcpy(&xfb_1.m_expected_data[0] + 1 * type_size_pck, &trunks_data_pck[0], type_size_pck);
24101         memcpy(&xfb_1.m_expected_data[0] + 2 * type_size_pck, &bra_data_pck[0], type_size_pck);
24102         memcpy(&xfb_3.m_expected_data[0] + 0 * type_size_pck, &gohan_data_pck[0], type_size_pck);
24103         memcpy(&xfb_3.m_expected_data[0] + 1 * type_size_pck, &goten_data_pck[0], type_size_pck);
24104 }
24105
24106 /** Source for given test case and stage
24107  *
24108  * @param test_case_index Index of test case
24109  * @param stage           Shader stage
24110  *
24111  * @return Shader source
24112  **/
24113 std::string XFBGlobalBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24114 {
24115         static const GLchar* fs =
24116                 "#version 430 core\n"
24117                 "#extension GL_ARB_enhanced_layouts : require\n"
24118                 "\n"
24119                 "flat in TYPE chichi;\n"
24120                 "flat in TYPE bulma;\n"
24121                 "in Vegeta {\n"
24122                 "    TYPE trunk;\n"
24123                 "    TYPE bra;\n"
24124                 "} vegeta;\n"
24125                 "in Goku {\n"
24126                 "    TYPE gohan;\n"
24127                 "    TYPE goten;\n"
24128                 "} goku;\n"
24129                 "\n"
24130                 "out vec4 fs_out;\n"
24131                 "\n"
24132                 "void main()\n"
24133                 "{\n"
24134                 "    fs_out = vec4(1);\n"
24135                 "    if (TYPE(1) != chichi + bulma + vegeta.trunk + vegeta.bra + goku.gohan + goku.goten)\n"
24136                 "    {\n"
24137                 "        fs_out = vec4(0);\n"
24138                 "    }\n"
24139                 "}\n"
24140                 "\n";
24141
24142         static const GLchar* gs = "#version 430 core\n"
24143                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24144                                                           "\n"
24145                                                           "layout(points)                   in;\n"
24146                                                           "layout(points, max_vertices = 1) out;\n"
24147                                                           "\n"
24148                                                           "INTERFACE"
24149                                                           "\n"
24150                                                           "void main()\n"
24151                                                           "{\n"
24152                                                           "ASSIGNMENTS"
24153                                                           "    EmitVertex();\n"
24154                                                           "}\n"
24155                                                           "\n";
24156
24157         static const GLchar* tcs = "#version 430 core\n"
24158                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24159                                                            "\n"
24160                                                            "layout(vertices = 1) out;\n"
24161                                                            "\n"
24162                                                            "\n"
24163                                                            "void main()\n"
24164                                                            "{\n"
24165                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24166                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24167                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24168                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24169                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24170                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24171                                                            "}\n"
24172                                                            "\n";
24173
24174         static const GLchar* tes = "#version 430 core\n"
24175                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24176                                                            "\n"
24177                                                            "layout(isolines, point_mode) in;\n"
24178                                                            "\n"
24179                                                            "INTERFACE"
24180                                                            "\n"
24181                                                            "void main()\n"
24182                                                            "{\n"
24183                                                            "ASSIGNMENTS"
24184                                                            "}\n"
24185                                                            "\n";
24186
24187         static const GLchar* vs = "#version 430 core\n"
24188                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24189                                                           "\n"
24190                                                           "void main()\n"
24191                                                           "{\n"
24192                                                           "}\n"
24193                                                           "\n";
24194
24195         static const GLchar* vs_tested = "#version 430 core\n"
24196                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24197                                                                          "\n"
24198                                                                          "INTERFACE"
24199                                                                          "\n"
24200                                                                          "void main()\n"
24201                                                                          "{\n"
24202                                                                          "ASSIGNMENTS"
24203                                                                          "}\n"
24204                                                                          "\n";
24205
24206         std::string              source;
24207         const _testCase& test_case = m_test_cases[test_case_index];
24208         const GLchar*   type_name = test_case.m_type.GetGLSLTypeName();
24209
24210         if (test_case.m_stage == stage)
24211         {
24212                 std::string assignments = "    chichi       = uni_chichi;\n"
24213                                                                   "    bulma        = uni_bulma;\n"
24214                                                                   "    vegeta.trunk = uni_trunk;\n"
24215                                                                   "    vegeta.bra   = uni_bra;\n"
24216                                                                   "    goku.gohan   = uni_gohan;\n"
24217                                                                   "    goku.goten   = uni_goten;\n";
24218
24219                 std::string interface = "layout (xfb_buffer = 3) out;\n"
24220                                                                 "\n"
24221                                                                 "const uint type_size = SIZE;\n"
24222                                                                 "\n"
24223                                                                 "layout (                xfb_offset = 2 * type_size) flat out TYPE chichi;\n"
24224                                                                 "layout (xfb_buffer = 1, xfb_offset = 0)             flat out TYPE bulma;\n"
24225                                                                 "layout (xfb_buffer = 1, xfb_offset = 1 * type_size) out Vegeta {\n"
24226                                                                 "    TYPE trunk;\n"
24227                                                                 "    TYPE bra;\n"
24228                                                                 "} vegeta;\n"
24229                                                                 "layout (                xfb_offset = 0)             out Goku {\n"
24230                                                                 "    TYPE gohan;\n"
24231                                                                 "    TYPE goten;\n"
24232                                                                 "} goku;\n"
24233                                                                 "\n"
24234                                                                 // Uniform block must be declared with std140, otherwise each block member is not packed
24235                                                                 "layout(binding = 0, std140) uniform block {\n"
24236                                                                 "    TYPE uni_chichi;\n"
24237                                                                 "    TYPE uni_bulma;\n"
24238                                                                 "    TYPE uni_trunk;\n"
24239                                                                 "    TYPE uni_bra;\n"
24240                                                                 "    TYPE uni_gohan;\n"
24241                                                                 "    TYPE uni_goten;\n"
24242                                                                 "};\n";
24243
24244                 /* Prepare interface string */
24245                 {
24246                         GLchar           buffer[16];
24247                         size_t           position  = 0;
24248                         const GLuint type_size = test_case.m_type.GetSize();
24249
24250                         sprintf(buffer, "%d", type_size);
24251
24252                         Utils::replaceToken("SIZE", position, buffer, interface);
24253                         Utils::replaceAllTokens("TYPE", type_name, interface);
24254                 }
24255
24256                 switch (stage)
24257                 {
24258                 case Utils::Shader::GEOMETRY:
24259                         source = gs;
24260                         break;
24261                 case Utils::Shader::TESS_EVAL:
24262                         source = tes;
24263                         break;
24264                 case Utils::Shader::VERTEX:
24265                         source = vs_tested;
24266                         break;
24267                 default:
24268                         TCU_FAIL("Invalid enum");
24269                 }
24270
24271                 /* Replace tokens */
24272                 {
24273                         size_t position = 0;
24274
24275                         Utils::replaceToken("INTERFACE", position, interface.c_str(), source);
24276                         Utils::replaceToken("ASSIGNMENTS", position, assignments.c_str(), source);
24277                 }
24278         }
24279         else
24280         {
24281                 switch (test_case.m_stage)
24282                 {
24283                 case Utils::Shader::GEOMETRY:
24284                         switch (stage)
24285                         {
24286                         case Utils::Shader::FRAGMENT:
24287                                 source = fs;
24288                                 Utils::replaceAllTokens("TYPE", type_name, source);
24289                                 break;
24290                         case Utils::Shader::VERTEX:
24291                                 source = vs;
24292                                 break;
24293                         default:
24294                                 source = "";
24295                         }
24296                         break;
24297                 case Utils::Shader::TESS_EVAL:
24298                         switch (stage)
24299                         {
24300                         case Utils::Shader::FRAGMENT:
24301                                 source = fs;
24302                                 Utils::replaceAllTokens("TYPE", type_name, source);
24303                                 break;
24304                         case Utils::Shader::TESS_CTRL:
24305                                 source = tcs;
24306                                 break;
24307                         case Utils::Shader::VERTEX:
24308                                 source = vs;
24309                                 break;
24310                         default:
24311                                 source = "";
24312                         }
24313                         break;
24314                 case Utils::Shader::VERTEX:
24315                         switch (stage)
24316                         {
24317                         case Utils::Shader::FRAGMENT:
24318                                 source = fs;
24319                                 Utils::replaceAllTokens("TYPE", type_name, source);
24320                                 break;
24321                         default:
24322                                 source = "";
24323                         }
24324                         break;
24325                 default:
24326                         TCU_FAIL("Invalid enum");
24327                         break;
24328                 }
24329         }
24330
24331         return source;
24332 }
24333
24334 /** Get name of test case
24335  *
24336  * @param test_case_index Index of test case
24337  *
24338  * @return Name of case
24339  **/
24340 std::string XFBGlobalBufferTest::getTestCaseName(GLuint test_case_index)
24341 {
24342         std::string              name;
24343         const _testCase& test_case = m_test_cases[test_case_index];
24344
24345         name = "Tested stage: ";
24346         name.append(Utils::Shader::GetStageName(test_case.m_stage));
24347         name.append(". Tested type: ");
24348         name.append(test_case.m_type.GetGLSLTypeName());
24349
24350         return name;
24351 }
24352
24353 /** Get number of cases
24354  *
24355  * @return Number of test cases
24356  **/
24357 GLuint XFBGlobalBufferTest::getTestCaseNumber()
24358 {
24359         return static_cast<GLuint>(m_test_cases.size());
24360 }
24361
24362 /** Prepare set of test cases
24363  *
24364  **/
24365 void XFBGlobalBufferTest::testInit()
24366 {
24367         GLuint n_types = getTypesNumber();
24368
24369         for (GLuint i = 0; i < n_types; ++i)
24370         {
24371                 const Utils::Type& type = getType(i);
24372                 /*
24373                  When the tfx varying is the following type, the number of output exceeds the gl_MaxVaryingComponents, which will
24374                  cause a link time error.
24375                  */
24376                 if (strcmp(type.GetGLSLTypeName(), "dmat3") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4") == 0 ||
24377                         strcmp(type.GetGLSLTypeName(), "dmat3x4") == 0 || strcmp(type.GetGLSLTypeName(), "dmat4x3") == 0)
24378                 {
24379                         continue;
24380                 }
24381                 const _testCase test_cases[] = { { Utils::Shader::VERTEX, type },
24382                                                                                  { Utils::Shader::GEOMETRY, type },
24383                                                                                  { Utils::Shader::TESS_EVAL, type } };
24384
24385                 m_test_cases.push_back(test_cases[0]);
24386                 m_test_cases.push_back(test_cases[1]);
24387                 m_test_cases.push_back(test_cases[2]);
24388         }
24389 }
24390
24391 /** Constructor
24392  *
24393  * @param context Test context
24394  **/
24395 XFBStrideTest::XFBStrideTest(deqp::Context& context)
24396         : BufferTestBase(context, "xfb_stride", "Test verifies that correct stride is used for all types")
24397 {
24398         /* Nothing to be done here */
24399 }
24400
24401 /** Execute drawArrays for single vertex
24402  *
24403  * @param test_case_index
24404  *
24405  * @return true
24406  **/
24407 bool XFBStrideTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
24408 {
24409         const Functions& gl                             = m_context.getRenderContext().getFunctions();
24410         GLenum                   primitive_type = GL_PATCHES;
24411         const testCase&  test_case              = m_test_cases[test_case_index];
24412
24413         if (Utils::Shader::VERTEX == test_case.m_stage)
24414         {
24415                 primitive_type = GL_POINTS;
24416         }
24417
24418         gl.disable(GL_RASTERIZER_DISCARD);
24419         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
24420
24421         gl.beginTransformFeedback(GL_POINTS);
24422         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
24423
24424         gl.drawArrays(primitive_type, 0 /* first */, 2 /* count */);
24425         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
24426
24427         gl.endTransformFeedback();
24428         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
24429
24430         return true;
24431 }
24432
24433 /** Get descriptors of buffers necessary for test
24434  *
24435  * @param test_case_index Index of test case
24436  * @param out_descriptors Descriptors of buffers used by test
24437  **/
24438 void XFBStrideTest::getBufferDescriptors(GLuint test_case_index, bufferDescriptor::Vector& out_descriptors)
24439 {
24440         const testCase& test_case = m_test_cases[test_case_index];
24441         const Utils::Type& type          = test_case.m_type;
24442
24443         /* Test needs single uniform and xfb */
24444         out_descriptors.resize(2);
24445
24446         /* Get references */
24447         bufferDescriptor& uniform = out_descriptors[0];
24448         bufferDescriptor& xfb    = out_descriptors[1];
24449
24450         /* Index */
24451         uniform.m_index = 0;
24452         xfb.m_index             = 0;
24453
24454         /* Target */
24455         uniform.m_target = Utils::Buffer::Uniform;
24456         xfb.m_target     = Utils::Buffer::Transform_feedback;
24457
24458         /* Data */
24459         const GLuint                            rand_start   = Utils::s_rand;
24460         const std::vector<GLubyte>& uniform_data = type.GenerateData();
24461
24462         Utils::s_rand                                            = rand_start;
24463         const std::vector<GLubyte>& xfb_data = type.GenerateDataPacked();
24464
24465         const GLuint uni_type_size = static_cast<GLuint>(uniform_data.size());
24466         const GLuint xfb_type_size = static_cast<GLuint>(xfb_data.size());
24467         /*
24468          Note: If xfb varying output from vertex shader, the variable "goku" will only output once to transform feedback buffer,
24469          if xfb varying output from TES or GS, because the input primitive type in TES is defined as "layout(isolines, point_mode) in;",
24470          the primitive type is line which make the variable "goku" will output twice to transform feedback buffer, so for vertex shader
24471          only one valid data should be initialized in xfb.m_expected_data
24472          */
24473         const GLuint xfb_data_size = (test_case.m_stage == Utils::Shader::VERTEX) ? xfb_type_size : xfb_type_size * 2;
24474         /* Uniform data */
24475         uniform.m_initial_data.resize(uni_type_size);
24476         memcpy(&uniform.m_initial_data[0] + 0 * uni_type_size, &uniform_data[0], uni_type_size);
24477
24478         /* XFB data */
24479         xfb.m_initial_data.resize(xfb_data_size);
24480         xfb.m_expected_data.resize(xfb_data_size);
24481
24482         for (GLuint i = 0; i < xfb_data_size; ++i)
24483         {
24484                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
24485                 xfb.m_expected_data[i] = (glw::GLubyte)i;
24486         }
24487
24488         if (test_case.m_stage == Utils::Shader::VERTEX)
24489         {
24490                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24491         }
24492         else
24493         {
24494                 memcpy(&xfb.m_expected_data[0] + 0 * xfb_type_size, &xfb_data[0], xfb_type_size);
24495                 memcpy(&xfb.m_expected_data[0] + 1 * xfb_type_size, &xfb_data[0], xfb_type_size);
24496         }
24497 }
24498
24499 /** Get body of main function for given shader stage
24500  *
24501  * @param test_case_index  Index of test case
24502  * @param stage            Shader stage
24503  * @param out_assignments  Set to empty
24504  * @param out_calculations Set to empty
24505  **/
24506 void XFBStrideTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_assignments,
24507                                                                   std::string& out_calculations)
24508 {
24509         const testCase& test_case = m_test_cases[test_case_index];
24510
24511         out_calculations = "";
24512
24513         static const GLchar* vs_tes_gs = "    goku = uni_goku;\n";
24514         static const GLchar* fs            = "    fs_out = vec4(1, 0.25, 0.5, 0.75);\n"
24515                                                           "    if (TYPE(0) == goku)\n"
24516                                                           "    {\n"
24517                                                           "         fs_out = vec4(1, 0.75, 0.5, 0.5);\n"
24518                                                           "    }\n";
24519
24520         const GLchar* assignments = "";
24521
24522         if (test_case.m_stage == stage)
24523         {
24524                 switch (stage)
24525                 {
24526                 case Utils::Shader::GEOMETRY:
24527                         assignments = vs_tes_gs;
24528                         break;
24529                 case Utils::Shader::TESS_EVAL:
24530                         assignments = vs_tes_gs;
24531                         break;
24532                 case Utils::Shader::VERTEX:
24533                         assignments = vs_tes_gs;
24534                         break;
24535                 default:
24536                         TCU_FAIL("Invalid enum");
24537                 }
24538         }
24539         else
24540         {
24541                 switch (stage)
24542                 {
24543                 case Utils::Shader::FRAGMENT:
24544                         assignments = fs;
24545                         break;
24546                 case Utils::Shader::GEOMETRY:
24547                 case Utils::Shader::TESS_CTRL:
24548                 case Utils::Shader::TESS_EVAL:
24549                 case Utils::Shader::VERTEX:
24550                         break;
24551                 default:
24552                         TCU_FAIL("Invalid enum");
24553                 }
24554         }
24555
24556         out_assignments = assignments;
24557
24558         if (Utils::Shader::FRAGMENT == stage)
24559         {
24560                 Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_assignments);
24561         }
24562 }
24563
24564 /** Get interface of shader
24565  *
24566  * @param test_case_index  Index of test case
24567  * @param stage            Shader stage
24568  * @param out_interface    Set to ""
24569  **/
24570 void XFBStrideTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage, std::string& out_interface)
24571 {
24572         static const GLchar* vs_tes_gs = "layout (xfb_offset = 0) FLAT out TYPE goku;\n"
24573                                                                          "\n"
24574                                                                          "layout(std140, binding = 0) uniform Goku {\n"
24575                                                                          "    TYPE uni_goku;\n"
24576                                                                          "};\n";
24577         static const GLchar* fs = "FLAT in TYPE goku;\n"
24578                                                           "\n"
24579                                                           "out vec4 fs_out;\n";
24580
24581         const testCase& test_case = m_test_cases[test_case_index];
24582         const GLchar*   interface = "";
24583         const GLchar*   flat      = "";
24584
24585         if (test_case.m_stage == stage)
24586         {
24587                 switch (stage)
24588                 {
24589                 case Utils::Shader::GEOMETRY:
24590                         interface = vs_tes_gs;
24591                         break;
24592                 case Utils::Shader::TESS_EVAL:
24593                         interface = vs_tes_gs;
24594                         break;
24595                 case Utils::Shader::VERTEX:
24596                         interface = vs_tes_gs;
24597                         break;
24598                 default:
24599                         TCU_FAIL("Invalid enum");
24600                 }
24601         }
24602         else
24603         {
24604                 switch (stage)
24605                 {
24606                 case Utils::Shader::FRAGMENT:
24607                         interface = fs;
24608                         break;
24609                 case Utils::Shader::GEOMETRY:
24610                 case Utils::Shader::TESS_CTRL:
24611                 case Utils::Shader::TESS_EVAL:
24612                 case Utils::Shader::VERTEX:
24613                         break;
24614                 default:
24615                         TCU_FAIL("Invalid enum");
24616                 }
24617         }
24618
24619         out_interface = interface;
24620
24621         if (Utils::Type::Float != test_case.m_type.m_basic_type)
24622         {
24623                 flat = "flat";
24624         }
24625
24626         Utils::replaceAllTokens("FLAT", flat, out_interface);
24627         Utils::replaceAllTokens("TYPE", test_case.m_type.GetGLSLTypeName(), out_interface);
24628 }
24629
24630 /** Get source code of shader
24631  *
24632  * @param test_case_index Index of test case
24633  * @param stage           Shader stage
24634  *
24635  * @return Source
24636  **/
24637 std::string XFBStrideTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24638 {
24639         std::string             source;
24640         const testCase& test_case = m_test_cases[test_case_index];
24641
24642         switch (test_case.m_stage)
24643         {
24644         case Utils::Shader::VERTEX:
24645                 switch (stage)
24646                 {
24647                 case Utils::Shader::FRAGMENT:
24648                 case Utils::Shader::VERTEX:
24649                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24650                         break;
24651                 default:
24652                         break;
24653                 }
24654                 break;
24655
24656         case Utils::Shader::TESS_EVAL:
24657                 switch (stage)
24658                 {
24659                 case Utils::Shader::FRAGMENT:
24660                 case Utils::Shader::TESS_CTRL:
24661                 case Utils::Shader::TESS_EVAL:
24662                 case Utils::Shader::VERTEX:
24663                         source = BufferTestBase::getShaderSource(test_case_index, stage);
24664                         break;
24665                 default:
24666                         break;
24667                 }
24668                 break;
24669
24670         case Utils::Shader::GEOMETRY:
24671                 source = BufferTestBase::getShaderSource(test_case_index, stage);
24672                 break;
24673
24674         default:
24675                 TCU_FAIL("Invalid enum");
24676                 break;
24677         }
24678
24679         /* */
24680         return source;
24681 }
24682
24683 /** Get name of test case
24684  *
24685  * @param test_case_index Index of test case
24686  *
24687  * @return Name of tested stage
24688  **/
24689 std::string XFBStrideTest::getTestCaseName(glw::GLuint test_case_index)
24690 {
24691         std::stringstream stream;
24692         const testCase&   test_case = m_test_cases[test_case_index];
24693
24694         stream << "Type: " << test_case.m_type.GetGLSLTypeName()
24695                    << ", stage: " << Utils::Shader::GetStageName(test_case.m_stage);
24696
24697         return stream.str();
24698 }
24699
24700 /** Returns number of test cases
24701  *
24702  * @return TEST_MAX
24703  **/
24704 glw::GLuint XFBStrideTest::getTestCaseNumber()
24705 {
24706         return static_cast<GLuint>(m_test_cases.size());
24707 }
24708
24709 /** Prepare all test cases
24710  *
24711  **/
24712 void XFBStrideTest::testInit()
24713 {
24714         const GLuint n_types = getTypesNumber();
24715
24716         for (GLuint i = 0; i < n_types; ++i)
24717         {
24718                 const Utils::Type& type = getType(i);
24719
24720                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
24721                 {
24722                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
24723                                 (Utils::Shader::TESS_CTRL == stage))
24724                         {
24725                                 continue;
24726                         }
24727
24728                         testCase test_case = { (Utils::Shader::STAGES)stage, type };
24729
24730                         m_test_cases.push_back(test_case);
24731                 }
24732         }
24733 }
24734
24735 /** Constructor
24736  *
24737  * @param context Test framework context
24738  **/
24739 XFBBlockMemberBufferTest::XFBBlockMemberBufferTest(deqp::Context& context)
24740         : NegativeTestBase(
24741                   context, "xfb_block_member_buffer",
24742                   "Test verifies that compiler reports error when block member has different xfb_buffer qualifier than buffer")
24743 {
24744 }
24745
24746 /** Source for given test case and stage
24747  *
24748  * @param test_case_index Index of test case
24749  * @param stage           Shader stage
24750  *
24751  * @return Shader source
24752  **/
24753 std::string XFBBlockMemberBufferTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
24754 {
24755         static const GLchar* var_definition = "layout (xfb_offset = 0) out Goku {\n"
24756                                                                                   "                            vec4 gohan;\n"
24757                                                                                   "    layout (xfb_buffer = 1) vec4 goten;\n"
24758                                                                                   "} gokuARRAY;\n";
24759         static const GLchar* var_use = "    gokuINDEX.gohan = result / 2;\n"
24760                                                                    "    gokuINDEX.goten = result / 4;\n";
24761         static const GLchar* fs = "#version 430 core\n"
24762                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24763                                                           "\n"
24764                                                           "in  vec4 gs_fs;\n"
24765                                                           "out vec4 fs_out;\n"
24766                                                           "\n"
24767                                                           "void main()\n"
24768                                                           "{\n"
24769                                                           "    fs_out = gs_fs;\n"
24770                                                           "}\n"
24771                                                           "\n";
24772         static const GLchar* gs_tested = "#version 430 core\n"
24773                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24774                                                                          "\n"
24775                                                                          "layout(points)                           in;\n"
24776                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
24777                                                                          "\n"
24778                                                                          "VAR_DEFINITION"
24779                                                                          "\n"
24780                                                                          "in  vec4 tes_gs[];\n"
24781                                                                          "out vec4 gs_fs;\n"
24782                                                                          "\n"
24783                                                                          "void main()\n"
24784                                                                          "{\n"
24785                                                                          "    vec4 result = tes_gs[0];\n"
24786                                                                          "\n"
24787                                                                          "VARIABLE_USE"
24788                                                                          "\n"
24789                                                                          "    gs_fs = result;\n"
24790                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
24791                                                                          "    EmitVertex();\n"
24792                                                                          "    gs_fs = result;\n"
24793                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
24794                                                                          "    EmitVertex();\n"
24795                                                                          "    gs_fs = result;\n"
24796                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
24797                                                                          "    EmitVertex();\n"
24798                                                                          "    gs_fs = result;\n"
24799                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
24800                                                                          "    EmitVertex();\n"
24801                                                                          "}\n"
24802                                                                          "\n";
24803         static const GLchar* tcs = "#version 430 core\n"
24804                                                            "#extension GL_ARB_enhanced_layouts : require\n"
24805                                                            "\n"
24806                                                            "layout(vertices = 1) out;\n"
24807                                                            "\n"
24808                                                            "in  vec4 vs_tcs[];\n"
24809                                                            "out vec4 tcs_tes[];\n"
24810                                                            "\n"
24811                                                            "void main()\n"
24812                                                            "{\n"
24813                                                            "\n"
24814                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
24815                                                            "\n"
24816                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
24817                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
24818                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
24819                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
24820                                                            "    gl_TessLevelInner[0] = 1.0;\n"
24821                                                            "    gl_TessLevelInner[1] = 1.0;\n"
24822                                                            "}\n"
24823                                                            "\n";
24824         static const GLchar* tcs_tested = "#version 430 core\n"
24825                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24826                                                                           "\n"
24827                                                                           "layout(vertices = 1) out;\n"
24828                                                                           "\n"
24829                                                                           "VAR_DEFINITION"
24830                                                                           "\n"
24831                                                                           "in  vec4 vs_tcs[];\n"
24832                                                                           "out vec4 tcs_tes[];\n"
24833                                                                           "\n"
24834                                                                           "void main()\n"
24835                                                                           "{\n"
24836                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
24837                                                                           "\n"
24838                                                                           "VARIABLE_USE"
24839                                                                           "\n"
24840                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
24841                                                                           "\n"
24842                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
24843                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
24844                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
24845                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
24846                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
24847                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
24848                                                                           "}\n"
24849                                                                           "\n";
24850         static const GLchar* tes_tested = "#version 430 core\n"
24851                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24852                                                                           "\n"
24853                                                                           "layout(isolines, point_mode) in;\n"
24854                                                                           "\n"
24855                                                                           "VAR_DEFINITION"
24856                                                                           "\n"
24857                                                                           "in  vec4 tcs_tes[];\n"
24858                                                                           "out vec4 tes_gs;\n"
24859                                                                           "\n"
24860                                                                           "void main()\n"
24861                                                                           "{\n"
24862                                                                           "    vec4 result = tcs_tes[0];\n"
24863                                                                           "\n"
24864                                                                           "VARIABLE_USE"
24865                                                                           "\n"
24866                                                                           "    tes_gs += result;\n"
24867                                                                           "}\n"
24868                                                                           "\n";
24869         static const GLchar* vs = "#version 430 core\n"
24870                                                           "#extension GL_ARB_enhanced_layouts : require\n"
24871                                                           "\n"
24872                                                           "in  vec4 in_vs;\n"
24873                                                           "out vec4 vs_tcs;\n"
24874                                                           "\n"
24875                                                           "void main()\n"
24876                                                           "{\n"
24877                                                           "    vs_tcs = in_vs;\n"
24878                                                           "}\n"
24879                                                           "\n";
24880         static const GLchar* vs_tested = "#version 430 core\n"
24881                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
24882                                                                          "\n"
24883                                                                          "VAR_DEFINITION"
24884                                                                          "\n"
24885                                                                          "in  vec4 in_vs;\n"
24886                                                                          "out vec4 vs_tcs;\n"
24887                                                                          "\n"
24888                                                                          "void main()\n"
24889                                                                          "{\n"
24890                                                                          "    vec4 result = in_vs;\n"
24891                                                                          "\n"
24892                                                                          "VARIABLE_USE"
24893                                                                          "\n"
24894                                                                          "    vs_tcs = result;\n"
24895                                                                          "}\n"
24896                                                                          "\n";
24897
24898         std::string source;
24899         testCase&   test_case = m_test_cases[test_case_index];
24900
24901         if (test_case.m_stage == stage)
24902         {
24903                 const GLchar* array     = "";
24904                 const GLchar* index     = "";
24905                 size_t            position = 0;
24906
24907                 switch (stage)
24908                 {
24909                 case Utils::Shader::GEOMETRY:
24910                         source = gs_tested;
24911                         array  = "[]";
24912                         index  = "[0]";
24913                         break;
24914                 case Utils::Shader::TESS_CTRL:
24915                         source = tcs_tested;
24916                         array  = "[]";
24917                         index  = "[gl_InvocationID]";
24918                         break;
24919                 case Utils::Shader::TESS_EVAL:
24920                         source = tes_tested;
24921                         array  = "[]";
24922                         index  = "[0]";
24923                         break;
24924                 case Utils::Shader::VERTEX:
24925                         source = vs_tested;
24926                         break;
24927                 default:
24928                         TCU_FAIL("Invalid enum");
24929                 }
24930
24931                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
24932                 position = 0;
24933                 Utils::replaceToken("ARRAY", position, array, source);
24934                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
24935
24936                 Utils::replaceAllTokens("INDEX", index, source);
24937         }
24938         else
24939         {
24940                 switch (test_case.m_stage)
24941                 {
24942                 case Utils::Shader::GEOMETRY:
24943                         switch (stage)
24944                         {
24945                         case Utils::Shader::FRAGMENT:
24946                                 source = fs;
24947                                 break;
24948                         case Utils::Shader::VERTEX:
24949                                 source = vs;
24950                                 break;
24951                         default:
24952                                 source = "";
24953                         }
24954                         break;
24955                 case Utils::Shader::TESS_CTRL:
24956                         switch (stage)
24957                         {
24958                         case Utils::Shader::FRAGMENT:
24959                                 source = fs;
24960                                 break;
24961                         case Utils::Shader::VERTEX:
24962                                 source = vs;
24963                                 break;
24964                         default:
24965                                 source = "";
24966                         }
24967                         break;
24968                 case Utils::Shader::TESS_EVAL:
24969                         switch (stage)
24970                         {
24971                         case Utils::Shader::FRAGMENT:
24972                                 source = fs;
24973                                 break;
24974                         case Utils::Shader::TESS_CTRL:
24975                                 source = tcs;
24976                                 break;
24977                         case Utils::Shader::VERTEX:
24978                                 source = vs;
24979                                 break;
24980                         default:
24981                                 source = "";
24982                         }
24983                         break;
24984                 case Utils::Shader::VERTEX:
24985                         switch (stage)
24986                         {
24987                         case Utils::Shader::FRAGMENT:
24988                                 source = fs;
24989                                 break;
24990                         default:
24991                                 source = "";
24992                         }
24993                         break;
24994                 default:
24995                         TCU_FAIL("Invalid enum");
24996                         break;
24997                 }
24998         }
24999
25000         return source;
25001 }
25002
25003 /** Get description of test case
25004  *
25005  * @param test_case_index Index of test case
25006  *
25007  * @return Test case description
25008  **/
25009 std::string XFBBlockMemberBufferTest::getTestCaseName(GLuint test_case_index)
25010 {
25011         std::stringstream stream;
25012         testCase&                 test_case = m_test_cases[test_case_index];
25013
25014         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
25015
25016         return stream.str();
25017 }
25018
25019 /** Get number of test cases
25020  *
25021  * @return Number of test cases
25022  **/
25023 GLuint XFBBlockMemberBufferTest::getTestCaseNumber()
25024 {
25025         return static_cast<GLuint>(m_test_cases.size());
25026 }
25027
25028 /** Selects if "compute" stage is relevant for test
25029  *
25030  * @param ignored
25031  *
25032  * @return false
25033  **/
25034 bool XFBBlockMemberBufferTest::isComputeRelevant(GLuint /* test_case_index */)
25035 {
25036         return false;
25037 }
25038
25039 /** Prepare all test cases
25040  *
25041  **/
25042 void XFBBlockMemberBufferTest::testInit()
25043 {
25044         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25045         {
25046                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25047                         (Utils::Shader::FRAGMENT == stage))
25048                 {
25049                         continue;
25050                 }
25051
25052                 testCase test_case = { (Utils::Shader::STAGES)stage };
25053
25054                 m_test_cases.push_back(test_case);
25055         }
25056 }
25057
25058 /** Constructor
25059  *
25060  * @param context Test framework context
25061  **/
25062 XFBOutputOverlappingTest::XFBOutputOverlappingTest(deqp::Context& context)
25063         : NegativeTestBase(context, "xfb_output_overlapping",
25064                                            "Test verifies that compiler reports error when two xfb qualified outputs overlap")
25065 {
25066 }
25067
25068 /** Source for given test case and stage
25069  *
25070  * @param test_case_index Index of test case
25071  * @param stage           Shader stage
25072  *
25073  * @return Shader source
25074  **/
25075 std::string XFBOutputOverlappingTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25076 {
25077         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n"
25078                                                                                   "layout (xfb_offset = OFFSET) out TYPE gotenARRAY;\n";
25079         static const GLchar* var_use = "    gohanINDEX = TYPE(0);\n"
25080                                                                    "    gotenINDEX = TYPE(1);\n"
25081                                                                    "    if (vec4(0) == result)\n"
25082                                                                    "    {\n"
25083                                                                    "        gohanINDEX = TYPE(1);\n"
25084                                                                    "        gotenINDEX = TYPE(0);\n"
25085                                                                    "    }\n";
25086         static const GLchar* fs = "#version 430 core\n"
25087                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25088                                                           "\n"
25089                                                           "in  vec4 gs_fs;\n"
25090                                                           "out vec4 fs_out;\n"
25091                                                           "\n"
25092                                                           "void main()\n"
25093                                                           "{\n"
25094                                                           "    fs_out = gs_fs;\n"
25095                                                           "}\n"
25096                                                           "\n";
25097         static const GLchar* gs_tested = "#version 430 core\n"
25098                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25099                                                                          "\n"
25100                                                                          "layout(points)                           in;\n"
25101                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25102                                                                          "\n"
25103                                                                          "VAR_DEFINITION"
25104                                                                          "\n"
25105                                                                          "in  vec4 tes_gs[];\n"
25106                                                                          "out vec4 gs_fs;\n"
25107                                                                          "\n"
25108                                                                          "void main()\n"
25109                                                                          "{\n"
25110                                                                          "    vec4 result = tes_gs[0];\n"
25111                                                                          "\n"
25112                                                                          "VARIABLE_USE"
25113                                                                          "\n"
25114                                                                          "    gs_fs = result;\n"
25115                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25116                                                                          "    EmitVertex();\n"
25117                                                                          "    gs_fs = result;\n"
25118                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25119                                                                          "    EmitVertex();\n"
25120                                                                          "    gs_fs = result;\n"
25121                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25122                                                                          "    EmitVertex();\n"
25123                                                                          "    gs_fs = result;\n"
25124                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25125                                                                          "    EmitVertex();\n"
25126                                                                          "}\n"
25127                                                                          "\n";
25128         static const GLchar* tcs = "#version 430 core\n"
25129                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25130                                                            "\n"
25131                                                            "layout(vertices = 1) out;\n"
25132                                                            "\n"
25133                                                            "in  vec4 vs_tcs[];\n"
25134                                                            "out vec4 tcs_tes[];\n"
25135                                                            "\n"
25136                                                            "void main()\n"
25137                                                            "{\n"
25138                                                            "\n"
25139                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25140                                                            "\n"
25141                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25142                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25143                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25144                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25145                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25146                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25147                                                            "}\n"
25148                                                            "\n";
25149         static const GLchar* tcs_tested = "#version 430 core\n"
25150                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25151                                                                           "\n"
25152                                                                           "layout(vertices = 1) out;\n"
25153                                                                           "\n"
25154                                                                           "VAR_DEFINITION"
25155                                                                           "\n"
25156                                                                           "in  vec4 vs_tcs[];\n"
25157                                                                           "out vec4 tcs_tes[];\n"
25158                                                                           "\n"
25159                                                                           "void main()\n"
25160                                                                           "{\n"
25161                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25162                                                                           "\n"
25163                                                                           "VARIABLE_USE"
25164                                                                           "\n"
25165                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25166                                                                           "\n"
25167                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25168                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25169                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25170                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25171                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25172                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25173                                                                           "}\n"
25174                                                                           "\n";
25175         static const GLchar* tes_tested = "#version 430 core\n"
25176                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25177                                                                           "\n"
25178                                                                           "layout(isolines, point_mode) in;\n"
25179                                                                           "\n"
25180                                                                           "VAR_DEFINITION"
25181                                                                           "\n"
25182                                                                           "in  vec4 tcs_tes[];\n"
25183                                                                           "out vec4 tes_gs;\n"
25184                                                                           "\n"
25185                                                                           "void main()\n"
25186                                                                           "{\n"
25187                                                                           "    vec4 result = tcs_tes[0];\n"
25188                                                                           "\n"
25189                                                                           "VARIABLE_USE"
25190                                                                           "\n"
25191                                                                           "    tes_gs += result;\n"
25192                                                                           "}\n"
25193                                                                           "\n";
25194         static const GLchar* vs = "#version 430 core\n"
25195                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25196                                                           "\n"
25197                                                           "in  vec4 in_vs;\n"
25198                                                           "out vec4 vs_tcs;\n"
25199                                                           "\n"
25200                                                           "void main()\n"
25201                                                           "{\n"
25202                                                           "    vs_tcs = in_vs;\n"
25203                                                           "}\n"
25204                                                           "\n";
25205         static const GLchar* vs_tested = "#version 430 core\n"
25206                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25207                                                                          "\n"
25208                                                                          "VAR_DEFINITION"
25209                                                                          "\n"
25210                                                                          "in  vec4 in_vs;\n"
25211                                                                          "out vec4 vs_tcs;\n"
25212                                                                          "\n"
25213                                                                          "void main()\n"
25214                                                                          "{\n"
25215                                                                          "    vec4 result = in_vs;\n"
25216                                                                          "\n"
25217                                                                          "VARIABLE_USE"
25218                                                                          "\n"
25219                                                                          "    vs_tcs = result;\n"
25220                                                                          "}\n"
25221                                                                          "\n";
25222
25223         std::string source;
25224         testCase&   test_case = m_test_cases[test_case_index];
25225
25226         if (test_case.m_stage == stage)
25227         {
25228                 const GLchar* array = "";
25229                 GLchar            buffer_gohan[16];
25230                 GLchar            buffer_goten[16];
25231                 const GLchar* index                      = "";
25232                 size_t            position               = 0;
25233                 size_t            position_start = 0;
25234                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25235
25236                 sprintf(buffer_gohan, "%d", test_case.m_offset_gohan);
25237                 sprintf(buffer_goten, "%d", test_case.m_offset_goten);
25238
25239                 switch (stage)
25240                 {
25241                 case Utils::Shader::GEOMETRY:
25242                         source = gs_tested;
25243                         array  = "[]";
25244                         index  = "[0]";
25245                         break;
25246                 case Utils::Shader::TESS_CTRL:
25247                         source = tcs_tested;
25248                         array  = "[]";
25249                         index  = "[gl_InvocationID]";
25250                         break;
25251                 case Utils::Shader::TESS_EVAL:
25252                         source = tes_tested;
25253                         array  = "[]";
25254                         index  = "[0]";
25255                         break;
25256                 case Utils::Shader::VERTEX:
25257                         source = vs_tested;
25258                         break;
25259                 default:
25260                         TCU_FAIL("Invalid enum");
25261                 }
25262
25263                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25264                 position = 0;
25265                 Utils::replaceToken("OFFSET", position, buffer_gohan, source);
25266                 Utils::replaceToken("TYPE", position, type_name, source);
25267                 Utils::replaceToken("ARRAY", position, array, source);
25268                 Utils::replaceToken("OFFSET", position, buffer_goten, source);
25269                 Utils::replaceToken("TYPE", position, type_name, source);
25270                 Utils::replaceToken("ARRAY", position, array, source);
25271                 position_start = position;
25272                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25273                 position = position_start;
25274                 Utils::replaceToken("INDEX", position, index, source);
25275                 Utils::replaceToken("TYPE", position, type_name, source);
25276                 Utils::replaceToken("INDEX", position, index, source);
25277                 Utils::replaceToken("TYPE", position, type_name, source);
25278                 Utils::replaceToken("INDEX", position, index, source);
25279                 Utils::replaceToken("TYPE", position, type_name, source);
25280                 Utils::replaceToken("INDEX", position, index, source);
25281                 Utils::replaceToken("TYPE", position, type_name, source);
25282         }
25283         else
25284         {
25285                 switch (test_case.m_stage)
25286                 {
25287                 case Utils::Shader::GEOMETRY:
25288                         switch (stage)
25289                         {
25290                         case Utils::Shader::FRAGMENT:
25291                                 source = fs;
25292                                 break;
25293                         case Utils::Shader::VERTEX:
25294                                 source = vs;
25295                                 break;
25296                         default:
25297                                 source = "";
25298                         }
25299                         break;
25300                 case Utils::Shader::TESS_CTRL:
25301                         switch (stage)
25302                         {
25303                         case Utils::Shader::FRAGMENT:
25304                                 source = fs;
25305                                 break;
25306                         case Utils::Shader::VERTEX:
25307                                 source = vs;
25308                                 break;
25309                         default:
25310                                 source = "";
25311                         }
25312                         break;
25313                 case Utils::Shader::TESS_EVAL:
25314                         switch (stage)
25315                         {
25316                         case Utils::Shader::FRAGMENT:
25317                                 source = fs;
25318                                 break;
25319                         case Utils::Shader::TESS_CTRL:
25320                                 source = tcs;
25321                                 break;
25322                         case Utils::Shader::VERTEX:
25323                                 source = vs;
25324                                 break;
25325                         default:
25326                                 source = "";
25327                         }
25328                         break;
25329                 case Utils::Shader::VERTEX:
25330                         switch (stage)
25331                         {
25332                         case Utils::Shader::FRAGMENT:
25333                                 source = fs;
25334                                 break;
25335                         default:
25336                                 source = "";
25337                         }
25338                         break;
25339                 default:
25340                         TCU_FAIL("Invalid enum");
25341                         break;
25342                 }
25343         }
25344
25345         return source;
25346 }
25347
25348 /** Get description of test case
25349  *
25350  * @param test_case_index Index of test case
25351  *
25352  * @return Test case description
25353  **/
25354 std::string XFBOutputOverlappingTest::getTestCaseName(GLuint test_case_index)
25355 {
25356         std::stringstream stream;
25357         testCase&                 test_case = m_test_cases[test_case_index];
25358
25359         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25360                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offsets: " << test_case.m_offset_gohan << " & "
25361                    << test_case.m_offset_goten;
25362
25363         return stream.str();
25364 }
25365
25366 /** Get number of test cases
25367  *
25368  * @return Number of test cases
25369  **/
25370 GLuint XFBOutputOverlappingTest::getTestCaseNumber()
25371 {
25372         return static_cast<GLuint>(m_test_cases.size());
25373 }
25374
25375 /** Selects if "compute" stage is relevant for test
25376  *
25377  * @param ignored
25378  *
25379  * @return false
25380  **/
25381 bool XFBOutputOverlappingTest::isComputeRelevant(GLuint /* test_case_index */)
25382 {
25383         return false;
25384 }
25385
25386 /** Prepare all test cases
25387  *
25388  **/
25389 void XFBOutputOverlappingTest::testInit()
25390 {
25391         const GLuint n_types = getTypesNumber();
25392
25393         for (GLuint i = 0; i < n_types; ++i)
25394         {
25395                 const Utils::Type& type                   = getType(i);
25396                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25397
25398                 /* Skip scalars, not applicable as:
25399                  *
25400                  *     The offset must be a multiple of the size of the first component of the first
25401                  *     qualified variable or block member, or a compile-time error results.
25402                  */
25403                 if ((1 == type.m_n_columns) && (1 == type.m_n_rows))
25404                 {
25405                         continue;
25406                 }
25407
25408                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25409                 {
25410                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25411                                 (Utils::Shader::FRAGMENT == stage))
25412                         {
25413                                 continue;
25414                         }
25415
25416                         testCase test_case = { 0 /* gohan offset */, base_alingment /* goten_offset */,
25417                                                                    (Utils::Shader::STAGES)stage, type };
25418
25419                         m_test_cases.push_back(test_case);
25420                 }
25421         }
25422 }
25423
25424 /** Constructor
25425  *
25426  * @param context Test framework context
25427  **/
25428 XFBInvalidOffsetAlignmentTest::XFBInvalidOffsetAlignmentTest(deqp::Context& context)
25429         : NegativeTestBase(context, "xfb_invalid_offset_alignment",
25430                                            "Test verifies that compiler reports error when xfb_offset has invalid alignment")
25431 {
25432 }
25433
25434 /** Source for given test case and stage
25435  *
25436  * @param test_case_index Index of test case
25437  * @param stage           Shader stage
25438  *
25439  * @return Shader source
25440  **/
25441 std::string XFBInvalidOffsetAlignmentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25442 {
25443         static const GLchar* var_definition = "layout (xfb_offset = OFFSET) out TYPE gohanARRAY;\n";
25444         static const GLchar* var_use            = "    gohanINDEX = TYPE(0);\n"
25445                                                                    "    if (vec4(0) == result)\n"
25446                                                                    "    {\n"
25447                                                                    "        gohanINDEX = TYPE(1);\n"
25448                                                                    "    }\n";
25449         static const GLchar* fs = "#version 430 core\n"
25450                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25451                                                           "\n"
25452                                                           "in  vec4 gs_fs;\n"
25453                                                           "out vec4 fs_out;\n"
25454                                                           "\n"
25455                                                           "void main()\n"
25456                                                           "{\n"
25457                                                           "    fs_out = gs_fs;\n"
25458                                                           "}\n"
25459                                                           "\n";
25460         static const GLchar* gs_tested = "#version 430 core\n"
25461                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25462                                                                          "\n"
25463                                                                          "layout(points)                           in;\n"
25464                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
25465                                                                          "\n"
25466                                                                          "VAR_DEFINITION"
25467                                                                          "\n"
25468                                                                          "in  vec4 tes_gs[];\n"
25469                                                                          "out vec4 gs_fs;\n"
25470                                                                          "\n"
25471                                                                          "void main()\n"
25472                                                                          "{\n"
25473                                                                          "    vec4 result = tes_gs[0];\n"
25474                                                                          "\n"
25475                                                                          "VARIABLE_USE"
25476                                                                          "\n"
25477                                                                          "    gs_fs = result;\n"
25478                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
25479                                                                          "    EmitVertex();\n"
25480                                                                          "    gs_fs = result;\n"
25481                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
25482                                                                          "    EmitVertex();\n"
25483                                                                          "    gs_fs = result;\n"
25484                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
25485                                                                          "    EmitVertex();\n"
25486                                                                          "    gs_fs = result;\n"
25487                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
25488                                                                          "    EmitVertex();\n"
25489                                                                          "}\n"
25490                                                                          "\n";
25491         static const GLchar* tcs = "#version 430 core\n"
25492                                                            "#extension GL_ARB_enhanced_layouts : require\n"
25493                                                            "\n"
25494                                                            "layout(vertices = 1) out;\n"
25495                                                            "\n"
25496                                                            "in  vec4 vs_tcs[];\n"
25497                                                            "out vec4 tcs_tes[];\n"
25498                                                            "\n"
25499                                                            "void main()\n"
25500                                                            "{\n"
25501                                                            "\n"
25502                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
25503                                                            "\n"
25504                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
25505                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
25506                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
25507                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
25508                                                            "    gl_TessLevelInner[0] = 1.0;\n"
25509                                                            "    gl_TessLevelInner[1] = 1.0;\n"
25510                                                            "}\n"
25511                                                            "\n";
25512         static const GLchar* tcs_tested = "#version 430 core\n"
25513                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25514                                                                           "\n"
25515                                                                           "layout(vertices = 1) out;\n"
25516                                                                           "\n"
25517                                                                           "VAR_DEFINITION"
25518                                                                           "\n"
25519                                                                           "in  vec4 vs_tcs[];\n"
25520                                                                           "out vec4 tcs_tes[];\n"
25521                                                                           "\n"
25522                                                                           "void main()\n"
25523                                                                           "{\n"
25524                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
25525                                                                           "\n"
25526                                                                           "VARIABLE_USE"
25527                                                                           "\n"
25528                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
25529                                                                           "\n"
25530                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
25531                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
25532                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
25533                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
25534                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
25535                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
25536                                                                           "}\n"
25537                                                                           "\n";
25538         static const GLchar* tes_tested = "#version 430 core\n"
25539                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25540                                                                           "\n"
25541                                                                           "layout(isolines, point_mode) in;\n"
25542                                                                           "\n"
25543                                                                           "VAR_DEFINITION"
25544                                                                           "\n"
25545                                                                           "in  vec4 tcs_tes[];\n"
25546                                                                           "out vec4 tes_gs;\n"
25547                                                                           "\n"
25548                                                                           "void main()\n"
25549                                                                           "{\n"
25550                                                                           "    vec4 result = tcs_tes[0];\n"
25551                                                                           "\n"
25552                                                                           "VARIABLE_USE"
25553                                                                           "\n"
25554                                                                           "    tes_gs += result;\n"
25555                                                                           "}\n"
25556                                                                           "\n";
25557         static const GLchar* vs = "#version 430 core\n"
25558                                                           "#extension GL_ARB_enhanced_layouts : require\n"
25559                                                           "\n"
25560                                                           "in  vec4 in_vs;\n"
25561                                                           "out vec4 vs_tcs;\n"
25562                                                           "\n"
25563                                                           "void main()\n"
25564                                                           "{\n"
25565                                                           "    vs_tcs = in_vs;\n"
25566                                                           "}\n"
25567                                                           "\n";
25568         static const GLchar* vs_tested = "#version 430 core\n"
25569                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
25570                                                                          "\n"
25571                                                                          "VAR_DEFINITION"
25572                                                                          "\n"
25573                                                                          "in  vec4 in_vs;\n"
25574                                                                          "out vec4 vs_tcs;\n"
25575                                                                          "\n"
25576                                                                          "void main()\n"
25577                                                                          "{\n"
25578                                                                          "    vec4 result = in_vs;\n"
25579                                                                          "\n"
25580                                                                          "VARIABLE_USE"
25581                                                                          "\n"
25582                                                                          "    vs_tcs = result;\n"
25583                                                                          "}\n"
25584                                                                          "\n";
25585
25586         std::string source;
25587         testCase&   test_case = m_test_cases[test_case_index];
25588
25589         if (test_case.m_stage == stage)
25590         {
25591                 const GLchar* array = "";
25592                 GLchar            buffer[16];
25593                 const GLchar* index                      = "";
25594                 size_t            position               = 0;
25595                 size_t            position_start = 0;
25596                 const GLchar* type_name          = test_case.m_type.GetGLSLTypeName();
25597
25598                 sprintf(buffer, "%d", test_case.m_offset);
25599
25600                 switch (stage)
25601                 {
25602                 case Utils::Shader::GEOMETRY:
25603                         source = gs_tested;
25604                         array  = "[]";
25605                         index  = "[0]";
25606                         break;
25607                 case Utils::Shader::TESS_CTRL:
25608                         source = tcs_tested;
25609                         array  = "[]";
25610                         index  = "[gl_InvocationID]";
25611                         break;
25612                 case Utils::Shader::TESS_EVAL:
25613                         source = tes_tested;
25614                         array  = "[]";
25615                         index  = "[0]";
25616                         break;
25617                 case Utils::Shader::VERTEX:
25618                         source = vs_tested;
25619                         break;
25620                 default:
25621                         TCU_FAIL("Invalid enum");
25622                 }
25623
25624                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
25625                 position = 0;
25626                 Utils::replaceToken("OFFSET", position, buffer, source);
25627                 Utils::replaceToken("TYPE", position, type_name, source);
25628                 Utils::replaceToken("ARRAY", position, array, source);
25629                 position_start = position;
25630                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
25631                 position = position_start;
25632                 Utils::replaceToken("INDEX", position, index, source);
25633                 Utils::replaceToken("TYPE", position, type_name, source);
25634                 Utils::replaceToken("INDEX", position, index, source);
25635                 Utils::replaceToken("TYPE", position, type_name, source);
25636         }
25637         else
25638         {
25639                 switch (test_case.m_stage)
25640                 {
25641                 case Utils::Shader::GEOMETRY:
25642                         switch (stage)
25643                         {
25644                         case Utils::Shader::FRAGMENT:
25645                                 source = fs;
25646                                 break;
25647                         case Utils::Shader::VERTEX:
25648                                 source = vs;
25649                                 break;
25650                         default:
25651                                 source = "";
25652                         }
25653                         break;
25654                 case Utils::Shader::TESS_CTRL:
25655                         switch (stage)
25656                         {
25657                         case Utils::Shader::FRAGMENT:
25658                                 source = fs;
25659                                 break;
25660                         case Utils::Shader::VERTEX:
25661                                 source = vs;
25662                                 break;
25663                         default:
25664                                 source = "";
25665                         }
25666                         break;
25667                 case Utils::Shader::TESS_EVAL:
25668                         switch (stage)
25669                         {
25670                         case Utils::Shader::FRAGMENT:
25671                                 source = fs;
25672                                 break;
25673                         case Utils::Shader::TESS_CTRL:
25674                                 source = tcs;
25675                                 break;
25676                         case Utils::Shader::VERTEX:
25677                                 source = vs;
25678                                 break;
25679                         default:
25680                                 source = "";
25681                         }
25682                         break;
25683                 case Utils::Shader::VERTEX:
25684                         switch (stage)
25685                         {
25686                         case Utils::Shader::FRAGMENT:
25687                                 source = fs;
25688                                 break;
25689                         default:
25690                                 source = "";
25691                         }
25692                         break;
25693                 default:
25694                         TCU_FAIL("Invalid enum");
25695                         break;
25696                 }
25697         }
25698
25699         return source;
25700 }
25701
25702 /** Get description of test case
25703  *
25704  * @param test_case_index Index of test case
25705  *
25706  * @return Test case description
25707  **/
25708 std::string XFBInvalidOffsetAlignmentTest::getTestCaseName(GLuint test_case_index)
25709 {
25710         std::stringstream stream;
25711         testCase&                 test_case = m_test_cases[test_case_index];
25712
25713         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage)
25714                    << ", type: " << test_case.m_type.GetGLSLTypeName() << ", offset: " << test_case.m_offset;
25715
25716         return stream.str();
25717 }
25718
25719 /** Get number of test cases
25720  *
25721  * @return Number of test cases
25722  **/
25723 GLuint XFBInvalidOffsetAlignmentTest::getTestCaseNumber()
25724 {
25725         return static_cast<GLuint>(m_test_cases.size());
25726 }
25727
25728 /** Selects if "compute" stage is relevant for test
25729  *
25730  * @param ignored
25731  *
25732  * @return false
25733  **/
25734 bool XFBInvalidOffsetAlignmentTest::isComputeRelevant(GLuint /* test_case_index */)
25735 {
25736         return false;
25737 }
25738
25739 /** Prepare all test cases
25740  *
25741  **/
25742 void XFBInvalidOffsetAlignmentTest::testInit()
25743 {
25744         const GLuint n_types = getTypesNumber();
25745
25746         for (GLuint i = 0; i < n_types; ++i)
25747         {
25748                 const Utils::Type& type                   = getType(i);
25749                 const GLuint       base_alingment = Utils::Type::GetTypeSize(type.m_basic_type);
25750
25751                 for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
25752                 {
25753                         if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::TESS_CTRL == stage) ||
25754                                 (Utils::Shader::FRAGMENT == stage))
25755                         {
25756                                 continue;
25757                         }
25758
25759                         for (GLuint offset = base_alingment + 1; offset < 2 * base_alingment; ++offset)
25760                         {
25761                                 testCase test_case = { offset, (Utils::Shader::STAGES)stage, type };
25762
25763                                 m_test_cases.push_back(test_case);
25764                         }
25765                 }
25766         }
25767 }
25768
25769 /** Constructor
25770  *
25771  * @param context Test context
25772  **/
25773 XFBCaptureInactiveOutputVariableTest::XFBCaptureInactiveOutputVariableTest(deqp::Context& context)
25774         : BufferTestBase(context, "xfb_capture_inactive_output_variable",
25775                                          "Test verifies that inactive variables are captured")
25776 {
25777         /* Nothing to be done here */
25778 }
25779
25780 /** Execute drawArrays for single vertex
25781  *
25782  * @param test_case_index
25783  *
25784  * @return true
25785  **/
25786 bool XFBCaptureInactiveOutputVariableTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
25787 {
25788         const Functions& gl                             = m_context.getRenderContext().getFunctions();
25789         GLenum                   primitive_type = GL_PATCHES;
25790
25791         if (TEST_VS == test_case_index)
25792         {
25793                 primitive_type = GL_POINTS;
25794         }
25795
25796         gl.disable(GL_RASTERIZER_DISCARD);
25797         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
25798
25799         gl.beginTransformFeedback(GL_POINTS);
25800         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
25801
25802         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
25803         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
25804
25805         gl.endTransformFeedback();
25806         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
25807
25808         return true;
25809 }
25810
25811 /** Get descriptors of buffers necessary for test
25812  *
25813  * @param ignored
25814  * @param out_descriptors Descriptors of buffers used by test
25815  **/
25816 void XFBCaptureInactiveOutputVariableTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
25817                                                                                                                                 bufferDescriptor::Vector& out_descriptors)
25818 {
25819         const Utils::Type& type = Utils::Type::vec4;
25820
25821         /* Test needs single uniform and xfb */
25822         out_descriptors.resize(2);
25823
25824         /* Get references */
25825         bufferDescriptor& uniform = out_descriptors[0];
25826         bufferDescriptor& xfb    = out_descriptors[1];
25827
25828         /* Index */
25829         uniform.m_index = 0;
25830         xfb.m_index             = 0;
25831
25832         /* Target */
25833         uniform.m_target = Utils::Buffer::Uniform;
25834         xfb.m_target     = Utils::Buffer::Transform_feedback;
25835
25836         /* Data */
25837         const std::vector<GLubyte>& gohan_data = type.GenerateData();
25838         const std::vector<GLubyte>& goten_data = type.GenerateData();
25839
25840         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
25841
25842         /* Uniform data */
25843         uniform.m_initial_data.resize(2 * type_size);
25844         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
25845         memcpy(&uniform.m_initial_data[0] + type_size, &goten_data[0], type_size);
25846
25847         /* XFB data */
25848         xfb.m_initial_data.resize(3 * type_size);
25849         xfb.m_expected_data.resize(3 * type_size);
25850
25851         for (GLuint i = 0; i < 3 * type_size; ++i)
25852         {
25853                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
25854                 xfb.m_expected_data[i] = (glw::GLubyte)i;
25855         }
25856
25857         memcpy(&xfb.m_expected_data[0] + 2 * type_size, &gohan_data[0], type_size);
25858         memcpy(&xfb.m_expected_data[0] + 0 * type_size, &goten_data[0], type_size);
25859 }
25860
25861 /** Get body of main function for given shader stage
25862  *
25863  * @param test_case_index  Index of test case
25864  * @param stage            Shader stage
25865  * @param out_assignments  Set to empty
25866  * @param out_calculations Set to empty
25867  **/
25868 void XFBCaptureInactiveOutputVariableTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
25869                                                                                                                  std::string& out_assignments, std::string& out_calculations)
25870 {
25871         out_calculations = "";
25872
25873         static const GLchar* vs_tes_gs = "    goten = uni_goten;\n"
25874                                                                          "    gohan = uni_gohan;\n";
25875         static const GLchar* fs = "    fs_out = goku + gohan + goten;\n";
25876
25877         const GLchar* assignments = "";
25878
25879         switch (stage)
25880         {
25881         case Utils::Shader::FRAGMENT:
25882                 assignments = fs;
25883                 break;
25884
25885         case Utils::Shader::GEOMETRY:
25886                 if (TEST_GS == test_case_index)
25887                 {
25888                         assignments = vs_tes_gs;
25889                 }
25890                 break;
25891
25892         case Utils::Shader::TESS_CTRL:
25893                 break;
25894
25895         case Utils::Shader::TESS_EVAL:
25896                 if (TEST_TES == test_case_index)
25897                 {
25898                         assignments = vs_tes_gs;
25899                 }
25900                 break;
25901
25902         case Utils::Shader::VERTEX:
25903                 if (TEST_VS == test_case_index)
25904                 {
25905                         assignments = vs_tes_gs;
25906                 }
25907                 break;
25908
25909         default:
25910                 TCU_FAIL("Invalid enum");
25911         }
25912
25913         out_assignments = assignments;
25914 }
25915
25916 /** Get interface of shader
25917  *
25918  * @param test_case_index  Index of test case
25919  * @param stage            Shader stage
25920  * @param out_interface    Set to ""
25921  **/
25922 void XFBCaptureInactiveOutputVariableTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
25923                                                                                                                           std::string& out_interface)
25924 {
25925         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
25926                                                                          "\n"
25927                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goku;\n"
25928                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 gohan;\n"
25929                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 goten;\n"
25930                                                                          "\n"
25931                                                                          "layout(binding = 0) uniform block {\n"
25932                                                                          "    vec4 uni_gohan;\n"
25933                                                                          "    vec4 uni_goten;\n"
25934                                                                          "};\n";
25935         static const GLchar* fs = "in vec4 goku;\n"
25936                                                           "in vec4 gohan;\n"
25937                                                           "in vec4 goten;\n"
25938                                                           "out vec4 fs_out;\n";
25939
25940         const GLchar* interface = "";
25941
25942         switch (stage)
25943         {
25944         case Utils::Shader::FRAGMENT:
25945                 interface = fs;
25946                 break;
25947
25948         case Utils::Shader::GEOMETRY:
25949                 if (TEST_GS == test_case_index)
25950                 {
25951                         interface = vs_tes_gs;
25952                 }
25953                 break;
25954
25955         case Utils::Shader::TESS_CTRL:
25956                 break;
25957
25958         case Utils::Shader::TESS_EVAL:
25959                 if (TEST_TES == test_case_index)
25960                 {
25961                         interface = vs_tes_gs;
25962                 }
25963                 break;
25964
25965         case Utils::Shader::VERTEX:
25966                 if (TEST_VS == test_case_index)
25967                 {
25968                         interface = vs_tes_gs;
25969                 }
25970                 break;
25971
25972         default:
25973                 TCU_FAIL("Invalid enum");
25974         }
25975
25976         out_interface = interface;
25977 }
25978
25979 /** Get source code of shader
25980  *
25981  * @param test_case_index Index of test case
25982  * @param stage           Shader stage
25983  *
25984  * @return Source
25985  **/
25986 std::string XFBCaptureInactiveOutputVariableTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
25987 {
25988         std::string source;
25989
25990         switch (test_case_index)
25991         {
25992         case TEST_VS:
25993                 switch (stage)
25994                 {
25995                 case Utils::Shader::FRAGMENT:
25996                 case Utils::Shader::VERTEX:
25997                         source = BufferTestBase::getShaderSource(test_case_index, stage);
25998                         break;
25999                 default:
26000                         break;
26001                 }
26002                 break;
26003
26004         case TEST_TES:
26005                 switch (stage)
26006                 {
26007                 case Utils::Shader::FRAGMENT:
26008                 case Utils::Shader::TESS_CTRL:
26009                 case Utils::Shader::TESS_EVAL:
26010                 case Utils::Shader::VERTEX:
26011                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26012                         break;
26013                 default:
26014                         break;
26015                 }
26016                 break;
26017
26018         case TEST_GS:
26019                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26020                 break;
26021
26022         default:
26023                 TCU_FAIL("Invalid enum");
26024                 break;
26025         }
26026
26027         /* */
26028         return source;
26029 }
26030
26031 /** Get name of test case
26032  *
26033  * @param test_case_index Index of test case
26034  *
26035  * @return Name of tested stage
26036  **/
26037 std::string XFBCaptureInactiveOutputVariableTest::getTestCaseName(glw::GLuint test_case_index)
26038 {
26039         const GLchar* name = 0;
26040
26041         switch (test_case_index)
26042         {
26043         case TEST_VS:
26044                 name = "vertex";
26045                 break;
26046         case TEST_TES:
26047                 name = "tessellation evaluation";
26048                 break;
26049         case TEST_GS:
26050                 name = "geometry";
26051                 break;
26052         default:
26053                 TCU_FAIL("Invalid enum");
26054         }
26055
26056         return name;
26057 }
26058
26059 /** Returns number of test cases
26060  *
26061  * @return TEST_MAX
26062  **/
26063 glw::GLuint XFBCaptureInactiveOutputVariableTest::getTestCaseNumber()
26064 {
26065         return TEST_MAX;
26066 }
26067
26068 /** Inspects program to check if all resources are as expected
26069  *
26070  * @param ignored
26071  * @param program         Program instance
26072  * @param out_stream      Error message
26073  *
26074  * @return true if everything is ok, false otherwise
26075  **/
26076 bool XFBCaptureInactiveOutputVariableTest::inspectProgram(GLuint /* test_case_index */, Utils::Program& program,
26077                                                                                                                   std::stringstream& out_stream)
26078 {
26079         GLint                      stride       = 0;
26080         const Utils::Type& type          = Utils::Type::vec4;
26081         const GLuint       type_size = type.GetSize();
26082
26083         program.GetResource(GL_TRANSFORM_FEEDBACK_BUFFER, 0 /* index */, GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE,
26084                                                 1 /* buf_size */, &stride);
26085
26086         if ((GLint)(3 * type_size) != stride)
26087         {
26088                 out_stream << "Stride is: " << stride << " expected: " << (3 * type_size);
26089
26090                 return false;
26091         }
26092
26093         return true;
26094 }
26095
26096 /** Verify contents of buffers
26097  *
26098  * @param buffers Collection of buffers to be verified
26099  *
26100  * @return true if everything is as expected, false otherwise
26101  **/
26102 bool XFBCaptureInactiveOutputVariableTest::verifyBuffers(bufferCollection& buffers)
26103 {
26104         bool result = true;
26105
26106         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26107         Utils::Buffer*                  buffer   = pair.m_buffer;
26108         bufferDescriptor*               descriptor = pair.m_descriptor;
26109
26110         /* Get pointer to contents of buffer */
26111         buffer->Bind();
26112         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26113
26114         /* Get pointer to expected data */
26115         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26116
26117         /* Compare */
26118         static const GLuint vec4_size = 16;
26119
26120         int res_gohan = memcmp(buffer_data + 2 * vec4_size, expected_data + 2 * vec4_size, vec4_size);
26121         int res_goten = memcmp(buffer_data + 0 * vec4_size, expected_data + 0 * vec4_size, vec4_size);
26122
26123         if ((0 != res_gohan) || (0 != res_goten))
26124         {
26125                 m_context.getTestContext().getLog()
26126                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26127                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26128
26129                 result = false;
26130         }
26131
26132         /* Release buffer mapping */
26133         buffer->UnMap();
26134
26135         return result;
26136 }
26137
26138 /** Constructor
26139  *
26140  * @param context Test context
26141  **/
26142 XFBCaptureInactiveOutputComponentTest::XFBCaptureInactiveOutputComponentTest(deqp::Context& context)
26143         : BufferTestBase(context, "xfb_capture_inactive_output_component",
26144                                          "Test verifies that inactive components are not modified")
26145 {
26146         /* Nothing to be done here */
26147 }
26148
26149 /** Execute drawArrays for single vertex
26150  *
26151  * @param test_case_index
26152  *
26153  * @return true
26154  **/
26155 bool XFBCaptureInactiveOutputComponentTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26156 {
26157         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26158         GLenum                   primitive_type = GL_PATCHES;
26159
26160         if (TEST_VS == test_case_index)
26161         {
26162                 primitive_type = GL_POINTS;
26163         }
26164
26165         gl.disable(GL_RASTERIZER_DISCARD);
26166         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26167
26168         gl.beginTransformFeedback(GL_POINTS);
26169         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26170
26171         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26172         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26173
26174         gl.endTransformFeedback();
26175         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26176
26177         return true;
26178 }
26179
26180 /** Get descriptors of buffers necessary for test
26181  *
26182  * @param ignored
26183  * @param out_descriptors Descriptors of buffers used by test
26184  **/
26185 void XFBCaptureInactiveOutputComponentTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26186                                                                                                                                  bufferDescriptor::Vector& out_descriptors)
26187 {
26188         const Utils::Type& type = Utils::Type::vec4;
26189
26190         /* Test needs single uniform and xfb */
26191         out_descriptors.resize(2);
26192
26193         /* Get references */
26194         bufferDescriptor& uniform = out_descriptors[0];
26195         bufferDescriptor& xfb    = out_descriptors[1];
26196
26197         /* Index */
26198         uniform.m_index = 0;
26199         xfb.m_index             = 0;
26200
26201         /* Target */
26202         uniform.m_target = Utils::Buffer::Uniform;
26203         xfb.m_target     = Utils::Buffer::Transform_feedback;
26204
26205         /* Data */
26206         const std::vector<GLubyte>& goku_data   = type.GenerateData();
26207         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26208         const std::vector<GLubyte>& goten_data  = type.GenerateData();
26209         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26210         const std::vector<GLubyte>& vegeta_data = type.GenerateData();
26211         const std::vector<GLubyte>& trunks_data = type.GenerateData();
26212         const std::vector<GLubyte>& bra_data    = type.GenerateData();
26213         const std::vector<GLubyte>& bulma_data  = type.GenerateData();
26214
26215         const GLuint comp_size = Utils::Type::GetTypeSize(type.m_basic_type);
26216         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26217
26218         /* Uniform data */
26219         uniform.m_initial_data.resize(8 * type_size);
26220         memcpy(&uniform.m_initial_data[0] + 0 * type_size, &goku_data[0], type_size);
26221         memcpy(&uniform.m_initial_data[0] + 1 * type_size, &gohan_data[0], type_size);
26222         memcpy(&uniform.m_initial_data[0] + 2 * type_size, &goten_data[0], type_size);
26223         memcpy(&uniform.m_initial_data[0] + 3 * type_size, &chichi_data[0], type_size);
26224         memcpy(&uniform.m_initial_data[0] + 4 * type_size, &vegeta_data[0], type_size);
26225         memcpy(&uniform.m_initial_data[0] + 5 * type_size, &trunks_data[0], type_size);
26226         memcpy(&uniform.m_initial_data[0] + 6 * type_size, &bra_data[0], type_size);
26227         memcpy(&uniform.m_initial_data[0] + 7 * type_size, &bulma_data[0], type_size);
26228
26229         /* XFB data */
26230         xfb.m_initial_data.resize(8 * type_size);
26231         xfb.m_expected_data.resize(8 * type_size);
26232
26233         for (GLuint i = 0; i < 8 * type_size; ++i)
26234         {
26235                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26236                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26237         }
26238
26239         /* goku - x, z - 32 */
26240         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 0 * comp_size, &goku_data[0] + 0 * comp_size, comp_size);
26241         memcpy(&xfb.m_expected_data[0] + 2 * type_size + 2 * comp_size, &goku_data[0] + 2 * comp_size, comp_size);
26242
26243         /* gohan - y, w - 0 */
26244         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 1 * comp_size, &gohan_data[0] + 1 * comp_size, comp_size);
26245         memcpy(&xfb.m_expected_data[0] + 0 * type_size + 3 * comp_size, &gohan_data[0] + 3 * comp_size, comp_size);
26246
26247         /* goten - x, y - 16 */
26248         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 0 * comp_size, &goten_data[0] + 0 * comp_size, comp_size);
26249         memcpy(&xfb.m_expected_data[0] + 1 * type_size + 1 * comp_size, &goten_data[0] + 1 * comp_size, comp_size);
26250
26251         /* chichi - z, w - 48 */
26252         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 2 * comp_size, &chichi_data[0] + 2 * comp_size, comp_size);
26253         memcpy(&xfb.m_expected_data[0] + 3 * type_size + 3 * comp_size, &chichi_data[0] + 3 * comp_size, comp_size);
26254
26255         /* vegeta - x - 112 */
26256         memcpy(&xfb.m_expected_data[0] + 7 * type_size + 0 * comp_size, &vegeta_data[0] + 0 * comp_size, comp_size);
26257
26258         /* trunks - y - 96 */
26259         memcpy(&xfb.m_expected_data[0] + 6 * type_size + 1 * comp_size, &trunks_data[0] + 1 * comp_size, comp_size);
26260
26261         /* bra - z - 80 */
26262         memcpy(&xfb.m_expected_data[0] + 5 * type_size + 2 * comp_size, &bra_data[0] + 2 * comp_size, comp_size);
26263
26264         /* bulma - w - 64 */
26265         memcpy(&xfb.m_expected_data[0] + 4 * type_size + 3 * comp_size, &bulma_data[0] + 3 * comp_size, comp_size);
26266 }
26267
26268 /** Get body of main function for given shader stage
26269  *
26270  * @param test_case_index  Index of test case
26271  * @param stage            Shader stage
26272  * @param out_assignments  Set to empty
26273  * @param out_calculations Set to empty
26274  **/
26275 void XFBCaptureInactiveOutputComponentTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26276                                                                                                                   std::string& out_assignments, std::string& out_calculations)
26277 {
26278         out_calculations = "";
26279
26280         static const GLchar* vs_tes_gs = "    goku.x    = uni_goku.x   ;\n"
26281                                                                          "    goku.z    = uni_goku.z   ;\n"
26282                                                                          "    gohan.y   = uni_gohan.y  ;\n"
26283                                                                          "    gohan.w   = uni_gohan.w  ;\n"
26284                                                                          "    goten.x   = uni_goten.x  ;\n"
26285                                                                          "    goten.y   = uni_goten.y  ;\n"
26286                                                                          "    chichi.z  = uni_chichi.z ;\n"
26287                                                                          "    chichi.w  = uni_chichi.w ;\n"
26288                                                                          "    vegeta.x  = uni_vegeta.x ;\n"
26289                                                                          "    trunks.y  = uni_trunks.y ;\n"
26290                                                                          "    bra.z     = uni_bra.z    ;\n"
26291                                                                          "    bulma.w   = uni_bulma.w  ;\n";
26292         static const GLchar* fs = "    fs_out = goku + gohan + goten + chichi + vegeta + trunks + bra + bulma;\n";
26293
26294         const GLchar* assignments = "";
26295
26296         switch (stage)
26297         {
26298         case Utils::Shader::FRAGMENT:
26299                 assignments = fs;
26300                 break;
26301
26302         case Utils::Shader::GEOMETRY:
26303                 if (TEST_GS == test_case_index)
26304                 {
26305                         assignments = vs_tes_gs;
26306                 }
26307                 break;
26308
26309         case Utils::Shader::TESS_CTRL:
26310                 break;
26311
26312         case Utils::Shader::TESS_EVAL:
26313                 if (TEST_TES == test_case_index)
26314                 {
26315                         assignments = vs_tes_gs;
26316                 }
26317                 break;
26318
26319         case Utils::Shader::VERTEX:
26320                 if (TEST_VS == test_case_index)
26321                 {
26322                         assignments = vs_tes_gs;
26323                 }
26324                 break;
26325
26326         default:
26327                 TCU_FAIL("Invalid enum");
26328         }
26329
26330         out_assignments = assignments;
26331 }
26332
26333 /** Get interface of shader
26334  *
26335  * @param test_case_index  Index of test case
26336  * @param stage            Shader stage
26337  * @param out_interface    Set to ""
26338  **/
26339 void XFBCaptureInactiveOutputComponentTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26340                                                                                                                            std::string& out_interface)
26341 {
26342         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26343                                                                          "\n"
26344                                                                          "layout (xfb_offset = 2 * sizeof_type) out vec4 goku;\n"
26345                                                                          "layout (xfb_offset = 0 * sizeof_type) out vec4 gohan;\n"
26346                                                                          "layout (xfb_offset = 1 * sizeof_type) out vec4 goten;\n"
26347                                                                          "layout (xfb_offset = 3 * sizeof_type) out vec4 chichi;\n"
26348                                                                          "layout (xfb_offset = 7 * sizeof_type) out vec4 vegeta;\n"
26349                                                                          "layout (xfb_offset = 6 * sizeof_type) out vec4 trunks;\n"
26350                                                                          "layout (xfb_offset = 5 * sizeof_type) out vec4 bra;\n"
26351                                                                          "layout (xfb_offset = 4 * sizeof_type) out vec4 bulma;\n"
26352                                                                          "\n"
26353                                                                          "layout(binding = 0) uniform block {\n"
26354                                                                          "    vec4 uni_goku;\n"
26355                                                                          "    vec4 uni_gohan;\n"
26356                                                                          "    vec4 uni_goten;\n"
26357                                                                          "    vec4 uni_chichi;\n"
26358                                                                          "    vec4 uni_vegeta;\n"
26359                                                                          "    vec4 uni_trunks;\n"
26360                                                                          "    vec4 uni_bra;\n"
26361                                                                          "    vec4 uni_bulma;\n"
26362                                                                          "};\n";
26363         static const GLchar* fs = "in vec4 vegeta;\n"
26364                                                           "in vec4 trunks;\n"
26365                                                           "in vec4 bra;\n"
26366                                                           "in vec4 bulma;\n"
26367                                                           "in vec4 goku;\n"
26368                                                           "in vec4 gohan;\n"
26369                                                           "in vec4 goten;\n"
26370                                                           "in vec4 chichi;\n"
26371                                                           "\n"
26372                                                           "out vec4 fs_out;\n";
26373
26374         const GLchar* interface = "";
26375
26376         switch (stage)
26377         {
26378         case Utils::Shader::FRAGMENT:
26379                 interface = fs;
26380                 break;
26381
26382         case Utils::Shader::GEOMETRY:
26383                 if (TEST_GS == test_case_index)
26384                 {
26385                         interface = vs_tes_gs;
26386                 }
26387                 break;
26388
26389         case Utils::Shader::TESS_CTRL:
26390                 break;
26391
26392         case Utils::Shader::TESS_EVAL:
26393                 if (TEST_TES == test_case_index)
26394                 {
26395                         interface = vs_tes_gs;
26396                 }
26397                 break;
26398
26399         case Utils::Shader::VERTEX:
26400                 if (TEST_VS == test_case_index)
26401                 {
26402                         interface = vs_tes_gs;
26403                 }
26404                 break;
26405
26406         default:
26407                 TCU_FAIL("Invalid enum");
26408         }
26409
26410         out_interface = interface;
26411 }
26412
26413 /** Get source code of shader
26414  *
26415  * @param test_case_index Index of test case
26416  * @param stage           Shader stage
26417  *
26418  * @return Source
26419  **/
26420 std::string XFBCaptureInactiveOutputComponentTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
26421 {
26422         std::string source;
26423
26424         switch (test_case_index)
26425         {
26426         case TEST_VS:
26427                 switch (stage)
26428                 {
26429                 case Utils::Shader::FRAGMENT:
26430                 case Utils::Shader::VERTEX:
26431                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26432                         break;
26433                 default:
26434                         break;
26435                 }
26436                 break;
26437
26438         case TEST_TES:
26439                 switch (stage)
26440                 {
26441                 case Utils::Shader::FRAGMENT:
26442                 case Utils::Shader::TESS_CTRL:
26443                 case Utils::Shader::TESS_EVAL:
26444                 case Utils::Shader::VERTEX:
26445                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26446                         break;
26447                 default:
26448                         break;
26449                 }
26450                 break;
26451
26452         case TEST_GS:
26453                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26454                 break;
26455
26456         default:
26457                 TCU_FAIL("Invalid enum");
26458                 break;
26459         }
26460
26461         /* */
26462         return source;
26463 }
26464
26465 /** Get name of test case
26466  *
26467  * @param test_case_index Index of test case
26468  *
26469  * @return Name of tested stage
26470  **/
26471 std::string XFBCaptureInactiveOutputComponentTest::getTestCaseName(glw::GLuint test_case_index)
26472 {
26473         const GLchar* name = 0;
26474
26475         switch (test_case_index)
26476         {
26477         case TEST_VS:
26478                 name = "vertex";
26479                 break;
26480         case TEST_TES:
26481                 name = "tessellation evaluation";
26482                 break;
26483         case TEST_GS:
26484                 name = "geometry";
26485                 break;
26486         default:
26487                 TCU_FAIL("Invalid enum");
26488         }
26489
26490         return name;
26491 }
26492
26493 /** Returns number of test cases
26494  *
26495  * @return TEST_MAX
26496  **/
26497 glw::GLuint XFBCaptureInactiveOutputComponentTest::getTestCaseNumber()
26498 {
26499         return TEST_MAX;
26500 }
26501
26502 /** Verify contents of buffers
26503  *
26504  * @param buffers Collection of buffers to be verified
26505  *
26506  * @return true if everything is as expected, false otherwise
26507  **/
26508 bool XFBCaptureInactiveOutputComponentTest::verifyBuffers(bufferCollection& buffers)
26509 {
26510         bool result = true;
26511
26512         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26513         Utils::Buffer*                  buffer   = pair.m_buffer;
26514         bufferDescriptor*               descriptor = pair.m_descriptor;
26515
26516         /* Get pointer to contents of buffer */
26517         buffer->Bind();
26518         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26519
26520         /* Get pointer to expected data */
26521         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26522
26523         /* Compare */
26524         static const GLuint comp_size = 4;
26525         static const GLuint vec4_size = 16;
26526
26527         int res_goku_x =
26528                 memcmp(buffer_data + 2 * vec4_size + 0 * comp_size, expected_data + 2 * vec4_size + 0 * comp_size, comp_size);
26529         int res_goku_z =
26530                 memcmp(buffer_data + 2 * vec4_size + 2 * comp_size, expected_data + 2 * vec4_size + 2 * comp_size, comp_size);
26531
26532         int res_gohan_y =
26533                 memcmp(buffer_data + 0 * vec4_size + 1 * comp_size, expected_data + 0 * vec4_size + 1 * comp_size, comp_size);
26534         int res_gohan_w =
26535                 memcmp(buffer_data + 0 * vec4_size + 3 * comp_size, expected_data + 0 * vec4_size + 3 * comp_size, comp_size);
26536
26537         int res_goten_x =
26538                 memcmp(buffer_data + 1 * vec4_size + 0 * comp_size, expected_data + 1 * vec4_size + 0 * comp_size, comp_size);
26539         int res_goten_y =
26540                 memcmp(buffer_data + 1 * vec4_size + 1 * comp_size, expected_data + 1 * vec4_size + 1 * comp_size, comp_size);
26541
26542         int res_chichi_z =
26543                 memcmp(buffer_data + 3 * vec4_size + 2 * comp_size, expected_data + 3 * vec4_size + 2 * comp_size, comp_size);
26544         int res_chichi_w =
26545                 memcmp(buffer_data + 3 * vec4_size + 3 * comp_size, expected_data + 3 * vec4_size + 3 * comp_size, comp_size);
26546
26547         int res_vegeta_x =
26548                 memcmp(buffer_data + 7 * vec4_size + 0 * comp_size, expected_data + 7 * vec4_size + 0 * comp_size, comp_size);
26549
26550         int res_trunks_y =
26551                 memcmp(buffer_data + 6 * vec4_size + 1 * comp_size, expected_data + 6 * vec4_size + 1 * comp_size, comp_size);
26552
26553         int res_bra_z =
26554                 memcmp(buffer_data + 5 * vec4_size + 2 * comp_size, expected_data + 5 * vec4_size + 2 * comp_size, comp_size);
26555
26556         int res_bulma_w =
26557                 memcmp(buffer_data + 4 * vec4_size + 3 * comp_size, expected_data + 4 * vec4_size + 3 * comp_size, comp_size);
26558
26559         if ((0 != res_goku_x) || (0 != res_goku_z) || (0 != res_gohan_y) || (0 != res_gohan_w) || (0 != res_goten_x) ||
26560                 (0 != res_goten_y) || (0 != res_chichi_z) || (0 != res_chichi_w) || (0 != res_vegeta_x) ||
26561                 (0 != res_trunks_y) || (0 != res_bra_z) || (0 != res_bulma_w))
26562         {
26563                 m_context.getTestContext().getLog()
26564                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26565                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26566
26567                 result = false;
26568         }
26569
26570         /* Release buffer mapping */
26571         buffer->UnMap();
26572
26573         return result;
26574 }
26575
26576 /** Constructor
26577  *
26578  * @param context Test context
26579  **/
26580 XFBCaptureInactiveOutputBlockMemberTest::XFBCaptureInactiveOutputBlockMemberTest(deqp::Context& context)
26581         : BufferTestBase(context, "xfb_capture_inactive_output_block_member",
26582                                          "Test verifies that inactive block members are captured")
26583 {
26584         /* Nothing to be done here */
26585 }
26586
26587 /** Execute drawArrays for single vertex
26588  *
26589  * @param test_case_index
26590  *
26591  * @return true
26592  **/
26593 bool XFBCaptureInactiveOutputBlockMemberTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26594 {
26595         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26596         GLenum                   primitive_type = GL_PATCHES;
26597
26598         if (TEST_VS == test_case_index)
26599         {
26600                 primitive_type = GL_POINTS;
26601         }
26602
26603         gl.disable(GL_RASTERIZER_DISCARD);
26604         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26605
26606         gl.beginTransformFeedback(GL_POINTS);
26607         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26608
26609         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26610         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26611
26612         gl.endTransformFeedback();
26613         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26614
26615         return true;
26616 }
26617
26618 /** Get descriptors of buffers necessary for test
26619  *
26620  * @param ignored
26621  * @param out_descriptors Descriptors of buffers used by test
26622  **/
26623 void XFBCaptureInactiveOutputBlockMemberTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26624                                                                                                                                    bufferDescriptor::Vector& out_descriptors)
26625 {
26626         const Utils::Type& type = Utils::Type::vec4;
26627
26628         /* Test needs single uniform and xfb */
26629         out_descriptors.resize(2);
26630
26631         /* Get references */
26632         bufferDescriptor& uniform = out_descriptors[0];
26633         bufferDescriptor& xfb    = out_descriptors[1];
26634
26635         /* Index */
26636         uniform.m_index = 0;
26637         xfb.m_index             = 0;
26638
26639         /* Target */
26640         uniform.m_target = Utils::Buffer::Uniform;
26641         xfb.m_target     = Utils::Buffer::Transform_feedback;
26642
26643         /* Data */
26644         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26645         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26646
26647         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26648
26649         /* Uniform data */
26650         uniform.m_initial_data.resize(2 * type_size);
26651         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26652         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26653
26654         /* XFB data */
26655         xfb.m_initial_data.resize(4 * type_size);
26656         xfb.m_expected_data.resize(4 * type_size);
26657
26658         for (GLuint i = 0; i < 4 * type_size; ++i)
26659         {
26660                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
26661                 xfb.m_expected_data[i] = (glw::GLubyte)i;
26662         }
26663
26664         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
26665         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
26666 }
26667
26668 /** Get body of main function for given shader stage
26669  *
26670  * @param test_case_index  Index of test case
26671  * @param stage            Shader stage
26672  * @param out_assignments  Set to empty
26673  * @param out_calculations Set to empty
26674  **/
26675 void XFBCaptureInactiveOutputBlockMemberTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
26676                                                                                                                         std::string& out_assignments, std::string& out_calculations)
26677 {
26678         out_calculations = "";
26679
26680         static const GLchar* vs_tes_gs = "    chichi = uni_chichi;\n"
26681                                                                          "    gohan  = uni_gohan;\n";
26682         static const GLchar* fs = "    fs_out = goten + gohan + chichi;\n";
26683
26684         const GLchar* assignments = "";
26685
26686         switch (stage)
26687         {
26688         case Utils::Shader::FRAGMENT:
26689                 assignments = fs;
26690                 break;
26691
26692         case Utils::Shader::GEOMETRY:
26693                 if (TEST_GS == test_case_index)
26694                 {
26695                         assignments = vs_tes_gs;
26696                 }
26697                 break;
26698
26699         case Utils::Shader::TESS_CTRL:
26700                 break;
26701
26702         case Utils::Shader::TESS_EVAL:
26703                 if (TEST_TES == test_case_index)
26704                 {
26705                         assignments = vs_tes_gs;
26706                 }
26707                 break;
26708
26709         case Utils::Shader::VERTEX:
26710                 if (TEST_VS == test_case_index)
26711                 {
26712                         assignments = vs_tes_gs;
26713                 }
26714                 break;
26715
26716         default:
26717                 TCU_FAIL("Invalid enum");
26718         }
26719
26720         out_assignments = assignments;
26721 }
26722
26723 /** Get interface of shader
26724  *
26725  * @param test_case_index  Index of test case
26726  * @param stage            Shader stage
26727  * @param out_interface    Set to ""
26728  **/
26729 void XFBCaptureInactiveOutputBlockMemberTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
26730                                                                                                                                  std::string& out_interface)
26731 {
26732         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
26733                                                                          "\n"
26734                                                                          "layout (xfb_offset = 1 * sizeof_type) out Goku {\n"
26735                                                                          "    vec4 gohan;\n"
26736                                                                          "    vec4 goten;\n"
26737                                                                          "    vec4 chichi;\n"
26738                                                                          "};\n"
26739                                                                          "\n"
26740                                                                          "layout(binding = 0) uniform block {\n"
26741                                                                          "    vec4 uni_gohan;\n"
26742                                                                          "    vec4 uni_chichi;\n"
26743                                                                          "};\n";
26744         static const GLchar* fs = "in Goku {\n"
26745                                                           "    vec4 gohan;\n"
26746                                                           "    vec4 goten;\n"
26747                                                           "    vec4 chichi;\n"
26748                                                           "};\n"
26749                                                           "out vec4 fs_out;\n";
26750
26751         const GLchar* interface = "";
26752
26753         switch (stage)
26754         {
26755         case Utils::Shader::FRAGMENT:
26756                 interface = fs;
26757                 break;
26758
26759         case Utils::Shader::GEOMETRY:
26760                 if (TEST_GS == test_case_index)
26761                 {
26762                         interface = vs_tes_gs;
26763                 }
26764                 break;
26765
26766         case Utils::Shader::TESS_CTRL:
26767                 break;
26768
26769         case Utils::Shader::TESS_EVAL:
26770                 if (TEST_TES == test_case_index)
26771                 {
26772                         interface = vs_tes_gs;
26773                 }
26774                 break;
26775
26776         case Utils::Shader::VERTEX:
26777                 if (TEST_VS == test_case_index)
26778                 {
26779                         interface = vs_tes_gs;
26780                 }
26781                 break;
26782
26783         default:
26784                 TCU_FAIL("Invalid enum");
26785         }
26786
26787         out_interface = interface;
26788 }
26789
26790 /** Get source code of shader
26791  *
26792  * @param test_case_index Index of test case
26793  * @param stage           Shader stage
26794  *
26795  * @return Source
26796  **/
26797 std::string XFBCaptureInactiveOutputBlockMemberTest::getShaderSource(GLuint                                test_case_index,
26798                                                                                                                                          Utils::Shader::STAGES stage)
26799 {
26800         std::string source;
26801
26802         switch (test_case_index)
26803         {
26804         case TEST_VS:
26805                 switch (stage)
26806                 {
26807                 case Utils::Shader::FRAGMENT:
26808                 case Utils::Shader::VERTEX:
26809                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26810                         break;
26811                 default:
26812                         break;
26813                 }
26814                 break;
26815
26816         case TEST_TES:
26817                 switch (stage)
26818                 {
26819                 case Utils::Shader::FRAGMENT:
26820                 case Utils::Shader::TESS_CTRL:
26821                 case Utils::Shader::TESS_EVAL:
26822                 case Utils::Shader::VERTEX:
26823                         source = BufferTestBase::getShaderSource(test_case_index, stage);
26824                         break;
26825                 default:
26826                         break;
26827                 }
26828                 break;
26829
26830         case TEST_GS:
26831                 source = BufferTestBase::getShaderSource(test_case_index, stage);
26832                 break;
26833
26834         default:
26835                 TCU_FAIL("Invalid enum");
26836                 break;
26837         }
26838
26839         /* */
26840         return source;
26841 }
26842
26843 /** Get name of test case
26844  *
26845  * @param test_case_index Index of test case
26846  *
26847  * @return Name of tested stage
26848  **/
26849 std::string XFBCaptureInactiveOutputBlockMemberTest::getTestCaseName(glw::GLuint test_case_index)
26850 {
26851         const GLchar* name = 0;
26852
26853         switch (test_case_index)
26854         {
26855         case TEST_VS:
26856                 name = "vertex";
26857                 break;
26858         case TEST_TES:
26859                 name = "tessellation evaluation";
26860                 break;
26861         case TEST_GS:
26862                 name = "geometry";
26863                 break;
26864         default:
26865                 TCU_FAIL("Invalid enum");
26866         }
26867
26868         return name;
26869 }
26870
26871 /** Returns number of test cases
26872  *
26873  * @return TEST_MAX
26874  **/
26875 glw::GLuint XFBCaptureInactiveOutputBlockMemberTest::getTestCaseNumber()
26876 {
26877         return TEST_MAX;
26878 }
26879
26880 /** Verify contents of buffers
26881  *
26882  * @param buffers Collection of buffers to be verified
26883  *
26884  * @return true if everything is as expected, false otherwise
26885  **/
26886 bool XFBCaptureInactiveOutputBlockMemberTest::verifyBuffers(bufferCollection& buffers)
26887 {
26888         bool result = true;
26889
26890         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
26891         Utils::Buffer*                  buffer   = pair.m_buffer;
26892         bufferDescriptor*               descriptor = pair.m_descriptor;
26893
26894         /* Get pointer to contents of buffer */
26895         buffer->Bind();
26896         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
26897
26898         /* Get pointer to expected data */
26899         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
26900
26901         /* Compare */
26902         static const GLuint vec4_size = 16;
26903
26904         int res_before = memcmp(buffer_data, expected_data, vec4_size);
26905         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
26906         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
26907
26908         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
26909         {
26910                 m_context.getTestContext().getLog()
26911                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
26912                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
26913
26914                 result = false;
26915         }
26916
26917         /* Release buffer mapping */
26918         buffer->UnMap();
26919
26920         return result;
26921 }
26922
26923 /** Constructor
26924  *
26925  * @param context Test context
26926  **/
26927 XFBCaptureStructTest::XFBCaptureStructTest(deqp::Context& context)
26928         : BufferTestBase(context, "xfb_capture_struct", "Test verifies that inactive structure members are captured")
26929 {
26930         /* Nothing to be done here */
26931 }
26932
26933 /** Execute drawArrays for single vertex
26934  *
26935  * @param test_case_index
26936  *
26937  * @return true
26938  **/
26939 bool XFBCaptureStructTest::executeDrawCall(bool /* tesEnabled */, GLuint test_case_index)
26940 {
26941         const Functions& gl                             = m_context.getRenderContext().getFunctions();
26942         GLenum                   primitive_type = GL_PATCHES;
26943
26944         if (TEST_VS == test_case_index)
26945         {
26946                 primitive_type = GL_POINTS;
26947         }
26948
26949         gl.disable(GL_RASTERIZER_DISCARD);
26950         GLU_EXPECT_NO_ERROR(gl.getError(), "Disable");
26951
26952         gl.beginTransformFeedback(GL_POINTS);
26953         GLU_EXPECT_NO_ERROR(gl.getError(), "BeginTransformFeedback");
26954
26955         gl.drawArrays(primitive_type, 0 /* first */, 1 /* count */);
26956         GLU_EXPECT_NO_ERROR(gl.getError(), "DrawArrays");
26957
26958         gl.endTransformFeedback();
26959         GLU_EXPECT_NO_ERROR(gl.getError(), "EndTransformFeedback");
26960
26961         return true;
26962 }
26963
26964 /** Get descriptors of buffers necessary for test
26965  *
26966  * @param ignored
26967  * @param out_descriptors Descriptors of buffers used by test
26968  **/
26969 void XFBCaptureStructTest::getBufferDescriptors(glw::GLuint /* test_case_index */,
26970                                                                                                 bufferDescriptor::Vector& out_descriptors)
26971 {
26972         const Utils::Type& type = Utils::Type::vec4;
26973
26974         /* Test needs single uniform and xfb */
26975         out_descriptors.resize(2);
26976
26977         /* Get references */
26978         bufferDescriptor& uniform = out_descriptors[0];
26979         bufferDescriptor& xfb    = out_descriptors[1];
26980
26981         /* Index */
26982         uniform.m_index = 0;
26983         xfb.m_index             = 0;
26984
26985         /* Target */
26986         uniform.m_target = Utils::Buffer::Uniform;
26987         xfb.m_target     = Utils::Buffer::Transform_feedback;
26988
26989         /* Data */
26990         const std::vector<GLubyte>& gohan_data  = type.GenerateData();
26991         const std::vector<GLubyte>& chichi_data = type.GenerateData();
26992
26993         const GLuint type_size = static_cast<GLuint>(gohan_data.size());
26994
26995         /* Uniform data */
26996         uniform.m_initial_data.resize(2 * type_size);
26997         memcpy(&uniform.m_initial_data[0] + 0, &gohan_data[0], type_size);
26998         memcpy(&uniform.m_initial_data[0] + type_size, &chichi_data[0], type_size);
26999
27000         /* XFB data */
27001         xfb.m_initial_data.resize(4 * type_size);
27002         xfb.m_expected_data.resize(4 * type_size);
27003
27004         for (GLuint i = 0; i < 4 * type_size; ++i)
27005         {
27006                 xfb.m_initial_data[i]  = (glw::GLubyte)i;
27007                 xfb.m_expected_data[i] = (glw::GLubyte)i;
27008         }
27009
27010         memcpy(&xfb.m_expected_data[0] + 1 * type_size, &gohan_data[0], type_size);
27011         memcpy(&xfb.m_expected_data[0] + 3 * type_size, &chichi_data[0], type_size);
27012 }
27013
27014 /** Get body of main function for given shader stage
27015  *
27016  * @param test_case_index  Index of test case
27017  * @param stage            Shader stage
27018  * @param out_assignments  Set to empty
27019  * @param out_calculations Set to empty
27020  **/
27021 void XFBCaptureStructTest::getShaderBody(GLuint test_case_index, Utils::Shader::STAGES stage,
27022                                                                                  std::string& out_assignments, std::string& out_calculations)
27023 {
27024         out_calculations = "";
27025
27026         static const GLchar* vs_tes_gs = "    goku.chichi = uni_chichi;\n"
27027                                                                          "    goku.gohan  = uni_gohan;\n";
27028         static const GLchar* fs = "    fs_out = goku.goten + goku.gohan + goku.chichi;\n";
27029
27030         const GLchar* assignments = "";
27031
27032         switch (stage)
27033         {
27034         case Utils::Shader::FRAGMENT:
27035                 assignments = fs;
27036                 break;
27037
27038         case Utils::Shader::GEOMETRY:
27039                 if (TEST_GS == test_case_index)
27040                 {
27041                         assignments = vs_tes_gs;
27042                 }
27043                 break;
27044
27045         case Utils::Shader::TESS_CTRL:
27046                 break;
27047
27048         case Utils::Shader::TESS_EVAL:
27049                 if (TEST_TES == test_case_index)
27050                 {
27051                         assignments = vs_tes_gs;
27052                 }
27053                 break;
27054
27055         case Utils::Shader::VERTEX:
27056                 if (TEST_VS == test_case_index)
27057                 {
27058                         assignments = vs_tes_gs;
27059                 }
27060                 break;
27061
27062         default:
27063                 TCU_FAIL("Invalid enum");
27064         }
27065
27066         out_assignments = assignments;
27067 }
27068
27069 /** Get interface of shader
27070  *
27071  * @param test_case_index  Index of test case
27072  * @param stage            Shader stage
27073  * @param out_interface    Set to ""
27074  **/
27075 void XFBCaptureStructTest::getShaderInterface(GLuint test_case_index, Utils::Shader::STAGES stage,
27076                                                                                           std::string& out_interface)
27077 {
27078         static const GLchar* vs_tes_gs = "const uint sizeof_type = 16;\n"
27079                                                                          "\n"
27080                                                                          "struct Goku {\n"
27081                                                                          "    vec4 gohan;\n"
27082                                                                          "    vec4 goten;\n"
27083                                                                          "    vec4 chichi;\n"
27084                                                                          "};\n"
27085                                                                          "\n"
27086                                                                          "layout (xfb_offset = sizeof_type) out Goku goku;\n"
27087                                                                          "\n"
27088                                                                          "layout(binding = 0, std140) uniform block {\n"
27089                                                                          "    vec4 uni_gohan;\n"
27090                                                                          "    vec4 uni_chichi;\n"
27091                                                                          "};\n";
27092         static const GLchar* fs = "struct Goku {\n"
27093                                                           "    vec4 gohan;\n"
27094                                                           "    vec4 goten;\n"
27095                                                           "    vec4 chichi;\n"
27096                                                           "};\n"
27097                                                           "\n"
27098                                                           "in Goku goku;\n"
27099                                                           "\n"
27100                                                           "out vec4 fs_out;\n";
27101
27102         const GLchar* interface = "";
27103
27104         switch (stage)
27105         {
27106         case Utils::Shader::FRAGMENT:
27107                 interface = fs;
27108                 break;
27109
27110         case Utils::Shader::GEOMETRY:
27111                 if (TEST_GS == test_case_index)
27112                 {
27113                         interface = vs_tes_gs;
27114                 }
27115                 break;
27116
27117         case Utils::Shader::TESS_CTRL:
27118                 break;
27119
27120         case Utils::Shader::TESS_EVAL:
27121                 if (TEST_TES == test_case_index)
27122                 {
27123                         interface = vs_tes_gs;
27124                 }
27125                 break;
27126
27127         case Utils::Shader::VERTEX:
27128                 if (TEST_VS == test_case_index)
27129                 {
27130                         interface = vs_tes_gs;
27131                 }
27132                 break;
27133
27134         default:
27135                 TCU_FAIL("Invalid enum");
27136         }
27137
27138         out_interface = interface;
27139 }
27140
27141 /** Get source code of shader
27142  *
27143  * @param test_case_index Index of test case
27144  * @param stage           Shader stage
27145  *
27146  * @return Source
27147  **/
27148 std::string XFBCaptureStructTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27149 {
27150         std::string source;
27151
27152         switch (test_case_index)
27153         {
27154         case TEST_VS:
27155                 switch (stage)
27156                 {
27157                 case Utils::Shader::FRAGMENT:
27158                 case Utils::Shader::VERTEX:
27159                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27160                         break;
27161                 default:
27162                         break;
27163                 }
27164                 break;
27165
27166         case TEST_TES:
27167                 switch (stage)
27168                 {
27169                 case Utils::Shader::FRAGMENT:
27170                 case Utils::Shader::TESS_CTRL:
27171                 case Utils::Shader::TESS_EVAL:
27172                 case Utils::Shader::VERTEX:
27173                         source = BufferTestBase::getShaderSource(test_case_index, stage);
27174                         break;
27175                 default:
27176                         break;
27177                 }
27178                 break;
27179
27180         case TEST_GS:
27181                 source = BufferTestBase::getShaderSource(test_case_index, stage);
27182                 break;
27183
27184         default:
27185                 TCU_FAIL("Invalid enum");
27186                 break;
27187         }
27188
27189         /* */
27190         return source;
27191 }
27192
27193 /** Get name of test case
27194  *
27195  * @param test_case_index Index of test case
27196  *
27197  * @return Name of tested stage
27198  **/
27199 std::string XFBCaptureStructTest::getTestCaseName(glw::GLuint test_case_index)
27200 {
27201         const GLchar* name = 0;
27202
27203         switch (test_case_index)
27204         {
27205         case TEST_VS:
27206                 name = "vertex";
27207                 break;
27208         case TEST_TES:
27209                 name = "tessellation evaluation";
27210                 break;
27211         case TEST_GS:
27212                 name = "geometry";
27213                 break;
27214         default:
27215                 TCU_FAIL("Invalid enum");
27216         }
27217
27218         return name;
27219 }
27220
27221 /** Returns number of test cases
27222  *
27223  * @return TEST_MAX
27224  **/
27225 glw::GLuint XFBCaptureStructTest::getTestCaseNumber()
27226 {
27227         return TEST_MAX;
27228 }
27229
27230 /** Verify contents of buffers
27231  *
27232  * @param buffers Collection of buffers to be verified
27233  *
27234  * @return true if everything is as expected, false otherwise
27235  **/
27236 bool XFBCaptureStructTest::verifyBuffers(bufferCollection& buffers)
27237 {
27238         bool result = true;
27239
27240         bufferCollection::pair& pair       = buffers.m_vector[1] /* xfb */;
27241         Utils::Buffer*                  buffer   = pair.m_buffer;
27242         bufferDescriptor*               descriptor = pair.m_descriptor;
27243
27244         /* Get pointer to contents of buffer */
27245         buffer->Bind();
27246         GLubyte* buffer_data = (GLubyte*)buffer->Map(Utils::Buffer::ReadOnly);
27247
27248         /* Get pointer to expected data */
27249         GLubyte* expected_data = (GLubyte*)&descriptor->m_expected_data[0];
27250
27251         /* Compare */
27252         static const GLuint vec4_size = 16;
27253
27254         int res_before = memcmp(buffer_data, expected_data, vec4_size);
27255         int res_gohan  = memcmp(buffer_data + 1 * vec4_size, expected_data + 1 * vec4_size, vec4_size);
27256         int res_chichi = memcmp(buffer_data + 3 * vec4_size, expected_data + 3 * vec4_size, vec4_size);
27257
27258         if ((0 != res_before) || (0 != res_gohan) || (0 != res_chichi))
27259         {
27260                 m_context.getTestContext().getLog()
27261                         << tcu::TestLog::Message << "Invalid result. Buffer: " << Utils::Buffer::GetBufferName(descriptor->m_target)
27262                         << ". Index: " << descriptor->m_index << tcu::TestLog::EndMessage;
27263
27264                 result = false;
27265         }
27266
27267         /* Release buffer mapping */
27268         buffer->UnMap();
27269
27270         return result;
27271 }
27272
27273 /** Constructor
27274  *
27275  * @param context Test framework context
27276  **/
27277 XFBCaptureUnsizedArrayTest::XFBCaptureUnsizedArrayTest(deqp::Context& context)
27278         : NegativeTestBase(context, "xfb_capture_unsized_array",
27279                                            "Test verifies that compiler reports error when unsized array is qualified with xfb_offset")
27280 {
27281 }
27282
27283 /** Source for given test case and stage
27284  *
27285  * @param test_case_index Index of test case
27286  * @param stage           Shader stage
27287  *
27288  * @return Shader source
27289  **/
27290 std::string XFBCaptureUnsizedArrayTest::getShaderSource(GLuint test_case_index, Utils::Shader::STAGES stage)
27291 {
27292         static const GLchar* var_definition = "layout (xfb_offset = 0) out vec4 gokuARRAY[];\n";
27293         static const GLchar* var_use            = "    gokuINDEX[0] = result / 2;\n";
27294         static const GLchar* fs                         = "#version 430 core\n"
27295                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27296                                                           "\n"
27297                                                           "in  vec4 gs_fs;\n"
27298                                                           "out vec4 fs_out;\n"
27299                                                           "\n"
27300                                                           "void main()\n"
27301                                                           "{\n"
27302                                                           "    fs_out = gs_fs;\n"
27303                                                           "}\n"
27304                                                           "\n";
27305         static const GLchar* gs_tested = "#version 430 core\n"
27306                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27307                                                                          "\n"
27308                                                                          "layout(points)                           in;\n"
27309                                                                          "layout(triangle_strip, max_vertices = 4) out;\n"
27310                                                                          "\n"
27311                                                                          "VAR_DEFINITION"
27312                                                                          "\n"
27313                                                                          "in  vec4 tes_gs[];\n"
27314                                                                          "out vec4 gs_fs;\n"
27315                                                                          "\n"
27316                                                                          "void main()\n"
27317                                                                          "{\n"
27318                                                                          "    vec4 result = tes_gs[0];\n"
27319                                                                          "\n"
27320                                                                          "VARIABLE_USE"
27321                                                                          "\n"
27322                                                                          "    gs_fs = result;\n"
27323                                                                          "    gl_Position  = vec4(-1, -1, 0, 1);\n"
27324                                                                          "    EmitVertex();\n"
27325                                                                          "    gs_fs = result;\n"
27326                                                                          "    gl_Position  = vec4(-1, 1, 0, 1);\n"
27327                                                                          "    EmitVertex();\n"
27328                                                                          "    gs_fs = result;\n"
27329                                                                          "    gl_Position  = vec4(1, -1, 0, 1);\n"
27330                                                                          "    EmitVertex();\n"
27331                                                                          "    gs_fs = result;\n"
27332                                                                          "    gl_Position  = vec4(1, 1, 0, 1);\n"
27333                                                                          "    EmitVertex();\n"
27334                                                                          "}\n"
27335                                                                          "\n";
27336         static const GLchar* tcs = "#version 430 core\n"
27337                                                            "#extension GL_ARB_enhanced_layouts : require\n"
27338                                                            "\n"
27339                                                            "layout(vertices = 1) out;\n"
27340                                                            "\n"
27341                                                            "in  vec4 vs_tcs[];\n"
27342                                                            "out vec4 tcs_tes[];\n"
27343                                                            "\n"
27344                                                            "void main()\n"
27345                                                            "{\n"
27346                                                            "\n"
27347                                                            "    tcs_tes[gl_InvocationID] = vs_tcs[gl_InvocationID];\n"
27348                                                            "\n"
27349                                                            "    gl_TessLevelOuter[0] = 1.0;\n"
27350                                                            "    gl_TessLevelOuter[1] = 1.0;\n"
27351                                                            "    gl_TessLevelOuter[2] = 1.0;\n"
27352                                                            "    gl_TessLevelOuter[3] = 1.0;\n"
27353                                                            "    gl_TessLevelInner[0] = 1.0;\n"
27354                                                            "    gl_TessLevelInner[1] = 1.0;\n"
27355                                                            "}\n"
27356                                                            "\n";
27357         static const GLchar* tcs_tested = "#version 430 core\n"
27358                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27359                                                                           "\n"
27360                                                                           "layout(vertices = 1) out;\n"
27361                                                                           "\n"
27362                                                                           "VAR_DEFINITION"
27363                                                                           "\n"
27364                                                                           "in  vec4 vs_tcs[];\n"
27365                                                                           "out vec4 tcs_tes[];\n"
27366                                                                           "\n"
27367                                                                           "void main()\n"
27368                                                                           "{\n"
27369                                                                           "    vec4 result = vs_tcs[gl_InvocationID];\n"
27370                                                                           "\n"
27371                                                                           "VARIABLE_USE"
27372                                                                           "\n"
27373                                                                           "    tcs_tes[gl_InvocationID] = result;\n"
27374                                                                           "\n"
27375                                                                           "    gl_TessLevelOuter[0] = 1.0;\n"
27376                                                                           "    gl_TessLevelOuter[1] = 1.0;\n"
27377                                                                           "    gl_TessLevelOuter[2] = 1.0;\n"
27378                                                                           "    gl_TessLevelOuter[3] = 1.0;\n"
27379                                                                           "    gl_TessLevelInner[0] = 1.0;\n"
27380                                                                           "    gl_TessLevelInner[1] = 1.0;\n"
27381                                                                           "}\n"
27382                                                                           "\n";
27383         static const GLchar* tes_tested = "#version 430 core\n"
27384                                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27385                                                                           "\n"
27386                                                                           "layout(isolines, point_mode) in;\n"
27387                                                                           "\n"
27388                                                                           "VAR_DEFINITION"
27389                                                                           "\n"
27390                                                                           "in  vec4 tcs_tes[];\n"
27391                                                                           "out vec4 tes_gs;\n"
27392                                                                           "\n"
27393                                                                           "void main()\n"
27394                                                                           "{\n"
27395                                                                           "    vec4 result = tcs_tes[0];\n"
27396                                                                           "\n"
27397                                                                           "VARIABLE_USE"
27398                                                                           "\n"
27399                                                                           "    tes_gs += result;\n"
27400                                                                           "}\n"
27401                                                                           "\n";
27402         static const GLchar* vs = "#version 430 core\n"
27403                                                           "#extension GL_ARB_enhanced_layouts : require\n"
27404                                                           "\n"
27405                                                           "in  vec4 in_vs;\n"
27406                                                           "out vec4 vs_tcs;\n"
27407                                                           "\n"
27408                                                           "void main()\n"
27409                                                           "{\n"
27410                                                           "    vs_tcs = in_vs;\n"
27411                                                           "}\n"
27412                                                           "\n";
27413         static const GLchar* vs_tested = "#version 430 core\n"
27414                                                                          "#extension GL_ARB_enhanced_layouts : require\n"
27415                                                                          "\n"
27416                                                                          "VAR_DEFINITION"
27417                                                                          "\n"
27418                                                                          "in  vec4 in_vs;\n"
27419                                                                          "out vec4 vs_tcs;\n"
27420                                                                          "\n"
27421                                                                          "void main()\n"
27422                                                                          "{\n"
27423                                                                          "    vec4 result = in_vs;\n"
27424                                                                          "\n"
27425                                                                          "VARIABLE_USE"
27426                                                                          "\n"
27427                                                                          "    vs_tcs = result;\n"
27428                                                                          "}\n"
27429                                                                          "\n";
27430
27431         std::string source;
27432         testCase&   test_case = m_test_cases[test_case_index];
27433
27434         if (test_case.m_stage == stage)
27435         {
27436                 const GLchar* array     = "";
27437                 const GLchar* index     = "";
27438                 size_t            position = 0;
27439
27440                 switch (stage)
27441                 {
27442                 case Utils::Shader::GEOMETRY:
27443                         source = gs_tested;
27444                         array  = "[]";
27445                         index  = "[0]";
27446                         break;
27447                 case Utils::Shader::TESS_CTRL:
27448                         source = tcs_tested;
27449                         array  = "[]";
27450                         index  = "[gl_InvocationID]";
27451                         break;
27452                 case Utils::Shader::TESS_EVAL:
27453                         source = tes_tested;
27454                         array  = "[]";
27455                         index  = "[0]";
27456                         break;
27457                 case Utils::Shader::VERTEX:
27458                         source = vs_tested;
27459                         break;
27460                 default:
27461                         TCU_FAIL("Invalid enum");
27462                 }
27463
27464                 Utils::replaceToken("VAR_DEFINITION", position, var_definition, source);
27465                 position = 0;
27466                 Utils::replaceToken("ARRAY", position, array, source);
27467                 Utils::replaceToken("VARIABLE_USE", position, var_use, source);
27468
27469                 Utils::replaceAllTokens("INDEX", index, source);
27470         }
27471         else
27472         {
27473                 switch (test_case.m_stage)
27474                 {
27475                 case Utils::Shader::GEOMETRY:
27476                         switch (stage)
27477                         {
27478                         case Utils::Shader::FRAGMENT:
27479                                 source = fs;
27480                                 break;
27481                         case Utils::Shader::VERTEX:
27482                                 source = vs;
27483                                 break;
27484                         default:
27485                                 source = "";
27486                         }
27487                         break;
27488                 case Utils::Shader::TESS_CTRL:
27489                         switch (stage)
27490                         {
27491                         case Utils::Shader::FRAGMENT:
27492                                 source = fs;
27493                                 break;
27494                         case Utils::Shader::VERTEX:
27495                                 source = vs;
27496                                 break;
27497                         default:
27498                                 source = "";
27499                         }
27500                         break;
27501                 case Utils::Shader::TESS_EVAL:
27502                         switch (stage)
27503                         {
27504                         case Utils::Shader::FRAGMENT:
27505                                 source = fs;
27506                                 break;
27507                         case Utils::Shader::TESS_CTRL:
27508                                 source = tcs;
27509                                 break;
27510                         case Utils::Shader::VERTEX:
27511                                 source = vs;
27512                                 break;
27513                         default:
27514                                 source = "";
27515                         }
27516                         break;
27517                 case Utils::Shader::VERTEX:
27518                         switch (stage)
27519                         {
27520                         case Utils::Shader::FRAGMENT:
27521                                 source = fs;
27522                                 break;
27523                         default:
27524                                 source = "";
27525                         }
27526                         break;
27527                 default:
27528                         TCU_FAIL("Invalid enum");
27529                         break;
27530                 }
27531         }
27532
27533         return source;
27534 }
27535
27536 /** Get description of test case
27537  *
27538  * @param test_case_index Index of test case
27539  *
27540  * @return Test case description
27541  **/
27542 std::string XFBCaptureUnsizedArrayTest::getTestCaseName(GLuint test_case_index)
27543 {
27544         std::stringstream stream;
27545         testCase&                 test_case = m_test_cases[test_case_index];
27546
27547         stream << "Stage: " << Utils::Shader::GetStageName(test_case.m_stage);
27548
27549         return stream.str();
27550 }
27551
27552 /** Get number of test cases
27553  *
27554  * @return Number of test cases
27555  **/
27556 GLuint XFBCaptureUnsizedArrayTest::getTestCaseNumber()
27557 {
27558         return static_cast<GLuint>(m_test_cases.size());
27559 }
27560
27561 /** Selects if "compute" stage is relevant for test
27562  *
27563  * @param ignored
27564  *
27565  * @return false
27566  **/
27567 bool XFBCaptureUnsizedArrayTest::isComputeRelevant(GLuint /* test_case_index */)
27568 {
27569         return false;
27570 }
27571
27572 /** Prepare all test cases
27573  *
27574  **/
27575 void XFBCaptureUnsizedArrayTest::testInit()
27576 {
27577         for (GLuint stage = 0; stage < Utils::Shader::STAGE_MAX; ++stage)
27578         {
27579                 /* Not aplicable for */
27580                 if ((Utils::Shader::COMPUTE == stage) || (Utils::Shader::FRAGMENT == stage) ||
27581                         (Utils::Shader::GEOMETRY == stage) || (Utils::Shader::TESS_EVAL == stage))
27582                 {
27583                         continue;
27584                 }
27585
27586                 testCase test_case = { (Utils::Shader::STAGES)stage };
27587
27588                 m_test_cases.push_back(test_case);
27589         }
27590 }
27591 } /* EnhancedLayouts namespace */
27592
27593 /** Constructor.
27594  *
27595  *  @param context Rendering context.
27596  **/
27597 EnhancedLayoutsTests::EnhancedLayoutsTests(deqp::Context& context)
27598         : TestCaseGroup(context, "enhanced_layouts", "Verifies \"enhanced layouts\" functionality")
27599 {
27600         /* Left blank on purpose */
27601 }
27602
27603 /** Initializes a texture_storage_multisample test group.
27604  *
27605  **/
27606 void EnhancedLayoutsTests::init(void)
27607 {
27608         addChild(new EnhancedLayouts::APIConstantValuesTest(m_context));
27609         addChild(new EnhancedLayouts::APIErrorsTest(m_context));
27610         addChild(new EnhancedLayouts::GLSLContantValuesTest(m_context));
27611         addChild(new EnhancedLayouts::GLSLContantImmutablityTest(m_context));
27612         addChild(new EnhancedLayouts::GLSLConstantIntegralExpressionTest(m_context));
27613         addChild(new EnhancedLayouts::UniformBlockLayoutQualifierConflictTest(m_context));
27614         addChild(new EnhancedLayouts::SSBMemberInvalidOffsetAlignmentTest(m_context));
27615         addChild(new EnhancedLayouts::SSBMemberOverlappingOffsetsTest(m_context));
27616         addChild(new EnhancedLayouts::VaryingExceedingComponentsTest(m_context));
27617         addChild(new EnhancedLayouts::VaryingComponentOfInvalidTypeTest(m_context));
27618         addChild(new EnhancedLayouts::OutputComponentAliasingTest(m_context));
27619         addChild(new EnhancedLayouts::VertexAttribLocationAPITest(m_context));
27620         addChild(new EnhancedLayouts::XFBInputTest(m_context));
27621         addChild(new EnhancedLayouts::XFBAllStagesTest(m_context));
27622         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputVariableTest(m_context));
27623         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputComponentTest(m_context));
27624         addChild(new EnhancedLayouts::XFBCaptureInactiveOutputBlockMemberTest(m_context));
27625         addChild(new EnhancedLayouts::XFBStrideTest(m_context));
27626
27627         addChild(new EnhancedLayouts::UniformBlockMemberOffsetAndAlignTest(m_context));
27628         addChild(new EnhancedLayouts::UniformBlockMemberInvalidOffsetAlignmentTest(m_context));
27629         addChild(new EnhancedLayouts::UniformBlockMemberOverlappingOffsetsTest(m_context));
27630         addChild(new EnhancedLayouts::UniformBlockMemberAlignNonPowerOf2Test(m_context));
27631         addChild(new EnhancedLayouts::SSBLayoutQualifierConflictTest(m_context));
27632         addChild(new EnhancedLayouts::SSBMemberAlignNonPowerOf2Test(m_context));
27633         addChild(new EnhancedLayouts::SSBAlignmentTest(m_context));
27634         addChild(new EnhancedLayouts::VaryingStructureMemberLocationTest(m_context));
27635         addChild(new EnhancedLayouts::VaryingBlockAutomaticMemberLocationsTest(m_context));
27636         addChild(new EnhancedLayouts::VaryingComponentWithoutLocationTest(m_context));
27637         addChild(new EnhancedLayouts::InputComponentAliasingTest(m_context));
27638         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedTypesTest(m_context));
27639         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedInterpolationTest(m_context));
27640         addChild(new EnhancedLayouts::VaryingLocationAliasingWithMixedAuxiliaryStorageTest(m_context));
27641         addChild(new EnhancedLayouts::XFBStrideOfEmptyListTest(m_context));
27642         addChild(new EnhancedLayouts::XFBStrideOfEmptyListAndAPITest(m_context));
27643         addChild(new EnhancedLayouts::XFBTooSmallStrideTest(m_context));
27644         addChild(new EnhancedLayouts::XFBBlockMemberStrideTest(m_context));
27645         addChild(new EnhancedLayouts::XFBDuplicatedStrideTest(m_context));
27646         addChild(new EnhancedLayouts::XFBGetProgramResourceAPITest(m_context));
27647         addChild(new EnhancedLayouts::XFBMultipleVertexStreamsTest(m_context));
27648         addChild(new EnhancedLayouts::XFBExceedBufferLimitTest(m_context));
27649         addChild(new EnhancedLayouts::XFBExceedOffsetLimitTest(m_context));
27650         addChild(new EnhancedLayouts::XFBBlockMemberBufferTest(m_context));
27651         addChild(new EnhancedLayouts::XFBOutputOverlappingTest(m_context));
27652         addChild(new EnhancedLayouts::XFBInvalidOffsetAlignmentTest(m_context));
27653         addChild(new EnhancedLayouts::XFBCaptureStructTest(m_context));
27654         addChild(new EnhancedLayouts::XFBCaptureUnsizedArrayTest(m_context));
27655         addChild(new EnhancedLayouts::UniformBlockAlignmentTest(m_context));
27656         addChild(new EnhancedLayouts::SSBMemberOffsetAndAlignTest(m_context));
27657         addChild(new EnhancedLayouts::VertexAttribLocationsTest(m_context));
27658         addChild(new EnhancedLayouts::VaryingLocationsTest(m_context));
27659         addChild(new EnhancedLayouts::VaryingArrayLocationsTest(m_context));
27660         addChild(new EnhancedLayouts::VaryingStructureLocationsTest(m_context));
27661         addChild(new EnhancedLayouts::VaryingBlockLocationsTest(m_context));
27662         addChild(new EnhancedLayouts::VaryingBlockMemberLocationsTest(m_context));
27663         addChild(new EnhancedLayouts::XFBVariableStrideTest(m_context));
27664         addChild(new EnhancedLayouts::XFBBlockStrideTest(m_context));
27665         addChild(new EnhancedLayouts::XFBOverrideQualifiersWithAPITest(m_context));
27666         addChild(new EnhancedLayouts::XFBVertexStreamsTest(m_context));
27667         addChild(new EnhancedLayouts::XFBGlobalBufferTest(m_context));
27668         addChild(new EnhancedLayouts::FragmentDataLocationAPITest(m_context));
27669         addChild(new EnhancedLayouts::VaryingLocationLimitTest(m_context));
27670         addChild(new EnhancedLayouts::VaryingComponentsTest(m_context));
27671         addChild(new EnhancedLayouts::VaryingArrayComponentsTest(m_context));
27672 }
27673
27674 } /* gl4cts namespace */